Skip to content

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

Remove dashboards entity (#74221)

Romeo Van Snick4697f52f5a83
diff --git a/frontend/src/metabase/collections/containers/FormCollectionAndDashboardPicker/FormCollectionAndDashboardPicker.tsx b/frontend/src/metabase/collections/containers/FormCollectionAndDashboardPicker/FormCollectionAndDashboardPicker.tsx
index 86c3e66880a..7ebf38ac0c1 100644
--- a/frontend/src/metabase/collections/containers/FormCollectionAndDashboardPicker/FormCollectionAndDashboardPicker.tsx
+++ b/frontend/src/metabase/collections/containers/FormCollectionAndDashboardPicker/FormCollectionAndDashboardPicker.tsx
@@ -6,6 +6,7 @@ import { t } from "ttag";
import {
skipToken,
useGetCollectionQuery,
+ useGetDashboardQuery,
useLazyGetDashboardQuery,
} from "metabase/api";
import {
@@ -15,6 +16,7 @@ import {
isValidCollectionId,
} from "metabase/collections/utils";
import { CollectionName } from "metabase/common/components/CollectionName";
+import { DashboardName } from "metabase/common/components/DashboardName";
import { FormField } from "metabase/common/components/FormField";
import type {
EntityPickerOptions,
@@ -30,8 +32,6 @@ import {
import { SnippetCollectionName } from "metabase/common/components/SnippetCollectionName";
import { useUniqueId } from "metabase/common/hooks/use-unique-id";
import { getCollectionIcon } from "metabase/entities/collections/utils";
-import { Dashboards } from "metabase/entities/dashboards";
-import { useSelector } from "metabase/redux";
import { Button, Flex, Icon } from "metabase/ui";
import type { CollectionId, DashboardId } from "metabase-types/api";
@@ -53,7 +53,7 @@ function ItemName({
return (
<Flex align="center" gap="sm">
<Icon name="dashboard" c="brand" />
- <Dashboards.Name id={dashboardId} />
+ <DashboardName id={dashboardId} />
</Flex>
);
}
@@ -126,10 +126,8 @@ export function FormCollectionAndDashboardPicker({
const { data: openCollection } = useGetCollectionQuery({ id: "root" });
- const selectedDashboard = useSelector((state) =>
- Dashboards.selectors.getObject(state, {
- entityId: dashboardIdInput.value,
- }),
+ const { currentData: selectedDashboard } = useGetDashboardQuery(
+ dashboardIdInput.value != null ? { id: dashboardIdInput.value } : skipToken,
);
const { data: selectedCollection } = useGetCollectionQuery(
collectionIdInput.value != null
@@ -138,7 +136,8 @@ export function FormCollectionAndDashboardPicker({
);
const selectedItem = selectedDashboard || selectedCollection;
- const namespace = selectedItem?.namespace;
+ const namespace =
+ selectedCollection?.namespace ?? selectedDashboard?.collection?.namespace;
const pickerValue: OmniPickerValue = dashboardIdInput.value
? { id: dashboardIdInput.value, model: "dashboard", namespace }
diff --git a/frontend/src/metabase/common/components/DashboardName.tsx b/frontend/src/metabase/common/components/DashboardName.tsx
new file mode 100644
index 00000000000..a513735676b
--- /dev/null
+++ b/frontend/src/metabase/common/components/DashboardName.tsx
@@ -0,0 +1,24 @@
+import { useGetDashboardQuery } from "metabase/api";
+import { useTranslateContent } from "metabase/i18n/hooks";
+import { getName } from "metabase/utils/name";
+import type { DashboardId } from "metabase-types/api";
+
+interface DashboardNameProps {
+ id: DashboardId | null | undefined;
+}
+
+export const DashboardName = ({ id }: DashboardNameProps) => {
+ if (id == null || (typeof id === "number" && isNaN(id))) {
+ return null;
+ }
+ return <FetchedDashboardName id={id} />;
+};
+
+const FetchedDashboardName = ({ id }: { id: DashboardId }) => {
+ const tc = useTranslateContent();
+ const { currentData: dashboard } = useGetDashboardQuery({ id });
+ if (!dashboard) {
+ return null;
+ }
+ return <span>{tc(getName(dashboard))}</span>;
+};
diff --git a/frontend/src/metabase/common/components/DashboardName.unit.spec.tsx b/frontend/src/metabase/common/components/DashboardName.unit.spec.tsx
new file mode 100644
index 00000000000..e694011e186
--- /dev/null
+++ b/frontend/src/metabase/common/components/DashboardName.unit.spec.tsx
@@ -0,0 +1,68 @@
+import fetchMock from "fetch-mock";
+
+import {
+ setupDashboardEndpoints,
+ setupDashboardNotFoundEndpoint,
+} from "__support__/server-mocks";
+import { renderWithProviders, screen, waitFor } from "__support__/ui";
+import { createMockDashboard } from "metabase-types/api/mocks";
+
+import { DashboardName } from "./DashboardName";
+
+const TEST_DASHBOARD = createMockDashboard({ name: "Sales overview" });
+
+const renderName = (id: Parameters<typeof DashboardName>[0]["id"]) =>
+ renderWithProviders(
+ <div data-testid="wrapper">
+ <DashboardName id={id} />
+ </div>,
+ );
+
+describe("DashboardName", () => {
+ it("renders the dashboard name returned from the API", async () => {
+ setupDashboardEndpoints(TEST_DASHBOARD);
+
+ renderName(TEST_DASHBOARD.id);
+
+ expect(await screen.findByText("Sales overview")).toBeInTheDocument();
+ });
+
+ it("renders nothing while the dashboard is loading", () => {
+ setupDashboardEndpoints(TEST_DASHBOARD);
+
+ renderName(TEST_DASHBOARD.id);
+
+ expect(screen.getByTestId("wrapper")).toBeEmptyDOMElement();
+ });
+
+ it("renders nothing when the dashboard cannot be found", async () => {
+ setupDashboardNotFoundEndpoint(TEST_DASHBOARD);
+
+ renderName(TEST_DASHBOARD.id);
+
+ await waitFor(() => {
+ expect(
+ fetchMock.callHistory.calls(`path:/api/dashboard/${TEST_DASHBOARD.id}`),
+ ).toHaveLength(1);
+ });
+ expect(screen.getByTestId("wrapper")).toBeEmptyDOMElement();
+ });
+
+ it("renders nothing when the id is null", () => {
+ renderName(null);
+
+ expect(screen.getByTestId("wrapper")).toBeEmptyDOMElement();
+ });
+
+ it("renders nothing when the id is undefined", () => {
+ renderName(undefined);
+
+ expect(screen.getByTestId("wrapper")).toBeEmptyDOMElement();
+ });
+
+ it("renders nothing when the id is NaN", () => {
+ renderName(NaN);
+
+ expect(screen.getByTestId("wrapper")).toBeEmptyDOMElement();
+ });
+});
diff --git a/frontend/src/metabase/common/hooks/entity-framework/index.ts b/frontend/src/metabase/common/hooks/entity-framework/index.ts
index 0f3f14b5499..2bdb31628e4 100644
--- a/frontend/src/metabase/common/hooks/entity-framework/index.ts
+++ b/frontend/src/metabase/common/hooks/entity-framework/index.ts
@@ -3,7 +3,6 @@
* Use "metabase/api" instead.
*/
-export * from "./use-dashboard-query";
export * from "./use-database-list-query";
export * from "./use-database-query";
export * from "./use-question-list-query";
diff --git a/frontend/src/metabase/common/hooks/entity-framework/use-dashboard-query/index.ts b/frontend/src/metabase/common/hooks/entity-framework/use-dashboard-query/index.ts
deleted file mode 100644
index a579418b8bc..00000000000
--- a/frontend/src/metabase/common/hooks/entity-framework/use-dashboard-query/index.ts
+++ /dev/null
@@ -1 +0,0 @@
-export * from "./use-dashboard-query";
diff --git a/frontend/src/metabase/common/hooks/entity-framework/use-dashboard-query/use-dashboard-query.ts b/frontend/src/metabase/common/hooks/entity-framework/use-dashboard-query/use-dashboard-query.ts
deleted file mode 100644
index f382fee29dc..00000000000
--- a/frontend/src/metabase/common/hooks/entity-framework/use-dashboard-query/use-dashboard-query.ts
+++ /dev/null
@@ -1,21 +0,0 @@
-import type {
- UseEntityQueryProps,
- UseEntityQueryResult,
-} from "metabase/common/hooks/entity-framework/use-entity-query";
-import { useEntityQuery } from "metabase/common/hooks/entity-framework/use-entity-query";
-import { Dashboards } from "metabase/entities/dashboards";
-import type { Dashboard, DashboardId } from "metabase-types/api";
-
-/**
- * @deprecated use "metabase/api" instead
- */
-export const useDashboardQuery = (
- props: UseEntityQueryProps<DashboardId, null>,
-): UseEntityQueryResult<Dashboard> => {
- return useEntityQuery(props, {
- fetch: Dashboards.actions.fetch,
- getObject: Dashboards.selectors.getObject,
- getLoading: Dashboards.selectors.getLoading,
- getError: Dashboards.selectors.getError,
- });
-};
diff --git a/frontend/src/metabase/common/hooks/entity-framework/use-dashboard-query/use-dashboard-query.unit.spec.tsx b/frontend/src/metabase/common/hooks/entity-framework/use-dashboard-query/use-dashboard-query.unit.spec.tsx
deleted file mode 100644
index 1fdd0e54bab..00000000000
--- a/frontend/src/metabase/common/hooks/entity-framework/use-dashboard-query/use-dashboard-query.unit.spec.tsx
+++ /dev/null
@@ -1,52 +0,0 @@
-import {
- setupDashboardEndpoints,
- setupDashboardNotFoundEndpoint,
-} from "__support__/server-mocks";
-import {
- renderWithProviders,
- screen,
- waitForLoaderToBeRemoved,
-} from "__support__/ui";
-import { LoadingAndErrorWrapper } from "metabase/common/components/LoadingAndErrorWrapper";
-import { createMockDashboard } from "metabase-types/api/mocks";
-
-import { useDashboardQuery } from "./use-dashboard-query";
-
-const TEST_DASHBOARD = createMockDashboard();
-
-const TestComponent = () => {
- const { data, isLoading, error } = useDashboardQuery({
- id: TEST_DASHBOARD.id,
- });
-
- if (isLoading || error) {
- return <LoadingAndErrorWrapper loading={isLoading} error={error} />;
- }
-
- return <div>{data?.name}</div>;
-};
-
-const setup = () => {
- setupDashboardEndpoints(TEST_DASHBOARD);
- renderWithProviders(<TestComponent />);
-};
-
-describe("useDashboardQuery", () => {
- it("should be initially loading", () => {
- setup();
- expect(screen.getByTestId("loading-indicator")).toBeInTheDocument();
- });
-
- it("should show data from the response", async () => {
- setup();
- await waitForLoaderToBeRemoved();
- expect(screen.getByText(TEST_DASHBOARD.name)).toBeInTheDocument();
- });
-
- it("should return an error when it can't find a dashboard", async () => {
- setupDashboardNotFoundEndpoint(TEST_DASHBOARD);
- renderWithProviders(<TestComponent />);
- await waitForLoaderToBeRemoved();
- expect(screen.getByText("An error occurred")).toBeInTheDocument();
- });
-});
diff --git a/frontend/src/metabase/dashboard/actions/save.ts b/frontend/src/metabase/dashboard/actions/save.ts
index b86c08815dc..4eff1d2ae42 100644
--- a/frontend/src/metabase/dashboard/actions/save.ts
+++ b/frontend/src/metabase/dashboard/actions/save.ts
@@ -1,8 +1,8 @@
import { assocIn, dissocIn, getIn } from "icepick";
import _ from "underscore";
-import { cardApi } from "metabase/api";
-import { Dashboards } from "metabase/entities/dashboards";
+import { cardApi, dashboardApi } from "metabase/api";
+import { entityCompatibleQuery } from "metabase/entities/utils";
import { clickBehaviorIsValid } from "metabase/parameters/utils/click-behavior";
import { createThunkAction } from "metabase/redux";
import { UPDATE_DASHBOARD_AND_CARDS } from "metabase/redux/dashboard";
@@ -191,12 +191,14 @@ export const updateDashboardAndCards = createThunkAction(
.filter((tab) => !tab.isRemoved)
.map(({ id, name }) => ({ id, name }));
- await dispatch(
- Dashboards.actions.update({
+ await entityCompatibleQuery(
+ {
...dashboard,
dashcards: dashcardsToUpdate,
tabs: tabsToUpdate,
- }),
+ },
+ dispatch,
+ dashboardApi.endpoints.updateDashboard,
);
const endTime = performance.now();
@@ -261,8 +263,10 @@ export const updateDashboard = createThunkAction(
if (attributeNames.length > 0) {
const attributes = _.pick(dashboard, attributeNames);
- await dispatch(
- Dashboards.actions.update({ id: dashboardId }, attributes),
+ await entityCompatibleQuery(
+ { id: dashboardId, ...attributes },
+ dispatch,
+ dashboardApi.endpoints.updateDashboard,
);
}
diff --git a/frontend/src/metabase/dashboard/actions/tabs.ts b/frontend/src/metabase/dashboard/actions/tabs.ts
index 69e0b5d72c0..645c3cf7dca 100644
--- a/frontend/src/metabase/dashboard/actions/tabs.ts
+++ b/frontend/src/metabase/dashboard/actions/tabs.ts
@@ -3,8 +3,8 @@ import type { Draft } from "@reduxjs/toolkit";
import { createAction, createReducer } from "@reduxjs/toolkit";
import { t } from "ttag";
+import { updateDashboard } from "metabase/api/dashboard";
import { CANCEL_EDITING_DASHBOARD } from "metabase/dashboard/actions/core";
-import { Dashboards } from "metabase/entities/dashboards";
import { INITIALIZE, selectTab } from "metabase/redux/dashboard";
import type {
DashboardState,
@@ -538,44 +538,6 @@ export const tabsReducer = createReducer<DashboardState>(
},
);
- builder.addCase(Dashboards.actionTypes.UPDATE, (state, { payload }) => {
- if (!payload.dashboard) {
- return;
- }
- const { dashcards: newDashcards, tabs: newTabs } = payload.dashboard;
-
- const { prevDash, prevTabs } = getPrevDashAndTabs({
- state,
- filterRemovedTabs: true,
- });
-
- if (!prevDash) {
- // If there's no previous version of the dashboard loaded we don't need to update
- // the IDs of dashcards and tabs. The app can't be in a state where the dashcards
- // and tabs have been updated.
- return;
- }
-
- // 1. Replace temporary with real dashcard ids
- const prevDashcardIds = prevDash.dashcards.filter(
- (id) => !state.dashcards[id].isRemoved,
- );
-
- prevDashcardIds.forEach((prevId, index) => {
- const prevDashcardData = state.dashcardData[prevId];
-
- if (prevDashcardData && newDashcards[index]?.id) {
- state.dashcardData[newDashcards[index].id] = prevDashcardData;
- }
- });
-
- // 2. Re-select the currently selected tab with its real id
- const selectedTabIndex = prevTabs.findIndex(
- (tab) => tab.id === state.selectedTabId,
- );
- state.selectedTabId = (newTabs && newTabs[selectedTabIndex]?.id) ?? null;
- });
-
builder.addCase(CANCEL_EDITING_DASHBOARD, (state) => {
const { editingDashboard, selectedTabId } = state;
const tabs = editingDashboard?.tabs ?? [];
@@ -611,5 +573,51 @@ export const tabsReducer = createReducer<DashboardState>(
state.selectedTabId = tabId;
});
+
+ builder.addMatcher(updateDashboard.matchFulfilled, (state, { payload }) => {
+ if (payload.id !== state.dashboardId) {
+ // Only react to saves for the dashboard that is currently loaded — otherwise
+ // updating an unrelated dashboard (e.g. moving/pinning from a collection) would
+ // remap dashcardData and selectedTabId using the other dashboard's data.
+ return;
+ }
+
+ const { dashcards: newDashcards, tabs: newTabs } = payload;
+
+ if (!newDashcards && !newTabs) {
+ return;
+ }
+
+ const { prevDash, prevTabs } = getPrevDashAndTabs({
+ state,
+ filterRemovedTabs: true,
+ });
+
+ if (!prevDash) {
+ // If there's no previous version of the dashboard loaded we don't need to update
+ // the IDs of dashcards and tabs. The app can't be in a state where the dashcards
+ // and tabs have been updated.
+ return;
+ }
+
+ // 1. Replace temporary with real dashcard ids
+ const prevDashcardIds = prevDash.dashcards.filter(
+ (id) => !state.dashcards[id].isRemoved,
+ );
+
+ prevDashcardIds.forEach((prevId, index) => {
+ const prevDashcardData = state.dashcardData[prevId];
+
+ if (prevDashcardData && newDashcards[index]?.id) {
+ state.dashcardData[newDashcards[index].id] = prevDashcardData;
+ }
+ });
+
+ // 2. Re-select the currently selected tab with its real id
+ const selectedTabIndex = prevTabs.findIndex(
+ (tab) => tab.id === state.selectedTabId,
+ );
+ state.selectedTabId = (newTabs && newTabs[selectedTabIndex]?.id) ?? null;
+ });
},
);
diff --git a/frontend/src/metabase/dashboard/actions/trash.ts b/frontend/src/metabase/dashboard/actions/trash.ts
index 06c6d582768..0c0934e8005 100644
--- a/frontend/src/metabase/dashboard/actions/trash.ts
+++ b/frontend/src/metabase/dashboard/actions/trash.ts
@@ -1,11 +1,12 @@
import { t } from "ttag";
import _ from "underscore";
+import { dashboardApi } from "metabase/api";
import { getTrashUndoMessage } from "metabase/archive/utils";
import { canonicalCollectionId } from "metabase/collections/utils";
import { fetchDashboard } from "metabase/dashboard/actions";
-import { Dashboards } from "metabase/entities/dashboards";
import { Questions } from "metabase/entities/questions";
+import { entityCompatibleQuery } from "metabase/entities/utils";
import { createThunkAction } from "metabase/redux";
import { addUndo } from "metabase/redux/undo";
@@ -22,8 +23,10 @@ export const setArchivedDashboard = createThunkAction(
? dashboards[dashboardId]
: { name: "Dashboard" };
- await dispatch(
- Dashboards.actions.update({ id: dashboardId }, { archived }),
+ await entityCompatibleQuery(
+ { id: dashboardId, archived },
+ dispatch,
+ dashboardApi.endpoints.updateDashboard,
);
if (!undoing) {
@@ -88,14 +91,14 @@ export const moveDashboardToCollection = createThunkAction(
const { id, archived, collection_id: current_collection_id } = dashboard;
- await dispatch(
- Dashboards.actions.update(
- { id },
- {
- collection_id: canonicalCollectionId(collection && collection.id),
- archived: forceArchive ?? false,
- },
- ),
+ await entityCompatibleQuery(
+ {
+ id,
+ collection_id: canonicalCollectionId(collection && collection.id),
+ archived: forceArchive ?? false,
+ },
+ dispatch,
+ dashboardApi.endpoints.updateDashboard,
);
if (!undoing) {
diff --git a/frontend/src/metabase/dashboard/components/ClickBehaviorSidebar/ClickBehaviorSidebar.tsx b/frontend/src/metabase/dashboard/components/ClickBehaviorSidebar/ClickBehaviorSidebar.tsx
index a4e9de348b3..0e5a0d0c857 100644
--- a/frontend/src/metabase/dashboard/components/ClickBehaviorSidebar/ClickBehaviorSidebar.tsx
+++ b/frontend/src/metabase/dashboard/components/ClickBehaviorSidebar/ClickBehaviorSidebar.tsx
@@ -2,8 +2,8 @@ import { getIn } from "icepick";
import { useCallback, useEffect, useMemo, useState } from "react";
import { useMount, usePrevious } from "react-use";
+import { skipToken, useGetDashboardQuery } from "metabase/api";
import { Sidebar } from "metabase/common/components/Sidebar";
-import { useDashboardQuery } from "metabase/common/hooks";
import {
type DashboardContextReturned,
useDashboardContext,
@@ -77,10 +77,11 @@ export function ClickBehaviorSidebarInner({
const isDashboardLink =
clickBehavior?.type === "link" && clickBehavior.linkType === "dashboard";
- const { data: targetDashboard } = useDashboardQuery({
- enabled: isDashboardLink,
- id: isDashboardLink ? clickBehavior.targetId : undefined,
- });
+ const { currentData: targetDashboard } = useGetDashboardQuery(
+ isDashboardLink && clickBehavior.targetId != null
+ ? { id: clickBehavior.targetId }
+ : skipToken,
+ );
const isValidClickBehavior = useMemo(
() => clickBehaviorIsValid(clickBehavior),
diff --git a/frontend/src/metabase/dashboard/components/ClickBehaviorSidebar/LinkOptions/LinkedEntityPicker/LinkedEntityPicker.tsx b/frontend/src/metabase/dashboard/components/ClickBehaviorSidebar/LinkOptions/LinkedEntityPicker/LinkedEntityPicker.tsx
index efa33a72717..b2b5386528a 100644
--- a/frontend/src/metabase/dashboard/components/ClickBehaviorSidebar/LinkOptions/LinkedEntityPicker/LinkedEntityPicker.tsx
+++ b/frontend/src/metabase/dashboard/components/ClickBehaviorSidebar/LinkOptions/LinkedEntityPicker/LinkedEntityPicker.tsx
@@ -3,12 +3,12 @@ import { t } from "ttag";
import { skipToken, useGetCardQuery, useGetDashboardQuery } from "metabase/api";
import { isPublicCollection } from "metabase/collections/utils";
+import { DashboardName } from "metabase/common/components/DashboardName";
import { LoadingAndErrorWrapper } from "metabase/common/components/LoadingAndErrorWrapper";
import {
DashboardPickerModal,
QuestionPickerModal,
} from "metabase/common/components/Pickers";
-import { useDashboardQuery } from "metabase/common/hooks";
import CS from "metabase/css/core/index.css";
import {
ClickMappings,
@@ -16,7 +16,6 @@ import {
} from "metabase/dashboard/components/ClickMappings";
import { getDashboard } from "metabase/dashboard/selectors";
import { ROOT_COLLECTION } from "metabase/entities/collections/constants";
-import { Dashboards } from "metabase/entities/dashboards";
import { Questions } from "metabase/entities/questions";
import { useSelector } from "metabase/redux";
import { getMetadata } from "metabase/selectors/metadata";
@@ -40,14 +39,18 @@ import S from "../LinkOptions.module.css";
const LINK_TARGETS = {
// TODO: we can probably just have one picker to pick either a question or a dashboard
question: {
- Entity: Questions,
+ Name: ({ id }: { id: CardId | DashboardId | undefined }) => (
+ <Questions.Name id={id} />
+ ),
PickerComponent: QuestionPickerModal,
pickerIcon: "bar" as const,
getModalTitle: () => t`Pick a question to link to`,
getPickerButtonLabel: () => t`Pick a question…`,
},
dashboard: {
- Entity: Dashboards,
+ Name: ({ id }: { id: CardId | DashboardId | undefined }) => (
+ <DashboardName id={id as DashboardId | undefined} />
+ ),
PickerComponent: DashboardPickerModal,
pickerIcon: "dashboard" as const,
getModalTitle: () => t`Pick a dashboard to link to`,
@@ -66,16 +69,16 @@ function PickerControl({
onCancel: () => void;
onClick?: () => void;
}) {
- const { Entity, pickerIcon, getPickerButtonLabel } =
+ const { Name, pickerIcon, getPickerButtonLabel } =
LINK_TARGETS[clickBehavior.linkType];
const renderLabel = useCallback(() => {
const hasSelectedTarget = clickBehavior.targetId != null;
if (hasSelectedTarget) {
- return <Entity.Name id={clickBehavior.targetId} />;
+ return <Name id={clickBehavior.targetId} />;
}
return getPickerButtonLabel();
- }, [Entity, clickBehavior.targetId, getPickerButtonLabel]);
+ }, [Name, clickBehavior.targetId, getPickerButtonLabel]);
return (
<Button.Group>
@@ -221,10 +224,9 @@ export function LinkedEntityPicker({
});
}, [clickBehavior, updateSettings]);
- const { data: targetDashboard } = useDashboardQuery({
- enabled: isDashboard,
- id: targetId,
- });
+ const { currentData: targetDashboard } = useGetDashboardQuery(
+ isDashboard && targetId != null ? { id: targetId } : skipToken,
+ );
const dashboardTabs = targetDashboard?.tabs ?? NO_DASHBOARD_TABS;
const defaultDashboardTabId: number | undefined = dashboardTabs[0]?.id;
const dashboardTabId = isDashboard
diff --git a/frontend/src/metabase/dashboard/components/ClickBehaviorSidebar/TableClickBehaviorView/Column.tsx b/frontend/src/metabase/dashboard/components/ClickBehaviorSidebar/TableClickBehaviorView/Column.tsx
index 5d1d74feca1..9c9bd42f6ea 100644
--- a/frontend/src/metabase/dashboard/components/ClickBehaviorSidebar/TableClickBehaviorView/Column.tsx
+++ b/frontend/src/metabase/dashboard/components/ClickBehaviorSidebar/TableClickBehaviorView/Column.tsx
@@ -1,6 +1,6 @@
import { jt, msgid, ngettext, t } from "ttag";
-import { Dashboards } from "metabase/entities/dashboards";
+import { DashboardName } from "metabase/common/components/DashboardName";
import { Questions } from "metabase/entities/questions";
import { getIconForField } from "metabase-lib/v1/metadata/utils/fields";
import type {
@@ -38,7 +38,7 @@ const getLinkTargetName = (clickBehavior: CustomDestinationClickBehavior) => {
if (clickBehavior.linkType === "dashboard") {
return (
<Quoted key="link-dashboard">
- <Dashboards.Name id={targetId} />
+ <DashboardName id={targetId} />
</Quoted>
);
}
diff --git a/frontend/src/metabase/dashboard/components/DashboardArchivedEntityBanner.tsx b/frontend/src/metabase/dashboard/components/DashboardArchivedEntityBanner.tsx
index ae769aa6ae5..a05ed66f841 100644
--- a/frontend/src/metabase/dashboard/components/DashboardArchivedEntityBanner.tsx
+++ b/frontend/src/metabase/dashboard/components/DashboardArchivedEntityBanner.tsx
@@ -1,8 +1,9 @@
-import { Api } from "metabase/api";
+import { Api, dashboardApi } from "metabase/api";
import { listTag } from "metabase/api/tags";
import { ArchivedEntityBanner } from "metabase/archive/components/ArchivedEntityBanner/ArchivedEntityBanner";
-import { Dashboards } from "metabase/entities/dashboards";
+import { entityCompatibleQuery } from "metabase/entities/utils";
import { useDispatch } from "metabase/redux";
+import type { Dispatch } from "metabase/redux/store";
import { useDashboardContext } from "../context";
@@ -40,7 +41,12 @@ export const DashboardArchivedEntityBanner = () => {
}}
onMove={({ id }) => moveDashboardToCollection({ id })}
onDeletePermanently={() => {
- const deleteAction = Dashboards.actions.delete({ id: dashboard?.id });
+ const deleteAction = (innerDispatch: Dispatch) =>
+ entityCompatibleQuery(
+ dashboard.id,
+ innerDispatch,
+ dashboardApi.endpoints.deleteDashboard,
+ );
deletePermanently(deleteAction);
}}
/>
diff --git a/frontend/src/metabase/dashboard/components/DashboardMoveModal.tsx b/frontend/src/metabase/dashboard/components/DashboardMoveModal.tsx
index f30b518e890..dbe43c91ac3 100644
--- a/frontend/src/metabase/dashboard/components/DashboardMoveModal.tsx
+++ b/frontend/src/metabase/dashboard/components/DashboardMoveModal.tsx
@@ -1,12 +1,15 @@
import { c, t } from "ttag";
-import { useGetCollectionQuery } from "metabase/api";
+import {
+ skipToken,
+ useGetCollectionQuery,
+ useGetDashboardQuery,
+} from "metabase/api";
import { Link } from "metabase/common/components/Link";
+import { LoadingAndErrorWrapper } from "metabase/common/components/LoadingAndErrorWrapper";
import { MoveModal } from "metabase/common/components/Pickers/MoveModal/MoveModal";
import { useSetCollection } from "metabase/common/hooks";
import { ROOT_COLLECTION } from "metabase/entities/collections";
-import { Dashboards } from "metabase/entities/dashboards";
-import type { State } from "metabase/redux/store";
import { Flex, Icon } from "metabase/ui";
import { color } from "metabase/ui/utils/colors";
import * as Urls from "metabase/urls";
@@ -87,7 +90,27 @@ const DashboardMoveToast = ({
);
};
-export const DashboardMoveModalConnected = Dashboards.load({
- id: (_state: State, props: { params: { slug: string } }) =>
- Urls.extractCollectionId(props.params.slug),
-})(DashboardMoveModal);
+export const DashboardMoveModalConnected = ({
+ params,
+ onClose,
+}: {
+ params: { slug: string };
+ onClose: () => void;
+}) => {
+ const id = Urls.extractCollectionId(params.slug);
+ const { currentData: dashboard, error } = useGetDashboardQuery(
+ id != null ? { id } : skipToken,
+ );
+
+ return (
+ <LoadingAndErrorWrapper
+ loading={id != null && !dashboard}
+ error={error}
+ noWrapper
+ >
+ {dashboard && (
+ <DashboardMoveModal dashboard={dashboard} onClose={onClose} />
+ )}
+ </LoadingAndErrorWrapper>
+ );
+};
diff --git a/frontend/src/metabase/dashboard/components/DashboardMoveModal.unit.spec.tsx b/frontend/src/metabase/dashboard/components/DashboardMoveModal.unit.spec.tsx
new file mode 100644
index 00000000000..8997b47189e
--- /dev/null
+++ b/frontend/src/metabase/dashboard/components/DashboardMoveModal.unit.spec.tsx
@@ -0,0 +1,96 @@
+import fetchMock from "fetch-mock";
+
+import {
+ setupCollectionByIdEndpoint,
+ setupCollectionItemsEndpoint,
+ setupCollectionsEndpoints,
+ setupDashboardEndpoints,
+ setupDashboardNotFoundEndpoint,
+ setupDatabasesEndpoints,
+ setupRecentViewsAndSelectionsEndpoints,
+ setupRootCollectionItemsEndpoint,
+} from "__support__/server-mocks";
+import {
+ mockGetBoundingClientRect,
+ renderWithProviders,
+ screen,
+} from "__support__/ui";
+import { ROOT_COLLECTION } from "metabase/entities/collections";
+import {
+ createMockCollection,
+ createMockDashboard,
+} from "metabase-types/api/mocks";
+
+import { DashboardMoveModalConnected } from "./DashboardMoveModal";
+
+const TEST_DASHBOARD = createMockDashboard({ id: 1, name: "Sales overview" });
+
+function setupPickerEndpoints() {
+ process.env.OVERSCAN = "20";
+ mockGetBoundingClientRect();
+
+ const rootCollection = createMockCollection(ROOT_COLLECTION);
+ setupRecentViewsAndSelectionsEndpoints([], ["views", "selections"]);
+ setupDatabasesEndpoints([]);
+ setupCollectionsEndpoints({ collections: [], rootCollection });
+ setupCollectionByIdEndpoint({ collections: [] });
+ setupRootCollectionItemsEndpoint({ rootCollectionItems: [] });
+ setupCollectionItemsEndpoint({
+ collection: rootCollection,
+ collectionItems: [],
+ });
+ fetchMock.get("path:/api/search", { data: [] });
+ fetchMock.get("path:/api/user/recipients", { data: [] });
+}
+
+const setup = ({
+ slug = "1-sales-overview",
+ onClose = jest.fn(),
+}: {
+ slug?: string;
+ onClose?: () => void;
+} = {}) => {
+ renderWithProviders(
+ <DashboardMoveModalConnected params={{ slug }} onClose={onClose} />,
+ );
+
+ return { onClose };
+};
+
+describe("DashboardMoveModalConnected", () => {
+ it("fetches the dashboard from the slug and renders the move modal", async () => {
+ setupPickerEndpoints();
+ setupDashboardEndpoints(TEST_DASHBOARD);
+
+ setup();
+
+ expect(await screen.findByText("Move dashboard to…")).toBeInTheDocument();
+ });
+
+ it("shows a loading spinner while the dashboard is loading", () => {
+ setupPickerEndpoints();
+ setupDashboardEndpoints(TEST_DASHBOARD);
+
+ setup();
+
+ expect(screen.queryByText("Move dashboard to…")).not.toBeInTheDocument();
+ expect(screen.getByTestId("loading-indicator")).toBeInTheDocument();
+ });
+
+ it("shows an error and does not render the modal when the dashboard cannot be found", async () => {
+ setupPickerEndpoints();
+ setupDashboardNotFoundEndpoint(TEST_DASHBOARD);
+
+ setup();
+
+ expect(await screen.findByText("An error occurred")).toBeInTheDocument();
+ expect(screen.queryByText("Move dashboard to…")).not.toBeInTheDocument();
+ });
+
+ it("renders nothing when the slug has no id", () => {
+ setup({ slug: "" });
+
+ expect(screen.queryByText("Move dashboard to…")).not.toBeInTheDocument();
+ expect(screen.queryByTestId("loading-indicator")).not.toBeInTheDocument();
+ });
+});
diff --git a/frontend/src/metabase/dashboard/containers/ArchiveDashboardModal.tsx b/frontend/src/metabase/dashboard/containers/ArchiveDashboardModal.tsx
index d3f49857eba..24b20aa7207 100644
--- a/frontend/src/metabase/dashboard/containers/ArchiveDashboardModal.tsx
+++ b/frontend/src/metabase/dashboard/containers/ArchiveDashboardModal.tsx
@@ -3,9 +3,10 @@ import { type WithRouterProps, withRouter } from "react-router";
import { t } from "ttag";
import _ from "underscore";
+import { skipToken, useGetDashboardQuery } from "metabase/api";
import { ArchiveModal } from "metabase/common/components/ArchiveModal";
+import { LoadingAndErrorWrapper } from "metabase/common/components/LoadingAndErrorWrapper";
import { setArchivedDashboard } from "metabase/dashboard/actions";
-import { Dashboards } from "metabase/entities/dashboards";
import { useDispatch } from "metabase/redux";
import * as Urls from "metabase/urls";
import type { Dashboard } from "metabase-types/api";
@@ -14,10 +15,9 @@ type OwnProps = {
onClose: () => void;
};
-type ArchiveDashboardModalProps = OwnProps &
- WithRouterProps & {
- dashboard: Dashboard;
- };
+type ArchiveDashboardModalProps = OwnProps & {
+ dashboard: Dashboard;
+};
const ArchiveDashboardModal = ({
onClose,
@@ -56,10 +56,27 @@ const ArchiveDashboardModal = ({
);
};
-export const ArchiveDashboardModalConnected = _.compose(
- Dashboards.load({
- id: (_state: unknown, props: WithRouterProps) =>
- Urls.extractCollectionId(props.params?.slug),
- }),
- withRouter,
-)(ArchiveDashboardModal);
+export const ArchiveDashboardModalConnectedInner = (
+ props: OwnProps & WithRouterProps,
+) => {
+ const id = Urls.extractCollectionId(props.params?.slug);
+ const { currentData: dashboard, error } = useGetDashboardQuery(
+ id != null ? { id } : skipToken,
+ );
+
+ return (
+ <LoadingAndErrorWrapper
+ loading={id != null && !dashboard}
+ error={error}
+ noWrapper
+ >
+ {dashboard && (
+ <ArchiveDashboardModal onClose={props.onClose} dashboard={dashboard} />
+ )}
+ </LoadingAndErrorWrapper>
+ );
+};
+
+export const ArchiveDashboardModalConnected = withRouter(
+ ArchiveDashboardModalConnectedInner,
+);
diff --git a/frontend/src/metabase/dashboard/containers/ArchiveDashboardModal.unit.spec.tsx b/frontend/src/metabase/dashboard/containers/ArchiveDashboardModal.unit.spec.tsx
new file mode 100644
index 00000000000..d0d765b0be0
--- /dev/null
+++ b/frontend/src/metabase/dashboard/containers/ArchiveDashboardModal.unit.spec.tsx
@@ -0,0 +1,72 @@
+import type { WithRouterProps } from "react-router";
+
+import {
+ setupDashboardEndpoints,
+ setupDashboardNotFoundEndpoint,
+} from "__support__/server-mocks";
+import { renderWithProviders, screen } from "__support__/ui";
+import { createMockDashboard } from "metabase-types/api/mocks";
+
+import { ArchiveDashboardModalConnectedInner } from "./ArchiveDashboardModal";
+
+const TEST_DASHBOARD = createMockDashboard({ id: 1, name: "Sales overview" });
+
+const setup = ({
+ slug = "1-sales-overview",
+ onClose = jest.fn(),
+}: {
+ slug?: string;
+ onClose?: () => void;
+} = {}) => {
+ const props = {
+ onClose,
+ params: { slug },
+ } as unknown as WithRouterProps & { onClose: () => void };
+
+ renderWithProviders(<ArchiveDashboardModalConnectedInner {...props} />);
+
+ return { onClose };
+};
+
+describe("ArchiveDashboardModalConnected", () => {
+ it("fetches the dashboard from the slug and renders the archive modal", async () => {
+ setupDashboardEndpoints(TEST_DASHBOARD);
+
+ setup();
+
+ expect(
+ await screen.findByText("Move this dashboard to trash?"),
+ ).toBeInTheDocument();
+ });
+
+ it("shows a loading spinner while the dashboard is loading", () => {
+ setupDashboardEndpoints(TEST_DASHBOARD);
+
+ setup();
+
+ expect(screen.getByTestId("loading-indicator")).toBeInTheDocument();
+ expect(
+ screen.queryByText("Move this dashboard to trash?"),
+ ).not.toBeInTheDocument();
+ });
+
+ it("shows an error and does not render the modal when the dashboard cannot be found", async () => {
+ setupDashboardNotFoundEndpoint(TEST_DASHBOARD);
+
+ setup();
+
+ expect(await screen.findByText("An error occurred")).toBeInTheDocument();
+ expect(
+ screen.queryByText("Move this dashboard to trash?"),
+ ).not.toBeInTheDocument();
+ });
+
+ it("renders nothing when the slug has no id", () => {
+ setup({ slug: "" });
+
+ expect(screen.queryByTestId("loading-indicator")).not.toBeInTheDocument();
+ expect(
+ screen.queryByText("Move this dashboard to trash?"),
+ ).not.toBeInTheDocument();
+ });
+});
diff --git a/frontend/src/metabase/dashboard/hooks/use-click-behavior-data.ts b/frontend/src/metabase/dashboard/hooks/use-click-behavior-data.ts
index 0e53b932172..ea274234a0f 100644
--- a/frontend/src/metabase/dashboard/hooks/use-click-behavior-data.ts
+++ b/frontend/src/metabase/dashboard/hooks/use-click-behavior-data.ts
@@ -11,7 +11,6 @@ import {
getParameterValuesBySlugMap,
getParameters,
} from "metabase/dashboard/selectors";
-import { Dashboards } from "metabase/entities/dashboards";
import { Questions } from "metabase/entities/questions";
import { useStore } from "metabase/redux";
import type { State } from "metabase/redux/store";
@@ -30,15 +29,6 @@ type EntityObject = {
};
type LinkedEntityTarget = {
- entity: {
- name: string;
- selectors: {
- getObject: (
- state: State,
- opts: { entityId: number | string | undefined },
- ) => unknown;
- };
- };
entityType: "question" | "dashboard";
entityId: number | string | undefined;
};
@@ -48,11 +38,10 @@ function isEntityObject(value: unknown): value is EntityObject {
}
function resolveLinkedObject(target: LinkedEntityTarget, state: State) {
- const object = target.entity.selectors.getObject(state, {
- entityId: target.entityId,
- });
-
if (target.entityType === "question") {
+ const object = Questions.selectors.getObject(state, {
+ entityId: target.entityId,
+ });
if (object instanceof Question) {
const card = object.card();
return isEntityObject(card) ? card : null;
@@ -60,7 +49,9 @@ function resolveLinkedObject(target: LinkedEntityTarget, state: State) {
return null;
}
- return isEntityObject(object) ? object : null;
+ const dashboard =
+ target.entityId != null ? state.entities.dashboards[target.entityId] : null;
+ return isEntityObject(dashboard) ? dashboard : null;
}
function getEntitiesByTypeAndId(
@@ -76,7 +67,8 @@ function getEntitiesByTypeAndId(
return acc;
}
- const entityName = target.entity.name;
+ const entityName =
+ target.entityType === "question" ? "questions" : "dashboards";
const bucket = acc[entityName] ?? {};
bucket[linkedObject.id] = linkedObject;
acc[entityName] = bucket;
@@ -163,7 +155,6 @@ function mapLinkedEntityToEntityQuery({
targetId: EntityCustomDestinationClickBehavior["targetId"];
}) {
return {
- entity: linkType === "question" ? Questions : Dashboards,
entityType: linkType,
entityId: targetId,
};
diff --git a/frontend/src/metabase/dashboard/reducers-typed.ts b/frontend/src/metabase/dashboard/reducers-typed.ts
index 7578b382e7e..ae072aa7db0 100644
--- a/frontend/src/metabase/dashboard/reducers-typed.ts
+++ b/frontend/src/metabase/dashboard/reducers-typed.ts
@@ -9,7 +9,6 @@ import {
updateDashboardEmbeddingParams,
updateDashboardEnableEmbedding,
} from "metabase/api";
-import { Dashboards } from "metabase/entities/dashboards";
import { Questions } from "metabase/entities/questions";
import { handleActions } from "metabase/redux";
import {
@@ -319,13 +318,6 @@ export const dashboards = createReducer(
const dashcardIds = dashcards.map(({ id }) => id);
state[dashboard_id].dashcards.push(...dashcardIds);
})
- .addCase(Dashboards.actionTypes.UPDATE, (state, { payload }) => {
- const draftDashboard = state[payload.dashboard?.id];
- if (draftDashboard) {
- draftDashboard.collection_id = payload.dashboard.collection_id;
- draftDashboard.collection = payload.dashboard.collection;
- }
- })
.addMatcher(updateDashboard.matchFulfilled, (state, { payload }) => {
const draftDashboard = state[payload.id];
if (draftDashboard) {
diff --git a/frontend/src/metabase/entities/containers/EntityName.unit.spec.tsx b/frontend/src/metabase/entities/containers/EntityName.unit.spec.tsx
index cd9a5239f74..b015d01efc4 100644
--- a/frontend/src/metabase/entities/containers/EntityName.unit.spec.tsx
+++ b/frontend/src/metabase/entities/containers/EntityName.unit.spec.tsx
@@ -1,35 +1,11 @@
-import {
- setupCardEndpoints,
- setupDashboardEndpoints,
-} from "__support__/server-mocks";
+import { setupCardEndpoints } from "__support__/server-mocks";
import { createMockEntitiesState } from "__support__/store";
import { renderWithProviders, screen } from "__support__/ui";
-import { createMockCard, createMockDashboard } from "metabase-types/api/mocks";
+import { createMockCard } from "metabase-types/api/mocks";
import { EntityName } from "./EntityName";
describe("EntityName", () => {
- describe("dashboards", () => {
- test("dashboard with name", async () => {
- const mockDash = createMockDashboard({
- name: "Testy dash dash",
- });
- setupDashboardEndpoints(mockDash);
-
- renderWithProviders(
- <EntityName entityType="dashboards" entityId={mockDash.id} />,
- {
- storeInitialState: {
- entities: createMockEntitiesState({
- dashboards: [mockDash],
- }),
- },
- },
- );
- expect(await screen.findByText("Testy dash dash")).toBeInTheDocument();
- });
- });
-
describe("questions", () => {
test("question with name (metabase#33192)", async () => {
const expectedQuestionName = "Mock Products question";
diff --git a/frontend/src/metabase/entities/containers/rtk-query/types/entities.ts b/frontend/src/metabase/entities/containers/rtk-query/types/entities.ts
index f6a605fe9d7..a507bd702d8 100644
--- a/frontend/src/metabase/entities/containers/rtk-query/types/entities.ts
+++ b/frontend/src/metabase/entities/containers/rtk-query/types/entities.ts
@@ -37,7 +37,6 @@ export type ReloadIntervalSelector<Entity> = (
export type EntityType =
| "alerts"
| "bookmarks"
- | "dashboards"
| "databases"
| "documents"
| "fields"
diff --git a/frontend/src/metabase/entities/dashboards.js b/frontend/src/metabase/entities/dashboards.js
deleted file mode 100644
index 5a67bfebf8f..00000000000
--- a/frontend/src/metabase/entities/dashboards.js
+++ /dev/null
@@ -1,90 +0,0 @@
-import { t } from "ttag";
-
-import {
- dashboardApi,
- useGetDashboardQuery,
- useListDashboardsQuery,
-} from "metabase/api/dashboard";
-import { getCollectionType } from "metabase/entities/collections/utils";
-
-import { createEntity, entityCompatibleQuery } from "./utils";
-
-/**
- * @deprecated use "metabase/api" instead
- */
-export const Dashboards = createEntity({
- name: "dashboards",
- nameOne: "dashboard",
- path: "/api/dashboard",
-
- // eslint-disable-next-line ttag/no-module-declaration -- see metabase#55045
- displayNameOne: t`dashboard`,
- // eslint-disable-next-line ttag/no-module-declaration -- see metabase#55045
- displayNameMany: t`dashboards`,
-
- rtk: () => ({
- getUseGetQuery: () => ({
- useGetQuery: useGetDashboardQuery,
- }),
- useListQuery: useListDashboardsQuery,
- }),
-
- api: {
- list: (entityQuery, dispatch) =>
- entityCompatibleQuery(
- entityQuery,
- dispatch,
- dashboardApi.endpoints.listDashboards,
- ),
- get: (entityQuery, options, dispatch) =>
- entityCompatibleQuery(
- { ...entityQuery, ignore_error: options?.noEvent },
- dispatch,
- dashboardApi.endpoints.getDashboard,
- ),
- create: (entityQuery, dispatch) =>
- entityCompatibleQuery(
- entityQuery,
- dispatch,
- dashboardApi.endpoints.createDashboard,
- ),
- update: (entityQuery, dispatch) =>
- entityCompatibleQuery(
- entityQuery,
- dispatch,
- dashboardApi.endpoints.updateDashboard,
- ),
- delete: ({ id }, dispatch) =>
- entityCompatibleQuery(
- id,
- dispatch,
- dashboardApi.endpoints.deleteDashboard,
- ),
- save: (entityQuery, dispatch) =>
- entityCompatibleQuery(
- entityQuery,
- dispatch,
- dashboardApi.endpoints.saveDashboard,
- ),
- },
-
- actions: {
- save: (dashboard) => async (dispatch) => {
- const savedDashboard = await entityCompatibleQuery(
- dashboard,
- dispatch,
- dashboardApi.endpoints.saveDashboard,
- );
- dispatch({ type: Dashboards.actionTypes.INVALIDATE_LISTS_ACTION });
- return {
- type: "metabase/entities/dashboards/SAVE_DASHBOARD",
- payload: savedDashboard,
- };
- },
- },
-
- getAnalyticsMetadata([object], { action }, getState) {
- const type = object && getCollectionType(object.collection_id, getState());
- return type && `collection=${type}`;
- },
-});
diff --git a/frontend/src/metabase/entities/index.ts b/frontend/src/metabase/entities/index.ts
index 0d9fb620b72..2367ca8092f 100644
--- a/frontend/src/metabase/entities/index.ts
+++ b/frontend/src/metabase/entities/index.ts
@@ -68,7 +68,6 @@
* )(BookContainer);
*/
-export { Dashboards as dashboards } from "./dashboards";
export { Questions as questions } from "./questions";
export { Databases as databases } from "./databases";
diff --git a/frontend/src/metabase/entities/utils.ts b/frontend/src/metabase/entities/utils.ts
index 4fba9a8df60..8d1958f5426 100644
--- a/frontend/src/metabase/entities/utils.ts
+++ b/frontend/src/metabase/entities/utils.ts
@@ -974,6 +974,7 @@ type CombinedEntities = {
*/
const RETIRED_ENTITY_NAMES = [
"collections",
+ "dashboards",
"measures",
"metrics",
"schemas",
diff --git a/frontend/src/metabase/questions/components/MoveCardModal/MoveCardModal.tsx b/frontend/src/metabase/questions/components/MoveCardModal/MoveCardModal.tsx
index 4d045f1deec..ebdc54a51a4 100644
--- a/frontend/src/metabase/questions/components/MoveCardModal/MoveCardModal.tsx
+++ b/frontend/src/metabase/questions/components/MoveCardModal/MoveCardModal.tsx
@@ -12,9 +12,9 @@ import {
getEntityTypeFromCardType,
} from "metabase/collections/utils";
import { ConfirmModal } from "metabase/common/components/ConfirmModal";
+import { DashboardName } from "metabase/common/components/DashboardName";
import type { OmniPickerCollectionItem } from "metabase/common/components/Pickers";
import { MoveModal } from "metabase/common/components/Pickers";
-import { Dashboards } from "metabase/entities/dashboards";
import { INJECT_RTK_QUERY_QUESTION_VALUE } from "metabase/entities/questions";
import { useDispatch } from "metabase/redux";
import { API_UPDATE_QUESTION } from "metabase/redux/query-builder";
@@ -168,7 +168,7 @@ export const MoveCardModal = ({ card, onClose }: MoveCardModalProps) => {
style={{ marginBottom: -2 }}
size={20}
/>{" "}
- <Dashboards.Name key="name" id={card.dashboard_id} />
+ <DashboardName key="name" id={card.dashboard_id} />
</>
)}?`}
</Title>
@@ -219,7 +219,7 @@ export const MoveCardModal = ({ card, onClose }: MoveCardModalProps) => {
style={{ marginBottom: -2 }}
size={20}
/>{" "}
- <Dashboards.Name key="name" id={card.dashboard_id} />
+ <DashboardName key="name" id={card.dashboard_id} />
</>
)}`}
</Title>
diff --git a/frontend/src/metabase/redux/user.ts b/frontend/src/metabase/redux/user.ts
index 032e4456848..e072504a857 100644
--- a/frontend/src/metabase/redux/user.ts
+++ b/frontend/src/metabase/redux/user.ts
@@ -1,6 +1,6 @@
import { createAction, createReducer } from "@reduxjs/toolkit";
-import { Dashboards } from "metabase/entities/dashboards";
+import { updateDashboard } from "metabase/api/dashboard";
import { CLOSE_QB_NEWB_MODAL } from "metabase/redux/query-builder";
import { createAsyncThunk } from "metabase/redux/utils";
import { UserApi } from "metabase/services";
@@ -49,13 +49,11 @@ export const currentUser = createReducer<User | null>(null, (builder) => {
}
return state;
})
- .addCase(Dashboards.actionTypes.UPDATE, (state, { payload }) => {
- const { dashboard } = payload;
+ .addMatcher(updateDashboard.matchFulfilled, (state, { payload }) => {
if (
- dashboard &&
state != null &&
- state.custom_homepage?.dashboard_id === dashboard.id &&
- dashboard.archived
+ state.custom_homepage?.dashboard_id === payload.id &&
+ payload.archived
) {
state.custom_homepage = null;
}
diff --git a/frontend/src/metabase/reference/selectors.js b/frontend/src/metabase/reference/selectors.js
index 2f48e92e270..91b9dddfb4c 100644
--- a/frontend/src/metabase/reference/selectors.js
+++ b/frontend/src/metabase/reference/selectors.js
@@ -1,8 +1,6 @@
import { createSelector } from "@reduxjs/toolkit";
import { getIn } from "icepick";
-import _ from "underscore";
-import { Dashboards } from "metabase/entities/dashboards";
import {
getShallowDatabases as getDatabases,
getShallowFields as getFields,
@@ -111,8 +109,3 @@ export const getIsEditing = (state, props) => state.reference.isEditing;
export const getIsFormulaExpanded = (state, props) =>
state.reference.isFormulaExpanded;
-
-export const getDashboards = (state, props) => {
- const list = Dashboards.selectors.getList(state);
- return list && _.indexBy(list, "id");
-};