Skip to content

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

Add a step to show fk tables in publish flow from Library (#72875)

Nick Fitzpatrick97f04b57f12f
diff --git a/e2e/test/scenarios/data-studio/data-studio-library.cy.spec.ts b/e2e/test/scenarios/data-studio/data-studio-library.cy.spec.ts
index a1f93d6d4ce..7bd5e9da681 100644
--- a/e2e/test/scenarios/data-studio/data-studio-library.cy.spec.ts
+++ b/e2e/test/scenarios/data-studio/data-studio-library.cy.spec.ts
@@ -130,6 +130,8 @@ describe("scenarios > data studio > library", () => {
select: true,
});
+ H.modal().button("Publish this table").click();
+
cy.log("Verify the table is published");
H.DataStudio.Tables.overviewPage().should("exist");
H.DataStudio.Tables.header().findByDisplayValue("Orders").should("exist");
@@ -217,6 +219,7 @@ describe("scenarios > data studio > library", () => {
H.entityPickerModalItem(1, "Sample Database").click();
H.entityPickerModalItem(2, "Orders").click();
H.entityPickerModal().button("Publish").click();
+ H.modal().button("Publish this table").click();
cy.log("Navigate back to Library via breadcrumbs");
H.DataStudio.breadcrumbs().findByRole("link", { name: "Data" }).click();
diff --git a/enterprise/frontend/src/metabase-enterprise/data-studio/library/LibraryPage/PublishTableModal.tsx b/enterprise/frontend/src/metabase-enterprise/data-studio/library/LibraryPage/PublishTableModal.tsx
index f6c8dbfdbeb..3e32e6620c5 100644
--- a/enterprise/frontend/src/metabase-enterprise/data-studio/library/LibraryPage/PublishTableModal.tsx
+++ b/enterprise/frontend/src/metabase-enterprise/data-studio/library/LibraryPage/PublishTableModal.tsx
@@ -1,3 +1,4 @@
+import { useState } from "react";
import { t } from "ttag";
import {
@@ -5,10 +6,8 @@ import {
type OmniPickerItem,
type OmniPickerTableItem,
} from "metabase/common/components/Pickers";
-import { trackDataStudioTablePublished } from "metabase/data-studio/analytics";
-import { useMetadataToasts } from "metabase/metadata/hooks/useMetadataToasts";
-import { usePublishTablesMutation } from "metabase-enterprise/api/table";
-import { isConcreteTableId } from "metabase-types/api";
+
+import { PublishTablesModal } from "../components/PublishTablesModal";
interface PublishTableModalProps {
opened: boolean;
@@ -24,20 +23,31 @@ export function PublishTableModal({
onClose,
onPublished,
}: PublishTableModalProps) {
- const { sendSuccessToast } = useMetadataToasts();
- const [publishTables] = usePublishTablesMutation();
+ const [selectedTable, setSelectedTable] =
+ useState<OmniPickerTableItem | null>(null);
- const onConfirm = async (item: OmniPickerItem) => {
+ const handlePickerConfirm = (item: OmniPickerItem) => {
if (!isTableItem(item)) {
return;
}
- await publishTables({ table_ids: [item.id] }).unwrap(); // unwrap() allows EntityPicker's error handling to take over
+ setSelectedTable(item);
+ };
+
+ const handleClose = () => {
+ setSelectedTable(null);
onClose();
- sendSuccessToast(t`Published`);
- if (isConcreteTableId(item.id)) {
- trackDataStudioTablePublished(item.id);
+ };
+
+ const handlePublish = () => {
+ if (selectedTable) {
+ setSelectedTable(null);
+ onClose();
+ onPublished(selectedTable);
}
- onPublished(item);
+ };
+
+ const handlePublishModalClose = () => {
+ setSelectedTable(null);
};
if (!opened) {
@@ -47,6 +57,17 @@ export function PublishTableModal({
const shouldDisableItem = (item: OmniPickerItem) =>
item.model === "table" && "is_published" in item && !!item.is_published;
+ if (selectedTable) {
+ return (
+ <PublishTablesModal
+ isOpened
+ tableIds={[selectedTable.id]}
+ onPublish={handlePublish}
+ onClose={handlePublishModalClose}
+ />
+ );
+ }
+
return (
<EntityPickerModal
title={t`Select a table to publish`}
@@ -61,8 +82,8 @@ export function PublishTableModal({
confirmButtonText: t`Publish`,
}}
isDisabledItem={shouldDisableItem}
- onChange={onConfirm}
- onClose={onClose}
+ onChange={handlePickerConfirm}
+ onClose={handleClose}
/>
);
}
diff --git a/enterprise/frontend/src/metabase-enterprise/data-studio/library/LibraryPage/PublishTableModal.unit.spec.tsx b/enterprise/frontend/src/metabase-enterprise/data-studio/library/LibraryPage/PublishTableModal.unit.spec.tsx
new file mode 100644
index 00000000000..69e548758e2
--- /dev/null
+++ b/enterprise/frontend/src/metabase-enterprise/data-studio/library/LibraryPage/PublishTableModal.unit.spec.tsx
@@ -0,0 +1,133 @@
+import userEvent from "@testing-library/user-event";
+
+import {
+ setupPublishTablesEndpoint,
+ setupTableSelectionInfoEndpoint,
+} from "__support__/server-mocks";
+import { renderWithProviders, screen, waitFor } from "__support__/ui";
+import type { OmniPickerItem } from "metabase/common/components/Pickers";
+import type { BulkTableSelectionInfo } from "metabase-types/api";
+import {
+ createMockBulkTableInfo,
+ createMockBulkTableSelectionInfo,
+} from "metabase-types/api/mocks";
+
+import { PublishTableModal } from "./PublishTableModal";
+
+jest.mock("metabase/common/components/Pickers/EntityPicker", () => ({
+ ...jest.requireActual(
+ "metabase/common/components/Pickers/EntityPicker/types",
+ ),
+ EntityPickerModal: ({
+ onChange,
+ onClose,
+ }: {
+ onChange: (item: OmniPickerItem) => void;
+ onClose: () => void;
+ }) => (
+ <div data-testid="entity-picker-modal">
+ <button
+ onClick={() =>
+ onChange({
+ model: "table",
+ id: 1,
+ name: "ORDERS",
+ database_id: 1,
+ } as OmniPickerItem)
+ }
+ >
+ Select Orders
+ </button>
+ <button onClick={onClose}>Close picker</button>
+ </div>
+ ),
+}));
+
+interface SetupOpts {
+ opened?: boolean;
+ selectionInfo?: BulkTableSelectionInfo;
+}
+
+function setup({
+ opened = true,
+ selectionInfo = createMockBulkTableSelectionInfo({
+ selected_table: createMockBulkTableInfo({
+ id: 1,
+ display_name: "Orders",
+ }),
+ }),
+}: SetupOpts = {}) {
+ const onClose = jest.fn();
+ const onPublished = jest.fn();
+
+ setupTableSelectionInfoEndpoint(selectionInfo);
+ setupPublishTablesEndpoint();
+
+ renderWithProviders(
+ <PublishTableModal
+ opened={opened}
+ onClose={onClose}
+ onPublished={onPublished}
+ />,
+ );
+
+ return { onClose, onPublished };
+}
+
+describe("PublishTableModal", () => {
+ it("should show the entity picker initially", () => {
+ setup();
+ expect(screen.getByTestId("entity-picker-modal")).toBeInTheDocument();
+ });
+
+ it("should show the publish confirmation modal after selecting a table and call onClose and onPublished on publish", async () => {
+ const { onClose, onPublished } = setup();
+ await userEvent.click(screen.getByText("Select Orders"));
+ expect(await screen.findByText("Publish Orders?")).toBeInTheDocument();
+ await userEvent.click(screen.getByText("Publish this table"));
+ await waitFor(() => expect(onPublished).toHaveBeenCalled());
+ expect(onClose).toHaveBeenCalled();
+ });
+
+ it("should show FK remapping warning when table has unpublished upstream tables", async () => {
+ setup({
+ selectionInfo: createMockBulkTableSelectionInfo({
+ selected_table: createMockBulkTableInfo({
+ id: 1,
+ display_name: "Orders",
+ }),
+ unpublished_upstream_tables: [
+ createMockBulkTableInfo({
+ id: 2,
+ display_name: "Products",
+ }),
+ createMockBulkTableInfo({
+ id: 3,
+ display_name: "People",
+ }),
+ ],
+ }),
+ });
+ await userEvent.click(screen.getByText("Select Orders"));
+ expect(
+ await screen.findByText("Publish Orders and the tables it depends on?"),
+ ).toBeInTheDocument();
+ expect(screen.getByText("Products")).toBeInTheDocument();
+ expect(screen.getByText("People")).toBeInTheDocument();
+ });
+
+ it("should return to picker when publish modal is closed", async () => {
+ setup();
+ await userEvent.click(screen.getByText("Select Orders"));
+ expect(await screen.findByText("Publish Orders?")).toBeInTheDocument();
+
+ await userEvent.click(screen.getByText("Cancel"));
+ expect(screen.getByTestId("entity-picker-modal")).toBeInTheDocument();
+ });
+
+ it("should call onClose when entity picker is closed", async () => {
+ const { onClose } = setup();
+ await userEvent.click(screen.getByText("Close picker"));
+ expect(onClose).toHaveBeenCalled();
+ });
+});