2023-05-02 06:42:16 +00:00
|
|
|
import { ColumnDef } from '@tanstack/react-table';
|
2022-11-22 12:16:34 +00:00
|
|
|
|
2024-05-15 05:26:23 +00:00
|
|
|
import { CollapseExpandButton } from '../CollapseExpandButton';
|
2022-11-22 12:16:34 +00:00
|
|
|
|
2023-09-04 09:33:07 +00:00
|
|
|
import { DefaultType } from './types';
|
|
|
|
|
|
|
|
export function buildExpandColumn<T extends DefaultType>(): ColumnDef<T> {
|
2022-11-22 12:16:34 +00:00
|
|
|
return {
|
|
|
|
id: 'expand',
|
2023-05-02 06:42:16 +00:00
|
|
|
header: ({ table }) => {
|
2023-08-13 17:09:40 +00:00
|
|
|
const hasExpandableItems = table.getCanSomeRowsExpand();
|
2022-11-22 12:16:34 +00:00
|
|
|
|
|
|
|
return (
|
|
|
|
hasExpandableItems && (
|
2024-05-15 05:26:23 +00:00
|
|
|
<CollapseExpandButton
|
|
|
|
isExpanded={table.getIsAllRowsExpanded()}
|
2023-05-02 06:42:16 +00:00
|
|
|
onClick={table.getToggleAllRowsExpandedHandler()}
|
2024-04-11 00:11:38 +00:00
|
|
|
data-cy="expand-all-rows-button"
|
2024-05-15 05:26:23 +00:00
|
|
|
aria-label={
|
|
|
|
table.getIsAllRowsExpanded()
|
|
|
|
? 'Collapse all rows'
|
|
|
|
: 'Expand all rows'
|
|
|
|
}
|
2022-11-22 12:16:34 +00:00
|
|
|
/>
|
|
|
|
)
|
|
|
|
);
|
|
|
|
},
|
2023-05-02 06:42:16 +00:00
|
|
|
cell: ({ row }) =>
|
|
|
|
row.getCanExpand() && (
|
2024-05-15 05:26:23 +00:00
|
|
|
<CollapseExpandButton
|
|
|
|
isExpanded={row.getIsExpanded()}
|
|
|
|
onClick={row.getToggleExpandedHandler()}
|
2024-04-11 00:11:38 +00:00
|
|
|
data-cy={`expand-row-button_${row.index}`}
|
2023-05-02 06:42:16 +00:00
|
|
|
/>
|
|
|
|
),
|
|
|
|
enableColumnFilter: false,
|
|
|
|
enableGlobalFilter: false,
|
|
|
|
enableHiding: false,
|
|
|
|
meta: {
|
|
|
|
width: 40,
|
|
|
|
},
|
2022-11-22 12:16:34 +00:00
|
|
|
};
|
|
|
|
}
|