Skip to content

Commit 5817b81

Browse files
authored
fix(ui): selection status not updating after toggleAll in useSelection hook (#11218)
### What? After clicking "Select all" `toggleAll(true)`, manually deselecting an item does not update the overall selection status. The bulk actions remain visible, and `selectAll` incorrectly stays as `AllAvailable`. ### How? Updated `setSelection()` logic to adjust `selectAll` when deselecting an item if it was previously set to `AllAvailable`. This ensures that the selection state updates correctly without altering the effect logic. `selectAll` switches to Some when an item is deselected after selecting all. Bulk actions now hide correctly if no items are selected. Fixes #10836
1 parent 847d8d8 commit 5817b81

File tree

3 files changed

+19
-7
lines changed

3 files changed

+19
-7
lines changed

packages/ui/src/providers/Selection/index.tsx

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -93,17 +93,16 @@ export const SelectionProvider: React.FC<Props> = ({ children, docs = [], totalD
9393
const existingValue = selected.get(id)
9494
const isSelected = typeof existingValue === 'boolean' ? !existingValue : true
9595

96-
let newMap = new Map()
96+
const newMap = new Map(selected.set(id, isSelected))
9797

98-
if (isSelected) {
99-
newMap = new Map(selected.set(id, isSelected))
100-
} else {
101-
newMap = new Map(selected.set(id, false))
98+
// If previously selected all and now deselecting, adjust status
99+
if (selectAll === SelectAllStatus.AllAvailable && !isSelected) {
100+
setSelectAll(SelectAllStatus.Some)
102101
}
103102

104103
setSelected(newMap)
105104
},
106-
[selected, docs, user?.id],
105+
[selected, docs, selectAll, user?.id],
107106
)
108107

109108
const getQueryParams = useCallback(

test/admin/e2e/general/e2e.spec.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -868,6 +868,20 @@ describe('General', () => {
868868
await expect(page.locator('.row-1 .cell-title')).toContainText(updatedPostTitle)
869869
})
870870

871+
test('should update selection state after deselecting item following select all', async () => {
872+
await deleteAllPosts()
873+
await createPost({ title: 'Post 1' })
874+
await page.goto(postsUrl.list)
875+
await page.locator('input#select-all').check()
876+
await page.locator('button.list-selection__button').click()
877+
878+
// Deselect the first row
879+
await page.locator('.row-1 input').click()
880+
881+
// eslint-disable-next-line jest-dom/prefer-checked
882+
await expect(page.locator('input#select-all')).not.toHaveAttribute('checked', '')
883+
})
884+
871885
test('should save globals', async () => {
872886
await page.goto(postsUrl.global(globalSlug))
873887

test/admin/payload-types.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,6 @@ export interface Config {
6464
auth: {
6565
users: UserAuthOperations;
6666
};
67-
blocks: {};
6867
collections: {
6968
uploads: Upload;
7069
posts: Post;

0 commit comments

Comments
 (0)