Skip to content
Open
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 @@ -328,4 +328,31 @@ describe("FieldLabelWrapperComponent - Render Fields", () => {
{ timeout: 1000, interval: 10 }
);
});

// Without an entry the builder resolves every entry on the page, one API
// call each, to fill in a tooltip that reads one row.
test("names the entry it needs when asking for the reference map", async () => {
await act(async () => {
render(
<FieldLabelWrapperComponent
fieldMetadata={mockFieldMetadata}
eventDetails={mockEventDetails}
parentPaths={[]}
getParentEditableElement={mockGetParentEditable}
/>
);
await new Promise<void>((resolve) =>
queueMicrotask(() => resolve())
);
});

expect(visualBuilderPostMessage!.send).toHaveBeenCalledWith(
VisualBuilderPostMessageEvents.REFERENCE_MAP,
{
entryUid: mockFieldMetadata.entry_uid,
contentTypeUid: mockFieldMetadata.content_type_uid,
locale: mockFieldMetadata.locale,
}
);
});
});
18 changes: 15 additions & 3 deletions src/visualBuilder/components/fieldLabelWrapper.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,21 @@ async function getContentTypeName(contentTypeUid: string) {
}
}

async function getReferenceParentMap() {
/**
* The parents of this field's entry.
*
* Names the entry rather than asking for the whole page: the builder resolved
* every entry on the page otherwise, one API call each (measured at 30 calls
* for a nav with roughly 24 links), while the label reads a single row. An
* older builder ignores the payload and still answers with the full map.
*/
async function getReferenceParentMap(fieldMetadata: CslpData) {
try {
const result = await visualBuilderPostMessage?.send<ReferenceParentMap>(VisualBuilderPostMessageEvents.REFERENCE_MAP, {}) ?? {};
const result = await visualBuilderPostMessage?.send<ReferenceParentMap>(VisualBuilderPostMessageEvents.REFERENCE_MAP, {
entryUid: fieldMetadata.entry_uid,
contentTypeUid: fieldMetadata.content_type_uid,
locale: fieldMetadata.locale,
}) ?? {};
return result;
} catch(e) {
console.warn("[getFieldLabelWrapper] Error getting reference parent map", e);
Expand Down Expand Up @@ -240,7 +252,7 @@ function FieldLabelWrapperComponent(
getContentTypeName(
props.fieldMetadata.content_type_uid
),
getReferenceParentMap()
getReferenceParentMap(props.fieldMetadata)
]);
const entryUid = props.fieldMetadata.entry_uid;

Expand Down
Loading