Skip to content

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

Fix: allow moving dashboard questions to their parent collection (#71550)

Nathan Voxland6a7e27195f88
diff --git a/frontend/src/metabase/common/components/Pickers/MoveModal/MoveModal.tsx b/frontend/src/metabase/common/components/Pickers/MoveModal/MoveModal.tsx
index d91d442534c..a42a67fe48a 100644
--- a/frontend/src/metabase/common/components/Pickers/MoveModal/MoveModal.tsx
+++ b/frontend/src/metabase/common/components/Pickers/MoveModal/MoveModal.tsx
@@ -346,7 +346,7 @@ export const BulkMoveModal = ({
);
};
-const isSameDestination = (
+export const isSameDestination = (
movingItem: OmniPickerCollectionItem,
movingTarget: OmniPickerCollectionItem,
) => {
@@ -359,6 +359,7 @@ const isSameDestination = (
if (
movingTarget.model === "collection" &&
+ !movingItem.dashboard_id &&
movingItem.collection?.id === movingTarget.id
) {
return true;
diff --git a/frontend/src/metabase/common/components/Pickers/MoveModal/MoveModal.unit.spec.ts b/frontend/src/metabase/common/components/Pickers/MoveModal/MoveModal.unit.spec.ts
new file mode 100644
index 00000000000..151967bb952
--- /dev/null
+++ b/frontend/src/metabase/common/components/Pickers/MoveModal/MoveModal.unit.spec.ts
@@ -0,0 +1,67 @@
+import type { OmniPickerCollectionItem } from "../EntityPicker";
+
+import { isSameDestination } from "./MoveModal";
+
+const makeItem = (
+ overrides: Partial<OmniPickerCollectionItem> = {},
+): OmniPickerCollectionItem =>
+ ({
+ id: 1,
+ name: "Test Item",
+ model: "card" as const,
+ ...overrides,
+ }) as OmniPickerCollectionItem;
+
+describe("isSameDestination", () => {
+ it("should return true when moving to same dashboard", () => {
+ const movingItem = makeItem({
+ dashboard_id: 10,
+ collection: { id: 7, name: "Collection 1", authority_level: null },
+ });
+ const movingTarget = makeItem({ model: "dashboard" as any, id: 10 });
+ expect(isSameDestination(movingItem, movingTarget)).toBe(true);
+ });
+
+ it("should return true when moving a regular item to its own collection", () => {
+ const movingItem = makeItem({
+ collection: { id: 7, name: "Collection 1", authority_level: null },
+ });
+ const movingTarget = makeItem({
+ model: "collection" as any,
+ id: 7,
+ });
+ expect(isSameDestination(movingItem, movingTarget)).toBe(true);
+ });
+
+ it("should return false when moving to a different collection", () => {
+ const movingItem = makeItem({
+ collection: { id: 7, name: "Collection 1", authority_level: null },
+ });
+ const movingTarget = makeItem({
+ model: "collection" as any,
+ id: 99,
+ });
+ expect(isSameDestination(movingItem, movingTarget)).toBe(false);
+ });
+
+ it("should allow moving a dashboard question to the collection where the dashboard lives", () => {
+ const movingItem = makeItem({
+ dashboard_id: 10,
+ collection: { id: 7, name: "Collection 1", authority_level: null },
+ });
+ const movingTarget = makeItem({
+ model: "collection" as any,
+ id: 7,
+ });
+ expect(isSameDestination(movingItem, movingTarget)).toBe(false);
+ });
+
+ it("should return false when moving to a different dashboard", () => {
+ const movingItem = makeItem({
+ dashboard_id: 10,
+ collection: { id: 7, name: "Collection 1", authority_level: null },
+ });
+ const movingTarget = makeItem({ model: "dashboard" as any, id: 20 });
+ expect(isSameDestination(movingItem, movingTarget)).toBe(false);
+ });
+});