Repository navigation
fix(pivot-table): hide all-null metric columns by default #46340
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1685,7 +1685,33 @@ class PivotData { | |
|
|
||
| getColKeys(): string[][] { | ||
| this.sortKeys(); | ||
| return this.colKeys; | ||
| if (!this.props.hideEmptyColumns) return this.colKeys; | ||
|
|
||
| // Filter display keys only. Keep every aggregator and record available to | ||
| // totals, fraction denominators and drill filters. A zero is not empty. | ||
| const populated = new Set<string>(); | ||
| const collect = (cells: Record<string, Aggregator>) => { | ||
| Object.entries(cells).forEach(([key, aggregator]) => { | ||
| // Test the underlying metric before percentage formatting. A zero | ||
| // numerator must keep its column even when its denominator is zero. | ||
| const metric = (aggregator as FractionDenominator).inner ?? aggregator; | ||
| if (metric.value() != null) populated.add(key); | ||
| }); | ||
| }; | ||
| Object.values(this.tree).forEach(collect); | ||
| collect(this.colTotals); | ||
|
|
||
| // Retain a parent header when a child has a value, even if the parent's | ||
| // own aggregate is null (for example an undefined ratio). | ||
| const visible = new Set<string>(); | ||
| this.colKeys.forEach(key => { | ||
| if (populated.has(flatKey(key))) { | ||
| for (let depth = 1; depth <= key.length; depth += 1) { | ||
| visible.add(flatKey(key.slice(0, depth))); | ||
| } | ||
| } | ||
| }); | ||
| return this.colKeys.filter(key => visible.has(flatKey(key))); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Suggestion: Filtering shifts surviving columns’ indices, but the renderer retains Assessment: 🟠 Prompt for AI Agent 🤖This is a comment left during a code review.
**Path:** superset-frontend/plugins/plugin-chart-pivot-table/src/react-pivottable/utilities.ts
**Line:** 1714:1714
**Comment:**
*Stale Reference: Filtering shifts surviving columns’ indices, but the renderer retains `activeSortColumn` and its sort direction. Hiding a column can leave the indicator missing or make the next click reset instead of toggle.
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 |
||
| } | ||
|
|
||
| getRowKeys(): string[][] { | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🟡 Toggling Hide empty columns leaves the sort indicator on the wrong column.
activeSortColumninTableRendereris an index into the visible columns. The sort-resetuseEffect(TableRenderers.tsx~826-837) doesn't depend onhideEmptyColumns, and this is the only render-trigger control that changes the column set. Repro: columns A, B (all null), C with hiding off. Sort by B ("Sorted by B ascending"), then turn hiding on. The label moves to "Sorted by C ascending" while the rows stay in B's order. It happens the other way round too.TableRenderers.tsxisn't in the diff, so here is the patch. With it, the repro passes and all pivot tests pass.@@ TableRenderers.tsx ~383 onContextMenu, allowRenderHtml, + hideEmptyColumns, } = props; @@ TableRenderers.tsx ~836 namesMappingProp, allowRenderHtml, + hideEmptyColumns, ]);