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
This commit is contained in:
@@ -93,17 +93,16 @@ export const SelectionProvider: React.FC<Props> = ({ children, docs = [], totalD
|
|||||||
const existingValue = selected.get(id)
|
const existingValue = selected.get(id)
|
||||||
const isSelected = typeof existingValue === 'boolean' ? !existingValue : true
|
const isSelected = typeof existingValue === 'boolean' ? !existingValue : true
|
||||||
|
|
||||||
let newMap = new Map()
|
const newMap = new Map(selected.set(id, isSelected))
|
||||||
|
|
||||||
if (isSelected) {
|
// If previously selected all and now deselecting, adjust status
|
||||||
newMap = new Map(selected.set(id, isSelected))
|
if (selectAll === SelectAllStatus.AllAvailable && !isSelected) {
|
||||||
} else {
|
setSelectAll(SelectAllStatus.Some)
|
||||||
newMap = new Map(selected.set(id, false))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
setSelected(newMap)
|
setSelected(newMap)
|
||||||
},
|
},
|
||||||
[selected, docs, user?.id],
|
[selected, docs, selectAll, user?.id],
|
||||||
)
|
)
|
||||||
|
|
||||||
const getQueryParams = useCallback(
|
const getQueryParams = useCallback(
|
||||||
|
|||||||
@@ -868,6 +868,20 @@ describe('General', () => {
|
|||||||
await expect(page.locator('.row-1 .cell-title')).toContainText(updatedPostTitle)
|
await expect(page.locator('.row-1 .cell-title')).toContainText(updatedPostTitle)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
test('should update selection state after deselecting item following select all', async () => {
|
||||||
|
await deleteAllPosts()
|
||||||
|
await createPost({ title: 'Post 1' })
|
||||||
|
await page.goto(postsUrl.list)
|
||||||
|
await page.locator('input#select-all').check()
|
||||||
|
await page.locator('button.list-selection__button').click()
|
||||||
|
|
||||||
|
// Deselect the first row
|
||||||
|
await page.locator('.row-1 input').click()
|
||||||
|
|
||||||
|
// eslint-disable-next-line jest-dom/prefer-checked
|
||||||
|
await expect(page.locator('input#select-all')).not.toHaveAttribute('checked', '')
|
||||||
|
})
|
||||||
|
|
||||||
test('should save globals', async () => {
|
test('should save globals', async () => {
|
||||||
await page.goto(postsUrl.global(globalSlug))
|
await page.goto(postsUrl.global(globalSlug))
|
||||||
|
|
||||||
|
|||||||
@@ -64,7 +64,6 @@ export interface Config {
|
|||||||
auth: {
|
auth: {
|
||||||
users: UserAuthOperations;
|
users: UserAuthOperations;
|
||||||
};
|
};
|
||||||
blocks: {};
|
|
||||||
collections: {
|
collections: {
|
||||||
uploads: Upload;
|
uploads: Upload;
|
||||||
posts: Post;
|
posts: Post;
|
||||||
|
|||||||
Reference in New Issue
Block a user