Skip to content

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

Move the query-action plug to querying and re-tier actions to platform (#79428)

Fraser9bed0e2f998f
diff --git a/frontend/lint/shared-tiers.mjs b/frontend/lint/shared-tiers.mjs
index d218279729a..1ea92e5f6c8 100644
--- a/frontend/lint/shared-tiers.mjs
+++ b/frontend/lint/shared-tiers.mjs
@@ -44,19 +44,18 @@ const SHARED_UTILS_LEVELS = [
];
const SHARED_PLATFORM_LEVELS = [
- // P0 — the data grid, a rendering primitive visualizations builds on.
- ["shared/data-grid"],
+ // P0 — independent peers: the data grid and writeback actions.
+ ["shared/data-grid", "shared/actions"],
// P1 — independent peers: chart rendering and database metadata/forms.
["shared/visualizations", "shared/databases"],
- // P2 — query editing and subscription editing compose visualizations;
- // querying and pulse have no edges between them.
+ // P2 — query editing and subscription editing compose visualizations.
+ // Querying and pulse have no edges between them.
["shared/querying", "shared/pulse"],
- // P3 — building blocks over querying; mutually independent.
+ // P3 — building blocks over querying, mutually independent.
["shared/metadata", "shared/parameters", "shared/questions"],
];
const SHARED_DOMAIN = [
- "shared/actions",
"shared/comments",
"shared/custom-viz",
"shared/detail-view",
diff --git a/frontend/src/metabase/visualizations/components/ObjectDetail/DeleteObjectModal.tsx b/frontend/src/metabase/actions/components/DeleteObjectModal/DeleteObjectModal.tsx
similarity index 96%
rename from frontend/src/metabase/visualizations/components/ObjectDetail/DeleteObjectModal.tsx
rename to frontend/src/metabase/actions/components/DeleteObjectModal/DeleteObjectModal.tsx
index 2445c021b0a..902ea442af8 100644
--- a/frontend/src/metabase/visualizations/components/ObjectDetail/DeleteObjectModal.tsx
+++ b/frontend/src/metabase/actions/components/DeleteObjectModal/DeleteObjectModal.tsx
@@ -8,11 +8,9 @@ import { useToast } from "metabase/common/hooks/use-toast";
import { Button } from "metabase/ui";
import type { WritebackActionId } from "metabase-types/api";
-import type { ObjectId } from "./types";
-
interface Props {
actionId: WritebackActionId | undefined;
- objectId: ObjectId | undefined;
+ objectId: number | string | null | undefined;
onClose: () => void;
onSuccess: () => void;
}
diff --git a/frontend/src/metabase/actions/components/DeleteObjectModal/index.ts b/frontend/src/metabase/actions/components/DeleteObjectModal/index.ts
new file mode 100644
index 00000000000..59c0f11a301
--- /dev/null
+++ b/frontend/src/metabase/actions/components/DeleteObjectModal/index.ts
@@ -0,0 +1 @@
+export { DeleteObjectModal } from "./DeleteObjectModal";
diff --git a/frontend/src/metabase/actions/containers/ActionCreator/ActionContext/QueryActionContextProvider/index.ts b/frontend/src/metabase/actions/containers/ActionCreator/ActionContext/QueryActionContextProvider/index.ts
deleted file mode 100644
index eeaba0bcc16..00000000000
--- a/frontend/src/metabase/actions/containers/ActionCreator/ActionContext/QueryActionContextProvider/index.ts
+++ /dev/null
@@ -1,3 +0,0 @@
-// eslint-disable-next-line import/no-default-export -- deprecated usage
-export { default } from "./QueryActionContextProvider";
-export * from "./QueryActionContextProvider";
diff --git a/frontend/src/metabase/actions/containers/ActionCreator/ActionContext/index.ts b/frontend/src/metabase/actions/containers/ActionCreator/ActionContext/index.ts
index e09f0ca1a86..d51f178dd76 100644
--- a/frontend/src/metabase/actions/containers/ActionCreator/ActionContext/index.ts
+++ b/frontend/src/metabase/actions/containers/ActionCreator/ActionContext/index.ts
@@ -1,3 +1,3 @@
-// eslint-disable-next-line import/no-default-export -- deprecated usage
-export { default } from "./ActionContextProvider";
-export { useActionContext } from "./ActionContext";
+export { ActionContext, useActionContext } from "./ActionContext";
+export type { ActionContextType } from "./ActionContext";
+export type { ActionContextProviderProps, EditorBodyProps } from "./types";
diff --git a/frontend/src/metabase/actions/containers/ActionCreator/ActionCreator.tsx b/frontend/src/metabase/actions/containers/ActionCreator/ActionCreator.tsx
index f644064e631..f620cb8acc4 100644
--- a/frontend/src/metabase/actions/containers/ActionCreator/ActionCreator.tsx
+++ b/frontend/src/metabase/actions/containers/ActionCreator/ActionCreator.tsx
@@ -1,71 +1,43 @@
import { useState } from "react";
import { t } from "ttag";
-import {
- skipToken,
- useCreateActionMutation,
- useGetActionQuery,
- useGetCardQuery,
- useListDatabasesQuery,
- useUpdateActionMutation,
-} from "metabase/api";
+import { useCreateActionMutation, useUpdateActionMutation } from "metabase/api";
import { LeaveRouteConfirmModal } from "metabase/common/components/LeaveConfirmModal";
import { useBeforeUnload } from "metabase/common/hooks/use-before-unload";
import { useCallbackEffect } from "metabase/common/hooks/use-callback-effect";
import { useToast } from "metabase/common/hooks/use-toast";
-import { connect, useSelector } from "metabase/redux";
-import type { State } from "metabase/redux/store";
-import { getMetadata } from "metabase/selectors/metadata";
import { Modal } from "metabase/ui";
import type Question from "metabase-lib/v1/Question";
-import type Metadata from "metabase-lib/v1/metadata/Metadata";
-import type {
- CardId,
- DatabaseId,
- WritebackAction,
- WritebackActionId,
-} from "metabase-types/api";
+import type { WritebackAction } from "metabase-types/api";
import { isSavedAction } from "../../utils";
-import ActionContext, { useActionContext } from "./ActionContext";
+import { useActionContext } from "./ActionContext";
import ActionCreatorView from "./ActionCreatorView";
import type { FormValues as CreateActionFormValues } from "./CreateActionForm";
import CreateActionForm from "./CreateActionForm";
+import type { DataReferenceSlot } from "./types";
-interface OwnProps {
- actionId?: WritebackActionId;
- modelId?: CardId;
- databaseId?: DatabaseId;
-
- action?: WritebackAction;
+export interface ActionCreatorProps {
+ model?: Question;
/**
* Whether the creator is mounted as its own route. A routed creator guards
* leaving with `LeaveRouteConfirmModal`; an inline one only has `beforeunload`.
*/
isRouted?: boolean;
+ dataReference: DataReferenceSlot;
onSubmit?: (action: WritebackAction) => void;
onClose?: () => void;
}
-interface ModelLoaderProps {
- model?: Question;
-}
-
-interface StateProps {
- metadata: Metadata;
-}
-
-export type ActionCreatorProps = OwnProps;
-
-type Props = OwnProps & ModelLoaderProps & StateProps;
-
-const mapStateToProps = (state: State) => ({
- metadata: getMetadata(state),
-});
-
-function ActionCreator({ model, onSubmit, onClose, isRouted }: Props) {
+export function ActionCreator({
+ model,
+ isRouted,
+ dataReference,
+ onSubmit,
+ onClose,
+}: ActionCreatorProps) {
const [createAction] = useCreateActionMutation();
const [updateAction] = useUpdateActionMutation();
const [sendToast] = useToast();
@@ -166,6 +138,7 @@ function ActionCreator({ model, onSubmit, onClose, isRouted }: Props) {
canSave={canSave}
isNew={isNew}
isEditable={isEditable}
+ dataReference={dataReference}
onChangeAction={handleActionChange}
onChangeFormSettings={handleFormSettingsChange}
onClickSave={handleClickSave}
@@ -195,41 +168,3 @@ function ActionCreator({ model, onSubmit, onClose, isRouted }: Props) {
</>
);
}
-
-function ActionCreatorWithContext({
- metadata,
- databaseId,
- action,
- ...props
-}: OwnProps & StateProps) {
- useListDatabasesQuery();
- useGetCardQuery(props.modelId != null ? { id: props.modelId } : skipToken);
- const model = useSelector((state) =>
- props.modelId != null
- ? (getMetadata(state).question(props.modelId) ?? undefined)
- : undefined,
- );
- const { data: initialAction } = useGetActionQuery(
- props.actionId != null ? { id: props.actionId } : skipToken,
- );
- // This is needed in case we already have an action and pass it from the outside
- const contextAction = action || initialAction;
-
- return (
- <ActionContext
- initialAction={contextAction}
- databaseId={databaseId}
- metadata={metadata}
- >
- <ActionCreator
- {...props}
- model={model}
- databaseId={databaseId}
- metadata={metadata}
- />
- </ActionContext>
- );
-}
-
-// eslint-disable-next-line import/no-default-export -- deprecated usage
-export default connect(mapStateToProps)(ActionCreatorWithContext);
diff --git a/frontend/src/metabase/actions/containers/ActionCreator/ActionCreatorView.tsx b/frontend/src/metabase/actions/containers/ActionCreator/ActionCreatorView.tsx
index 305fe6ccb75..998e3f28636 100644
--- a/frontend/src/metabase/actions/containers/ActionCreator/ActionCreatorView.tsx
+++ b/frontend/src/metabase/actions/containers/ActionCreator/ActionCreatorView.tsx
@@ -1,6 +1,10 @@
import { useCallback, useState } from "react";
import { t } from "ttag";
+import { Button } from "metabase/ui";
+import { isNotNull } from "metabase/utils/types";
+import type { ActionFormSettings, WritebackAction } from "metabase-types/api";
+
import {
ActionCreatorBodyContainer,
EditorContainer,
@@ -8,21 +12,17 @@ import {
ModalLeft,
ModalRight,
ModalRoot,
-} from "metabase/actions/containers/ActionCreator/ActionCreator.styled";
-import ActionCreatorHeader from "metabase/actions/containers/ActionCreator/ActionCreatorHeader";
-import { FormCreator } from "metabase/actions/containers/ActionCreator/FormCreator";
-import {
- DataReferenceInline,
- DataReferenceTriggerButton,
-} from "metabase/actions/containers/ActionCreator/InlineDataReference";
-import { Button } from "metabase/ui";
-import { isNotNull } from "metabase/utils/types";
-import type { ActionFormSettings, WritebackAction } from "metabase-types/api";
-
+} from "./ActionCreator.styled";
+import ActionCreatorHeader from "./ActionCreatorHeader";
+import { FormCreator } from "./FormCreator";
import InlineActionSettings, {
ActionSettingsTriggerButton,
} from "./InlineActionSettings";
-import type { ActionCreatorUIProps, SideView } from "./types";
+import type {
+ ActionCreatorUIProps,
+ DataReferenceSlot,
+ SideView,
+} from "./types";
interface ActionCreatorProps extends ActionCreatorUIProps {
action: Partial<WritebackAction>;
@@ -31,6 +31,7 @@ interface ActionCreatorProps extends ActionCreatorUIProps {
canSave: boolean;
isNew: boolean;
isEditable: boolean;
+ dataReference: DataReferenceSlot;
children: React.ReactNode;
@@ -51,6 +52,7 @@ export default function ActionCreatorView({
isEditable,
canRename,
canChangeFieldSettings,
+ dataReference,
children,
onChangeAction,
onChangeFormSettings,
@@ -94,7 +96,7 @@ export default function ActionCreatorView({
isEditable={isEditable}
onChangeName={(name) => onChangeAction({ name })}
actionButtons={[
- <DataReferenceTriggerButton
+ <dataReference.TriggerButton
key="dataReference"
onClick={toggleDataRef}
/>,
@@ -131,7 +133,7 @@ export default function ActionCreatorView({
onClose={onCloseModal}
/>
) : activeSideView === "dataReference" ? (
- <DataReferenceInline
+ <dataReference.Panel
onClose={onCloseModal}
onBack={closeSideView}
/>
diff --git a/frontend/src/metabase/actions/containers/ActionCreator/index.tsx b/frontend/src/metabase/actions/containers/ActionCreator/index.tsx
deleted file mode 100644
index 7e62dd9976a..00000000000
--- a/frontend/src/metabase/actions/containers/ActionCreator/index.tsx
+++ /dev/null
@@ -1,3 +0,0 @@
-// eslint-disable-next-line import/no-default-export -- deprecated usage
-export { default } from "./ActionCreator";
-export * from "./ActionCreator";
diff --git a/frontend/src/metabase/actions/containers/ActionCreator/types.ts b/frontend/src/metabase/actions/containers/ActionCreator/types.ts
index 7e8e32b0f9e..ae54d4ccc4f 100644
--- a/frontend/src/metabase/actions/containers/ActionCreator/types.ts
+++ b/frontend/src/metabase/actions/containers/ActionCreator/types.ts
@@ -1,6 +1,15 @@
+import type { ComponentType } from "react";
+
export type SideView = "dataReference" | "actionForm" | "actionSettings";
export interface ActionCreatorUIProps {
canRename: boolean;
canChangeFieldSettings: boolean;
}
+
+// The data reference is query-editing UI from a module above this one,
+// so the composing module supplies it through this slot.
+export interface DataReferenceSlot {
+ TriggerButton: ComponentType<{ onClick: () => void }>;
+ Panel: ComponentType<{ onClose?: () => void; onBack?: () => void }>;
+}
diff --git a/frontend/src/metabase/actions/utils.ts b/frontend/src/metabase/actions/utils.ts
index 4b820badca4..868752085f3 100644
--- a/frontend/src/metabase/actions/utils.ts
+++ b/frontend/src/metabase/actions/utils.ts
@@ -2,6 +2,7 @@ import { match } from "ts-pattern";
import { t } from "ttag";
import * as Yup from "yup";
+import { hasActionsEnabled } from "metabase/common/utils/database";
import type { ButtonProps } from "metabase/ui";
import * as Errors from "metabase/utils/errors";
import type Field from "metabase-lib/v1/metadata/Field";
@@ -12,9 +13,11 @@ import type {
ActionFormSettings,
BaseDashboardCard,
Card,
+ Database,
FieldSettings,
FieldSettingsMap,
FieldType,
+ IconName,
InputComponentType,
InputSettingType,
Parameter,
@@ -353,3 +356,56 @@ export const isImplicitDeleteAction = (action: WritebackAction): boolean =>
export const isImplicitUpdateAction = (action: WritebackAction): boolean =>
action.type === "implicit" && action.kind === "row/update";
+
+export const isValidImplicitDeleteAction = (action: WritebackAction): boolean =>
+ isImplicitDeleteAction(action) && !action.archived;
+
+export const isValidImplicitUpdateAction = (action: WritebackAction): boolean =>
+ isImplicitUpdateAction(action) && !action.archived;
+
+export type ActionItem = {
+ title: string;
+ icon: IconName;
+ action: () => void;
+};
+
+// Accepts both plain API databases and metabase-lib Database wrappers.
+type DatabaseActionsSource = Pick<Database, "id" | "settings">;
+
+const canRunActionOnDatabase = (
+ action: WritebackAction,
+ databases: DatabaseActionsSource[],
+) => {
+ const database = databases.find(({ id }) => id === action.database_id);
+ return database != null && hasActionsEnabled(database);
+};
+
+export const getActionItems = ({
+ actions,
+ databases,
+ onDelete,
+ onUpdate,
+}: {
+ actions: WritebackAction[];
+ databases: DatabaseActionsSource[];
+ onDelete: (action: WritebackAction) => void;
+ onUpdate: (action: WritebackAction) => void;
+}): ActionItem[] => {
+ const actionItems: ActionItem[] = [];
+ // There is no endpoint for running public actions (#32320).
+ const privateActions = actions.filter((action) => !action.public_uuid);
+ const deleteAction = privateActions.find(isValidImplicitDeleteAction);
+ const updateAction = privateActions.find(isValidImplicitUpdateAction);
+
+ if (updateAction && canRunActionOnDatabase(updateAction, databases)) {
+ const action = () => onUpdate(updateAction);
+ actionItems.push({ title: t`Update`, icon: "pencil", action });
+ }
+
+ if (deleteAction && canRunActionOnDatabase(deleteAction, databases)) {
+ const action = () => onDelete(deleteAction);
+ actionItems.push({ title: t`Delete`, icon: "trash", action });
+ }
+
+ return actionItems;
+};
diff --git a/frontend/src/metabase/actions/utils.unit.spec.ts b/frontend/src/metabase/actions/utils.unit.spec.ts
index 3e4b741b0df..380c0414dbc 100644
--- a/frontend/src/metabase/actions/utils.unit.spec.ts
+++ b/frontend/src/metabase/actions/utils.unit.spec.ts
@@ -1,6 +1,15 @@
import {
+ createMockImplicitQueryAction,
+ createMockNativeDatasetQuery,
+} from "metabase-types/api/mocks";
+import { createSampleDatabase } from "metabase-types/api/mocks/presets";
+
+import {
+ getActionItems,
getDefaultFieldSettings,
getDefaultFormSettings,
+ isValidImplicitDeleteAction,
+ isValidImplicitUpdateAction,
sortActionParams,
} from "./utils";
@@ -43,3 +52,146 @@ describe("sortActionParams", () => {
expect(sortedParams[2].id).toEqual("c");
});
});
+
+const ACTIONS_ENABLED_DB_ID = 10;
+
+const ACTIONS_DISABLED_DB_ID = 11;
+
+const databaseWithEnabledActions = createSampleDatabase({
+ id: ACTIONS_ENABLED_DB_ID,
+ settings: { "database-enable-actions": true },
+});
+
+const databaseWithDisabledActions = createSampleDatabase({
+ id: ACTIONS_DISABLED_DB_ID,
+ settings: { "database-enable-actions": false },
+});
+
+const implicitCreateAction = createMockImplicitQueryAction({
+ database_id: ACTIONS_ENABLED_DB_ID,
+ name: "Create",
+ kind: "row/create",
+});
+
+const implicitDeleteAction = createMockImplicitQueryAction({
+ database_id: ACTIONS_ENABLED_DB_ID,
+ name: "Delete",
+ kind: "row/delete",
+});
+
+const implicitUpdateAction = createMockImplicitQueryAction({
+ database_id: ACTIONS_ENABLED_DB_ID,
+ name: "Update",
+ kind: "row/update",
+});
+
+describe("getActionItems", () => {
+ const onDelete = jest.fn();
+ const onUpdate = jest.fn();
+ const actions = [
+ implicitDeleteAction,
+ implicitUpdateAction,
+ implicitCreateAction,
+ ];
+
+ it("should return delete and update action items", () => {
+ expect(
+ getActionItems({
+ actions,
+ databases: [databaseWithEnabledActions],
+ onDelete,
+ onUpdate,
+ }),
+ ).toMatchObject([
+ { title: "Update", icon: "pencil" },
+ { title: "Delete", icon: "trash" },
+ ]);
+ });
+
+ it("should not return any items when database actions are disabled", () => {
+ expect(
+ getActionItems({
+ actions,
+ databases: [databaseWithDisabledActions],
+ onDelete,
+ onUpdate,
+ }),
+ ).toEqual([]);
+ });
+
+ it("should not return any items when there are no databases", () => {
+ expect(
+ getActionItems({
+ actions,
+ databases: [],
+ onDelete,
+ onUpdate,
+ }),
+ ).toEqual([]);
+ });
+
+ it("should not return any items when there are no actions", () => {
+ expect(
+ getActionItems({
+ actions: [],
+ databases: [databaseWithDisabledActions, databaseWithEnabledActions],
+ onDelete,
+ onUpdate,
+ }),
+ ).toEqual([]);
+ });
+});
+
+describe("isValidImplicitDeleteAction", () => {
+ it("should detect implicit delete action", () => {
+ expect(isValidImplicitDeleteAction(implicitCreateAction)).toBe(false);
+ expect(isValidImplicitDeleteAction(implicitDeleteAction)).toBe(true);
+ expect(isValidImplicitDeleteAction(implicitUpdateAction)).toBe(false);
+ });
+
+ it("should ignore archived action", () => {
+ expect(
+ isValidImplicitDeleteAction({
+ ...implicitDeleteAction,
+ archived: true,
+ }),
+ ).toBe(false);
+ });
+
+ it("should ignore non-implicit action", () => {
+ expect(
+ isValidImplicitDeleteAction({
+ ...implicitDeleteAction,
+ type: "query",
+ dataset_query: createMockNativeDatasetQuery(),
+ }),
+ ).toBe(false);
+ });
+});
+
+describe("isValidImplicitUpdateAction", () => {
+ it("should detect implicit update action", () => {
+ expect(isValidImplicitUpdateAction(implicitCreateAction)).toBe(false);
+ expect(isValidImplicitUpdateAction(implicitDeleteAction)).toBe(false);
+ expect(isValidImplicitUpdateAction(implicitUpdateAction)).toBe(true);
+ });
+
+ it("should ignore archived action", () => {
+ expect(
+ isValidImplicitUpdateAction({
+ ...implicitUpdateAction,
+ archived: true,
+ }),
+ ).toBe(false);
+ });
+
+ it("should ignore non-implicit action", () => {
+ expect(
+ isValidImplicitUpdateAction({
+ ...implicitUpdateAction,
+ type: "query",
+ dataset_query: createMockNativeDatasetQuery(),
+ }),
+ ).toBe(false);
+ });
+});
diff --git a/frontend/src/metabase/common/components/Glossary/GlossaryTable.tsx b/frontend/src/metabase/common/components/Glossary/GlossaryTable.tsx
index bfbe9c33ded..1d29a39694b 100644
--- a/frontend/src/metabase/common/components/Glossary/GlossaryTable.tsx
+++ b/frontend/src/metabase/common/components/Glossary/GlossaryTable.tsx
@@ -2,7 +2,6 @@ import cx from "classnames";
import { useMemo, useState } from "react";
import { t } from "ttag";
-import { EmptyState } from "metabase/actions/containers/ActionPicker/ActionPicker.styled";
import type { GlossaryItem } from "metabase/api";
import { ConfirmModal } from "metabase/common/components/ConfirmModal";
import { Table as CommonTable } from "metabase/common/components/Table/Table";
@@ -20,6 +19,8 @@ import {
} from "metabase/ui";
import type { SortDirection } from "metabase-types/api";
+import { EmptyState } from "../EmptyState";
+
import S from "./Glossary.module.css";
import { GlossaryRowEditor } from "./GlossaryRowEditor";
import type { GlossaryField } from "./types";
@@ -125,10 +126,12 @@ export function GlossaryTable({
}
emptyBody={
<Center>
- <EmptyState
- message={t`No terms yet`}
- illustrationElement={<NoObjectError mb="-1.5rem" />}
- />
+ <Box mb="md">
+ <EmptyState
+ message={t`No terms yet`}
+ illustrationElement={<NoObjectError mb="-1.5rem" />}
+ />
+ </Box>
</Center>
}
sortColumnName={sortColumnName}
diff --git a/frontend/src/metabase/dashboard/components/ActionViz/ActionDashcardSettings.tsx b/frontend/src/metabase/dashboard/components/ActionViz/ActionDashcardSettings.tsx
index c915bf67702..ad28a0b1b1f 100644
--- a/frontend/src/metabase/dashboard/components/ActionViz/ActionDashcardSettings.tsx
+++ b/frontend/src/metabase/dashboard/components/ActionViz/ActionDashcardSettings.tsx
@@ -1,7 +1,6 @@
import { useMemo } from "react";
import { t } from "ttag";
-import { ConnectedActionPicker } from "metabase/actions/containers/ActionPicker";
import { EmptyState } from "metabase/common/components/EmptyState";
import CS from "metabase/css/core/index.css";
import { setActionForDashcard } from "metabase/dashboard/actions";
@@ -25,6 +24,7 @@ import {
ActionParameterMappingForm,
getTargetKey,
} from "./ActionParameterMapping";
+import { ConnectedActionPicker } from "./ActionPicker";
import { ExplainerText } from "./ExplainerText";
import {
getParameterDefaultValue,
diff --git a/frontend/src/metabase/actions/containers/ActionPicker/ActionPicker.styled.tsx b/frontend/src/metabase/dashboard/components/ActionViz/ActionPicker/ActionPicker.styled.tsx
similarity index 100%
rename from frontend/src/metabase/actions/containers/ActionPicker/ActionPicker.styled.tsx
rename to frontend/src/metabase/dashboard/components/ActionViz/ActionPicker/ActionPicker.styled.tsx
diff --git a/frontend/src/metabase/actions/containers/ActionPicker/ActionPicker.tsx b/frontend/src/metabase/dashboard/components/ActionViz/ActionPicker/ActionPicker.tsx
similarity index 98%
rename from frontend/src/metabase/actions/containers/ActionPicker/ActionPicker.tsx
rename to frontend/src/metabase/dashboard/components/ActionViz/ActionPicker/ActionPicker.tsx
index 9a51ec14201..efc7c95f508 100644
--- a/frontend/src/metabase/actions/containers/ActionPicker/ActionPicker.tsx
+++ b/frontend/src/metabase/dashboard/components/ActionViz/ActionPicker/ActionPicker.tsx
@@ -2,11 +2,11 @@ import type { MouseEvent } from "react";
import { useMemo, useState } from "react";
import { t } from "ttag";
-import ActionCreator from "metabase/actions/containers/ActionCreator";
import { useListActionsQuery, useSearchQuery } from "metabase/api";
import { LoadingAndErrorWrapper } from "metabase/common/components/LoadingAndErrorWrapper";
import { useToggle } from "metabase/common/hooks/use-toggle";
import CS from "metabase/css/core/index.css";
+import { ActionCreator } from "metabase/querying/action-creator";
import {
ActionIcon,
Button,
diff --git a/frontend/src/metabase/actions/containers/ActionPicker/index.ts b/frontend/src/metabase/dashboard/components/ActionViz/ActionPicker/index.ts
similarity index 100%
rename from frontend/src/metabase/actions/containers/ActionPicker/index.ts
rename to frontend/src/metabase/dashboard/components/ActionViz/ActionPicker/index.ts
diff --git a/frontend/src/metabase/actions/containers/ActionPicker/types.ts b/frontend/src/metabase/dashboard/components/ActionViz/ActionPicker/types.ts
similarity index 100%
rename from frontend/src/metabase/actions/containers/ActionPicker/types.ts
rename to frontend/src/metabase/dashboard/components/ActionViz/ActionPicker/types.ts
diff --git a/frontend/src/metabase/actions/containers/ActionPicker/utils.ts b/frontend/src/metabase/dashboard/components/ActionViz/ActionPicker/utils.ts
similarity index 100%
rename from frontend/src/metabase/actions/containers/ActionPicker/utils.ts
rename to frontend/src/metabase/dashboard/components/ActionViz/ActionPicker/utils.ts
diff --git a/frontend/src/metabase/actions/containers/ActionPicker/utils.unit.spec.ts b/frontend/src/metabase/dashboard/components/ActionViz/ActionPicker/utils.unit.spec.ts
similarity index 100%
rename from frontend/src/metabase/actions/containers/ActionPicker/utils.unit.spec.ts
rename to frontend/src/metabase/dashboard/components/ActionViz/ActionPicker/utils.unit.spec.ts
diff --git a/frontend/src/metabase/dashboard/components/ActionViz/ActionVizForm.tsx b/frontend/src/metabase/dashboard/components/ActionViz/ActionVizForm.tsx
index 187aa867649..22e27fcc75e 100644
--- a/frontend/src/metabase/dashboard/components/ActionViz/ActionVizForm.tsx
+++ b/frontend/src/metabase/dashboard/components/ActionViz/ActionVizForm.tsx
@@ -1,7 +1,6 @@
import type { FormikHelpers } from "formik";
import { useCallback, useState } from "react";
-import ActionCreator from "metabase/actions/containers/ActionCreator/ActionCreator";
import ActionParametersInputForm, {
ActionParametersInputModal,
} from "metabase/actions/containers/ActionParametersInputForm";
@@ -9,6 +8,7 @@ import { useActionInitialValues } from "metabase/actions/hooks/use-action-initia
import { getFormTitle, isImplicitUpdateAction } from "metabase/actions/utils";
import { actionApi, publicApi } from "metabase/api";
import { runRtkEndpoint } from "metabase/api/utils/run-rtk-endpoint";
+import { ActionCreator } from "metabase/querying/action-creator";
import { useDispatch } from "metabase/redux";
import { Modal, PREVENT_AUTOCOMPLETE_CLIPPING_MODAL_PROPS } from "metabase/ui";
import { getDashboardType } from "metabase/utils/dashboard";
diff --git a/frontend/src/metabase/detail-view/components/DetailViewSidesheet/DetailViewSidesheet.tsx b/frontend/src/metabase/detail-view/components/DetailViewSidesheet/DetailViewSidesheet.tsx
index 84e322c3e17..8c2d8e4644b 100644
--- a/frontend/src/metabase/detail-view/components/DetailViewSidesheet/DetailViewSidesheet.tsx
+++ b/frontend/src/metabase/detail-view/components/DetailViewSidesheet/DetailViewSidesheet.tsx
@@ -2,7 +2,9 @@ import { useDisclosure, useHotkeys } from "@mantine/hooks";
import { useCallback, useEffect, useMemo, useState } from "react";
import { t } from "ttag";
+import { DeleteObjectModal } from "metabase/actions/components/DeleteObjectModal";
import { ActionExecuteModal } from "metabase/actions/containers/ActionExecuteModal";
+import { getActionItems } from "metabase/actions/utils";
import {
actionApi,
skipToken,
@@ -37,7 +39,6 @@ import {
Tooltip,
rem,
} from "metabase/ui";
-import { DeleteObjectModal } from "metabase/visualizations/components/ObjectDetail/DeleteObjectModal";
import * as Lib from "metabase-lib";
import { isPK } from "metabase-lib/v1/types/utils/isa";
import type {
@@ -51,7 +52,7 @@ import type {
} from "metabase-types/api";
import { Sidesheet } from "./Sidesheet";
-import { extractData, getActionItems, getModelId } from "./utils";
+import { extractData, getModelId } from "./utils";
interface Props {
columnSettings: TableColumnOrderSetting[] | undefined;
diff --git a/frontend/src/metabase/detail-view/components/DetailViewSidesheet/utils.ts b/frontend/src/metabase/detail-view/components/DetailViewSidesheet/utils.ts
index c3ac57876ce..1458be3af61 100644
--- a/frontend/src/metabase/detail-view/components/DetailViewSidesheet/utils.ts
+++ b/frontend/src/metabase/detail-view/components/DetailViewSidesheet/utils.ts
@@ -1,73 +1,14 @@
-import { t } from "ttag";
-
-import {
- isImplicitDeleteAction,
- isImplicitUpdateAction,
-} from "metabase/actions/utils";
-import { hasActionsEnabled } from "metabase/common/utils/database";
import { extractRemappedColumns } from "metabase/visualizations";
import { getQuestionIdFromVirtualTableId } from "metabase-lib/v1/metadata/utils/saved-questions";
import { findColumnIndexesForColumnSettings } from "metabase-lib/v1/queries/utils/dataset";
import type {
- Database,
Dataset,
DatasetColumn,
- IconName,
RowValues,
Table,
TableColumnOrderSetting,
- WritebackAction,
} from "metabase-types/api";
-type ActionItem = {
- title: string;
- icon: IconName;
- action: () => void;
-};
-
-export const getActionItems = ({
- actions,
- databases,
- onDelete,
- onUpdate,
-}: {
- actions: WritebackAction[];
- databases: Database[];
- onDelete: (action: WritebackAction) => void;
- onUpdate: (action: WritebackAction) => void;
-}): ActionItem[] => {
- const actionItems: ActionItem[] = [];
- const privateActions = actions.filter((action) => !action.public_uuid);
- const deleteAction = privateActions.find(isValidImplicitDeleteAction);
- const updateAction = privateActions.find(isValidImplicitUpdateAction);
-
- if (updateAction && canRunAction(updateAction, databases)) {
- const action = () => onUpdate(updateAction);
- actionItems.push({ title: t`Update`, icon: "pencil", action });
- }
-
- if (deleteAction && canRunAction(deleteAction, databases)) {
- const action = () => onDelete(deleteAction);
- actionItems.push({ title: t`Delete`, icon: "trash", action });
- }
-
- return actionItems;
-};
-
-export const isValidImplicitDeleteAction = (action: WritebackAction): boolean =>
- isImplicitDeleteAction(action) && !action.archived;
-
-export const isValidImplicitUpdateAction = (action: WritebackAction): boolean =>
- isImplicitUpdateAction(action) && !action.archived;
-
-export const canRunAction = (
- action: WritebackAction,
- databases: Database[],
-) => {
- const database = databases.find(({ id }) => id === action.database_id);
- return database != null && hasActionsEnabled(database);
-};
-
export function extractData(
dataset: Dataset | undefined,
columnsFromProp: DatasetColumn[],
diff --git a/frontend/src/metabase/actions/containers/ActionCreatorModal/ActionCreatorModal.tsx b/frontend/src/metabase/models/containers/ActionCreatorModal/ActionCreatorModal.tsx
similarity index 97%
rename from frontend/src/metabase/actions/containers/ActionCreatorModal/ActionCreatorModal.tsx
rename to frontend/src/metabase/models/containers/ActionCreatorModal/ActionCreatorModal.tsx
index 6ccc7e44373..db785060284 100644
--- a/frontend/src/metabase/actions/containers/ActionCreatorModal/ActionCreatorModal.tsx
+++ b/frontend/src/metabase/models/containers/ActionCreatorModal/ActionCreatorModal.tsx
@@ -3,6 +3,7 @@ import { useEffect } from "react";
import { skipToken, useGetActionQuery, useGetCardQuery } from "metabase/api";
import { LoadingAndErrorWrapper } from "metabase/common/components/LoadingAndErrorWrapper";
import type { ModalComponentProps } from "metabase/common/components/ModalRoute";
+import { ActionCreator } from "metabase/querying/action-creator";
import { useDispatch, useSelector } from "metabase/redux";
import { setErrorPage } from "metabase/redux/app";
import { useNavigate } from "metabase/router";
@@ -11,8 +12,6 @@ import * as Urls from "metabase/urls";
import type Question from "metabase-lib/v1/Question";
import type { WritebackAction } from "metabase-types/api";
-import ActionCreator from "../ActionCreator";
-
interface OwnProps {
params: {
slug?: string;
diff --git a/frontend/src/metabase/actions/containers/ActionCreatorModal/ActionCreatorModal.unit.spec.tsx b/frontend/src/metabase/models/containers/ActionCreatorModal/ActionCreatorModal.unit.spec.tsx
similarity index 100%
rename from frontend/src/metabase/actions/containers/ActionCreatorModal/ActionCreatorModal.unit.spec.tsx
rename to frontend/src/metabase/models/containers/ActionCreatorModal/ActionCreatorModal.unit.spec.tsx
diff --git a/frontend/src/metabase/actions/containers/ActionCreatorModal/index.ts b/frontend/src/metabase/models/containers/ActionCreatorModal/index.ts
similarity index 100%
rename from frontend/src/metabase/actions/containers/ActionCreatorModal/index.ts
rename to frontend/src/metabase/models/containers/ActionCreatorModal/index.ts
diff --git a/frontend/src/metabase/models/containers/ModelActions/ModelActions.unit.spec.tsx b/frontend/src/metabase/models/containers/ModelActions/ModelActions.unit.spec.tsx
index 02fb8345270..0614bd8d251 100644
--- a/frontend/src/metabase/models/containers/ModelActions/ModelActions.unit.spec.tsx
+++ b/frontend/src/metabase/models/containers/ModelActions/ModelActions.unit.spec.tsx
@@ -17,7 +17,6 @@ import {
waitForLoaderToBeRemoved,
within,
} from "__support__/ui";
-import ActionCreator from "metabase/actions/containers/ActionCreatorModal";
import { modalRoute } from "metabase/common/components/ModalRoute";
import {
createMockSettingsState,
@@ -54,12 +53,13 @@ import {
createSavedStructuredCard,
} from "metabase-types/api/mocks/presets";
+import ActionCreatorModal from "../ActionCreatorModal";
+
import ModelActions from "./ModelActions";
-// eslint-disable-next-line react/display-name
-jest.mock("metabase/actions/containers/ActionCreator", () => () => (
- <div data-testid="mock-action-editor" />
-));
+jest.mock("metabase/querying/action-creator", () => ({
+ ActionCreator: () => <div data-testid="mock-action-editor" />,
+}));
const TEST_DATABASE_ID = 1;
const TEST_TABLE_ID = 1;
@@ -224,10 +224,10 @@ async function setup({
<Route path="/model/:slug/detail">
<Route index element={redirect("actions")} />
<Route path="actions" element={<ModelActions />}>
- {modalRoute("new", ActionCreator, {
+ {modalRoute("new", ActionCreatorModal, {
modalProps: { transitionProps: { duration: 0 } },
})}
- {modalRoute(":actionId", ActionCreator, {
+ {modalRoute(":actionId", ActionCreatorModal, {
modalProps: { transitionProps: { duration: 0 } },
})}
</Route>
diff --git a/frontend/src/metabase/models/routes.tsx b/frontend/src/metabase/models/routes.tsx
index 7dcecbb66c7..a1faf87addf 100644
--- a/frontend/src/metabase/models/routes.tsx
+++ b/frontend/src/metabase/models/routes.tsx
@@ -1,4 +1,3 @@
-import ActionCreatorModal from "metabase/actions/containers/ActionCreatorModal/ActionCreatorModal";
import { modalRoute } from "metabase/common/components/ModalRoute";
import { ModelDetailPage } from "metabase/detail-view/pages/ModelDetailPage/ModelDetailPage";
import ModelActions from "metabase/models/containers/ModelActions/ModelActions";
@@ -8,6 +7,8 @@ import {
PREVENT_AUTOCOMPLETE_CLIPPING_MODAL_PROPS,
} from "metabase/ui";
+import ActionCreatorModal from "./containers/ActionCreatorModal/ActionCreatorModal";
+
export const getRoutes = () => {
const modalProps: Partial<ModalProps> = {
...PREVENT_AUTOCOMPLETE_CLIPPING_MODAL_PROPS,
diff --git a/frontend/src/metabase/new/components/NewModals/NewModals.tsx b/frontend/src/metabase/new/components/NewModals/NewModals.tsx
index 7e4a8e5adf7..a4888ff4288 100644
--- a/frontend/src/metabase/new/components/NewModals/NewModals.tsx
+++ b/frontend/src/metabase/new/components/NewModals/NewModals.tsx
@@ -1,6 +1,5 @@
import { Suspense, lazy, useCallback, useEffect } from "react";
-import ActionCreator from "metabase/actions/containers/ActionCreator";
import { CreateDashboardModal } from "metabase/common/CreateDashboard/CreateDashboardModal";
import CreateCollectionModal, {
type CreateCollectionModalOwnProps,
@@ -14,6 +13,7 @@ import type {
LegacyStaticEmbeddingModalProps,
SdkIframeEmbedSetupModalProps,
} from "metabase/plugins";
+import { ActionCreator } from "metabase/querying/action-creator";
import { useDispatch, useSelector } from "metabase/redux";
import type { State } from "metabase/redux/store";
import type { ModalState } from "metabase/redux/store/modal";
diff --git a/frontend/src/metabase/new/components/NewModals/NewModals.unit.spec.tsx b/frontend/src/metabase/new/components/NewModals/NewModals.unit.spec.tsx
new file mode 100644
index 00000000000..5b76fbcd6e2
--- /dev/null
+++ b/frontend/src/metabase/new/components/NewModals/NewModals.unit.spec.tsx
@@ -0,0 +1,50 @@
+import userEvent from "@testing-library/user-event";
+
+import {
+ setupCardsEndpoints,
+ setupCollectionsEndpoints,
+ setupDatabasesEndpoints,
+} from "__support__/server-mocks";
+import { act, renderWithProviders, screen, waitFor } from "__support__/ui";
+import { setOpenModal } from "metabase/redux/ui";
+import { Route } from "metabase/router";
+import { createMockDatabase } from "metabase-types/api/mocks";
+
+import { NewModals } from "./NewModals";
+
+async function setup() {
+ setupDatabasesEndpoints([createMockDatabase()]);
+ setupCardsEndpoints([]);
+ setupCollectionsEndpoints({ collections: [] });
+
+ const { store } = renderWithProviders(
+ <Route path="/" element={<NewModals />} />,
+ { withRouter: true },
+ );
+
+ act(() => {
+ store.dispatch(setOpenModal("action"));
+ });
+
+ await screen.findByTestId("action-creator");
+}
+
+describe("NewModals", () => {
+ it("opens the action creator in new query action mode", async () => {
+ await setup();
+
+ expect(screen.getByText(/New action/i)).toBeInTheDocument();
+ expect(screen.getByTestId("mock-native-query-editor")).toBeInTheDocument();
+ expect(screen.getByRole("button", { name: "Save" })).toBeInTheDocument();
+ });
+
+ it("closes the action creator on cancel", async () => {
+ await setup();
+
+ await userEvent.click(screen.getByRole("button", { name: "Cancel" }));
+
+ await waitFor(() => {
+ expect(screen.queryByTestId("action-creator")).not.toBeInTheDocument();
+ });
+ });
+});
diff --git a/frontend/src/metabase/actions/containers/ActionCreator/ActionContext/ActionContextProvider.tsx b/frontend/src/metabase/querying/action-creator/ActionContextProvider.tsx
similarity index 63%
rename from frontend/src/metabase/actions/containers/ActionCreator/ActionContext/ActionContextProvider.tsx
rename to frontend/src/metabase/querying/action-creator/ActionContextProvider.tsx
index ba04b51be30..85ab2ddb7f5 100644
--- a/frontend/src/metabase/actions/containers/ActionCreator/ActionContext/ActionContextProvider.tsx
+++ b/frontend/src/metabase/querying/action-creator/ActionContextProvider.tsx
@@ -1,16 +1,16 @@
+import type { ImplicitActionContextProviderProps } from "metabase/actions/containers/ActionCreator/ActionContext/ImplicitActionContextProvider";
+import ImplicitActionContextProvider from "metabase/actions/containers/ActionCreator/ActionContext/ImplicitActionContextProvider";
import type { WritebackAction } from "metabase-types/api";
-import type { ImplicitActionContextProviderProps } from "./ImplicitActionContextProvider";
-import ImplicitActionContextProvider from "./ImplicitActionContextProvider";
import type { QueryActionContextProviderProps } from "./QueryActionContextProvider";
-import QueryActionContextProvider from "./QueryActionContextProvider";
+import { QueryActionContextProvider } from "./QueryActionContextProvider";
type Props = Omit<ImplicitActionContextProviderProps, "initialAction"> &
Omit<QueryActionContextProviderProps, "initialAction"> & {
initialAction?: WritebackAction;
};
-function ActionContextProvider({ initialAction, ...props }: Props) {
+export function ActionContextProvider({ initialAction, ...props }: Props) {
if (initialAction?.type === "query") {
return (
<QueryActionContextProvider {...props} initialAction={initialAction} />
@@ -26,6 +26,3 @@ function ActionContextProvider({ initialAction, ...props }: Props) {
// Fallback to "new query action" mode when the action type is not supported
return <QueryActionContextProvider {...props} />;
}
-
-// eslint-disable-next-line import/no-default-export -- deprecated usage
-export default ActionContextProvider;
diff --git a/frontend/src/metabase/querying/action-creator/ActionCreator.tsx b/frontend/src/metabase/querying/action-creator/ActionCreator.tsx
new file mode 100644
index 00000000000..32f0ea5da52
--- /dev/null
+++ b/frontend/src/metabase/querying/action-creator/ActionCreator.tsx
@@ -0,0 +1,80 @@
+import { ActionCreator as ActionCreatorContent } from "metabase/actions/containers/ActionCreator/ActionCreator";
+import type { DataReferenceSlot } from "metabase/actions/containers/ActionCreator/types";
+import {
+ skipToken,
+ useGetActionQuery,
+ useGetCardQuery,
+ useListDatabasesQuery,
+} from "metabase/api";
+import { useSelector } from "metabase/redux";
+import { getMetadata } from "metabase/selectors/metadata";
+import type {
+ CardId,
+ DatabaseId,
+ WritebackAction,
+ WritebackActionId,
+} from "metabase-types/api";
+
+import { ActionContextProvider } from "./ActionContextProvider";
+import {
+ DataReferenceInline,
+ DataReferenceTriggerButton,
+} from "./InlineDataReference";
+
+interface ActionCreatorProps {
+ actionId?: WritebackActionId;
+ modelId?: CardId;
+ databaseId?: DatabaseId;
+
+ action?: WritebackAction;
+ /**
+ * Whether the creator is mounted as its own route. A routed creator guards
+ * leaving with `LeaveRouteConfirmModal`; an inline one only has `beforeunload`.
+ */
+ isRouted?: boolean;
+
+ onSubmit?: (action: WritebackAction) => void;
+ onClose?: () => void;
+}
+
+const DATA_REFERENCE: DataReferenceSlot = {
+ TriggerButton: DataReferenceTriggerButton,
+ Panel: DataReferenceInline,
+};
+
+export function ActionCreator({
+ actionId,
+ modelId,
+ databaseId,
+ action,
+ isRouted,
+ onSubmit,
+ onClose,
+}: ActionCreatorProps) {
+ useListDatabasesQuery();
+ useGetCardQuery(modelId != null ? { id: modelId } : skipToken);
+ const metadata = useSelector(getMetadata);
+ const model =
+ modelId != null ? (metadata.question(modelId) ?? undefined) : undefined;
+ const { data: initialAction } = useGetActionQuery(
+ actionId != null ? { id: actionId } : skipToken,
+ );
+ // This is needed in case we already have an action and pass it from the outside
+ const contextAction = action || initialAction;
+
+ return (
+ <ActionContextProvider
+ initialAction={contextAction}
+ databaseId={databaseId}
+ metadata={metadata}
+ >
+ <ActionCreatorContent
+ model={model}
+ isRouted={isRouted}
+ dataReference={DATA_REFERENCE}
+ onSubmit={onSubmit}
+ onClose={onClose}
+ />
+ </ActionContextProvider>
+ );
+}
diff --git a/frontend/src/metabase/actions/containers/ActionCreator/InlineDataReference.tsx b/frontend/src/metabase/querying/action-creator/InlineDataReference.tsx
similarity index 85%
rename from frontend/src/metabase/actions/containers/ActionCreator/InlineDataReference.tsx
rename to frontend/src/metabase/querying/action-creator/InlineDataReference.tsx
index c65df4ada1d..89b7e632965 100644
--- a/frontend/src/metabase/actions/containers/ActionCreator/InlineDataReference.tsx
+++ b/frontend/src/metabase/querying/action-creator/InlineDataReference.tsx
@@ -1,10 +1,11 @@
import { useState } from "react";
import { t } from "ttag";
-import { DataReference } from "metabase/querying/components/DataReference/DataReference";
-import type { DataReferenceItem } from "metabase/querying/components/DataReference/types";
import { ActionIcon, Icon, Tooltip } from "metabase/ui";
+import { DataReference } from "../components/DataReference/DataReference";
+import type { DataReferenceItem } from "../components/DataReference/types";
+
export const DataReferenceInline = ({
onClose,
onBack,
diff --git a/frontend/src/metabase/actions/containers/ActionCreator/ActionContext/QueryActionContextProvider/QueryActionContextProvider.tsx b/frontend/src/metabase/querying/action-creator/QueryActionContextProvider/QueryActionContextProvider.tsx
similarity index 93%
rename from frontend/src/metabase/actions/containers/ActionCreator/ActionContext/QueryActionContextProvider/QueryActionContextProvider.tsx
rename to frontend/src/metabase/querying/action-creator/QueryActionContextProvider/QueryActionContextProvider.tsx
index 53c9d35f64e..1edec36c334 100644
--- a/frontend/src/metabase/actions/containers/ActionCreator/ActionContext/QueryActionContextProvider/QueryActionContextProvider.tsx
+++ b/frontend/src/metabase/querying/action-creator/QueryActionContextProvider/QueryActionContextProvider.tsx
@@ -1,7 +1,14 @@
import { useCallback, useEffect, useMemo, useState } from "react";
import _ from "underscore";
+import type {
+ ActionContextProviderProps,
+ ActionContextType,
+ EditorBodyProps,
+} from "metabase/actions/containers/ActionCreator/ActionContext";
+import { ActionContext } from "metabase/actions/containers/ActionCreator/ActionContext";
import type { CreateQueryActionParams } from "metabase/actions/types";
+import { getDefaultFormSettings } from "metabase/actions/utils";
import Question from "metabase-lib/v1/Question";
import type Metadata from "metabase-lib/v1/metadata/Metadata";
import { getTemplateTagParametersFromCard } from "metabase-lib/v1/parameters/utils/template-tags";
@@ -16,12 +23,7 @@ import type {
WritebackQueryAction,
} from "metabase-types/api";
-import { getDefaultFormSettings } from "../../../../utils";
-import type { ActionContextType } from "../ActionContext";
-import { ActionContext } from "../ActionContext";
-import type { ActionContextProviderProps, EditorBodyProps } from "../types";
-
-import QueryActionEditor from "./QueryActionEditor";
+import { QueryActionEditor } from "./QueryActionEditor";
import {
setParameterTypesFromFieldSettings,
setTemplateTagTypesFromFieldSettings,
@@ -132,7 +134,7 @@ function resolveQuestion(
: newQuestion(metadata, databaseId);
}
-function QueryActionContextProvider({
+export function QueryActionContextProvider({
initialAction,
metadata,
databaseId,
@@ -254,6 +256,3 @@ function QueryActionContextProvider({
<ActionContext.Provider value={value}>{children}</ActionContext.Provider>
);
}
-
-// eslint-disable-next-line import/no-default-export -- deprecated usage
-export default QueryActionContextProvider;
diff --git a/frontend/src/metabase/actions/containers/ActionCreator/ActionContext/QueryActionContextProvider/QueryActionEditor.tsx b/frontend/src/metabase/querying/action-creator/QueryActionContextProvider/QueryActionEditor.tsx
similarity index 73%
rename from frontend/src/metabase/actions/containers/ActionCreator/ActionContext/QueryActionContextProvider/QueryActionEditor.tsx
rename to frontend/src/metabase/querying/action-creator/QueryActionContextProvider/QueryActionEditor.tsx
index 8b4fde0b5ee..48c3be73cf9 100644
--- a/frontend/src/metabase/actions/containers/ActionCreator/ActionContext/QueryActionContextProvider/QueryActionEditor.tsx
+++ b/frontend/src/metabase/querying/action-creator/QueryActionContextProvider/QueryActionEditor.tsx
@@ -1,8 +1,9 @@
-import { NativeQueryEditor } from "metabase/querying/components/NativeQueryEditor";
import type Question from "metabase-lib/v1/Question";
import type NativeQuery from "metabase-lib/v1/queries/NativeQuery";
-function QueryActionEditor({
+import { NativeQueryEditor } from "../../components/NativeQueryEditor";
+
+export function QueryActionEditor({
query,
question,
isEditable,
@@ -27,6 +28,3 @@ function QueryActionEditor({
</NativeQueryEditor>
);
}
-
-// eslint-disable-next-line import/no-default-export -- deprecated usage
-export default QueryActionEditor;
diff --git a/frontend/src/metabase/querying/action-creator/QueryActionContextProvider/index.ts b/frontend/src/metabase/querying/action-creator/QueryActionContextProvider/index.ts
new file mode 100644
index 00000000000..2ad0339bfca
--- /dev/null
+++ b/frontend/src/metabase/querying/action-creator/QueryActionContextProvider/index.ts
@@ -0,0 +1,4 @@
+export {
+ QueryActionContextProvider,
+ type QueryActionContextProviderProps,
+} from "./QueryActionContextProvider";
diff --git a/frontend/src/metabase/actions/containers/ActionCreator/ActionContext/QueryActionContextProvider/utils.ts b/frontend/src/metabase/querying/action-creator/QueryActionContextProvider/utils.ts
similarity index 100%
rename from frontend/src/metabase/actions/containers/ActionCreator/ActionContext/QueryActionContextProvider/utils.ts
rename to frontend/src/metabase/querying/action-creator/QueryActionContextProvider/utils.ts
diff --git a/frontend/src/metabase/actions/containers/ActionCreator/ActionContext/QueryActionContextProvider/utils.unit.spec.ts b/frontend/src/metabase/querying/action-creator/QueryActionContextProvider/utils.unit.spec.ts
similarity index 100%
rename from frontend/src/metabase/actions/containers/ActionCreator/ActionContext/QueryActionContextProvider/utils.unit.spec.ts
rename to frontend/src/metabase/querying/action-creator/QueryActionContextProvider/utils.unit.spec.ts
diff --git a/frontend/src/metabase/querying/action-creator/index.ts b/frontend/src/metabase/querying/action-creator/index.ts
new file mode 100644
index 00000000000..f485f36e8d7
--- /dev/null
+++ b/frontend/src/metabase/querying/action-creator/index.ts
@@ -0,0 +1 @@
+export { ActionCreator } from "./ActionCreator";
diff --git a/frontend/src/metabase/actions/containers/ActionCreator/tests/ActionCreator-Common.unit.spec.tsx b/frontend/src/metabase/querying/action-creator/tests/ActionCreator-Common.unit.spec.tsx
similarity index 100%
rename from frontend/src/metabase/actions/containers/ActionCreator/tests/ActionCreator-Common.unit.spec.tsx
rename to frontend/src/metabase/querying/action-creator/tests/ActionCreator-Common.unit.spec.tsx
diff --git a/frontend/src/metabase/actions/containers/ActionCreator/tests/ActionCreator-ImplicitActions.unit.spec.ts b/frontend/src/metabase/querying/action-creator/tests/ActionCreator-ImplicitActions.unit.spec.ts
similarity index 100%
rename from frontend/src/metabase/actions/containers/ActionCreator/tests/ActionCreator-ImplicitActions.unit.spec.ts
rename to frontend/src/metabase/querying/action-creator/tests/ActionCreator-ImplicitActions.unit.spec.ts
diff --git a/frontend/src/metabase/actions/containers/ActionCreator/tests/ActionCreator-QueryActions.unit.spec.ts b/frontend/src/metabase/querying/action-creator/tests/ActionCreator-QueryActions.unit.spec.ts
similarity index 100%
rename from frontend/src/metabase/actions/containers/ActionCreator/tests/ActionCreator-QueryActions.unit.spec.ts
rename to frontend/src/metabase/querying/action-creator/tests/ActionCreator-QueryActions.unit.spec.ts
diff --git a/frontend/src/metabase/actions/containers/ActionCreator/tests/ActionCreator-Sharing.unit.spec.tsx b/frontend/src/metabase/querying/action-creator/tests/ActionCreator-Sharing.unit.spec.tsx
similarity index 100%
rename from frontend/src/metabase/actions/containers/ActionCreator/tests/ActionCreator-Sharing.unit.spec.tsx
rename to frontend/src/metabase/querying/action-creator/tests/ActionCreator-Sharing.unit.spec.tsx
diff --git a/frontend/src/metabase/actions/containers/ActionCreator/tests/common.tsx b/frontend/src/metabase/querying/action-creator/tests/common.tsx
similarity index 97%
rename from frontend/src/metabase/actions/containers/ActionCreator/tests/common.tsx
rename to frontend/src/metabase/querying/action-creator/tests/common.tsx
index 4012b3c5e30..a293f1a6e38 100644
--- a/frontend/src/metabase/actions/containers/ActionCreator/tests/common.tsx
+++ b/frontend/src/metabase/querying/action-creator/tests/common.tsx
@@ -21,7 +21,7 @@ import {
createMockUser,
} from "metabase-types/api/mocks";
-import ActionCreator from "../ActionCreator";
+import { ActionCreator } from "../ActionCreator";
export const SITE_URL = "http://localhost:3000";
diff --git a/frontend/src/metabase/visualizations/components/ObjectDetail/ObjectDetailHeader.tsx b/frontend/src/metabase/visualizations/components/ObjectDetail/ObjectDetailHeader.tsx
index b7ac4e15e91..80f3dd085f1 100644
--- a/frontend/src/metabase/visualizations/components/ObjectDetail/ObjectDetailHeader.tsx
+++ b/frontend/src/metabase/visualizations/components/ObjectDetail/ObjectDetailHeader.tsx
@@ -1,12 +1,12 @@
import cx from "classnames";
import { t } from "ttag";
+import type { ActionItem } from "metabase/actions/utils";
import CS from "metabase/css/core/index.css";
import { ActionIcon, Box, Flex, Icon, Menu, Text } from "metabase/ui";
import S from "./ObjectDetailHeader.module.css";
import type { ObjectId } from "./types";
-import type { ActionItem } from "./utils";
export interface ObjectDetailHeaderProps {
actionItems: ActionItem[];
diff --git a/frontend/src/metabase/visualizations/components/ObjectDetail/ObjectDetailPanel.tsx b/frontend/src/metabase/visualizations/components/ObjectDetail/ObjectDetailPanel.tsx
index 6943900d49c..a5e9c5744c7 100644
--- a/frontend/src/metabase/visualizations/components/ObjectDetail/ObjectDetailPanel.tsx
+++ b/frontend/src/metabase/visualizations/components/ObjectDetail/ObjectDetailPanel.tsx
@@ -3,7 +3,9 @@ import { useMount, usePrevious } from "react-use";
import { t } from "ttag";
import _ from "underscore";
+import { DeleteObjectModal } from "metabase/actions/components/DeleteObjectModal";
import { ActionExecuteModal } from "metabase/actions/containers/ActionExecuteModal";
+import { getActionItems } from "metabase/actions/utils";
import {
actionApi,
datasetApi,
@@ -25,7 +27,6 @@ import type {
WritebackActionId,
} from "metabase-types/api";
-import { DeleteObjectModal } from "./DeleteObjectModal";
import { ObjectDetailBody } from "./ObjectDetailBody";
import { ObjectDetailHeader } from "./ObjectDetailHeader";
import {
@@ -34,12 +35,7 @@ import {
ObjectDetailLayout,
} from "./ObjectDetailPanel.styled";
import type { ObjectDetailProps, ObjectId } from "./types";
-import {
- getActionItems,
- getDisplayId,
- getObjectName,
- getSinglePKIndex,
-} from "./utils";
+import { getDisplayId, getObjectName, getSinglePKIndex } from "./utils";
function filterByPk(
query: Lib.Query,
diff --git a/frontend/src/metabase/visualizations/components/ObjectDetail/utils.ts b/frontend/src/metabase/visualizations/components/ObjectDetail/utils.ts
index e1760fcdb34..619bdb01600 100644
--- a/frontend/src/metabase/visualizations/components/ObjectDetail/utils.ts
+++ b/frontend/src/metabase/visualizations/components/ObjectDetail/utils.ts
@@ -1,15 +1,9 @@
import { t } from "ttag";
-import {
- isImplicitDeleteAction,
- isImplicitUpdateAction,
-} from "metabase/actions/utils";
import * as Urls from "metabase/urls";
import { singularize } from "metabase/utils/formatting";
import { formatValue } from "metabase/value-formatting";
import type Question from "metabase-lib/v1/Question";
-import { canRunAction } from "metabase-lib/v1/actions/utils";
-import type Database from "metabase-lib/v1/metadata/Database";
import type Table from "metabase-lib/v1/metadata/Table";
import {
getIsPKFromTablePredicate,
@@ -20,10 +14,8 @@ import type {
Table as ApiTable,
DatasetColumn,
DatasetData,
- IconName,
TableId,
VisualizationSettings,
- WritebackAction,
} from "metabase-types/api";
import type { ObjectId } from "./types";
@@ -141,55 +133,6 @@ export const getSinglePKIndex = (cols: DatasetColumn[]) => {
return index === -1 ? undefined : index;
};
-export type ActionItem = {
- title: string;
- icon: IconName;
- action: () => void;
-};
-
-// TODO: Reuse helpers from DetailView (@stasgavrylov / 13.06.26)
-export const getActionItems = ({
- actions,
- databases,
- onDelete,
- onUpdate,
-}: {
- actions: WritebackAction[];
- databases: Database[];
- onDelete: (action: WritebackAction) => void;
- onUpdate: (action: WritebackAction) => void;
-}): ActionItem[] => {
- const actionItems: ActionItem[] = [];
- /**
- * Public actions require an additional endpoint which is out of scope
- * of Milestone 1 in #32320 epic.
- *
- * @see https://github.com/metabase/metabase/issues/32320
- * @see https://metaboat.slack.com/archives/C057T1QTB3L/p1689845931726009?thread_ts=1689665950.493399&cid=C057T1QTB3L
- */
- const privateActions = actions.filter((action) => !action.public_uuid);
- const deleteAction = privateActions.find(isValidImplicitDeleteAction);
- const updateAction = privateActions.find(isValidImplicitUpdateAction);
-
- if (updateAction && canRunAction(updateAction, databases)) {
- const action = () => onUpdate(updateAction);
- actionItems.push({ title: t`Update`, icon: "pencil", action });
- }
-
- if (deleteAction && canRunAction(deleteAction, databases)) {
- const action = () => onDelete(deleteAction);
- actionItems.push({ title: t`Delete`, icon: "trash", action });
- }
-
- return actionItems;
-};
-
-export const isValidImplicitDeleteAction = (action: WritebackAction): boolean =>
- isImplicitDeleteAction(action) && !action.archived;
-
-export const isValidImplicitUpdateAction = (action: WritebackAction): boolean =>
- isImplicitUpdateAction(action) && !action.archived;
-
export function getApiTable(
table: Table | undefined | null,
): ApiTable | undefined {
diff --git a/frontend/src/metabase/visualizations/components/ObjectDetail/utils.unit.spec.ts b/frontend/src/metabase/visualizations/components/ObjectDetail/utils.unit.spec.ts
index 982e25ba877..1f63b1bdf59 100644
--- a/frontend/src/metabase/visualizations/components/ObjectDetail/utils.unit.spec.ts
+++ b/frontend/src/metabase/visualizations/components/ObjectDetail/utils.unit.spec.ts
@@ -3,8 +3,6 @@ import Question from "metabase-lib/v1/Question";
import {
createMockColumn,
createMockDatasetData,
- createMockImplicitQueryAction,
- createMockNativeDatasetQuery,
createMockTable,
} from "metabase-types/api/mocks";
import {
@@ -15,20 +13,13 @@ import {
} from "metabase-types/api/mocks/presets";
import {
- getActionItems,
getDisplayId,
getIdValue,
getObjectName,
getRowUrl,
getSinglePKIndex,
- isValidImplicitDeleteAction,
- isValidImplicitUpdateAction,
} from "./utils";
-const ACTIONS_ENABLED_DB_ID = 10;
-
-const ACTIONS_DISABLED_DB_ID = 11;
-
const card = createSavedStructuredCard({
name: "Special Order",
});
@@ -36,42 +27,10 @@ const card = createSavedStructuredCard({
const database = createSampleDatabase();
const metadata = createMockMetadata({
- databases: [
- database,
- createSampleDatabase({
- id: ACTIONS_ENABLED_DB_ID,
- settings: { "database-enable-actions": true },
- }),
- createSampleDatabase({
- id: ACTIONS_DISABLED_DB_ID,
- settings: { "database-enable-actions": false },
- }),
- ],
+ databases: [database],
questions: [card],
});
-const databaseWithEnabledActions = metadata.database(ACTIONS_ENABLED_DB_ID)!;
-
-const databaseWithDisabledActions = metadata.database(ACTIONS_DISABLED_DB_ID)!;
-
-const implicitCreateAction = createMockImplicitQueryAction({
- database_id: ACTIONS_ENABLED_DB_ID,
- name: "Create",
- kind: "row/create",
-});
-
-const implicitDeleteAction = createMockImplicitQueryAction({
- database_id: ACTIONS_ENABLED_DB_ID,
- name: "Delete",
- kind: "row/delete",
-});
-
-const implicitUpdateAction = createMockImplicitQueryAction({
- database_id: ACTIONS_ENABLED_DB_ID,
- name: "Update",
- kind: "row/update",
-});
-
describe("ObjectDetail utils", () => {
const productIdCol = createMockColumn({
name: "product_id",
@@ -294,115 +253,4 @@ describe("ObjectDetail utils", () => {
);
});
});
-
- describe("getActionItems", () => {
- const onDelete = jest.fn();
- const onUpdate = jest.fn();
- const actions = [
- implicitDeleteAction,
- implicitUpdateAction,
- implicitCreateAction,
- ];
-
- it("should return delete and update action items", () => {
- expect(
- getActionItems({
- actions,
- databases: [databaseWithEnabledActions],
- onDelete,
- onUpdate,
- }),
- ).toMatchObject([
- { title: "Update", icon: "pencil" },
- { title: "Delete", icon: "trash" },
- ]);
- });
-
- it("should not return any items when database actions are disabled", () => {
- expect(
- getActionItems({
- actions,
- databases: [databaseWithDisabledActions],
- onDelete,
- onUpdate,
- }),
- ).toEqual([]);
- });
-
- it("should not return any items when there are no databases", () => {
- expect(
- getActionItems({
- actions,
- databases: [],
- onDelete,
- onUpdate,
- }),
- ).toEqual([]);
- });
-
- it("should not return any items when there are no actions", () => {
- expect(
- getActionItems({
- actions: [],
- databases: [databaseWithDisabledActions, databaseWithEnabledActions],
- onDelete,
- onUpdate,
- }),
- ).toEqual([]);
- });
- });
-
- describe("isValidImplicitDeleteAction", () => {
- it("should detect implicit delete action", () => {
- expect(isValidImplicitDeleteAction(implicitCreateAction)).toBe(false);
- expect(isValidImplicitDeleteAction(implicitDeleteAction)).toBe(true);
- expect(isValidImplicitDeleteAction(implicitUpdateAction)).toBe(false);
- });
-
- it("should ignore archived action", () => {
- expect(
- isValidImplicitDeleteAction({
- ...implicitDeleteAction,
- archived: true,
- }),
- ).toBe(false);
- });
-
- it("should ignore non-implicit action", () => {
- expect(
- isValidImplicitDeleteAction({
- ...implicitDeleteAction,
- type: "query",
- dataset_query: createMockNativeDatasetQuery(),
- }),
- ).toBe(false);
- });
- });
-
- describe("isValidImplicitUpdateAction", () => {
- it("should detect implicit update action", () => {
- expect(isValidImplicitUpdateAction(implicitCreateAction)).toBe(false);
- expect(isValidImplicitUpdateAction(implicitDeleteAction)).toBe(false);
- expect(isValidImplicitUpdateAction(implicitUpdateAction)).toBe(true);
- });
-
- it("should ignore archived action", () => {
- expect(
- isValidImplicitUpdateAction({
- ...implicitUpdateAction,
- archived: true,
- }),
- ).toBe(false);
- });
-
- it("should ignore non-implicit action", () => {
- expect(
- isValidImplicitUpdateAction({
- ...implicitUpdateAction,
- type: "query",
- dataset_query: createMockNativeDatasetQuery(),
- }),
- ).toBe(false);
- });
- });
});