Skip to content
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

fix: datagrid select all behavior in virtual scroll #6546

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@
import { TableSelectAll } from '@carbon/react';
import cx from 'classnames';
import { pkg } from '../../../settings';
import { handleOnPageSelectAllRowData } from './addons/stateReducer';
import {
handleOnPageSelectAllRowData,
handleSelectAllRowData,
} from './addons/stateReducer';
import { DataGridState, DataGridToggleAllRowsProps } from '../types';

const blockClass = `${pkg.prefix}--datagrid`;
Expand Down Expand Up @@ -41,6 +44,8 @@
dispatch,
rows,
getRowId,
toggleAllRowsSelected,
withVirtualScroll,
onAllRowSelect,
} = datagridState;
const isFirstColumnStickyLeft =
Expand Down Expand Up @@ -75,6 +80,33 @@
return onChange?.(event);
};

const handleSelectAllChange = (event) => {
if (indeterminate) {
handleSelectAllRowData({

Check warning on line 85 in packages/ibm-products/src/components/Datagrid/Datagrid/DatagridSelectAll.tsx

View check run for this annotation

Codecov / codecov/patch

packages/ibm-products/src/components/Datagrid/Datagrid/DatagridSelectAll.tsx#L84-L85

Added lines #L84 - L85 were not covered by tests
dispatch,
rows,
getRowId,
indeterminate: true,
isChecked: undefined,
});
toggleAllRowsSelected(false);
onAllRowSelect?.(rows, event);

Check warning on line 93 in packages/ibm-products/src/components/Datagrid/Datagrid/DatagridSelectAll.tsx

View check run for this annotation

Codecov / codecov/patch

packages/ibm-products/src/components/Datagrid/Datagrid/DatagridSelectAll.tsx#L92-L93

Added lines #L92 - L93 were not covered by tests

return onChange?.({

Check warning on line 95 in packages/ibm-products/src/components/Datagrid/Datagrid/DatagridSelectAll.tsx

View check run for this annotation

Codecov / codecov/patch

packages/ibm-products/src/components/Datagrid/Datagrid/DatagridSelectAll.tsx#L95

Added line #L95 was not covered by tests
target: { checked: false },
} as any);
}
handleSelectAllRowData({

Check warning on line 99 in packages/ibm-products/src/components/Datagrid/Datagrid/DatagridSelectAll.tsx

View check run for this annotation

Codecov / codecov/patch

packages/ibm-products/src/components/Datagrid/Datagrid/DatagridSelectAll.tsx#L99

Added line #L99 was not covered by tests
dispatch,
rows,
getRowId,
isChecked: event.target.checked,
indeterminate,
});
onAllRowSelect?.(rows, event);
return onChange?.(event);

Check warning on line 107 in packages/ibm-products/src/components/Datagrid/Datagrid/DatagridSelectAll.tsx

View check run for this annotation

Codecov / codecov/patch

packages/ibm-products/src/components/Datagrid/Datagrid/DatagridSelectAll.tsx#L106-L107

Added lines #L106 - L107 were not covered by tests
};

return (
<TableSelectAll
{...selectProps}
Expand All @@ -89,7 +121,9 @@
}
)}
name={`${tableId}-select-all-checkbox-name`}
onSelect={handleOnPageSelectAllChange}
onSelect={
withVirtualScroll ? handleSelectAllChange : handleOnPageSelectAllChange
}
disabled={isFetching || selectProps?.disabled}
id={`${tableId}-select-all-checkbox-id`}
/>
Expand Down
Loading