The easy-to-use open source Business Intelligence and Embedded Analytics tool that lets everyone work with data :bar_chart:
TypeScript analyticsbibusiness-intelligencebusinessintelligenceclojuredashboarddatadata-analysisdata-visualizationdatabasemetabasemysqlpostgrespostgresqlreportingslacksql-editorvisualization
show a warning message when removing items from the library (#65169)
Nick Fitzpatrickfdac82dba2d4
diff --git a/enterprise/frontend/src/metabase-enterprise/remote_sync/components/ChangesLists/AllChangesView.tsx b/enterprise/frontend/src/metabase-enterprise/remote_sync/components/ChangesLists/AllChangesView.tsxindex 2e3dba9b3fb..5156142255e 100644--- a/enterprise/frontend/src/metabase-enterprise/remote_sync/components/ChangesLists/AllChangesView.tsx+++ b/enterprise/frontend/src/metabase-enterprise/remote_sync/components/ChangesLists/AllChangesView.tsx@@ -1,8 +1,18 @@import { Fragment, useMemo } from "react";+import { t } from "ttag";import _ from "underscore";import { useListCollectionsTreeQuery } from "metabase/api";-import { Box, Divider, Group, Icon, Paper, Stack, Title } from "metabase/ui";+import {+ Box,+ Divider,+ Group,+ Icon,+ Paper,+ Stack,+ Text,+ Title,+} from "metabase/ui";import {buildCollectionMap,getCollectionPathSegments,@@ -46,6 +56,14 @@ export const AllChangesView = ({return map;}, [collectionTree, collections]);+ const hasRemovals = useMemo(() => {+ return (+ entities.findIndex((e) =>+ ["removed", "delete"].includes(e.sync_status),+ ) >= 0+ );+ }, [entities]);+const groupedData = useMemo(() => {const byCollection = _.groupBy(entities, (e) => e.collection_id || 0);@@ -150,6 +168,14 @@ export const AllChangesView = ({))}</Stack></Paper>+ {hasRemovals && (+ <Text+ c="error"+ fz="sm"+ lh="sm"+ mt="sm"+ >{t`Other instances using this library may have items that depend on the items you're removing.`}</Text>+ )}</Box>);};diff --git a/enterprise/frontend/src/metabase-enterprise/remote_sync/components/ChangesLists/AllChangesView.unit.spec.tsx b/enterprise/frontend/src/metabase-enterprise/remote_sync/components/ChangesLists/AllChangesView.unit.spec.tsxnew file mode 100644index 00000000000..0aee34ac216--- /dev/null+++ b/enterprise/frontend/src/metabase-enterprise/remote_sync/components/ChangesLists/AllChangesView.unit.spec.tsx@@ -0,0 +1,61 @@+import fetchMock from "fetch-mock";++import { renderWithProviders, screen } from "__support__/ui";+import type { RemoteSyncEntity } from "metabase-types/api";+import { createMockCollection } from "metabase-types/api/mocks";+import { createMockRemoteSyncEntity } from "metabase-types/api/mocks/remote-sync";++import { AllChangesView } from "./AllChangesView";++const updatedEntity = createMockRemoteSyncEntity({+ collection_id: 1,+});+const removedEntity = createMockRemoteSyncEntity({+ id: 2,+ name: "Removed Question",+ sync_status: "removed",+ collection_id: 1,+});+const deletedEntity = createMockRemoteSyncEntity({+ id: 3,+ name: "Deleted Question",+ sync_status: "delete",+ collection_id: 1,+});++const setup = ({+ entities = [updatedEntity],+}: {+ entities: RemoteSyncEntity[];+}) => {+ const collections = [createMockCollection({ name: "Entity Collection" })];++ fetchMock.get("/api/collection/tree", collections);+ renderWithProviders(+ <AllChangesView entities={entities} collections={collections} />,+ );+};++describe("AllChangesView", () => {+ describe("warning message", () => {+ it("should show a warning when removing entities", () => {+ setup({ entities: [updatedEntity, removedEntity] });++ expect(screen.getByText(/that depend on the items/)).toBeInTheDocument();+ });++ it("should show a warning when deleting entities", () => {+ setup({ entities: [updatedEntity, deletedEntity] });++ expect(screen.getByText(/that depend on the items/)).toBeInTheDocument();+ });++ it("should not show a warning when no items have been removed or deleted", () => {+ setup({ entities: [updatedEntity] });++ expect(+ screen.queryByText(/that depend on the items/),+ ).not.toBeInTheDocument();+ });+ });+});diff --git a/frontend/src/metabase-types/api/mocks/remote-sync.ts b/frontend/src/metabase-types/api/mocks/remote-sync.tsnew file mode 100644index 00000000000..349434f9f96--- /dev/null+++ b/frontend/src/metabase-types/api/mocks/remote-sync.ts@@ -0,0 +1,14 @@+import type { RemoteSyncEntity } from "../remote-sync";++export const createMockRemoteSyncEntity = (+ opts?: Partial<RemoteSyncEntity>,+): RemoteSyncEntity => ({+ id: 1,+ name: "My Question",+ description: null,+ created_at: "2015-01-01T20:10:30.200",+ updated_at: "2015-01-01T20:10:30.200",+ model: "card",+ sync_status: "update",+ ...opts,+});