bito-code-review[bot] commented on code in PR #35777:
URL: https://github.com/apache/superset/pull/35777#discussion_r2450168138
##########
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:
<div>
<div id="suggestion">
<div id="issue"><b>TypeScript error from mismatched localStorage helper
usage</b></div>
<div id="fix">
The code is using typed localStorage helpers (`setItem` and `getItem`) with
dynamic string keys that aren't part of the `LocalStorageKeys` enum, which will
cause TypeScript compilation errors since these functions are strictly typed to
only accept enum values. For dynamic keys like `chart_legend_state_${chartId}`,
we need to use the untyped `dangerouslySetItemDoNotUse` and
`dangerouslyGetItemDoNotUse` functions instead. This also allows simplifying
the loading logic since `dangerouslyGetItemDoNotUse` handles JSON parsing
internally. The unused `LocalStorageKeys` import can be removed as well.
</div>
<details>
<summary>
<b>Code suggestion</b>
</summary>
<blockquote>Check the AI-generated fix before applying</blockquote>
<div id="code">
```
- LocalStorageKeys,
- setItem,
- getItem,
+ dangerouslySetItemDoNotUse,
+ dangerouslyGetItemDoNotUse,
} from 'src/utils/localStorageHelpers';
@@ -97,11 +97,7 @@
// 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) {
- }
+ const savedLegendState = dangerouslyGetItemDoNotUse(legendStateKey,
undefined);
+ const savedLegendIndex = dangerouslyGetItemDoNotUse(legendIndexKey, 0);
@@ -279,9 +279,5 @@
handleLegendStateChanged(legendState) {
this.setState({ legendState });
- try {
- setItem(
- `chart_legend_state_${this.props.chartId}`,
- JSON.stringify(legendState),
- );
- } catch (e) {
- }
+ dangerouslySetItemDoNotUse(
+ `chart_legend_state_${this.props.chartId}`,
+ legendState,
+ );
}
@@ -299,9 +299,5 @@
handleLegendScroll(legendIndex) {
this.setState({ legendIndex });
- try {
- setItem(
- `chart_legend_index_${this.props.chartId}`,
- JSON.stringify(legendIndex),
- );
- } catch (e) {
- }
+ dangerouslySetItemDoNotUse(
+ `chart_legend_index_${this.props.chartId}`,
+ legendIndex,
+ );
}
```
</div>
</details>
</div>
<small><i>Code Review Run <a
href=https://github.com/apache/superset/pull/35777#issuecomment-3430157633>#f8d66b</a></i></small>
</div>
---
Should Bito avoid suggestions like this for future reviews? (<a
href=https://alpha.bito.ai/home/ai-agents/review-rules>Manage Rules</a>)
- [ ] Yes, avoid them
--
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]