From 24602d190ec575c50938caaa0e0beca39adf9b92 Mon Sep 17 00:00:00 2001 From: Doug Martin Date: Thu, 20 Jun 2024 09:38:12 -0400 Subject: [PATCH] fix: Authored state lookup in authoring mode [PT-187809702] This fixes a couple of issues found when testing out authoring: In authoring mode the authoredState comes in as a string which was causing the authoring preview to show an error that the experiment was not selected. There was still a reference to the "Save Authored State" button, which I believe came from the S3 authoring version. --- src/lara-app/components/authoring.tsx | 1 - src/lara-app/hooks/interactive-api.ts | 16 +++++++++++++--- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/src/lara-app/components/authoring.tsx b/src/lara-app/components/authoring.tsx index ff9805f..ff27f7a 100644 --- a/src/lara-app/components/authoring.tsx +++ b/src/lara-app/components/authoring.tsx @@ -38,7 +38,6 @@ export const AuthoringComponent = (props : IProps) => { })} -
Once you select an experiment please click the "Save authored state" button above to save your choice.
); }; diff --git a/src/lara-app/hooks/interactive-api.ts b/src/lara-app/hooks/interactive-api.ts index 857448b..7f29733 100644 --- a/src/lara-app/hooks/interactive-api.ts +++ b/src/lara-app/hooks/interactive-api.ts @@ -70,9 +70,19 @@ export const useInteractiveApi = (options: {setError: (error: any) => void}) => setConnectedToLara(true); let _experiment; - if (data.authoredState && (data.authoredState.version === "1.0")) { - experimentId.current = data.authoredState.experimentId; - _experiment = findExperiment(data.authoredState.experimentId); + let authoredState = data.authoredState; + // In authoring mode the authored state comes in as a string + // which causes the authoring preview to show an error + if (typeof authoredState === "string") { + try { + authoredState = JSON.parse(authoredState); + } catch (e) { + // noop + } + } + if (authoredState?.version === "1.0") { + experimentId.current = authoredState.experimentId; + _experiment = findExperiment(authoredState.experimentId); setExperiment(_experiment); }