From be99c73c8859352b2ee132b7b072fef9e9062c38 Mon Sep 17 00:00:00 2001 From: Adam Brin Date: Wed, 3 Apr 2024 11:34:54 -0700 Subject: [PATCH] expose partOf --- .../src/components/AtlasCanvas/AtlasCanvas.tsx | 10 ++++++++-- packages/canvas-panel/src/helpers/eventbus.ts | 9 ++++++++- .../canvas-panel/src/hooks/use-generic-atlas-props.ts | 3 ++- 3 files changed, 18 insertions(+), 4 deletions(-) diff --git a/packages/canvas-panel/src/components/AtlasCanvas/AtlasCanvas.tsx b/packages/canvas-panel/src/components/AtlasCanvas/AtlasCanvas.tsx index 2197ca3..13cb403 100644 --- a/packages/canvas-panel/src/components/AtlasCanvas/AtlasCanvas.tsx +++ b/packages/canvas-panel/src/components/AtlasCanvas/AtlasCanvas.tsx @@ -125,8 +125,14 @@ export function AtlasCanvas({ })) as any[], label: (ref as any).label, }; - choiceEventChannel.emit('onChoiceChange', { choice }); - + choiceEventChannel.emit('onChoiceChange', { + choice, + partOf: { + canvasId: canvas.id, + choiceId: body.id, + manifestId: manifest?.id, + }, + }); } } // this returns 1 choice diff --git a/packages/canvas-panel/src/helpers/eventbus.ts b/packages/canvas-panel/src/helpers/eventbus.ts index 78e7905..ea67297 100644 --- a/packages/canvas-panel/src/helpers/eventbus.ts +++ b/packages/canvas-panel/src/helpers/eventbus.ts @@ -30,7 +30,14 @@ export const choiceEventChannel = eventbus<{ * @param payload - the id and options for the choice * */ - onChoiceChange: (payload: { choice?: ChoiceDescription }) => void; + onChoiceChange: (payload: { + choice?: ChoiceDescription; + partOf?: { + choiceId?: string; + canvasId?: string; + manifestId?: string; + }; + }) => void; /** * When a canvas is changed, or a sequence is changed, this signals that * the current set of choices should be reset diff --git a/packages/canvas-panel/src/hooks/use-generic-atlas-props.ts b/packages/canvas-panel/src/hooks/use-generic-atlas-props.ts index 034ef40..a45e4b0 100644 --- a/packages/canvas-panel/src/hooks/use-generic-atlas-props.ts +++ b/packages/canvas-panel/src/hooks/use-generic-atlas-props.ts @@ -155,7 +155,7 @@ export function useGenericAtlasProps>(props: GenericAtl seenChoices.current = {}; }); - const onChoiceChange = (payload: { choice?: ChoiceDescription }) => { + const onChoiceChange = (payload: { choice?: ChoiceDescription, partOf?: any }) => { const choice = payload.choice; // sort the choices by ID in order to help with de-duping if (webComponent?.current && choice && choice.items) { @@ -181,6 +181,7 @@ export function useGenericAtlasProps>(props: GenericAtl (seenChoices.current as any)[key] = value; // move this outside the IF if we want to fire on every page + (choice as any).partOf = payload.partOf; webComponent.current.dispatchEvent(new CustomEvent('choice', { detail: { choice } })); } };