Skip to content

Conversation

@robjuffermans
Copy link

@robjuffermans robjuffermans commented Dec 28, 2025

User description

Add controls to configure how deeply rows and columns are expanded by default when a Pivot Table chart loads. This allows charts to start with deeper hierarchy levels collapsed for better overview.

  • Add defaultRowExpansionDepth and defaultColExpansionDepth controls
  • Controls only appear when subtotals are enabled and depth > 1
  • Add computeCollapsedMap helper function for initial state seeding
  • Apply initial collapse in componentDidMount (not render) to avoid React anti-pattern
  • Add unit tests for computeCollapsedMap helper

SUMMARY

BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF

TESTING INSTRUCTIONS

ADDITIONAL INFORMATION

  • Has associated issue:
  • Required feature flags:
  • Changes UI
  • Includes DB Migration (follow approval process in SIP-59)
    • Migration is atomic, supports rollback & is backwards-compatible
    • Confirm DB migration upgrade and downgrade tested
    • Runtime estimates and downtime expectations provided
  • Introduces new feature or API
  • Removes existing feature or API

CodeAnt-AI Description

Add controls to set how deeply Pivot Table rows and columns are expanded when the chart loads

What Changed

  • Pivot Table can start with row or column groups collapsed to a configured depth so deeper hierarchy levels are hidden on initial load
  • New chart controls "Default row expansion depth" and "Default column expansion depth" appear when subtotals are enabled and there are multiple group levels; 0 means fully expanded
  • Initial collapse is applied when the table mounts (prevents render flicker) and a helper with unit tests computes which groups to collapse

Impact

✅ Clearer pivot overviews on load
✅ Fewer manual collapses required after chart load
✅ Consistent initial expansion state across loads

💡 Usage Guide

Checking Your Pull Request

Every time you make a pull request, our system automatically looks through it. We check for security issues, mistakes in how you're setting up your infrastructure, and common code problems. We do this to make sure your changes are solid and won't cause any trouble later.

Talking to CodeAnt AI

Got a question or need a hand with something in your pull request? You can easily get in touch with CodeAnt AI right here. Just type the following in a comment on your pull request, and replace "Your question here" with whatever you want to ask:

@codeant-ai ask: Your question here

This lets you have a chat with CodeAnt AI about your pull request, making it easier to understand and improve your code.

Example

@codeant-ai ask: Can you suggest a safer alternative to storing this secret?

Preserve Org Learnings with CodeAnt

You can record team preferences so CodeAnt AI applies them in future reviews. Reply directly to the specific CodeAnt AI suggestion (in the same thread) and replace "Your feedback here" with your input:

@codeant-ai: Your feedback here

This helps CodeAnt AI learn and adapt to your team's coding style and standards.

Example

@codeant-ai: Do not flag unused imports.

Retrigger review

Ask CodeAnt AI to review the PR again, by typing:

@codeant-ai: review

Check Your Repository Health

To analyze the health of your code repository, visit our dashboard at https://app.codeant.ai. This tool helps you identify potential issues and areas for improvement in your codebase, ensuring your repository maintains high standards of code health.

@codeant-ai-for-open-source
Copy link
Contributor

CodeAnt AI is reviewing your PR.


Thanks for using CodeAnt! 🎉

We're free for open-source projects. if you're enjoying it, help us grow by sharing.

Share on X ·
Reddit ·
LinkedIn

@bito-code-review
Copy link
Contributor

bito-code-review bot commented Dec 28, 2025

Code Review Agent Run #d34f78

Actionable Suggestions - 0
Review Details
  • Files reviewed - 7 · Commit Range: 59d0512..59d0512
    • superset-frontend/plugins/plugin-chart-pivot-table/src/PivotTableChart.tsx
    • superset-frontend/plugins/plugin-chart-pivot-table/src/plugin/controlPanel.tsx
    • superset-frontend/plugins/plugin-chart-pivot-table/src/plugin/transformProps.ts
    • superset-frontend/plugins/plugin-chart-pivot-table/src/react-pivottable/TableRenderers.jsx
    • superset-frontend/plugins/plugin-chart-pivot-table/src/types.ts
    • superset-frontend/plugins/plugin-chart-pivot-table/test/plugin/transformProps.test.ts
    • superset-frontend/plugins/plugin-chart-pivot-table/test/react-pivottable/computeCollapsedMap.test.ts
  • Files skipped - 0
  • Tools
    • Eslint (Linter) - ✔︎ Successful
    • Whispers (Secret Scanner) - ✔︎ Successful
    • Detect-secrets (Secret Scanner) - ✔︎ Successful

Bito Usage Guide

Commands

Type the following command in the pull request comment and save the comment.

  • /review - Manually triggers a full AI review.

  • /pause - Pauses automatic reviews on this pull request.

  • /resume - Resumes automatic reviews.

  • /resolve - Marks all Bito-posted review comments as resolved.

  • /abort - Cancels all in-progress reviews.

Refer to the documentation for additional commands.

Configuration

This repository uses Superset You can customize the agent settings here or contact your Bito workspace admin at [email protected].

Documentation & Help

AI Code Review powered by Bito Logo

@dosubot dosubot bot added the viz:charts:pivot Related to the Pivot Table charts label Dec 28, 2025
@codeant-ai-for-open-source codeant-ai-for-open-source bot added the size:L This PR changes 100-499 lines, ignoring generated files label Dec 28, 2025
@codeant-ai-for-open-source
Copy link
Contributor

Nitpicks 🔍

🔒 No security issues identified
⚡ Recommended areas for review

  • Input Validation
    The new helper computeCollapsedMap accepts keys and depth but does not validate that keys is an array of arrays nor that depth is a positive integer. Unexpected inputs (null, non-array keys, non-integer or out-of-range depth) could lead to no-op behavior or inadvertent state mutations. Consider validating inputs and normalizing depth.

  • Missing validation
    The new defaultRowExpansionDepth and defaultColExpansionDepth values are passed through directly from formData with no normalization or clamping. If these values are undefined, non-numeric, negative, or excessively large, downstream code that uses them to seed initial expanded/collapsed state may behave unexpectedly or suffer performance issues.

  • Potential performance impact
    Unbounded expansion depth values could cause heavy initial work when computing collapse/expand maps (e.g., iterating very deep trees). It's safer to cap the depth to a reasonable maximum (or to the available hierarchy depth) before returning the props.

  • Implicit-parent collapse
    The current implementation of computeCollapsedMap only collapses keys whose length exactly equals depth (it filters with k.length === depth). If parent keys are implicit (not present in keys) but only deeper child keys exist (e.g., only ['A','X','1'] and ['A','X','2']), the parent key ['A','X'] will not be collapsed even though the UI probably expects it to be. Add tests and/or update the function to derive parent keys from longer keys (slice first depth elements) so implicit parents are collapsed.

  • Initial state application
    componentDidMount calls this.getBasePivotSettings() which constructs a new PivotData and computes keys. This duplicates work done in render/caching and could be expensive. Also, setState(updates) may write empty {} collapsed maps when computeCollapsedMap returns empty objects — this can overwrite any prior state unintentionally. Consider reusing cached settings (if present) and only set state when collapsed maps are non-empty.

@codeant-ai-for-open-source
Copy link
Contributor

CodeAnt AI finished reviewing your PR.

Add controls to configure how deeply rows and columns are expanded
by default when a Pivot Table chart loads. This allows charts to
start with deeper hierarchy levels collapsed for better overview.

- Add defaultRowExpansionDepth and defaultColExpansionDepth controls
- Controls only appear when subtotals are enabled and depth > 1
- Add computeCollapsedMap helper function for initial state seeding
- Apply initial collapse in componentDidMount (not render) to avoid
  React anti-pattern
- Add unit tests for computeCollapsedMap helper
@robjuffermans robjuffermans force-pushed the feat/pivot-table-default-expansion-depth branch from 59d0512 to 33d0ebe Compare December 28, 2025 13:21
Copy link
Contributor

@bito-code-review bito-code-review bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review Agent Run #8e0549

Actionable Suggestions - 1
  • superset-frontend/plugins/plugin-chart-pivot-table/src/react-pivottable/TableRenderers.jsx - 1
Review Details
  • Files reviewed - 7 · Commit Range: 33d0ebe..33d0ebe
    • superset-frontend/plugins/plugin-chart-pivot-table/src/PivotTableChart.tsx
    • superset-frontend/plugins/plugin-chart-pivot-table/src/plugin/controlPanel.tsx
    • superset-frontend/plugins/plugin-chart-pivot-table/src/plugin/transformProps.ts
    • superset-frontend/plugins/plugin-chart-pivot-table/src/react-pivottable/TableRenderers.jsx
    • superset-frontend/plugins/plugin-chart-pivot-table/src/types.ts
    • superset-frontend/plugins/plugin-chart-pivot-table/test/plugin/transformProps.test.ts
    • superset-frontend/plugins/plugin-chart-pivot-table/test/react-pivottable/computeCollapsedMap.test.ts
  • Files skipped - 0
  • Tools
    • Eslint (Linter) - ✔︎ Successful
    • Whispers (Secret Scanner) - ✔︎ Successful
    • Detect-secrets (Secret Scanner) - ✔︎ Successful

Bito Usage Guide

Commands

Type the following command in the pull request comment and save the comment.

  • /review - Manually triggers a full AI review.

  • /pause - Pauses automatic reviews on this pull request.

  • /resume - Resumes automatic reviews.

  • /resolve - Marks all Bito-posted review comments as resolved.

  • /abort - Cancels all in-progress reviews.

Refer to the documentation for additional commands.

Configuration

This repository uses Superset You can customize the agent settings here or contact your Bito workspace admin at [email protected].

Documentation & Help

AI Code Review powered by Bito Logo

* @param {number} depth - The depth at which to collapse (1-based). Keys at this depth will be collapsed.
* @returns {Object} A map of flatKey => true for all keys that should be collapsed
*/
export function computeCollapsedMap(keys, depth) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Convert JS to TS

This file is written in JavaScript, but the Superset development standards require converting all JavaScript files to TypeScript as part of ongoing modernization. The added computeCollapsedMap function and componentDidMount logic should be typed for better safety and maintainability.

Citations

Code Review Run #8e0549


Should Bito avoid suggestions like this for future reviews? (Manage Rules)

  • Yes, avoid them

@robjuffermans
Copy link
Author

Thanks for the feedback! You're correct that the project is modernizing to TypeScript. However, converting the entire TableRenderers.jsx file (~950 lines) to TypeScript is a significant refactoring effort that's beyond the scope of this feature PR.

I'd prefer to keep this PR focused on the new functionality. The TypeScript conversion of the react-pivottable folder would be better suited as a separate modernization PR.

Would you be okay with merging this as-is and addressing the TS conversion in a follow-up?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

plugins size/L size:L This PR changes 100-499 lines, ignoring generated files viz:charts:pivot Related to the Pivot Table charts

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant