DataTable: add summary statistics for selected cells#8326
Open
andrewsoonqn wants to merge 17 commits intomarimo-team:mainfrom
Open
DataTable: add summary statistics for selected cells#8326andrewsoonqn wants to merge 17 commits intomarimo-team:mainfrom
andrewsoonqn wants to merge 17 commits intomarimo-team:mainfrom
Conversation
Use selectedCellsAtom to get size of cell selection and display.
Accordingly reorder components such that CellSelectionProvider's scope covers new CellSelectionStats component for it to use the selectedCellsAtom.
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Add a new test-utils.ts exporting shared mock helpers (createMockCell, createMockColumn, createMockRow, createMockTable, createSelectedCell) and update utils.test.ts to import and use those helpers.
CellSelectionStats counts checkbox column on the left indicating whether a row is selected. This is counter-intuitive. Introduce utility to count all cells excluding the checkbox column.
Contributor
There was a problem hiding this comment.
Pull request overview
This PR adds Excel-like summary statistics (Count, Sum, Average) to the DataTable component that appear when users select two or more cells. The feature filters numeric values intelligently, excluding non-numeric data from Sum and Average calculations while including all data cells in the Count. The statistics display is positioned below the table and only appears when multiple cells are selected.
Changes:
- Added
getNumericValuesFromSelectedCellsandcountDataCellsInSelectionutility functions to extract and count cell data - Created
CellSelectionStatscomponent to display Count, Sum, and Average statistics - Moved
CellSelectionProviderto wrap both the table and the new stats component, enabling state sharing
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| frontend/src/components/data-table/range-focus/utils.ts | Added utility functions to count selected cells and extract numeric values, filtering out checkbox columns and non-numeric data |
| frontend/src/components/data-table/range-focus/cell-selection-stats.tsx | New component displaying statistics (Count, Sum, Average) for selected cells with 8 decimal place rounding |
| frontend/src/components/data-table/range-focus/tests/utils.test.ts | Added comprehensive tests for new utility functions and refactored existing test helpers into test-utils.ts |
| frontend/src/components/data-table/range-focus/tests/test-utils.ts | Extracted reusable mock helper functions (createMockCell, createMockRow, createMockTable) for test consistency |
| frontend/src/components/data-table/range-focus/tests/cell-selection-stats.test.tsx | Added thorough tests covering various scenarios: numeric/non-numeric values, rounding, checkbox exclusion, and edge cases |
| frontend/src/components/data-table/data-table.tsx | Repositioned CellSelectionProvider to wrap both table and stats component, added CellSelectionStats below the table |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
frontend/src/components/data-table/range-focus/cell-selection-stats.tsx
Outdated
Show resolved
Hide resolved
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
📝 Summary
Closes #6015
Introduce summary statistics for selected cells to the data table component. When users select two or more cells, the UI now displays the count, sum, and average of the selected numeric values.
Demo:
cell-selection-data.mov
Works also with other components where DataTable is used, e.g., dataframes.
data-frame-selection-data.mov
🔍 Description of Changes
Decisions made:
CellSelectionStatscomponent only shows when 2 or more cells are selectedFuture considerations:
Implementation Details
CellSelectionStatscomponent that displays the count, sum, and average of selected cells when two or more are selected.CellSelectionStatsinto theDataTableInternalcomponent, position is below the table. Wrap it in theCellSelectionProvidercontext.getNumericValuesFromSelectedCellsutility function inutils.tsto extract numeric values from selected cells, filtering out non-numeric and special columns.📋 Checklist