-
Notifications
You must be signed in to change notification settings - Fork 11.2k
fix(web): count selected subRows in bulk actions toolbar #7154
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
Open
ryanchou1994
wants to merge
2
commits into
QuantumNous:main
Choose a base branch
from
ryanchou1994:fix/bulk-actions-tree-selection
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
110 changes: 110 additions & 0 deletions
110
web/src/components/data-table/__tests__/bulk-actions.test.tsx
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,110 @@ | ||
| /* | ||
| Copyright (C) 2023-2026 QuantumNous | ||
|
|
||
| This program is free software: you can redistribute it and/or modify | ||
| it under the terms of the GNU Affero General Public License as | ||
| published by the Free Software Foundation, either version 3 of the | ||
| License, or (at your option) any later version. | ||
|
|
||
| This program is distributed in the hope that it will be useful, | ||
| but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| GNU Affero General Public License for more details. | ||
|
|
||
| You should have received a copy of the GNU Affero General Public License | ||
| along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
|
|
||
| For commercial licensing, please contact support@quantumnous.com | ||
| */ | ||
| import { | ||
| getCoreRowModel, | ||
| useReactTable, | ||
| type ColumnDef, | ||
| type Row, | ||
| type RowSelectionState, | ||
| } from '@tanstack/react-table' | ||
| import { render, screen } from '@testing-library/react' | ||
| import { describe, expect, test } from 'vitest' | ||
|
|
||
| import { DataTableBulkActions } from '../toolbar/bulk-actions' | ||
|
|
||
| // Regression tests for issue #6885: with tag mode + batch mode enabled on the | ||
| // channels table, selecting channels never showed the bulk-actions toolbar. | ||
| // Tag mode turns the data into a tree (tag rows on top, channels as subRows) | ||
| // and tag rows are not selectable, so every selected row is a subRow. The | ||
| // toolbar must count selected subRows too, not only selected top-level rows. | ||
|
|
||
| type TreeRow = { | ||
| id: string | ||
| label: string | ||
| children?: TreeRow[] | ||
| } | ||
|
|
||
| const columns: ColumnDef<TreeRow>[] = [ | ||
| { id: 'label', accessorFn: (row) => row.label }, | ||
| ] | ||
|
|
||
| function Harness({ | ||
| data, | ||
| initialSelection, | ||
| }: { | ||
| data: TreeRow[] | ||
| initialSelection: RowSelectionState | ||
| }) { | ||
| const table = useReactTable({ | ||
| data, | ||
| columns, | ||
| getCoreRowModel: getCoreRowModel(), | ||
| getRowId: (row) => row.id, | ||
| getSubRows: (row) => row.children, | ||
| // Mirrors the channels table in tag mode: aggregate (parent) rows are not | ||
| // selectable, leaf rows are. See channels-table.tsx enableRowSelection. | ||
| enableRowSelection: (row: Row<TreeRow>) => | ||
| !Array.isArray(row.original.children), | ||
| initialState: { rowSelection: initialSelection }, | ||
| }) | ||
|
|
||
| return ( | ||
| <DataTableBulkActions table={table} entityName='channel'> | ||
| <button type='button'>bulk action</button> | ||
| </DataTableBulkActions> | ||
| ) | ||
| } | ||
|
|
||
| const treeData: TreeRow[] = [ | ||
| { | ||
| id: 'tag:alpha', | ||
| label: 'alpha', | ||
| children: [ | ||
| { id: 'channel:1', label: 'channel one' }, | ||
| { id: 'channel:2', label: 'channel two' }, | ||
| ], | ||
| }, | ||
| ] | ||
|
|
||
| const flatData: TreeRow[] = [ | ||
| { id: 'channel:1', label: 'channel one' }, | ||
| { id: 'channel:2', label: 'channel two' }, | ||
| ] | ||
|
|
||
| describe('DataTableBulkActions selection counting', () => { | ||
| test('shows the toolbar when only a subRow of a tree table is selected (issue #6885)', () => { | ||
| render(<Harness data={treeData} initialSelection={{ 'channel:1': true }} />) | ||
|
|
||
| const toolbar = screen.getByRole('toolbar') | ||
| expect(toolbar).toHaveAccessibleName('Bulk actions for 1 selected channel') | ||
| }) | ||
|
Comment on lines
+95
to
+97
Author
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. Addressed in b32ec8f — both assertions now match the accessible name by regex ( |
||
|
|
||
| test('still shows the toolbar for a selected top-level row in a flat table', () => { | ||
| render(<Harness data={flatData} initialSelection={{ 'channel:1': true }} />) | ||
|
|
||
| const toolbar = screen.getByRole('toolbar') | ||
| expect(toolbar).toHaveAccessibleName('Bulk actions for 1 selected channel') | ||
| }) | ||
|
|
||
| test('renders nothing when no row is selected', () => { | ||
| render(<Harness data={treeData} initialSelection={{}} />) | ||
|
|
||
| expect(screen.queryByRole('toolbar')).toBeNull() | ||
| }) | ||
| }) | ||
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
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
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.
Uh oh!
There was an error while loading. Please reload this page.