Skip to content

Commit

Permalink
Fix treatment units tree not initially expanded for selection in quer…
Browse files Browse the repository at this point in the history
…y params (#2369)

* refresh tree of available treatment units after query params has completed loading

* apiQueriesCompleted should only be true the first time the query has changed from loading to not loading
  • Loading branch information
jo-inge-arnes authored Apr 22, 2024
1 parent a2ca3a4 commit e1d0d4d
Showing 1 changed file with 15 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ export function TreatmentQualityFilterMenu({
// the first call after the prerender is done.

const [prevReady, setPrevReady] = useState(router.isReady);
const shouldRefreshInititalState = prevReady !== router.isReady;
const prerenderFinished = prevReady !== router.isReady;

useEffect(() => {
setPrevReady(router.isReady);
Expand Down Expand Up @@ -170,6 +170,15 @@ export function TreatmentQualityFilterMenu({
queryContext.type,
);

const [prevApiQueryLoading, setPrevApiQueryLoading] = useState(
unitNamesQuery.isLoading,
);
const apiQueriesCompleted = prevApiQueryLoading && !unitNamesQuery.isLoading;

useEffect(() => {
setPrevApiQueryLoading(unitNamesQuery.isLoading);
}, [unitNamesQuery.isLoading]);

const treatmentUnits = getTreatmentUnitsTree(unitNamesQuery);

optionsMap.set(treatmentUnitsKey, {
Expand Down Expand Up @@ -270,6 +279,8 @@ export function TreatmentQualityFilterMenu({
return filterSettingsValue?.valueLabel ?? null;
};

const shouldRefreshInitialState = prerenderFinished || apiQueriesCompleted;

return (
<>
{!(medicalFieldData || registryNameData) && (
Expand All @@ -278,7 +289,7 @@ export function TreatmentQualityFilterMenu({
</Alert>
)}
<FilterMenu
refreshState={shouldRefreshInititalState}
refreshState={shouldRefreshInitialState}
onSelectionChanged={handleFilterChanged}
onFilterInitialized={onFilterInitialized}
>
Expand Down Expand Up @@ -310,7 +321,7 @@ export function TreatmentQualityFilterMenu({
filterkey={levelKey}
/>
<TreeViewFilterSection
refreshState={shouldRefreshInititalState}
refreshState={shouldRefreshInitialState}
treedata={medicalFields.treedata}
defaultvalues={medicalFields.defaults}
autouncheckid={medicalFields.defaults[0].value}
Expand All @@ -326,7 +337,7 @@ export function TreatmentQualityFilterMenu({
searchbox={true}
/>
<TreeViewFilterSection
refreshState={shouldRefreshInititalState}
refreshState={shouldRefreshInitialState}
treedata={treatmentUnits.treedata}
defaultvalues={treatmentUnits.defaults}
initialselections={
Expand Down

0 comments on commit e1d0d4d

Please sign in to comment.