Skip to content

Commit

Permalink
Merge pull request #1170 from securityscorecard/ajkl2533@UXD-1647
Browse files Browse the repository at this point in the history
feat(DatatableV2): add option to disable selection toolbar
  • Loading branch information
ajkl2533 authored Oct 14, 2024
2 parents c5539a1 + df29254 commit 1e5010d
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 1 deletion.
9 changes: 9 additions & 0 deletions src/components/DatatableV2/Datatable.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,7 @@ export interface ParsedDatatableOptions<D>
enableRowActions?: DatatableOptions<D>['enableRowActions'];
enableRowsPerPage?: DatatableOptions<D>['enableRowsPerPage'];
enableSelectAll?: DatatableOptions<D>['enableSelectAll'];
enableSelectionToolbar?: DatatableOptions<D>['enableSelectionToolbar'];
enableTopToolbar?: DatatableOptions<D>['enableTopToolbar'];
initialState?: DatatableOptions<D>['initialState'];
onShowColumnSettings?: DatatableOptions<D>['onShowColumnSettings'];
Expand Down Expand Up @@ -452,6 +453,14 @@ export interface DatatableOptions<D>
* @default true
*/
enableSelectAll?: boolean;
/**
* Enables/disables the selection toolbar with the batch action buttons. If this is set to `false`
* consumers has to control the selection state on their own as the Datatable doesn't provide other
* way how to access the interal state.
*
* @default true
*/
enableSelectionToolbar?: boolean;
/**
* Enables/disables table sorting
*
Expand Down
2 changes: 2 additions & 0 deletions src/components/DatatableV2/hooks/useOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ export const useOptions = <D>({
enableRowSelection = true,
enableRowsPerPage = false,
enableSelectAll = true,
enableSelectionToolbar = true,
enableSorting = true,
enableSortingRemoval = true,
enableTopToolbar = true,
Expand Down Expand Up @@ -80,6 +81,7 @@ export const useOptions = <D>({
enableRowSelection,
enableRowsPerPage,
enableSelectAll,
enableSelectionToolbar,
enableSorting,
enableSortingRemoval,
enableTopToolbar,
Expand Down
7 changes: 7 additions & 0 deletions src/components/DatatableV2/stories/Selection.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,13 @@ RowSelectionActions.parameters = {
screenshot: { skip: false },
};

export const DisabledSelectionToolbar: Story = Template.bind({});
DisabledSelectionToolbar.args = {
...SelectionEnabled.args,
initialState: RowSelectionActions.args.initialState,
enableSelectionToolbar: false,
};

export const SelectionManagedState: Story = (args) => {
const [rowSelection, setRowSelection] = useState<RowSelectionState>({
'e23968c3-3f19-44b2-aee9-c4a1d7c326ee': true,
Expand Down
3 changes: 2 additions & 1 deletion src/components/DatatableV2/table/TableSurface.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,8 @@ const TableSurface = <D,>({ table }: { table: DatatableInstance<D> }) => {
{table.options.enableTopToolbar && <TopToolbar table={table} />}
<Table table={table} />
</Surface>
{table.options.enableRowSelection && <Selection table={table} />}
{table.options.enableRowSelection &&
table.options.enableSelectionToolbar && <Selection table={table} />}
{table.options.enablePagination &&
table.getRowModel().rows.length > 0 && <Pagination table={table} />}
</DatatableRoot>
Expand Down

0 comments on commit 1e5010d

Please sign in to comment.