Skip to content

Commit

Permalink
fix: Dataset views not loading saved attribute [PT-188345477]
Browse files Browse the repository at this point in the history
This was an issue with the view mode not being set before the data change handler was called at load time.
  • Loading branch information
dougmartin committed Sep 27, 2024
1 parent d730a40 commit 58360df
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/hooks/use-codap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -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);
}
}
}
Expand Down

0 comments on commit 58360df

Please sign in to comment.