codeant-ai-for-open-source[bot] commented on code in PR #32958:
URL: https://github.com/apache/superset/pull/32958#discussion_r3464388333
##########
superset-frontend/src/dashboard/actions/dashboardState.ts:
##########
@@ -538,6 +538,7 @@ export function saveDashboardRequest(
? getColorSchemeDomain(colorScheme)
: [],
expanded_slices: data.metadata?.expanded_slices || {},
+ expand_all_slices: data.metadata?.expand_all_slices || false,
Review Comment:
**Suggestion:** Using `|| false` does not normalize to a boolean and
preserves truthy non-boolean values like the string `"false"`, which will later
be treated as enabled when coerced in UI logic. Normalize this field strictly
to a boolean when saving metadata so legacy/string values cannot flip behavior
incorrectly. [type error]
<details>
<summary><b>Severity Level:</b> Major ⚠️</summary>
```mdx
- ❌ Legacy dashboards with string flags show descriptions expanded.
- ⚠️ Saved dashboard metadata stores non-boolean expand_all_slices.
```
</details>
<details>
<summary><b>Steps of Reproduction ✅ </b></summary>
```mdx
1. Import or create a dashboard whose `json_metadata` contains a string
value for
`expand_all_slices`, e.g. `"expand_all_slices": "False"` as shown in the
import/export
fixture at `tests/integration_tests/fixtures/importexport.py:72`.
2. When this dashboard is loaded in the UI, the Redux hydration logic in
`superset-frontend/src/dashboard/actions/hydrate.ts:360-399` sets
`dashboardState.expandAllSlices` via `expandAllSlices:
metadata?.expand_all_slices ||
false`, so the string `"False"` (truthy) is propagated unchanged into the
dashboard state.
3. Open the dashboard and observe that chart descriptions are treated as
expanded because
`Chart` computes `isExpanded` as `!!((state.dashboardState as
JsonObject).expandedSlices?.[props.id] ?? (state.dashboardState as
JsonObject).expandAllSlices)` in
`superset-frontend/src/dashboard/components/gridComponents/Chart/Chart.tsx:39-45`,
so a
truthy string `expandAllSlices` becomes `true`.
4. Save the dashboard via the Save dialog
(`superset-frontend/src/dashboard/components/SaveModal.tsx:29-55`), which
calls
`saveDashboardRequest` and builds `cleanedData.metadata` in
`superset-frontend/src/dashboard/actions/dashboardState.ts:27-73`, where
`expand_all_slices: data.metadata?.expand_all_slices || false` at line 541
re-persists the
truthy string instead of normalizing to a boolean, cementing the
inconsistent non-boolean
state for future loads.
```
</details>
[](https://app.codeant.ai/fix-in-ide?tool=cursor&prompt_id=9b2241465aa04bb9bf76b427d33c6443&service=github&base_url=https%3A%2F%2Fgithub.com&org=apache&repo=apache%2Fsuperset)
[](https://app.codeant.ai/fix-in-ide?tool=vscode-claude&prompt_id=9b2241465aa04bb9bf76b427d33c6443&service=github&base_url=https%3A%2F%2Fgithub.com&org=apache&repo=apache%2Fsuperset)
*(Use Cmd/Ctrl + Click for best experience)*
<details>
<summary><b>Prompt for AI Agent 🤖 </b></summary>
```mdx
This is a comment left during a code review.
**Path:** superset-frontend/src/dashboard/actions/dashboardState.ts
**Line:** 541:541
**Comment:**
*Type Error: Using `|| false` does not normalize to a boolean and
preserves truthy non-boolean values like the string `"false"`, which will later
be treated as enabled when coerced in UI logic. Normalize this field strictly
to a boolean when saving metadata so legacy/string values cannot flip behavior
incorrectly.
Validate the correctness of the flagged issue. If correct, How can I resolve
this? If you propose a fix, implement it and please make it concise.
Once fix is implemented, also check other comments on the same PR, and ask
user if the user wants to fix the rest of the comments as well. if said yes,
then fetch all the comments validate the correctness and implement a minimal fix
```
</details>
<a
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F32958&comment_hash=11666ae505cef2042bd87793b32a3212513afc9b8e3b2e302313fa639cb948b0&reaction=like'>👍</a>
| <a
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F32958&comment_hash=11666ae505cef2042bd87793b32a3212513afc9b8e3b2e302313fa639cb948b0&reaction=dislike'>👎</a>
##########
superset-frontend/src/dashboard/components/gridComponents/Chart/Chart.tsx:
##########
@@ -207,7 +207,10 @@ const Chart = (props: ChartProps) => {
);
const isExpanded = useSelector(
(state: RootState) =>
- !!(state.dashboardState as JsonObject).expandedSlices?.[props.id],
+ !!(
+ (state.dashboardState as JsonObject).expandedSlices?.[props.id] ??
+ (state.dashboardState as JsonObject).expandAllSlices
+ ),
Review Comment:
**Suggestion:** The fallback logic makes charts expanded when
`expandAllSlices` is true, but the toggle action still flips
`expandedSlices[sliceId]` from `undefined` to `true`. That means the first
"Hide chart description" click for globally expanded charts does not collapse
the description. Store an explicit per-slice override when global expansion is
active (or adjust the computed expansion logic to treat first toggle as
`false`) so hide/show works on first click. [incorrect condition logic]
<details>
<summary><b>Severity Level:</b> Major ⚠️</summary>
```mdx
- ❌ First "Hide chart description" click has no effect.
- ⚠️ Global expand-all setting yields confusing toggle behavior.
```
</details>
<details>
<summary><b>Steps of Reproduction ✅ </b></summary>
```mdx
1. Enable the dashboard-level setting to expand all chart descriptions so
that
`metadata.expand_all_slices` is `true` in the dashboard JSON; on load,
`hydrateDashboard`
sets `dashboardState.expandAllSlices` via `expandAllSlices:
metadata?.expand_all_slices ||
false` at `superset-frontend/src/dashboard/actions/hydrate.ts:360-399`.
2. Load that dashboard in the UI: the `Chart` component computes
`isExpanded` with
`!!((state.dashboardState as JsonObject).expandedSlices?.[props.id] ??
(state.dashboardState as JsonObject).expandAllSlices)` at
`superset-frontend/src/dashboard/components/gridComponents/Chart/Chart.tsx:39-45`,
so with
`expandedSlices[props.id]` undefined and `expandAllSlices === true`,
`isExpanded` is
`true` and each chart description is initially shown.
3. Open a chart's context menu and click "Hide chart description", which is
wired in
`superset-frontend/src/dashboard/components/SliceHeaderControls/index.tsx:15-21`
using
`props.isDescriptionExpanded` (from `Chart`'s `isExpanded`) and the
`MenuKeys.ToggleChartDescription` item; this triggers the
`toggleExpandSlice` action
passed from `Chart` at
`superset-frontend/src/dashboard/components/gridComponents/Chart/Chart.tsx:30-38`.
4. The reducer in
`superset-frontend/src/dashboard/reducers/dashboardState.ts:98-104`
handles `TOGGLE_EXPAND_SLICE` by computing `updatedExpandedSlices[sliceId] =
!updatedExpandedSlices[sliceId]`, so for an undefined entry it sets
`expandedSlices[sliceId]` to `true`; after this, `isExpanded` re-evaluates
to `!!(true ??
true)` (still `true`), so the "Hide chart description" click does not
actually collapse
the description until the second click, breaking the expected hide/show
semantics when
`expandAllSlices` is enabled.
```
</details>
[](https://app.codeant.ai/fix-in-ide?tool=cursor&prompt_id=384d52faf64f495db1ea41ab39897846&service=github&base_url=https%3A%2F%2Fgithub.com&org=apache&repo=apache%2Fsuperset)
[](https://app.codeant.ai/fix-in-ide?tool=vscode-claude&prompt_id=384d52faf64f495db1ea41ab39897846&service=github&base_url=https%3A%2F%2Fgithub.com&org=apache&repo=apache%2Fsuperset)
*(Use Cmd/Ctrl + Click for best experience)*
<details>
<summary><b>Prompt for AI Agent 🤖 </b></summary>
```mdx
This is a comment left during a code review.
**Path:**
superset-frontend/src/dashboard/components/gridComponents/Chart/Chart.tsx
**Line:** 211:213
**Comment:**
*Incorrect Condition Logic: The fallback logic makes charts expanded
when `expandAllSlices` is true, but the toggle action still flips
`expandedSlices[sliceId]` from `undefined` to `true`. That means the first
"Hide chart description" click for globally expanded charts does not collapse
the description. Store an explicit per-slice override when global expansion is
active (or adjust the computed expansion logic to treat first toggle as
`false`) so hide/show works on first click.
Validate the correctness of the flagged issue. If correct, How can I resolve
this? If you propose a fix, implement it and please make it concise.
Once fix is implemented, also check other comments on the same PR, and ask
user if the user wants to fix the rest of the comments as well. if said yes,
then fetch all the comments validate the correctness and implement a minimal fix
```
</details>
<a
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F32958&comment_hash=0528a77e333ccfb2e2f3dde4f10de2134171d3563a35891533cb738021875e12&reaction=like'>👍</a>
| <a
href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F32958&comment_hash=0528a77e333ccfb2e2f3dde4f10de2134171d3563a35891533cb738021875e12&reaction=dislike'>👎</a>
--
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]