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

[IndexTable] Allow paginatedSelectAllAction to be visible without having to provide bulkActions prop #11670

Merged
merged 3 commits into from
Feb 29, 2024
Merged
Show file tree
Hide file tree
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
5 changes: 5 additions & 0 deletions .changeset/breezy-beers-explode.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@shopify/polaris': patch
---

Updated IndexTable so that no bulk actions are required to see the paginated select all text
Original file line number Diff line number Diff line change
Expand Up @@ -1075,6 +1075,7 @@ export function WithSelectionAndNoBulkActions() {
allResourcesSelected ? 'All' : selectedResources.length
}
onSelectionChange={handleSelectionChange}
hasMoreItems
headings={[
{title: 'Name'},
{title: 'Location'},
Expand Down
7 changes: 1 addition & 6 deletions polaris-react/src/components/IndexTable/IndexTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -461,11 +461,6 @@ function IndexTableBase({
);
}, [tableInitialized, resizeTableScrollBar, condensed]);

const hasBulkActions = Boolean(
(promotedBulkActions && promotedBulkActions.length > 0) ||
(bulkActions && bulkActions.length > 0),
);

const headingsMarkup = headings
.map(renderHeading)
.reduce<JSX.Element[]>((acc, heading) => acc.concat(heading), []);
Expand Down Expand Up @@ -1125,7 +1120,7 @@ function IndexTableBase({
}

function getPaginatedSelectAllAction() {
if (!selectable || !hasBulkActions || !hasMoreItems) {
if (!selectable || !hasMoreItems) {
return;
}

Expand Down
21 changes: 21 additions & 0 deletions polaris-react/src/components/IndexTable/tests/IndexTable.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -426,6 +426,27 @@ describe('<IndexTable>', () => {
expect(index.find(BulkActions)).toContainReactText(customString);
});

it('does not need the bulkActions or promotedBulkActions props present to render the custom select all string', () => {
const onSelectionChangeSpy = jest.fn();
const customString = 'Foo bar baz';
const index = mountWithApp(
<IndexTable
{...defaultProps}
selectable
hasMoreItems
selectedItemsCount={1}
itemCount={2}
bulkActions={undefined}
promotedBulkActions={undefined}
onSelectionChange={onSelectionChangeSpy}
paginatedSelectAllActionText={customString}
>
{mockTableItems.map(mockRenderRow)}
</IndexTable>,
);
expect(index.find(BulkActions)).toContainReactText(customString);
});

it('toggles all page resources when onToggleAll is triggered', () => {
const onSelectionChangeSpy = jest.fn();
const index = mountWithApp(
Expand Down
Loading