rusackas commented on code in PR #35777:
URL: https://github.com/apache/superset/pull/35777#discussion_r4077843208
##########
superset-frontend/src/components/Chart/ChartRenderer.tsx:
##########
@@ -65,7 +65,7 @@ import { getTabId } from 'src/hooks/useTabId';
type FilterValue = string | number | boolean | null | undefined;
// LegendState type based on ECharts
-interface LegendState {
+export interface LegendState {
[name: string]: boolean;
}
Review Comment:
New helper, capped at 200 tracked charts (tune as needed):
```suggestion
export interface LegendState {
[name: string]: boolean;
}
// Caps how many distinct charts' legend state sessionStorage tracks in one
// tab session. Without this, a long-lived tab that visits many different
// charts accumulates one entry per chartId ever seen, unbounded, for as long
// as the tab stays open. Evicting the least-recently-touched chart once the
// cap is exceeded keeps total storage bounded regardless of session length.
const MAX_TRACKED_LEGEND_CHARTS = 200;
const LEGEND_LRU_KEY = 'chart_legend_lru';
function touchLegendLru(chartId: number): void {
try {
const raw = sessionStorage.getItem(LEGEND_LRU_KEY);
const lru: number[] = raw ? JSON.parse(raw) : [];
const next = [chartId, ...lru.filter(id => id !== chartId)];
next.splice(MAX_TRACKED_LEGEND_CHARTS).forEach(evictedId => {
sessionStorage.removeItem(`chart_legend_state_${evictedId}`);
sessionStorage.removeItem(`chart_legend_index_${evictedId}`);
});
sessionStorage.setItem(LEGEND_LRU_KEY, JSON.stringify(next));
} catch (error) {
logging.warn('[ChartRenderer] Failed to update legend LRU tracking:',
error);
}
}
```
##########
superset-frontend/src/components/Chart/ChartRenderer.tsx:
##########
@@ -359,13 +384,38 @@ function ChartRendererComponent({
const handleLegendStateChanged = useCallback(
(legendState: LegendState): void => {
setState(prev => ({ ...prev, legendState }));
+ try {
+ sessionStorage.setItem(
+ `chart_legend_state_${chartId}`,
+ JSON.stringify(legendState),
+ );
Review Comment:
```suggestion
);
touchLegendLru(chartId);
```
##########
superset-frontend/src/components/Chart/ChartRenderer.tsx:
##########
@@ -359,13 +384,38 @@ function ChartRendererComponent({
const handleLegendStateChanged = useCallback(
(legendState: LegendState): void => {
setState(prev => ({ ...prev, legendState }));
+ try {
+ sessionStorage.setItem(
+ `chart_legend_state_${chartId}`,
+ JSON.stringify(legendState),
+ );
+ } catch (error) {
+ logging.warn(
+ '[ChartRenderer] Failed to save legend state to sessionStorage:',
+ error,
+ );
+ }
},
- [],
+ [chartId],
);
- const handleLegendScroll = useCallback((legendIndex: number): void => {
- setState(prev => ({ ...prev, legendIndex }));
- }, []);
+ const handleLegendScroll = useCallback(
+ (legendIndex: number): void => {
+ setState(prev => ({ ...prev, legendIndex }));
+ try {
+ sessionStorage.setItem(
+ `chart_legend_index_${chartId}`,
+ JSON.stringify(legendIndex),
+ );
Review Comment:
Same call here:
```suggestion
);
touchLegendLru(chartId);
```
--
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]