From 58360df898fab080e94ab8d273dd1796d20a8355 Mon Sep 17 00:00:00 2001 From: Doug Martin Date: Fri, 27 Sep 2024 11:06:33 -0400 Subject: [PATCH] fix: Dataset views not loading saved attribute [PT-188345477] This was an issue with the view mode not being set before the data change handler was called at load time. --- src/hooks/use-codap.ts | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/hooks/use-codap.ts b/src/hooks/use-codap.ts index d42282a..ebd5947 100644 --- a/src/hooks/use-codap.ts +++ b/src/hooks/use-codap.ts @@ -75,10 +75,12 @@ export const useCODAP = ({onCODAPDataChanged, getGraph, setGraph, setInitialGrap }]); }; - const handleDataChanged = useCallback(async ({datasetName, collectionName, attributeName}: CODAPAttribute) => { + const handleDataChanged = useCallback(async (codapAttribute: CODAPAttribute, viewModeOverride?: ViewMode ) => { + const {datasetName, collectionName, attributeName} = codapAttribute; const values = await getValuesForAttribute(datasetName, collectionName, attributeName); const valuesChanged = !valuesRef.current || (JSON.stringify(values) !== JSON.stringify(valuesRef.current)); - if (viewMode === "dataset" && valuesChanged) { + const currentViewMode = viewModeOverride ?? viewMode; + if (currentViewMode === "dataset" && valuesChanged) { onCODAPDataChanged(values); valuesRef.current = values; } @@ -100,7 +102,7 @@ export const useCODAP = ({onCODAPDataChanged, getGraph, setGraph, setInitialGrap } else { if (values?.attribute) { setAttribute(values.attribute); - handleDataChanged(values.attribute); + handleDataChanged(values.attribute, values.viewMode); } } }