Skip to content

The easy-to-use open source Business Intelligence and Embedded Analytics tool that lets everyone work with data :bar_chart:

Fix: Bookmark list is not updated when you archive a collection containing a bookmarked item (#67148)

github-actions[bot]4120da5c4e1b
diff --git a/e2e/test/scenarios/organization/bookmarks-collection.cy.spec.js b/e2e/test/scenarios/organization/bookmarks-collection.cy.spec.js
index f137afdc380..832b6a6076f 100644
--- a/e2e/test/scenarios/organization/bookmarks-collection.cy.spec.js
+++ b/e2e/test/scenarios/organization/bookmarks-collection.cy.spec.js
@@ -74,6 +74,46 @@ describe("scenarios > organization > bookmarks > collection", () => {
bookmarkThenArchive("Orders in a dashboard");
});
+ it("should update bookmarks list when restoring a collection containing bookmarked items (metabase#44499)", () => {
+ const collectionName = "First collection";
+ const questionName = "Orders in First Collection";
+
+ // Create a question in the collection and bookmark it
+ H.createQuestion({
+ name: questionName,
+ query: { "source-table": STATIC_ORDERS_ID },
+ collection_id: FIRST_COLLECTION_ID,
+ }).then(({ body: { id: questionId } }) => {
+ cy.request("POST", `/api/bookmark/card/${questionId}`);
+ });
+
+ H.visitCollection("root");
+
+ // Verify bookmark appears in sidebar
+ H.navigationSidebar()
+ .findByRole("section", { name: "Bookmarks" })
+ .should("contain", questionName);
+
+ // Archive the collection
+ H.openCollectionItemMenu(collectionName);
+ H.popover().findByTextEnsureVisible("Move to trash").click();
+
+ // The bookmarked question should be removed from bookmarks
+ H.navigationSidebar()
+ .findByRole("section", { name: "Bookmarks" })
+ .should("not.exist");
+
+ // Restore the collection
+ cy.visit("/trash");
+ H.openCollectionItemMenu(collectionName);
+ H.popover().findByTextEnsureVisible("Restore").click();
+
+ // The bookmarked question should reappear in bookmarks
+ H.navigationSidebar()
+ .findByRole("section", { name: "Bookmarks" })
+ .should("contain", questionName);
+ });
+
it("can remove bookmark from item in sidebar", () => {
H.visitCollection(ADMIN_PERSONAL_COLLECTION_ID);
diff --git a/frontend/src/metabase/api/collection.ts b/frontend/src/metabase/api/collection.ts
index ad5a7a6239e..9f4f9039ab9 100644
--- a/frontend/src/metabase/api/collection.ts
+++ b/frontend/src/metabase/api/collection.ts
@@ -102,11 +102,19 @@ export const collectionApi = Api.injectEndpoints({
body,
}),
invalidatesTags: (_, error, payload) => {
- return invalidateTags(error, [
+ const tags = [
listTag("collection"),
idTag("collection", payload.id),
idTag("collection", payload.parent_id ?? "root"),
- ]);
+ ];
+
+ // When archiving/restoring a collection, invalidate bookmarks
+ // since items within the collection may be bookmarked
+ if ("archived" in payload) {
+ tags.push(listTag("bookmark"));
+ }
+
+ return invalidateTags(error, tags);
},
}),
deleteCollection: builder.mutation<void, DeleteCollectionRequest>({