From 28b222fffacf4a030aedadd3496d5ef91a431505 Mon Sep 17 00:00:00 2001 From: James Player Date: Wed, 12 Mar 2025 10:34:07 +1300 Subject: [PATCH] fix(app): Make sure empty tables don't have select all rows checkbox checked (#489) --- app/react/components/datatables/Datatable.test.tsx | 3 +++ app/react/components/datatables/select-column.tsx | 3 ++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/app/react/components/datatables/Datatable.test.tsx b/app/react/components/datatables/Datatable.test.tsx index 5664a3ed6..67ff85f70 100644 --- a/app/react/components/datatables/Datatable.test.tsx +++ b/app/react/components/datatables/Datatable.test.tsx @@ -155,6 +155,9 @@ describe('Datatable', () => { ); expect(screen.getByText('No data available')).toBeInTheDocument(); + const selectAllCheckbox: HTMLInputElement = + screen.getByLabelText('Select all rows'); + expect(selectAllCheckbox.checked).toBe(false); }); it('selects/deselects only page rows when select all is clicked', () => { diff --git a/app/react/components/datatables/select-column.tsx b/app/react/components/datatables/select-column.tsx index 46329588a..2e4a04272 100644 --- a/app/react/components/datatables/select-column.tsx +++ b/app/react/components/datatables/select-column.tsx @@ -3,7 +3,8 @@ import { ColumnDef, Row, Table } from '@tanstack/react-table'; import { Checkbox } from '@@/form-components/Checkbox'; function allRowsSelected(table: Table) { - return table.getCoreRowModel().rows.every((row) => row.getIsSelected()); + const { rows } = table.getCoreRowModel(); + return rows.length > 0 && rows.every((row) => row.getIsSelected()); } function someRowsSelected(table: Table) {