rusackas commented on code in PR #35777:
URL: https://github.com/apache/superset/pull/35777#discussion_r3943104073
##########
superset-frontend/src/components/Chart/ChartRenderer.jsx:
##########
@@ -88,14 +93,28 @@ class ChartRenderer extends Component {
const suppressContextMenu = getChartMetadataRegistry().get(
props.formData.viz_type ?? props.vizType,
)?.suppressContextMenu;
+
+ // Load legend state from localStorage (per-chart)
+ const legendStateKey = `chart_legend_state_${props.chartId}`;
+ const legendIndexKey = `chart_legend_index_${props.chartId}`;
+ let savedLegendState;
+ let savedLegendIndex = 0;
+ try {
+ const savedState = getItem(legendStateKey);
+ if (savedState) savedLegendState = JSON.parse(savedState);
+ const savedIndex = getItem(legendIndexKey);
+ if (savedIndex) savedLegendIndex = JSON.parse(savedIndex);
+ } catch (e) {
+ }
Review Comment:
This one's stale now. There's no constructor anymore since the port to
hooks, and the read is two tiny sessionStorage keys inside a lazy `useState`
initializer. Deferring it until after mount would just paint the wrong legend
and then re-render, which is the flicker we're trying to avoid. Resolving.
##########
superset-frontend/src/components/Chart/ChartRenderer.jsx:
##########
@@ -33,6 +33,11 @@ import { Logger, LOG_ACTIONS_RENDER_CHART } from
'src/logger/LogUtils';
import { EmptyState } from '@superset-ui/core/components';
import { ChartSource } from 'src/types/ChartSource';
import ChartContextMenu from './ChartContextMenu/ChartContextMenu';
+import {
Review Comment:
No longer applies... the `localStorageHelpers` import went away when this
got ported over to sessionStorage, so it's plain
`sessionStorage.getItem`/`setItem` now with no typed-key enum in the picture.
Resolving.
##########
superset-frontend/src/components/Chart/ChartRenderer.jsx:
##########
@@ -89,14 +89,37 @@ class ChartRenderer extends Component {
const suppressContextMenu = getChartMetadataRegistry().get(
props.formData.viz_type ?? props.vizType,
)?.suppressContextMenu;
+
+ // Load legend state from sessionStorage (per-chart)
+ const legendStateKey = `chart_legend_state_${props.chartId}`;
+ const legendIndexKey = `chart_legend_index_${props.chartId}`;
+ let savedLegendState = null;
+ let savedLegendIndex = 0;
+ try {
+ const storedState = sessionStorage.getItem(legendStateKey);
+ if (storedState !== null) {
+ savedLegendState = JSON.parse(storedState);
+ }
+ const storedIndex = sessionStorage.getItem(legendIndexKey);
+ if (storedIndex !== null) {
+ console.log(storedIndex);
+ savedLegendIndex = JSON.parse(storedIndex);
+ }
+ } catch (e) {
+ logging.warn(
+ '[ChartRenderer] Failed to load legend state from sessionStorage:',
+ e,
+ );
Review Comment:
I think this is covered now. The read sits in a `try/catch` with a
`logging.warn` inside the `useState` initializer, and the stray `console.log`
is gone. We don't do SSR on the frontend, so the `typeof window` check would be
belt and suspenders on top of the catch. Resolving.
##########
superset-frontend/src/components/Chart/ChartRenderer.jsx:
##########
@@ -261,6 +284,17 @@ class ChartRenderer extends Component {
handleLegendStateChanged(legendState) {
this.setState({ legendState });
+ try {
+ sessionStorage.setItem(
+ `chart_legend_state_${this.props.chartId}`,
+ JSON.stringify(legendState),
+ );
+ } catch (e) {
+ logging.warn(
+ '[ChartRenderer] Failed to save legend state to sessionStorage:',
+ e,
+ );
Review Comment:
Covered in the current version. The write in `handleLegendStateChanged` is
wrapped in a `try/catch` with a `logging.warn`, which also catches the
missing-global case. Resolving.
##########
superset-frontend/src/components/Chart/ChartRenderer.jsx:
##########
@@ -274,6 +308,17 @@ class ChartRenderer extends Component {
handleLegendScroll(legendIndex) {
this.setState({ legendIndex });
+ try {
+ sessionStorage.setItem(
+ `chart_legend_index_${this.props.chartId}`,
+ JSON.stringify(legendIndex),
+ );
+ } catch (e) {
+ logging.warn(
+ '[ChartRenderer] Failed to save legend index to sessionStorage:',
+ e,
+ );
Review Comment:
Same as the legend state write above, `handleLegendScroll` has the
`try/catch` and `logging.warn` now. Resolving.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]