Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Custom DC] Fix Disappearing Stat Var bug on Map and Scatter tool #4251

Merged
merged 16 commits into from
May 31, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions server/templates/custom_dc/custom/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@
{% if OVERRIDE_CSS_PATH %}
<link href="{{ OVERRIDE_CSS_PATH }}" rel="stylesheet">
{% endif %}
<script>
globalThis.isCustomDC = {{ config['CUSTOM']|int }};
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this approach will require existing custom DC users to add this line in order to see the fix. is there a way we can push the fix to them requiring them to change any code?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of setting a value in base.html, switched to using a config variable in app_env/*.py files, and setting globalThis on the tools pages themselves, instead of the template which could be overridden.

</script>
</head>

<body>
Expand Down
9 changes: 5 additions & 4 deletions static/js/tools/map/stat_var_chooser.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -114,10 +114,11 @@ export function StatVarChooser(props: StatVarChooserProps): JSX.Element {
selectSV={(svDcid) =>
selectStatVar(dateCtx, statVar, display, placeInfo, svDcid)
}
numEntitiesExistence={Math.min(
NUM_ENTITIES_EXISTENCE,
samplePlaces.length
)}
numEntitiesExistence={
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you extract this logic to a function and add some comments explaining the isCustomDC vs NUM_ENTITIES_EXISTENCE check

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good idea. Extracted to a helper function and added an explaining comment.

globalThis.isCustomDC
? 1
: Math.min(NUM_ENTITIES_EXISTENCE, samplePlaces.length)
}
/>
);
}
Expand Down
10 changes: 7 additions & 3 deletions static/js/tools/scatter/chart.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -139,11 +139,15 @@ export function Chart(props: ChartPropsType): JSX.Element {
}
}, DEBOUNCE_INTERVAL_MS);
const resizeObserver = new ResizeObserver(debouncedHandler);
if (chartContainerRef.current) {
resizeObserver.observe(chartContainerRef.current);
// The value of chartContainerRef.current may change between setting the
// observe and unobserving during cleanup, so we store the current value
// in a variable.
const currentChartContainerElement = chartContainerRef.current;
if (currentChartContainerElement) {
resizeObserver.observe(currentChartContainerElement);
}
return () => {
resizeObserver.unobserve(chartContainerRef.current);
resizeObserver.unobserve(currentChartContainerElement);
debouncedHandler.cancel();
};
}, [props, chartContainerRef, geoJsonFetched]);
Expand Down
9 changes: 5 additions & 4 deletions static/js/tools/scatter/statvar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -164,10 +164,11 @@ export function StatVarChooser(props: StatVarChooserProps): JSX.Element {
}
selectedSVs={selectedSvs}
selectSV={(sv) => addStatVar(x, y, sv, setThirdStatVar, setModalOpen)}
numEntitiesExistence={Math.min(
NUM_ENTITIES_EXISTENCE,
samplePlaces.length
)}
numEntitiesExistence={
globalThis.isCustomDC
? 1
: Math.min(NUM_ENTITIES_EXISTENCE, samplePlaces.length)
}
/>
{/* Modal for selecting 2 stat vars when a third is selected */}
<Modal isOpen={modalOpen} backdrop="static" id="statvar-modal">
Expand Down
Loading