Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -96,16 +96,37 @@ export function ConfigureObjectsStep() {
[configHandlers],
);

const optionalFieldItems: CheckboxItem[] = useMemo(
() =>
optionalFields.map((field) => ({
id: getFieldName(field),
// Build the list of optional-field checkboxes shown on the Additional page.
// Merge explicit optionalFields (from amp.yaml) with auto-discovered customer
// fields (e.g. when amp.yaml uses `optionalFieldsAuto: all`). Explicit
// entries win on conflicts so the configured display name is preserved.
const optionalFieldItems: CheckboxItem[] = useMemo(() => {
const items: CheckboxItem[] = [];
const seen = new Set<string>();

optionalFields.forEach((field) => {
const fieldName = getFieldName(field);
if (!fieldName || seen.has(fieldName)) return;
seen.add(fieldName);
items.push({
id: fieldName,
label: getFieldDisplayName(field),
isChecked:
configHandlers?.getSelectedField(getFieldName(field)) ?? false,
})),
[optionalFields, configHandlers],
);
isChecked: configHandlers?.getSelectedField(fieldName) ?? false,
});
});

Object.entries(customerFields).forEach(([fieldName, meta]) => {
if (!fieldName || seen.has(fieldName)) return;
seen.add(fieldName);
items.push({
id: fieldName,
label: meta.displayName || fieldName,
isChecked: configHandlers?.getSelectedField(fieldName) ?? false,
});
});

return items;
}, [optionalFields, customerFields, configHandlers]);

// Check if all required mappings have been filled
const requiredMappingsComplete = useMemo(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,18 @@ export function getSubPages(manifest: Manifest, objectName: string): SubPage[] {
(obj.getOptionalMapFields()?.length ?? 0) > 0;
if (hasMappings) pages.push("mappings");

const hasOptionalFields =
// An object has optional fields to show on the "additional" page if it has
// an explicit optionalFields list OR if it has auto-discovered customer
// fields (e.g. from `optionalFieldsAuto: all` in amp.yaml). The latter
// surface via manifest.getCustomerFieldsForObject(...).allFields.
const hasExplicitOptionalFields =
(obj.getOptionalFields("no-mappings")?.length ?? 0) > 0;
if (hasOptionalFields) pages.push("additional");
const hasAutoOptionalFields =
Object.keys(manifest.getCustomerFieldsForObject(objectName).allFields ?? {})
.length > 0;
if (hasExplicitOptionalFields || hasAutoOptionalFields) {
pages.push("additional");
}

return pages.length > 0 ? pages : ["fields"];
}
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,20 @@ export function useSubPageNavigation() {
return required > 0 || optional > 0;
}, [currentManifestObject]);

// Mirrors the check in getSubPages(): an object has an "additional" page if
// it has explicit optionalFields OR auto-discovered customer fields (e.g.
// from `optionalFieldsAuto: all`).
const hasOptionalFields = useMemo(() => {
return (
(currentManifestObject?.getOptionalFields("no-mappings")?.length ?? 0) > 0
);
}, [currentManifestObject]);
const hasExplicit =
(currentManifestObject?.getOptionalFields("no-mappings")?.length ?? 0) >
0;
const hasAuto =
!!currentObjectName &&
Object.keys(
manifest.getCustomerFieldsForObject(currentObjectName).allFields ?? {},
).length > 0;
return hasExplicit || hasAuto;
}, [currentManifestObject, manifest, currentObjectName]);

const hasFieldsContent = useMemo(() => {
const hasRequiredFields =
Expand Down
Loading