mirror of
https://github.com/portainer/portainer.git
synced 2025-07-19 13:29:41 +02:00
chore(deps): upgrade react-table to v8 [EE-4837] (#8245)
This commit is contained in:
parent
f20d3e72b9
commit
757461d58b
140 changed files with 1805 additions and 2872 deletions
67
app/react/components/datatables/select-column.tsx
Normal file
67
app/react/components/datatables/select-column.tsx
Normal file
|
@ -0,0 +1,67 @@
|
|||
import { ColumnDef, Row } from '@tanstack/react-table';
|
||||
|
||||
import { Checkbox } from '@@/form-components/Checkbox';
|
||||
|
||||
export function createSelectColumn<T>(): ColumnDef<T> {
|
||||
let lastSelectedId = '';
|
||||
|
||||
return {
|
||||
id: 'select',
|
||||
header: ({ table }) => (
|
||||
<Checkbox
|
||||
id="select-all"
|
||||
checked={table.getIsAllRowsSelected()}
|
||||
indeterminate={table.getIsSomeRowsSelected()}
|
||||
onChange={table.getToggleAllRowsSelectedHandler()}
|
||||
/>
|
||||
),
|
||||
cell: ({ row, table }) => (
|
||||
<Checkbox
|
||||
id={`select-row-${row.id}`}
|
||||
checked={row.getIsSelected()}
|
||||
indeterminate={row.getIsSomeSelected()}
|
||||
onChange={row.getToggleSelectedHandler()}
|
||||
onClick={(e) => {
|
||||
if (e.shiftKey) {
|
||||
const { rows, rowsById } = table.getRowModel();
|
||||
const rowsToToggle = getRowRange(rows, row.id, lastSelectedId);
|
||||
const isLastSelected = rowsById[lastSelectedId].getIsSelected();
|
||||
rowsToToggle.forEach((row) => row.toggleSelected(isLastSelected));
|
||||
}
|
||||
|
||||
lastSelectedId = row.id;
|
||||
}}
|
||||
/>
|
||||
),
|
||||
meta: {
|
||||
width: 50,
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
function getRowRange<T>(rows: Array<Row<T>>, idA: string, idB: string) {
|
||||
const range: Array<Row<T>> = [];
|
||||
let foundStart = false;
|
||||
let foundEnd = false;
|
||||
for (let index = 0; index < rows.length; index += 1) {
|
||||
const row = rows[index];
|
||||
if (row.id === idA || row.id === idB) {
|
||||
if (foundStart) {
|
||||
foundEnd = true;
|
||||
}
|
||||
if (!foundStart) {
|
||||
foundStart = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (foundStart) {
|
||||
range.push(row);
|
||||
}
|
||||
|
||||
if (foundEnd) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return range;
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue