diff --git a/frontend/src/metabase/collections/containers/CollectionContent.jsx b/frontend/src/metabase/collections/containers/CollectionContent.jsx index f39657a082f52f4d8bb6f0ea123223fcadbad89b..3252fd474631023e8381f363e55df99e110110df 100644 --- a/frontend/src/metabase/collections/containers/CollectionContent.jsx +++ b/frontend/src/metabase/collections/containers/CollectionContent.jsx @@ -166,16 +166,13 @@ function CollectionContent({ const showFilters = filter || unpinnedItems.length >= MIN_ITEMS_TO_SHOW_FILTERS; - const unselected = unpinnedItems.filter( + const unselected = [...pinnedItems, ...unpinnedItems].filter( item => !getIsSelected(item), ); const hasUnselected = unselected.length > 0; const handleSelectAll = () => { - const pinnedUnselcted = pinnedItems.filter( - item => !getIsSelected(item), - ); - toggleAll([...unselected, ...pinnedUnselcted]); + toggleAll(unselected); }; return ( diff --git a/frontend/test/metabase/scenarios/collections/collections.cy.spec.js b/frontend/test/metabase/scenarios/collections/collections.cy.spec.js index 591feb2598ae5ac17ab2cd86524f46a5b381fc92..9581f062c6c3cfd34022202fe8e08667bea7efc0 100644 --- a/frontend/test/metabase/scenarios/collections/collections.cy.spec.js +++ b/frontend/test/metabase/scenarios/collections/collections.cy.spec.js @@ -583,36 +583,44 @@ describe("scenarios > collection_defaults", () => { cy.findByText("First Collection"); }); - describe("bulk actions", () => { - beforeEach(() => { - cy.visit("/collection/root"); - openEllipsisMenuFor("Orders in a dashboard"); - cy.findByText("Pin this item").click(); - }); + it("should be possible to select pinned item using checkbox (metabase#15338)", () => { + cy.visit("/collection/root"); + openEllipsisMenuFor("Orders in a dashboard"); + cy.findByText("Pin this item").click(); - it("should be possible to apply bulk selection to items (metabase#14705)", () => { - selectItemUsingCheckbox("Orders"); - cy.findByText("1 item selected").should("be.visible"); - selectItemUsingCheckbox("Orders in a dashboard", "dashboard"); - cy.findByText("2 items selected").should("be.visible"); + cy.findByText(/Pinned items/i); + selectItemUsingCheckbox("Orders in a dashboard", "dashboard"); + cy.findByText("1 item selected"); + }); - // Select all - cy.icon("dash").click(); - cy.icon("dash").should("not.exist"); - cy.findByText("4 items selected"); + describe("bulk actions", () => { + describe("selection", () => { + it("should be possible to apply bulk selection to all items (metabase#14705)", () => { + bulkSelectDeselectWorkflow(); + }); - // Deselect all - cy.findByTestId("bulk-action-bar").within(() => { - cy.icon("check").click(); + it("should be possible to apply bulk selection when all items are pinned (metabase#16497)", () => { + pinAllRootItems(); + bulkSelectDeselectWorkflow(); }); - cy.icon("check").should("not.exist"); - cy.findByTestId("bulk-action-bar").should("not.be.visible"); - }); - it("should be possible to select pinned item using checkbox (metabase#15338)", () => { - cy.findByText(/Pinned items/i); - selectItemUsingCheckbox("Orders in a dashboard", "dashboard"); - cy.findByText("1 item selected"); + function bulkSelectDeselectWorkflow() { + cy.visit("/collection/root"); + selectItemUsingCheckbox("Orders"); + cy.findByText("1 item selected").should("be.visible"); + + // Select all + cy.icon("dash").click(); + cy.icon("dash").should("not.exist"); + cy.findByText("4 items selected"); + + // Deselect all + cy.findByTestId("bulk-action-bar").within(() => { + cy.icon("check").click(); + }); + cy.icon("check").should("not.exist"); + cy.findByTestId("bulk-action-bar").should("not.be.visible"); + } }); }); }); @@ -669,3 +677,17 @@ function getSidebarCollectionChildrenFor(item) { .parent() .parent(); } + +function pinAllRootItems() { + cy.request("GET", "/api/collection/root/items").then(resp => { + const ALL_ITEMS = resp.body.data; + + ALL_ITEMS.forEach(({ model, id }, index) => { + if (model !== "collection") { + cy.request("PUT", `/api/${model}/${id}`, { + collection_position: index++, + }); + } + }); + }); +}