Refresh HiveGrid Cloud reference snapshot
This commit is contained in:
1 parent
5e99e14772
commit
7f88026f79
5955 files changed
+1177325
-188362
No files matched your search
+51
@@ -0,0 +1,51 @@
|
||||
import "@testing-library/jest-dom";
|
||||
import { fireEvent, render, screen } from "@testing-library/react";
|
||||
import { describe, expect, it, vi } from "vitest";
|
||||
|
||||
import { AutomationArchiveDialog } from "./AutomationArchiveDialog";
|
||||
|
||||
vi.mock("react-i18next", () => ({
|
||||
useTranslation: () => ({
|
||||
t: (key: string, options?: { name?: string }) => (options?.name ? `${key}:${options.name}` : key),
|
||||
}),
|
||||
}));
|
||||
|
||||
describe("AutomationArchiveDialog", () => {
|
||||
it("shows a HiveGrid confirmation instead of a native browser prompt", () => {
|
||||
const onOpenChange = vi.fn();
|
||||
const onConfirm = vi.fn();
|
||||
|
||||
render(
|
||||
<AutomationArchiveDialog
|
||||
ruleName="Meine Automation"
|
||||
open
|
||||
onOpenChange={onOpenChange}
|
||||
onConfirm={onConfirm}
|
||||
/>
|
||||
);
|
||||
|
||||
expect(screen.getByRole("dialog")).toBeVisible();
|
||||
expect(screen.getByText("automation.list.actions.deleteDialogTitle")).toBeVisible();
|
||||
expect(screen.getByText("automation.list.actions.deleteDialogBody:Meine Automation")).toBeVisible();
|
||||
|
||||
fireEvent.click(screen.getByRole("button", { name: "shared.cancel" }));
|
||||
expect(onOpenChange).toHaveBeenCalledWith(false);
|
||||
expect(onConfirm).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("requires an explicit destructive confirmation", () => {
|
||||
const onConfirm = vi.fn();
|
||||
|
||||
render(
|
||||
<AutomationArchiveDialog
|
||||
ruleName="Meine Automation"
|
||||
open
|
||||
onOpenChange={vi.fn()}
|
||||
onConfirm={onConfirm}
|
||||
/>
|
||||
);
|
||||
|
||||
fireEvent.click(screen.getByRole("button", { name: "automation.list.actions.deleteDialogConfirm" }));
|
||||
expect(onConfirm).toHaveBeenCalledOnce();
|
||||
});
|
||||
});
|
||||
+51
@@ -0,0 +1,51 @@
|
||||
import { useTranslation } from "react-i18next";
|
||||
import { FeatherTrash2 } from "@subframe/core";
|
||||
|
||||
import { Button } from "~/ui/components/Button";
|
||||
import { Dialog } from "~/ui/components/Dialog";
|
||||
|
||||
export type AutomationArchiveDialogProps = {
|
||||
ruleName: string;
|
||||
open: boolean;
|
||||
onOpenChange: (open: boolean) => void;
|
||||
onConfirm: () => void;
|
||||
};
|
||||
|
||||
/** Replaces the native browser confirm with the standard HiveGrid dialog. */
|
||||
export function AutomationArchiveDialog({ ruleName, open, onOpenChange, onConfirm }: AutomationArchiveDialogProps): React.JSX.Element {
|
||||
const { t } = useTranslation();
|
||||
|
||||
return (
|
||||
<Dialog open={open} onOpenChange={onOpenChange}>
|
||||
<Dialog.Content className="w-[420px] max-w-[90vw] p-8" data-ui-id="ui.automation.archiveDialog">
|
||||
<div className="flex w-full flex-col gap-6">
|
||||
<div className="flex flex-col gap-2">
|
||||
<span className="text-heading-3 font-heading-3 text-text-neutral-primary">
|
||||
{t("automation.list.actions.deleteDialogTitle")}
|
||||
</span>
|
||||
<span className="text-body-default-regular-150 font-body-default-regular-150 text-text-neutral-secondary">
|
||||
{t("automation.list.actions.deleteDialogBody", { name: ruleName })}
|
||||
</span>
|
||||
</div>
|
||||
|
||||
<div className="flex items-center justify-end gap-2 mobile:flex-col-reverse mobile:items-stretch">
|
||||
<Button type="button" variant="tertiary" onClick={() => onOpenChange(false)}>
|
||||
{t("shared.cancel")}
|
||||
</Button>
|
||||
<Button
|
||||
type="button"
|
||||
variant="destructive"
|
||||
icon={<FeatherTrash2 />}
|
||||
onClick={onConfirm}
|
||||
data-ui-id="ui.automation.archiveDialog.confirm"
|
||||
>
|
||||
{t("automation.list.actions.deleteDialogConfirm")}
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
</Dialog.Content>
|
||||
</Dialog>
|
||||
);
|
||||
}
|
||||
|
||||
export default AutomationArchiveDialog;
|
||||
+192
@@ -0,0 +1,192 @@
|
||||
import { useMemo, useState } from "react";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import * as SubframeCore from "@subframe/core";
|
||||
import { FeatherGitBranch, FeatherMousePointerClick, FeatherX, FeatherZap } from "@subframe/core";
|
||||
import { Drawer } from "~/ui/components/Drawer";
|
||||
import { BadgeFeedback } from "~/ui/components/BadgeFeedback";
|
||||
import { HelpCircle } from "~/ui/components/HelpCircle";
|
||||
import { IconButton } from "~/ui/components/IconButton";
|
||||
import { IconWithBackground } from "~/ui/components/IconWithBackground";
|
||||
import { SearchInput } from "~/ui/components/SearchInput";
|
||||
import { Tooltip } from "~/ui/components/Tooltip";
|
||||
import type { AutomationNodeDefinition } from "~/services/automation/automation.registry";
|
||||
import { nodeIcon } from "../automationUi";
|
||||
|
||||
export type BausteinPickerDrawerProps = {
|
||||
open: boolean;
|
||||
onOpenChange: (open: boolean) => void;
|
||||
catalog: readonly AutomationNodeDefinition[];
|
||||
canManage: boolean;
|
||||
submitting: boolean;
|
||||
onPick: (nodeType: string) => void;
|
||||
};
|
||||
|
||||
type PickerCategory = "trigger" | "action" | "logic";
|
||||
|
||||
const CATEGORIES: readonly {
|
||||
key: PickerCategory;
|
||||
icon: React.ComponentType<{ className?: string }>;
|
||||
tileVariant: "warning" | "information" | "neutral";
|
||||
dotClass: string;
|
||||
headerClass: string;
|
||||
}[] = [
|
||||
{ key: "trigger", icon: FeatherZap, tileVariant: "warning", dotClass: "bg-surface-feedback-solid-warning", headerClass: "text-text-feedback-warning" },
|
||||
{ key: "action", icon: FeatherMousePointerClick, tileVariant: "information", dotClass: "bg-surface-feedback-solid-information", headerClass: "text-text-feedback-information" },
|
||||
{ key: "logic", icon: FeatherGitBranch, tileVariant: "neutral", dotClass: "bg-surface-feedback-solid-neutral", headerClass: "text-text-neutral-tertiary" },
|
||||
];
|
||||
|
||||
function categoryOf(definition: AutomationNodeDefinition): PickerCategory {
|
||||
if (definition.kind === "trigger") return "trigger";
|
||||
if (definition.kind === "flow_control" || definition.kind === "condition") return "logic";
|
||||
return "action";
|
||||
}
|
||||
|
||||
/**
|
||||
* Node picker drawer after David's "Picker Kachel-Filter" page: category
|
||||
* tiles (Ausloeser/Aktionen/Logik), search, and per-node cards with a
|
||||
* plain-language tooltip. Renders the permission-filtered registry catalog,
|
||||
* so design-only nodes without a registry counterpart never appear.
|
||||
*/
|
||||
export function BausteinPickerDrawer({ open, onOpenChange, catalog, canManage, submitting, onPick }: BausteinPickerDrawerProps): React.JSX.Element {
|
||||
const { t } = useTranslation();
|
||||
const [query, setQuery] = useState("");
|
||||
const [activeCategory, setActiveCategory] = useState<PickerCategory | null>(null);
|
||||
|
||||
const sections = useMemo(() => {
|
||||
const normalizedQuery = query.trim().toLocaleLowerCase();
|
||||
return CATEGORIES.map((category) => ({
|
||||
...category,
|
||||
items: catalog.filter((definition) => {
|
||||
if (categoryOf(definition) !== category.key) return false;
|
||||
if (activeCategory && activeCategory !== category.key) return false;
|
||||
if (!normalizedQuery) return true;
|
||||
return (
|
||||
t(definition.titleKey).toLocaleLowerCase().includes(normalizedQuery) ||
|
||||
t(definition.descriptionKey).toLocaleLowerCase().includes(normalizedQuery) ||
|
||||
definition.key.toLocaleLowerCase().includes(normalizedQuery)
|
||||
);
|
||||
}),
|
||||
})).filter((section) => section.items.length > 0);
|
||||
}, [catalog, query, activeCategory, t]);
|
||||
|
||||
return (
|
||||
<Drawer open={open} onOpenChange={onOpenChange}>
|
||||
<Drawer.Content className="z-50" motionDirection="full-from-right">
|
||||
<div className="flex h-full w-[400px] flex-col items-start bg-surface-neutral-secondary mobile:w-full" data-ui-id="ui.automation.editor.picker">
|
||||
<div className="flex w-full items-center justify-between border-b border-solid border-border-default px-5 py-4">
|
||||
<div className="flex flex-col items-start gap-0.5">
|
||||
<span className="text-body-large-0 font-body-large-0 text-text-neutral-primary">{t("automation.editor.picker.title")}</span>
|
||||
<span className="text-body-extra-small-regular-0 font-body-extra-small-regular-0 text-text-neutral-tertiary">
|
||||
{t("automation.editor.picker.subtitle")}
|
||||
</span>
|
||||
</div>
|
||||
<IconButton variant="ghost" size="small" icon={<FeatherX />} aria-label={t("shared.close")} onClick={() => onOpenChange(false)} />
|
||||
</div>
|
||||
|
||||
<div className="flex w-full flex-col items-start border-b border-solid border-border-default px-5 py-3">
|
||||
<SearchInput
|
||||
className="h-9 w-full flex-none"
|
||||
fillContainer
|
||||
hideShortcut
|
||||
placeholder={t("automation.editor.picker.searchPlaceholder")}
|
||||
value={query}
|
||||
onChange={(event) => setQuery(event.target.value)}
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div className="flex w-full items-start gap-2.5 border-b border-solid border-border-default px-5 py-4">
|
||||
{CATEGORIES.map((category) => {
|
||||
const CategoryIcon = category.icon;
|
||||
const active = activeCategory === category.key;
|
||||
return (
|
||||
<button
|
||||
key={category.key}
|
||||
type="button"
|
||||
onClick={() => setActiveCategory(active ? null : category.key)}
|
||||
className={
|
||||
active
|
||||
? "flex flex-1 cursor-pointer flex-col items-center gap-1.5 rounded-md border border-solid border-border-strong bg-surface-neutral-tertiary px-3 py-3 shadow-sm"
|
||||
: "flex flex-1 cursor-pointer flex-col items-center gap-1.5 rounded-md border border-solid border-border-default bg-surface-neutral-secondary px-3 py-3 hover:border-border-strong hover:bg-surface-neutral-tertiary hover:shadow-sm"
|
||||
}
|
||||
data-ui-id={`ui.automation.editor.picker.category.${category.key}`}
|
||||
>
|
||||
<IconWithBackground variant={category.tileVariant} size="small" icon={<CategoryIcon />} />
|
||||
<span className="text-body-extra-small-semibold-0 font-body-extra-small-semibold-0 text-text-neutral-primary">
|
||||
{t(`automation.editor.picker.categories.${category.key}`)}
|
||||
</span>
|
||||
</button>
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
|
||||
<div className="flex w-full flex-1 flex-col items-start gap-6 overflow-y-auto px-5 py-5">
|
||||
{sections.length === 0 ? (
|
||||
<span className="text-body-small-regular-150 font-body-small-regular-150 text-text-neutral-tertiary">
|
||||
{t("automation.editor.picker.emptyResults")}
|
||||
</span>
|
||||
) : (
|
||||
sections.map((section) => (
|
||||
<div key={section.key} className="flex w-full flex-col items-start gap-2.5">
|
||||
<div className="flex w-full items-center gap-2">
|
||||
<span className={`flex h-2.5 w-2.5 flex-none rounded-round ${section.dotClass}`} />
|
||||
<span className={`text-body-extra-small-semibold-0 font-body-extra-small-semibold-0 uppercase tracking-wider ${section.headerClass}`}>
|
||||
{t(`automation.editor.picker.categories.${section.key}`)}
|
||||
</span>
|
||||
<span className="text-body-extra-small-regular-0 font-body-extra-small-regular-0 text-text-neutral-tertiary">
|
||||
{t(`automation.editor.picker.categoryHints.${section.key}`)}
|
||||
</span>
|
||||
</div>
|
||||
{section.items.map((definition) => {
|
||||
const NodeIcon = nodeIcon(definition.key);
|
||||
const helpText = t(`automation.editor.nodeConfig.${definition.key.replaceAll(".", "_")}.helpBox`, {
|
||||
defaultValue: t(definition.descriptionKey),
|
||||
});
|
||||
return (
|
||||
<button
|
||||
key={definition.key}
|
||||
type="button"
|
||||
className="flex w-full cursor-pointer items-center gap-3 rounded-md border border-solid border-border-default bg-surface-neutral-secondary px-3 py-2.5 text-left hover:border-border-strong hover:bg-surface-neutral-tertiary hover:shadow-sm disabled:cursor-not-allowed disabled:opacity-50"
|
||||
onClick={() => onPick(definition.key)}
|
||||
disabled={!canManage || submitting}
|
||||
data-ui-id={`ui.automation.editor.picker.${definition.key}`}
|
||||
>
|
||||
<IconWithBackground variant={section.tileVariant} size="medium" icon={<NodeIcon />} />
|
||||
<span className="flex flex-1 flex-col">
|
||||
<span className="text-body-small-semibold-0 font-body-small-semibold-0 text-text-neutral-primary">{t(definition.titleKey)}</span>
|
||||
<span className="line-clamp-1 text-body-extra-small-regular-0 font-body-extra-small-regular-0 text-text-neutral-tertiary">
|
||||
{t(definition.descriptionKey)}
|
||||
</span>
|
||||
</span>
|
||||
{definition.availability === "extension_slot" ? (
|
||||
<BadgeFeedback farbe="subtle-neutral" size="small">
|
||||
{t("automation.editor.picker.prepared")}
|
||||
</BadgeFeedback>
|
||||
) : null}
|
||||
<SubframeCore.Tooltip.Provider>
|
||||
<SubframeCore.Tooltip.Root>
|
||||
<SubframeCore.Tooltip.Trigger asChild>
|
||||
<span className="flex-none">
|
||||
<HelpCircle size="small" />
|
||||
</span>
|
||||
</SubframeCore.Tooltip.Trigger>
|
||||
<SubframeCore.Tooltip.Portal>
|
||||
<SubframeCore.Tooltip.Content side="left" align="center" sideOffset={6} asChild>
|
||||
<Tooltip className="max-w-72">{helpText}</Tooltip>
|
||||
</SubframeCore.Tooltip.Content>
|
||||
</SubframeCore.Tooltip.Portal>
|
||||
</SubframeCore.Tooltip.Root>
|
||||
</SubframeCore.Tooltip.Provider>
|
||||
</button>
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
))
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
</Drawer.Content>
|
||||
</Drawer>
|
||||
);
|
||||
}
|
||||
|
||||
export default BausteinPickerDrawer;
|
||||
+81
@@ -0,0 +1,81 @@
|
||||
// @vitest-environment jsdom
|
||||
import "@testing-library/jest-dom/vitest";
|
||||
import { useState } from "react";
|
||||
import { fireEvent, render, screen } from "@testing-library/react";
|
||||
import { describe, expect, it, vi } from "vitest";
|
||||
|
||||
import type { AutomationEditorStep } from "~/services/automation/automation.editor";
|
||||
import type { NodeConfigFieldDescriptor } from "../nodeConfigDescriptors";
|
||||
import { compactNodeConfigDraft, isNodeConfigFieldVisible, NodeConfigDialog } from "./NodeConfigDialog";
|
||||
|
||||
vi.mock("react-i18next", () => ({
|
||||
useTranslation: () => ({ t: (key: string) => key }),
|
||||
}));
|
||||
|
||||
vi.mock("~/ui/components/Dialog", () => {
|
||||
function Root({ open, children }: { open: boolean; children: React.ReactNode }) {
|
||||
return <div data-testid="dialog-root" data-open={String(open)}>{children}</div>;
|
||||
}
|
||||
function Content({ children, ...props }: React.HTMLAttributes<HTMLDivElement>) {
|
||||
return <div {...props}>{children}</div>;
|
||||
}
|
||||
return { Dialog: Object.assign(Root, { Content }) };
|
||||
});
|
||||
|
||||
const step: AutomationEditorStep = {
|
||||
stepKey: "task",
|
||||
kind: "action",
|
||||
nodeType: "task.create",
|
||||
parentStepIds: ["trigger"],
|
||||
config: { title: "Nachfassen" },
|
||||
position: { x: 320, y: 220 },
|
||||
sortOrder: 1,
|
||||
summaryKey: "automation.steps.createTask",
|
||||
};
|
||||
|
||||
describe("NodeConfigDialog", () => {
|
||||
it("keeps its content mounted while the confirm close transition runs", () => {
|
||||
const onApply = vi.fn();
|
||||
|
||||
function Harness() {
|
||||
const [open, setOpen] = useState(true);
|
||||
const [selectedStep, setSelectedStep] = useState<AutomationEditorStep | null>(step);
|
||||
return (
|
||||
<NodeConfigDialog
|
||||
open={open}
|
||||
onOpenChange={(nextOpen) => {
|
||||
setOpen(nextOpen);
|
||||
if (!nextOpen) setSelectedStep(null);
|
||||
}}
|
||||
step={selectedStep}
|
||||
descriptor={null}
|
||||
canManage
|
||||
submitting={false}
|
||||
onApply={onApply}
|
||||
/>
|
||||
);
|
||||
}
|
||||
|
||||
render(<Harness />);
|
||||
fireEvent.click(screen.getByRole("button", { name: "automation.editor.nodeConfig.apply" }));
|
||||
|
||||
expect(onApply).toHaveBeenCalledWith({ title: "Nachfassen" });
|
||||
expect(screen.getByTestId("dialog-root")).toHaveAttribute("data-open", "false");
|
||||
expect(document.querySelector('[data-ui-id="ui.automation.editor.nodeConfig"]')).toBeInTheDocument();
|
||||
});
|
||||
|
||||
it("omits blank fields so they do not override values from the trigger payload", () => {
|
||||
expect(compactNodeConfigDraft({ projectId: "", portalUserId: " ", role: "customer" })).toEqual({ role: "customer" });
|
||||
});
|
||||
|
||||
it("shows conditional fields only for the configured selector value", () => {
|
||||
const field: NodeConfigFieldDescriptor = {
|
||||
kind: "text",
|
||||
configKey: "taskId",
|
||||
labelKey: "taskId",
|
||||
visibleWhen: { configKey: "aufgabe", equals: "bestimmteAufgabe" },
|
||||
};
|
||||
expect(isNodeConfigFieldVisible(field, { aufgabe: "ausVorherigemSchritt" })).toBe(false);
|
||||
expect(isNodeConfigFieldVisible(field, { aufgabe: "bestimmteAufgabe" })).toBe(true);
|
||||
});
|
||||
});
|
||||
+273
@@ -0,0 +1,273 @@
|
||||
import { useEffect, useRef, useState } from "react";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import { FeatherCheck, FeatherHelpCircle } from "@subframe/core";
|
||||
import { BadgeFeedback } from "~/ui/components/BadgeFeedback";
|
||||
import { Button } from "~/ui/components/Button";
|
||||
import { Dialog } from "~/ui/components/Dialog";
|
||||
import { IconWithBackground } from "~/ui/components/IconWithBackground";
|
||||
import { Select } from "~/ui/components/Select";
|
||||
import { TextArea } from "~/ui/components/TextArea";
|
||||
import { TextInput } from "~/ui/components/TextInput";
|
||||
import type { AutomationEditorStep } from "~/services/automation/automation.editor";
|
||||
import { nodeTitle } from "../automationUi";
|
||||
import type { NodeConfigDescriptor, NodeConfigFieldDescriptor, NodeConfigTone } from "../nodeConfigDescriptors";
|
||||
|
||||
export type NodeConfigDialogProps = {
|
||||
open: boolean;
|
||||
onOpenChange: (open: boolean) => void;
|
||||
step: AutomationEditorStep | null;
|
||||
descriptor: NodeConfigDescriptor | null;
|
||||
canManage: boolean;
|
||||
submitting: boolean;
|
||||
onApply: (config: Record<string, string>) => void;
|
||||
};
|
||||
|
||||
const HELP_BOX_CLASSES: Record<NodeConfigTone, { box: string; icon: string }> = {
|
||||
positive: { box: "border-border-positive-subtle bg-surface-feedback-subtle-positive", icon: "text-icon-feedback-positive" },
|
||||
warning: { box: "border-border-warning-subtle bg-surface-feedback-subtle-warning", icon: "text-icon-feedback-warning" },
|
||||
information: { box: "border-border-information-subtle bg-surface-feedback-subtle-information", icon: "text-icon-feedback-information" },
|
||||
negative: { box: "border-border-negative-subtle bg-surface-feedback-subtle-negative", icon: "text-icon-feedback-negative" },
|
||||
neutral: { box: "border-border-default bg-surface-neutral-tertiary", icon: "text-icon-neutral-tertiary" },
|
||||
};
|
||||
|
||||
/**
|
||||
* Schema-driven node configuration dialog after David's K-node cards
|
||||
* ("(MCP) HiveGrid Workflow Engine / Automationen P12"). Nodes without a
|
||||
* descriptor (extension slots, unknown types) fall back to the generic
|
||||
* key/value editor so every step stays configurable.
|
||||
*/
|
||||
export function NodeConfigDialog({ open, onOpenChange, step, descriptor, canManage, submitting, onApply }: NodeConfigDialogProps): React.JSX.Element {
|
||||
const { t } = useTranslation();
|
||||
const [draft, setDraft] = useState<Record<string, string>>({});
|
||||
const lastStep = useRef<AutomationEditorStep | null>(null);
|
||||
const lastDescriptor = useRef<NodeConfigDescriptor | null>(null);
|
||||
|
||||
// The parent clears its selected step as soon as closing starts. Keep the
|
||||
// last payload available while Radix holds the dialog in `data-state=closed`
|
||||
// so its exit transition can finish instead of losing the whole subtree.
|
||||
if (step) {
|
||||
lastStep.current = step;
|
||||
lastDescriptor.current = descriptor;
|
||||
}
|
||||
const renderedStep = step ?? lastStep.current;
|
||||
const renderedDescriptor = step ? descriptor : lastDescriptor.current;
|
||||
|
||||
useEffect(() => {
|
||||
if (!open || !step) return;
|
||||
const initial: Record<string, string> = {};
|
||||
for (const [key, value] of Object.entries(step.config)) {
|
||||
initial[key] = typeof value === "string" ? value : value == null ? "" : String(value);
|
||||
}
|
||||
if (descriptor) {
|
||||
for (const field of descriptor.fields) {
|
||||
if (field.kind === "number-unit") {
|
||||
initial[field.configKey] = initial[field.configKey] ?? field.defaultValue;
|
||||
initial[field.unitConfigKey] = initial[field.unitConfigKey] ?? field.unitOptions[0]?.value ?? "";
|
||||
} else if (!(field.configKey in initial)) {
|
||||
initial[field.configKey] = "";
|
||||
}
|
||||
}
|
||||
}
|
||||
setDraft(initial);
|
||||
}, [open, step, descriptor]);
|
||||
|
||||
if (!renderedStep) return <></>;
|
||||
|
||||
const NodeIcon = renderedDescriptor?.icon;
|
||||
const helpTone = renderedDescriptor ? HELP_BOX_CLASSES[renderedDescriptor.helpBox.tone] : null;
|
||||
const title = nodeTitle(t, renderedStep.nodeType);
|
||||
const subtitle = t(`automation.nodes.${renderedStep.nodeType.replaceAll(".", "_")}.description`, { defaultValue: "" });
|
||||
const widthClass = renderedDescriptor?.size === "medium" ? "w-[720px]" : "w-[560px]";
|
||||
|
||||
function setValue(key: string, value: string) {
|
||||
setDraft((current) => ({ ...current, [key]: value }));
|
||||
}
|
||||
|
||||
return (
|
||||
<Dialog open={open} onOpenChange={onOpenChange}>
|
||||
<Dialog.Content className={`${widthClass} max-w-full gap-0 p-0`} data-ui-id="ui.automation.editor.nodeConfig">
|
||||
<div className="flex w-full items-start gap-3 border-b border-solid border-border-default px-6 py-4">
|
||||
{NodeIcon && renderedDescriptor ? <IconWithBackground variant={renderedDescriptor.iconVariant} size="medium" icon={<NodeIcon />} /> : null}
|
||||
<div className="flex flex-1 flex-col items-start gap-1">
|
||||
<div className="flex flex-wrap items-center gap-2">
|
||||
<span className="text-heading- font-heading- text-text-neutral-primary">{title}</span>
|
||||
{renderedDescriptor ? (
|
||||
<BadgeFeedback farbe={renderedDescriptor.badgeFarbe} size="small">
|
||||
{t(renderedDescriptor.badgeLabelKey)}
|
||||
</BadgeFeedback>
|
||||
) : null}
|
||||
{renderedDescriptor?.proBadge ? (
|
||||
<BadgeFeedback farbe="subtle-neutral" size="small">
|
||||
{t("automation.editor.nodeConfig.badges.pro")}
|
||||
</BadgeFeedback>
|
||||
) : null}
|
||||
</div>
|
||||
{subtitle ? <span className="text-body-small-regular-150 font-body-small-regular-150 text-text-neutral-tertiary">{subtitle}</span> : null}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="flex max-h-[60vh] w-full flex-col gap-4 overflow-y-auto px-6 py-5">
|
||||
{renderedDescriptor && renderedDescriptor.fields.length > 0 ? (
|
||||
renderedDescriptor.fields
|
||||
.filter((field) => isNodeConfigFieldVisible(field, draft))
|
||||
.map((field) => <NodeConfigField key={fieldKey(field)} field={field} draft={draft} onChange={setValue} disabled={!canManage} />)
|
||||
) : (
|
||||
<GenericConfigFields draft={draft} onChange={setValue} disabled={!canManage} emptyHint={t("automation.editor.inspector.emptyConfiguration")} />
|
||||
)}
|
||||
{renderedDescriptor && helpTone ? (
|
||||
<div className={`flex w-full items-start gap-2 rounded-md border border-solid px-4 py-3 ${helpTone.box}`}>
|
||||
<FeatherHelpCircle className={`mt-0.5 flex-none text-body-small-regular-0 font-body-small-regular-0 ${helpTone.icon}`} />
|
||||
<span className="flex-1 text-body-small-regular-150 font-body-small-regular-150 text-text-neutral-secondary">{t(renderedDescriptor.helpBox.textKey)}</span>
|
||||
</div>
|
||||
) : null}
|
||||
</div>
|
||||
|
||||
<div className="flex w-full items-center justify-end gap-2 border-t border-solid border-border-default px-6 py-4">
|
||||
<Button variant="tertiary" onClick={() => onOpenChange(false)}>
|
||||
{t("shared.cancel")}
|
||||
</Button>
|
||||
<Button
|
||||
icon={<FeatherCheck />}
|
||||
loading={submitting}
|
||||
disabled={!canManage}
|
||||
onClick={() => {
|
||||
onApply(compactNodeConfigDraft(draft));
|
||||
onOpenChange(false);
|
||||
}}
|
||||
>
|
||||
{t("automation.editor.nodeConfig.apply")}
|
||||
</Button>
|
||||
</div>
|
||||
</Dialog.Content>
|
||||
</Dialog>
|
||||
);
|
||||
}
|
||||
|
||||
export function isNodeConfigFieldVisible(field: NodeConfigFieldDescriptor, draft: Record<string, string>): boolean {
|
||||
return !field.visibleWhen || draft[field.visibleWhen.configKey] === field.visibleWhen.equals;
|
||||
}
|
||||
|
||||
export function compactNodeConfigDraft(draft: Record<string, string>): Record<string, string> {
|
||||
return Object.fromEntries(Object.entries(draft).filter(([, value]) => value.trim().length > 0));
|
||||
}
|
||||
|
||||
function fieldKey(field: NodeConfigFieldDescriptor): string {
|
||||
return field.kind === "number-unit" ? `${field.configKey}-${field.unitConfigKey}` : field.configKey;
|
||||
}
|
||||
|
||||
function NodeConfigField({
|
||||
field,
|
||||
draft,
|
||||
onChange,
|
||||
disabled,
|
||||
}: {
|
||||
field: NodeConfigFieldDescriptor;
|
||||
draft: Record<string, string>;
|
||||
onChange: (key: string, value: string) => void;
|
||||
disabled: boolean;
|
||||
}): React.JSX.Element {
|
||||
const { t } = useTranslation();
|
||||
|
||||
if (field.kind === "select") {
|
||||
return (
|
||||
<Select
|
||||
className="h-auto w-full flex-none"
|
||||
label={t(field.labelKey)}
|
||||
showLabel
|
||||
placeholder={field.placeholderKey ? t(field.placeholderKey) : undefined}
|
||||
helpText={field.helpTextKey ? t(field.helpTextKey) : undefined}
|
||||
value={draft[field.configKey] || undefined}
|
||||
onValueChange={(value) => onChange(field.configKey, value)}
|
||||
disabled={disabled}
|
||||
>
|
||||
{field.options.map((option) => (
|
||||
<Select.Item key={option.value} value={option.value}>
|
||||
{t(option.labelKey)}
|
||||
</Select.Item>
|
||||
))}
|
||||
</Select>
|
||||
);
|
||||
}
|
||||
|
||||
if (field.kind === "textarea") {
|
||||
return (
|
||||
<TextArea className="w-full" label={t(field.labelKey)} helpText={field.helpTextKey ? t(field.helpTextKey) : undefined} showLabel>
|
||||
<TextArea.Input
|
||||
value={draft[field.configKey] ?? ""}
|
||||
placeholder={field.placeholderKey ? t(field.placeholderKey) : undefined}
|
||||
onChange={(event) => onChange(field.configKey, event.target.value)}
|
||||
disabled={disabled}
|
||||
/>
|
||||
</TextArea>
|
||||
);
|
||||
}
|
||||
|
||||
if (field.kind === "number-unit") {
|
||||
return (
|
||||
<div className="flex w-full items-end gap-2">
|
||||
<TextInput className="w-24 flex-none" label={t(field.labelKey)} showLabel>
|
||||
<TextInput.Input
|
||||
type="number"
|
||||
min={0}
|
||||
value={draft[field.configKey] ?? field.defaultValue}
|
||||
onChange={(event) => onChange(field.configKey, event.target.value)}
|
||||
disabled={disabled}
|
||||
/>
|
||||
</TextInput>
|
||||
<Select
|
||||
className="h-auto flex-1"
|
||||
label=""
|
||||
value={draft[field.unitConfigKey] || field.unitOptions[0]?.value}
|
||||
onValueChange={(value) => onChange(field.unitConfigKey, value)}
|
||||
disabled={disabled}
|
||||
>
|
||||
{field.unitOptions.map((option) => (
|
||||
<Select.Item key={option.value} value={option.value}>
|
||||
{t(option.labelKey)}
|
||||
</Select.Item>
|
||||
))}
|
||||
</Select>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
return (
|
||||
<TextInput className="w-full" label={t(field.labelKey)} helpText={field.helpTextKey ? t(field.helpTextKey) : undefined} showLabel>
|
||||
<TextInput.Input
|
||||
value={draft[field.configKey] ?? ""}
|
||||
placeholder={field.placeholderKey ? t(field.placeholderKey) : undefined}
|
||||
onChange={(event) => onChange(field.configKey, event.target.value)}
|
||||
disabled={disabled}
|
||||
/>
|
||||
</TextInput>
|
||||
);
|
||||
}
|
||||
|
||||
/** Fallback for extension-slot/unknown nodes: edit the raw config bag like the previous inspector did. */
|
||||
function GenericConfigFields({
|
||||
draft,
|
||||
onChange,
|
||||
disabled,
|
||||
emptyHint,
|
||||
}: {
|
||||
draft: Record<string, string>;
|
||||
onChange: (key: string, value: string) => void;
|
||||
disabled: boolean;
|
||||
emptyHint: string;
|
||||
}): React.JSX.Element {
|
||||
const entries = Object.entries(draft);
|
||||
if (entries.length === 0) {
|
||||
return <span className="text-body-small-regular-150 font-body-small-regular-150 text-text-neutral-secondary">{emptyHint}</span>;
|
||||
}
|
||||
return (
|
||||
<>
|
||||
{entries.map(([key]) => (
|
||||
<TextInput key={key} className="w-full" label={key} showLabel>
|
||||
<TextInput.Input value={draft[key] ?? ""} onChange={(event) => onChange(key, event.target.value)} disabled={disabled} />
|
||||
</TextInput>
|
||||
))}
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
export default NodeConfigDialog;
|
||||
+240
@@ -0,0 +1,240 @@
|
||||
import { useState } from "react";
|
||||
import { Form as RouterForm, Link } from "react-router";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import {
|
||||
FeatherAlertTriangle,
|
||||
FeatherArrowLeft,
|
||||
FeatherDatabase,
|
||||
FeatherInfo,
|
||||
FeatherListChecks,
|
||||
FeatherPlay,
|
||||
FeatherUsers,
|
||||
FeatherX,
|
||||
} from "@subframe/core";
|
||||
import { BadgeFeedback } from "~/ui/components/BadgeFeedback";
|
||||
import { Button } from "~/ui/components/Button";
|
||||
import { Dialog } from "~/ui/components/Dialog";
|
||||
import { IconButton } from "~/ui/components/IconButton";
|
||||
import { TextInput } from "~/ui/components/TextInput";
|
||||
import type { AutomationExecutionListVM, AutomationExecutionsActionData } from "~/services/automation/automation.server";
|
||||
import { useLocaleFormatters } from "~/locale/format";
|
||||
import { localizedValue, nodeIcon, nodeTitle } from "../automationUi";
|
||||
|
||||
/** WF-P12 M01 "Probelauf pruefen": dry-run preview form + result (intent=dry-run, csrf-guarded). */
|
||||
export function ProbelaufDialog({
|
||||
vm,
|
||||
csrf,
|
||||
actionData,
|
||||
open,
|
||||
onOpenChange,
|
||||
}: {
|
||||
vm: AutomationExecutionListVM;
|
||||
csrf: string;
|
||||
actionData?: AutomationExecutionsActionData;
|
||||
open: boolean;
|
||||
onOpenChange: (open: boolean) => void;
|
||||
}): React.JSX.Element | null {
|
||||
const { t } = useTranslation();
|
||||
const formatters = useLocaleFormatters();
|
||||
const [confirmationPhrase, setConfirmationPhrase] = useState("");
|
||||
|
||||
if (!open) return null;
|
||||
|
||||
const preview = actionData?.dryRunPreview;
|
||||
const needsConfirmation = preview?.requiresConfirmation ?? false;
|
||||
const phrase = preview?.confirmationPhrase ?? t("automation.editor.dryRun.confirmationPhrase");
|
||||
|
||||
return (
|
||||
<Dialog open onOpenChange={(nextOpen: boolean) => (nextOpen ? undefined : onOpenChange(false))}>
|
||||
<Dialog.Content className="w-[640px] max-w-full gap-0 p-0">
|
||||
<div className="flex w-full items-start justify-between gap-3 border-b border-solid border-border-default bg-surface-neutral-secondary px-6 py-5 mobile:px-4">
|
||||
<div className="flex items-start gap-3">
|
||||
<div className="flex h-9 w-9 flex-none items-center justify-center rounded-md bg-surface-feedback-subtle-information">
|
||||
<FeatherPlay className="text-body-large-0 font-body-large-0 text-icon-feedback-information" />
|
||||
</div>
|
||||
<div className="flex flex-col items-start gap-1">
|
||||
<span className="text-heading- font-heading- text-text-neutral-primary">{t("automation.editor.dryRun.dialogTitle")}</span>
|
||||
<span className="text-body-small-regular-150 font-body-small-regular-150 text-text-neutral-tertiary">
|
||||
{t("automation.editor.dryRun.dialogSubtitle")}
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
<IconButton variant="ghost" size="small" icon={<FeatherX />} aria-label={t("shared.close")} onClick={() => onOpenChange(false)} />
|
||||
</div>
|
||||
|
||||
<div className="flex w-full flex-col items-start gap-5 px-6 py-5 max-h-[65vh] overflow-y-auto mobile:px-4">
|
||||
{actionData && !actionData.ok ? (
|
||||
<div className="flex w-full items-center gap-2 rounded-md border border-solid border-border-negative-subtle bg-surface-feedback-subtle-negative px-4 py-3">
|
||||
<FeatherAlertTriangle className="text-body-default-regular-0 font-body-default-regular-0 text-icon-feedback-negative" />
|
||||
<span className="text-body-small-regular-150 font-body-small-regular-150 text-text-feedback-negative">{t(actionData.errorKey)}</span>
|
||||
</div>
|
||||
) : null}
|
||||
|
||||
<RouterForm method="post" className="flex w-full flex-col items-start gap-4">
|
||||
<input type="hidden" name="csrf" value={csrf} readOnly />
|
||||
<input type="hidden" name="intent" value="dry-run" />
|
||||
<div className="flex w-full items-start gap-2 rounded-md border border-solid border-border-default bg-surface-neutral-secondary px-4 py-3">
|
||||
<FeatherInfo className="text-body-default-regular-0 font-body-default-regular-0 text-icon-feedback-information" />
|
||||
<span className="grow shrink-0 basis-0 text-body-small-regular-150 font-body-small-regular-150 text-text-neutral-secondary">
|
||||
{t("automation.editor.dryRun.dataSourceHelp", { limit: 500 })}
|
||||
</span>
|
||||
</div>
|
||||
{needsConfirmation ? (
|
||||
<div className="flex w-full flex-col items-start gap-3 rounded-md border border-solid border-border-warning-subtle bg-surface-feedback-subtle-warning px-4 py-3.5">
|
||||
<div className="flex w-full items-start gap-2">
|
||||
<FeatherAlertTriangle className="text-body-default-regular-0 font-body-default-regular-0 text-icon-feedback-warning" />
|
||||
<span className="grow shrink-0 basis-0 text-body-small-medium-150 font-body-small-medium-150 text-text-feedback-warning">
|
||||
{t("automation.editor.dryRun.confirmationHint", { phrase })}
|
||||
</span>
|
||||
</div>
|
||||
<TextInput className="w-full" label={t("automation.editor.dryRun.confirmationLabel")} showLabel>
|
||||
<TextInput.Input
|
||||
name="confirmationPhrase"
|
||||
value={confirmationPhrase}
|
||||
onChange={(event: React.ChangeEvent<HTMLInputElement>) => setConfirmationPhrase(event.target.value)}
|
||||
/>
|
||||
</TextInput>
|
||||
</div>
|
||||
) : null}
|
||||
<Button type="submit" icon={<FeatherPlay />}>
|
||||
{t("automation.editor.dryRun.start")}
|
||||
</Button>
|
||||
</RouterForm>
|
||||
|
||||
{preview ? (
|
||||
<div className="flex w-full flex-col items-start gap-5 border-t border-solid border-border-default pt-5">
|
||||
<div className="flex w-full flex-col items-start gap-3 rounded-lg border border-solid border-border-warning-subtle bg-surface-feedback-subtle-warning px-4 py-4">
|
||||
<div className="flex w-full items-center gap-3 mobile:flex-col mobile:items-start">
|
||||
<div className="flex h-10 w-10 flex-none items-center justify-center rounded-round bg-surface-neutral-secondary">
|
||||
<FeatherDatabase className="text-heading- font-heading- text-icon-feedback-warning" />
|
||||
</div>
|
||||
<div className="flex grow shrink-0 basis-0 flex-col items-start">
|
||||
<span className="text-subtitle font-subtitle text-text-neutral-primary">
|
||||
{t("automation.editor.dryRun.matched", { count: preview.matchedRecords, formattedCount: formatters.number(preview.matchedRecords) })}
|
||||
</span>
|
||||
<span className="text-body-small-regular-150 font-body-small-regular-150 text-text-neutral-tertiary">
|
||||
{nodeTitle(t, vm.rule.triggerKey)}
|
||||
</span>
|
||||
</div>
|
||||
{preview.requiresConfirmation ? (
|
||||
<BadgeFeedback farbe="subtle-warning">{t("automation.editor.dryRun.confirmationBadge")}</BadgeFeedback>
|
||||
) : null}
|
||||
</div>
|
||||
{preview.requiresConfirmation ? (
|
||||
<div className="flex w-full items-center gap-2 border-t border-solid border-border-warning-subtle pt-3">
|
||||
<FeatherAlertTriangle className="text-body-default-regular-0 font-body-default-regular-0 text-icon-feedback-warning" />
|
||||
<span className="grow shrink-0 basis-0 text-body-small-medium-150 font-body-small-medium-150 text-text-feedback-warning">
|
||||
{t("automation.editor.dryRun.thresholdWarning")}
|
||||
</span>
|
||||
</div>
|
||||
) : null}
|
||||
<span className="text-body-extra-small-regular-0 font-body-extra-small-regular-0 text-text-neutral-tertiary">
|
||||
{t(preview.sampleLimitReached ? "automation.editor.dryRun.sourceSummaryLimited" : "automation.editor.dryRun.sourceSummary", {
|
||||
count: preview.inspectedEvents,
|
||||
formattedCount: formatters.number(preview.inspectedEvents),
|
||||
})}
|
||||
</span>
|
||||
</div>
|
||||
|
||||
{preview.examples.length > 0 ? (
|
||||
<div className="flex w-full flex-col items-start gap-3">
|
||||
<div className="flex w-full items-center gap-2">
|
||||
<FeatherUsers className="text-body-default-regular-0 font-body-default-regular-0 text-icon-neutral-tertiary" />
|
||||
<span className="grow shrink-0 basis-0 text-body-default-semibold-150 font-body-default-semibold-150 text-text-neutral-primary">
|
||||
{t("automation.editor.dryRun.examplesTitle", { count: preview.examples.length })}
|
||||
</span>
|
||||
</div>
|
||||
<div className="flex w-full flex-col items-start rounded-md border border-solid border-border-default bg-surface-neutral-secondary">
|
||||
{preview.examples.map((example, index) => (
|
||||
<div
|
||||
key={`${example}-${index}`}
|
||||
className={
|
||||
index < preview.examples.length - 1
|
||||
? "flex w-full items-center gap-3 border-b border-solid border-border-default px-4 py-2.5"
|
||||
: "flex w-full items-center gap-3 px-4 py-2.5"
|
||||
}
|
||||
>
|
||||
<span className="grow shrink-0 basis-0 text-body-small-medium-150 font-body-small-medium-150 text-text-neutral-primary">
|
||||
{example}
|
||||
</span>
|
||||
<BadgeFeedback farbe="subtle-neutral" size="small">
|
||||
{nodeTitle(t, vm.rule.triggerKey)}
|
||||
</BadgeFeedback>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
) : null}
|
||||
|
||||
<div className="flex w-full flex-col items-start gap-3">
|
||||
<div className="flex w-full items-center gap-2">
|
||||
<FeatherListChecks className="text-body-default-regular-0 font-body-default-regular-0 text-icon-neutral-tertiary" />
|
||||
<span className="grow shrink-0 basis-0 text-body-default-semibold-150 font-body-default-semibold-150 text-text-neutral-primary">
|
||||
{t("automation.editor.dryRun.simulationTitle")}
|
||||
</span>
|
||||
<BadgeFeedback farbe="subtle-information" size="small">
|
||||
{t("automation.editor.dryRun.previewOnly")}
|
||||
</BadgeFeedback>
|
||||
</div>
|
||||
<div className="flex w-full flex-col items-start gap-2 rounded-md border border-solid border-border-default bg-surface-neutral-primary px-4 py-4">
|
||||
{preview.steps.map((step, index) => {
|
||||
const StepIcon = nodeIcon(step.nodeType);
|
||||
return (
|
||||
<span key={step.stepKey} className="contents">
|
||||
{index > 0 ? (
|
||||
<span className="flex h-4 w-6 flex-none flex-col items-center">
|
||||
<span className="flex h-4 w-px flex-none flex-col items-center bg-border-strong" />
|
||||
</span>
|
||||
) : null}
|
||||
<div className="flex w-full items-start gap-3">
|
||||
<div className="flex h-6 w-6 flex-none items-center justify-center rounded-round bg-surface-feedback-subtle-information">
|
||||
<StepIcon className="text-body-small-regular-0 font-body-small-regular-0 text-icon-feedback-information" />
|
||||
</div>
|
||||
<div className="flex grow shrink-0 basis-0 flex-col items-start">
|
||||
<span className="text-body-small-medium-150 font-body-small-medium-150 text-text-neutral-primary">
|
||||
{t(step.summaryKey, { defaultValue: nodeTitle(t, step.nodeType) })}
|
||||
</span>
|
||||
<span className="text-body-extra-small-regular-0 font-body-extra-small-regular-0 text-text-neutral-tertiary">
|
||||
{t(step.effectKey, { node: nodeTitle(t, step.nodeType) })}
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
</span>
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{preview.warnings.length > 0 ? (
|
||||
<div className="flex w-full flex-col items-start gap-2 rounded-md border border-solid border-border-warning-subtle bg-surface-feedback-subtle-warning px-4 py-3">
|
||||
<span className="text-body-small-semibold-150 font-body-small-semibold-150 text-text-feedback-warning">
|
||||
{t("automation.editor.dryRun.warningsTitle")}
|
||||
</span>
|
||||
{preview.warnings.map((warningKey, index) => (
|
||||
<div key={`${warningKey}-${index}`} className="flex w-full items-start gap-2">
|
||||
<FeatherInfo className="mt-0.5 text-body-small-regular-0 font-body-small-regular-0 text-icon-feedback-warning" />
|
||||
<span className="grow shrink-0 basis-0 text-body-small-regular-150 font-body-small-regular-150 text-text-neutral-secondary">
|
||||
{localizedValue(t, warningKey, "automation.values.unknownWarning")}
|
||||
</span>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
) : null}
|
||||
</div>
|
||||
) : null}
|
||||
</div>
|
||||
|
||||
<div className="flex w-full items-center justify-end gap-2 border-t border-solid border-border-default bg-surface-neutral-secondary px-6 py-4 mobile:flex-col-reverse mobile:items-stretch mobile:px-4">
|
||||
<Button type="button" className="mobile:w-full" variant="tertiary" onClick={() => onOpenChange(false)}>
|
||||
{t("shared.cancel")}
|
||||
</Button>
|
||||
<Link to={vm.rule.editUrl} className="mobile:w-full">
|
||||
<Button type="button" className="mobile:w-full" variant="secondary" icon={<FeatherArrowLeft />}>
|
||||
{t("automation.editor.dryRun.backToEditor")}
|
||||
</Button>
|
||||
</Link>
|
||||
</div>
|
||||
</Dialog.Content>
|
||||
</Dialog>
|
||||
);
|
||||
}
|
||||
+119
@@ -0,0 +1,119 @@
|
||||
import { Link, useSubmit } from "react-router";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import { FeatherActivity, FeatherAlertTriangle, FeatherPause, FeatherRefreshCw, FeatherWrench, FeatherZap } from "@subframe/core";
|
||||
import { BadgeFeedback } from "~/ui/components/BadgeFeedback";
|
||||
import { Button } from "~/ui/components/Button";
|
||||
import { Dialog } from "~/ui/components/Dialog";
|
||||
import { IconWithBackground } from "~/ui/components/IconWithBackground";
|
||||
import type { AutomationListActionData, AutomationListItemVM } from "~/services/automation/automation.server";
|
||||
import { useLocaleFormatters } from "~/locale/format";
|
||||
import { anomalyMessage, localizedValue } from "../automationUi";
|
||||
|
||||
/**
|
||||
* WF-P12 M02 "Schleife oder zu hohe Rate erkannt": shown for a rule the trigger
|
||||
* volume meter auto-paused. "Trotzdem aktivieren" posts intent=activate (the
|
||||
* server re-validates the flow and blocks invalid ones).
|
||||
*/
|
||||
export function SchleifenWarnungDialog({
|
||||
rule,
|
||||
csrf,
|
||||
actionData,
|
||||
open,
|
||||
onOpenChange,
|
||||
}: {
|
||||
rule: AutomationListItemVM;
|
||||
csrf: string;
|
||||
actionData?: AutomationListActionData;
|
||||
open: boolean;
|
||||
onOpenChange: (open: boolean) => void;
|
||||
}): React.JSX.Element | null {
|
||||
const { t } = useTranslation();
|
||||
const formatters = useLocaleFormatters();
|
||||
const submit = useSubmit();
|
||||
|
||||
if (!open) return null;
|
||||
|
||||
const activateAnyway = () => {
|
||||
const formData = new FormData();
|
||||
formData.set("csrf", csrf);
|
||||
formData.set("intent", "activate");
|
||||
formData.set("ruleId", rule.id);
|
||||
void submit(formData, { method: "post" });
|
||||
};
|
||||
|
||||
return (
|
||||
<Dialog open onOpenChange={(nextOpen: boolean) => (nextOpen ? undefined : onOpenChange(false))}>
|
||||
<Dialog.Content className="w-[640px] max-w-full gap-4 px-6 py-6">
|
||||
<div className="flex w-full items-start gap-4">
|
||||
<IconWithBackground variant="warning" size="large" round icon={<FeatherRefreshCw />} />
|
||||
<div className="flex grow shrink-0 basis-0 flex-col items-start gap-2">
|
||||
<div className="flex w-full flex-wrap items-center gap-2">
|
||||
<span className="text-heading- font-heading- text-text-neutral-primary">{t("automation.dialogs.loop.title")}</span>
|
||||
<BadgeFeedback farbe="subtle-warning" size="small">
|
||||
{t("automation.status.paused")}
|
||||
</BadgeFeedback>
|
||||
</div>
|
||||
<span className="w-full text-body-small-regular-150 font-body-small-regular-150 text-text-neutral-tertiary">
|
||||
{t("automation.dialogs.loop.description", { name: rule.name })}
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{actionData && !actionData.ok ? (
|
||||
<div className="flex w-full items-start gap-2 rounded-md border border-solid border-border-negative-subtle bg-surface-feedback-subtle-negative px-4 py-3">
|
||||
<FeatherAlertTriangle className="mt-0.5 text-body-default-regular-0 font-body-default-regular-0 text-icon-feedback-negative" />
|
||||
<div className="flex grow shrink-0 basis-0 flex-col items-start">
|
||||
<span className="text-body-small-semibold-150 font-body-small-semibold-150 text-text-feedback-negative">{t(actionData.errorKey)}</span>
|
||||
{actionData.detail ? (
|
||||
<span className="text-body-small-regular-150 font-body-small-regular-150 text-text-neutral-secondary">
|
||||
{localizedValue(t, actionData.detail, "automation.values.unknownError")}
|
||||
</span>
|
||||
) : null}
|
||||
</div>
|
||||
</div>
|
||||
) : null}
|
||||
|
||||
<div className="flex h-px w-full flex-none flex-col items-center bg-border-default" />
|
||||
|
||||
<div className="flex w-full flex-col items-start gap-2 rounded-md border border-solid border-border-warning-subtle bg-surface-feedback-subtle-warning px-4 py-3.5">
|
||||
<div className="flex w-full items-center gap-2">
|
||||
<FeatherActivity className="text-body-default-regular-0 font-body-default-regular-0 text-icon-feedback-warning" />
|
||||
<span className="grow shrink-0 basis-0 text-body-small-semibold-150 font-body-small-semibold-150 text-text-feedback-warning">
|
||||
{t("automation.dialogs.loop.rateTitle")}
|
||||
</span>
|
||||
</div>
|
||||
<span className="w-full text-body-small-regular-150 font-body-small-regular-150 text-text-neutral-secondary">
|
||||
{anomalyMessage(t, rule) ?? t("automation.dialogs.loop.explainer")}
|
||||
</span>
|
||||
{rule.anomalyPausedUntil ? (
|
||||
<span className="w-full text-body-small-regular-150 font-body-small-regular-150 text-text-neutral-secondary">
|
||||
{t("automation.dialogs.loop.pausedUntil", {
|
||||
date: formatters.date(rule.anomalyPausedUntil, { dateStyle: "medium", timeStyle: "short" }),
|
||||
})}
|
||||
</span>
|
||||
) : null}
|
||||
</div>
|
||||
|
||||
<span className="w-full text-body-small-regular-150 font-body-small-regular-150 text-text-neutral-tertiary">
|
||||
{t("automation.dialogs.loop.explainer")}
|
||||
</span>
|
||||
|
||||
<div className="flex w-full items-center justify-end gap-2 mobile:flex-col-reverse mobile:items-stretch">
|
||||
<Button type="button" className="mobile:w-full" variant="destructive" icon={<FeatherZap />} onClick={activateAnyway}>
|
||||
{t("automation.dialogs.loop.activateAnyway")}
|
||||
</Button>
|
||||
<div className="flex grow shrink-0 basis-0 items-center justify-end gap-2 mobile:grow-0 mobile:flex-col-reverse mobile:items-stretch">
|
||||
<Button type="button" className="mobile:w-full" variant="secondary" icon={<FeatherPause />} onClick={() => onOpenChange(false)}>
|
||||
{t("automation.dialogs.loop.keepPaused")}
|
||||
</Button>
|
||||
<Link to={rule.editUrl} className="mobile:w-full">
|
||||
<Button type="button" className="mobile:w-full" variant="primary" icon={<FeatherWrench />}>
|
||||
{t("automation.dialogs.loop.fix")}
|
||||
</Button>
|
||||
</Link>
|
||||
</div>
|
||||
</div>
|
||||
</Dialog.Content>
|
||||
</Dialog>
|
||||
);
|
||||
}
|
||||
+81
@@ -0,0 +1,81 @@
|
||||
import "@testing-library/jest-dom";
|
||||
import { fireEvent, render, screen } from "@testing-library/react";
|
||||
import { createMemoryRouter, RouterProvider } from "react-router";
|
||||
import { beforeEach, describe, expect, it, vi } from "vitest";
|
||||
import type { AutomationListVM } from "~/services/automation/automation.server";
|
||||
|
||||
import { StartAuswahlDialog } from "./StartAuswahlDialog";
|
||||
|
||||
const mocks = vi.hoisted(() => ({
|
||||
submit: vi.fn(),
|
||||
}));
|
||||
|
||||
vi.mock("react-router", async () => {
|
||||
const actual = await vi.importActual<typeof import("react-router")>("react-router");
|
||||
return {
|
||||
...actual,
|
||||
useSubmit: () => mocks.submit,
|
||||
};
|
||||
});
|
||||
|
||||
vi.mock("react-i18next", () => ({
|
||||
useTranslation: () => ({ t: (key: string) => key }),
|
||||
}));
|
||||
|
||||
const vm: AutomationListVM = {
|
||||
tenantSlug: "acme",
|
||||
currentUserId: "user-1",
|
||||
rules: [],
|
||||
templates: [],
|
||||
templatesUrl: "/acme/automations/templates",
|
||||
canManage: true,
|
||||
canRun: true,
|
||||
};
|
||||
|
||||
function renderDialog(onCreateConfirmed = vi.fn(), onOpenChange = vi.fn()) {
|
||||
const router = createMemoryRouter(
|
||||
[
|
||||
{
|
||||
path: "/",
|
||||
element: (
|
||||
<StartAuswahlDialog
|
||||
vm={vm}
|
||||
csrf="csrf"
|
||||
open
|
||||
onOpenChange={onOpenChange}
|
||||
onCreateConfirmed={onCreateConfirmed}
|
||||
/>
|
||||
),
|
||||
},
|
||||
],
|
||||
{ initialEntries: ["/"] }
|
||||
);
|
||||
render(<RouterProvider router={router} />);
|
||||
return { onCreateConfirmed, onOpenChange };
|
||||
}
|
||||
|
||||
describe("StartAuswahlDialog", () => {
|
||||
beforeEach(() => {
|
||||
vi.clearAllMocks();
|
||||
});
|
||||
|
||||
it("confirms the canvas transition immediately before creating the automation", () => {
|
||||
const { onCreateConfirmed } = renderDialog();
|
||||
|
||||
fireEvent.click(screen.getByRole("button", { name: "automation.list.dialogs.start.continue" }));
|
||||
|
||||
expect(onCreateConfirmed).toHaveBeenCalledOnce();
|
||||
expect(mocks.submit).toHaveBeenCalledOnce();
|
||||
expect(onCreateConfirmed.mock.invocationCallOrder[0]).toBeLessThan(mocks.submit.mock.invocationCallOrder[0]);
|
||||
});
|
||||
|
||||
it("does not confirm the canvas transition when the dialog is cancelled", () => {
|
||||
const { onCreateConfirmed, onOpenChange } = renderDialog();
|
||||
|
||||
fireEvent.click(screen.getByRole("button", { name: "shared.cancel" }));
|
||||
|
||||
expect(onOpenChange).toHaveBeenCalledWith(false);
|
||||
expect(onCreateConfirmed).not.toHaveBeenCalled();
|
||||
expect(mocks.submit).not.toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
+352
@@ -0,0 +1,352 @@
|
||||
import { useMemo, useState } from "react";
|
||||
import { Form as RouterForm, useSubmit } from "react-router";
|
||||
import { useTranslation } from "react-i18next";
|
||||
import {
|
||||
FeatherArrowRight,
|
||||
FeatherCheckCircle2,
|
||||
FeatherLayoutTemplate,
|
||||
FeatherPlus,
|
||||
FeatherUser,
|
||||
FeatherX,
|
||||
} from "@subframe/core";
|
||||
import { BadgeFeedback } from "~/ui/components/BadgeFeedback";
|
||||
import { Button } from "~/ui/components/Button";
|
||||
import { Dialog } from "~/ui/components/Dialog";
|
||||
import { IconButton } from "~/ui/components/IconButton";
|
||||
import { IconWithBackground } from "~/ui/components/IconWithBackground";
|
||||
import { SearchInput } from "~/ui/components/SearchInput";
|
||||
import { Tag_Label } from "~/ui/components/Tag_Label";
|
||||
import { TextInput } from "~/ui/components/TextInput";
|
||||
import type { AutomationListVM } from "~/services/automation/automation.server";
|
||||
import { localizedValue, nodeIcon } from "../automationUi";
|
||||
|
||||
type TemplateTab = "shk" | "own";
|
||||
|
||||
/**
|
||||
* WF-P12 M03 "Neue Automation starten": blank start (intent=create on the list
|
||||
* route, csrf-guarded) or template start (intent=use-template posted to the
|
||||
* templates route, no csrf contract there).
|
||||
*/
|
||||
export function StartAuswahlDialog({
|
||||
vm,
|
||||
csrf,
|
||||
open,
|
||||
onOpenChange,
|
||||
onCreateConfirmed,
|
||||
}: {
|
||||
vm: AutomationListVM;
|
||||
csrf: string;
|
||||
open: boolean;
|
||||
onOpenChange: (open: boolean) => void;
|
||||
onCreateConfirmed: () => void;
|
||||
}): React.JSX.Element | null {
|
||||
const { t } = useTranslation();
|
||||
const submit = useSubmit();
|
||||
const [mode, setMode] = useState<"blank" | "template">("blank");
|
||||
const [selectedTemplateId, setSelectedTemplateId] = useState<string | null>(null);
|
||||
const [templateTab, setTemplateTab] = useState<TemplateTab>("shk");
|
||||
const [query, setQuery] = useState("");
|
||||
const [ruleName, setRuleName] = useState<string>(() => t("automation.list.dialogs.start.defaultName"));
|
||||
|
||||
const templates = useMemo(
|
||||
() =>
|
||||
vm.templates.map((template) => ({
|
||||
...template,
|
||||
// The list VM carries no tenant flag; seeded platform templates keep
|
||||
// their i18n-key names, tenant templates carry free-text names.
|
||||
isPlatform: template.name.startsWith("automation."),
|
||||
})),
|
||||
[vm.templates]
|
||||
);
|
||||
|
||||
const counts = useMemo(
|
||||
() => ({
|
||||
shk: templates.filter((template) => template.isPlatform).length,
|
||||
own: templates.filter((template) => !template.isPlatform).length,
|
||||
}),
|
||||
[templates]
|
||||
);
|
||||
|
||||
const visibleTemplates = useMemo(() => {
|
||||
const needle = query.trim().toLowerCase();
|
||||
return templates.filter((template) => {
|
||||
if (templateTab === "shk" && !template.isPlatform) return false;
|
||||
if (templateTab === "own" && template.isPlatform) return false;
|
||||
if (needle) {
|
||||
const label = localizedValue(t, template.name, "automation.values.unknownTemplate");
|
||||
if (!`${label} ${template.category}`.toLowerCase().includes(needle)) return false;
|
||||
}
|
||||
return true;
|
||||
});
|
||||
}, [templates, templateTab, query, t]);
|
||||
|
||||
if (!open) return null;
|
||||
|
||||
const submitUseTemplate = (templateId: string) => {
|
||||
const formData = new FormData();
|
||||
formData.set("intent", "use-template");
|
||||
formData.set("templateId", templateId);
|
||||
if (ruleName.trim()) formData.set("ruleName", ruleName.trim());
|
||||
onCreateConfirmed();
|
||||
void submit(formData, { method: "post", action: vm.templatesUrl });
|
||||
};
|
||||
|
||||
const continueWithSelection = () => {
|
||||
if (mode === "template") {
|
||||
if (selectedTemplateId) submitUseTemplate(selectedTemplateId);
|
||||
return;
|
||||
}
|
||||
if (!ruleName.trim()) return;
|
||||
const formData = new FormData();
|
||||
formData.set("csrf", csrf);
|
||||
formData.set("intent", "create");
|
||||
formData.set("ruleName", ruleName.trim());
|
||||
onCreateConfirmed();
|
||||
void submit(formData, { method: "post" });
|
||||
};
|
||||
|
||||
return (
|
||||
<Dialog open onOpenChange={(nextOpen: boolean) => (nextOpen ? undefined : onOpenChange(false))}>
|
||||
<Dialog.Content className="w-[760px] max-w-full gap-0 p-0">
|
||||
<div className="flex w-full items-start justify-between gap-3 border-b border-solid border-border-default bg-surface-neutral-secondary px-6 py-5 mobile:px-4">
|
||||
<div className="flex flex-col items-start gap-1">
|
||||
<span className="text-heading- font-heading- text-text-neutral-primary">{t("automation.list.dialogs.start.title")}</span>
|
||||
<span className="text-body-small-regular-150 font-body-small-regular-150 text-text-neutral-tertiary">
|
||||
{t("automation.list.dialogs.start.subtitle")}
|
||||
</span>
|
||||
</div>
|
||||
<IconButton variant="ghost" size="small" icon={<FeatherX />} aria-label={t("shared.close")} onClick={() => onOpenChange(false)} />
|
||||
</div>
|
||||
|
||||
<div className="flex w-full flex-col items-start gap-6 px-6 py-5 max-h-[65vh] overflow-y-auto mobile:px-4">
|
||||
<div className="flex w-full flex-col items-start gap-3">
|
||||
<span className="text-body-extra-small-semibold-0 font-body-extra-small-semibold-0 uppercase tracking-wide text-text-neutral-tertiary">
|
||||
{t("automation.list.dialogs.start.howToBegin")}
|
||||
</span>
|
||||
<div className="grid w-full grid-cols-2 items-stretch gap-4 mobile:grid-cols-1">
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => setMode("blank")}
|
||||
className={
|
||||
mode === "blank"
|
||||
? "flex flex-col items-start gap-3 rounded-lg border-2 border-solid border-brand-brand-secondary-border-solid-default bg-surface-neutral-secondary px-5 py-5 text-left shadow-sm"
|
||||
: "flex flex-col items-start gap-3 rounded-lg border border-solid border-border-default bg-surface-neutral-secondary px-5 py-5 text-left hover:border-border-strong"
|
||||
}
|
||||
>
|
||||
<div className="flex w-full items-start gap-3">
|
||||
<IconWithBackground variant="neutral" size="large" icon={<FeatherPlus />} />
|
||||
<div className="flex grow shrink-0 basis-0 flex-col items-start gap-1">
|
||||
<div className="flex w-full items-center gap-2">
|
||||
<span className="grow shrink-0 basis-0 text-body-default-semibold-150 font-body-default-semibold-150 text-text-neutral-primary">
|
||||
{t("automation.list.dialogs.start.blank.title")}
|
||||
</span>
|
||||
{mode === "blank" ? <FeatherCheckCircle2 className="text-body-large font-body-large text-icon-feedback-information" /> : null}
|
||||
</div>
|
||||
<span className="text-body-small-regular-150 font-body-small-regular-150 text-text-neutral-tertiary">
|
||||
{t("automation.list.dialogs.start.blank.description")}
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => setMode("template")}
|
||||
className={
|
||||
mode === "template"
|
||||
? "flex flex-col items-start gap-3 rounded-lg border-2 border-solid border-brand-brand-secondary-border-solid-default bg-surface-neutral-secondary px-5 py-5 text-left shadow-sm"
|
||||
: "flex flex-col items-start gap-3 rounded-lg border border-solid border-border-default bg-surface-neutral-secondary px-5 py-5 text-left hover:border-border-strong"
|
||||
}
|
||||
>
|
||||
<div className="flex w-full items-start gap-3">
|
||||
<IconWithBackground variant="information" size="large" icon={<FeatherLayoutTemplate />} />
|
||||
<div className="flex grow shrink-0 basis-0 flex-col items-start gap-1">
|
||||
<div className="flex w-full items-center gap-2">
|
||||
<span className="grow shrink-0 basis-0 text-body-default-semibold-150 font-body-default-semibold-150 text-text-neutral-primary">
|
||||
{t("automation.list.dialogs.start.template.title")}
|
||||
</span>
|
||||
{mode === "template" ? (
|
||||
<FeatherCheckCircle2 className="text-body-large font-body-large text-icon-feedback-information" />
|
||||
) : (
|
||||
<BadgeFeedback farbe="subtle-information" size="small">
|
||||
{t("automation.list.dialogs.start.template.available", { count: templates.length })}
|
||||
</BadgeFeedback>
|
||||
)}
|
||||
</div>
|
||||
<span className="text-body-small-regular-150 font-body-small-regular-150 text-text-neutral-tertiary">
|
||||
{t("automation.list.dialogs.start.template.description")}
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<RouterForm
|
||||
className="flex w-full flex-col items-start gap-2"
|
||||
onSubmit={(event) => {
|
||||
event.preventDefault();
|
||||
continueWithSelection();
|
||||
}}
|
||||
>
|
||||
<TextInput className="w-full" label={t("automation.list.dialogs.start.nameLabel")} showLabel>
|
||||
<TextInput.Input
|
||||
name="ruleName"
|
||||
required
|
||||
value={ruleName}
|
||||
onChange={(event: React.ChangeEvent<HTMLInputElement>) => setRuleName(event.target.value)}
|
||||
/>
|
||||
</TextInput>
|
||||
</RouterForm>
|
||||
|
||||
<div className="flex w-full flex-col items-start gap-4 rounded-lg border border-solid border-border-default bg-surface-neutral-primary px-5 py-5 mobile:px-4">
|
||||
<div className="flex w-full items-center gap-2">
|
||||
<FeatherLayoutTemplate className="text-body-large font-body-large text-icon-neutral-tertiary" />
|
||||
<span className="grow shrink-0 basis-0 text-body-default-semibold-150 font-body-default-semibold-150 text-text-neutral-primary">
|
||||
{t("automation.list.dialogs.start.catalog.title")}
|
||||
</span>
|
||||
<BadgeFeedback farbe="subtle-neutral" size="small">
|
||||
{t("automation.list.dialogs.start.catalog.count", { count: templates.length })}
|
||||
</BadgeFeedback>
|
||||
</div>
|
||||
<SearchInput
|
||||
className="h-8 w-full flex-none"
|
||||
size="small"
|
||||
hideShortcut
|
||||
placeholder={t("automation.list.dialogs.start.catalog.searchPlaceholder")}
|
||||
value={query}
|
||||
onChange={(event: React.ChangeEvent<HTMLInputElement>) => setQuery(event.target.value)}
|
||||
/>
|
||||
<div className="flex w-full items-center gap-2 border-b border-solid border-border-default">
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => setTemplateTab("shk")}
|
||||
className={
|
||||
templateTab === "shk"
|
||||
? "flex items-center gap-2 border-b-2 border-solid border-brand-brand-secondary-border-solid-default px-3 py-2"
|
||||
: "flex cursor-pointer items-center gap-2 border-b-2 border-solid border-transparent px-3 py-2 hover:border-border-strong"
|
||||
}
|
||||
>
|
||||
<FeatherLayoutTemplate className="text-body-small-regular-0 font-body-small-regular-0 text-icon-neutral-tertiary" />
|
||||
<span
|
||||
className={
|
||||
templateTab === "shk"
|
||||
? "text-body-small-medium-0 font-body-small-medium-0 text-text-neutral-primary"
|
||||
: "text-body-small-regular-0 font-body-small-regular-0 text-text-neutral-secondary"
|
||||
}
|
||||
>
|
||||
{t("automation.list.dialogs.start.tabs.shk")}
|
||||
</span>
|
||||
<BadgeFeedback farbe="subtle-information" size="small">
|
||||
{counts.shk}
|
||||
</BadgeFeedback>
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => setTemplateTab("own")}
|
||||
className={
|
||||
templateTab === "own"
|
||||
? "flex items-center gap-2 border-b-2 border-solid border-brand-brand-secondary-border-solid-default px-3 py-2"
|
||||
: "flex cursor-pointer items-center gap-2 border-b-2 border-solid border-transparent px-3 py-2 hover:border-border-strong"
|
||||
}
|
||||
>
|
||||
<FeatherUser className="text-body-small-regular-0 font-body-small-regular-0 text-icon-neutral-tertiary" />
|
||||
<span
|
||||
className={
|
||||
templateTab === "own"
|
||||
? "text-body-small-medium-0 font-body-small-medium-0 text-text-neutral-primary"
|
||||
: "text-body-small-regular-0 font-body-small-regular-0 text-text-neutral-secondary"
|
||||
}
|
||||
>
|
||||
{t("automation.list.dialogs.start.tabs.own")}
|
||||
</span>
|
||||
<BadgeFeedback farbe="subtle-neutral" size="small">
|
||||
{counts.own}
|
||||
</BadgeFeedback>
|
||||
</button>
|
||||
</div>
|
||||
{visibleTemplates.length === 0 ? (
|
||||
<span className="text-body-small-regular-150 font-body-small-regular-150 text-text-neutral-tertiary">
|
||||
{t("automation.templatesPage.noMatches.title")}
|
||||
</span>
|
||||
) : (
|
||||
<div className="grid w-full grid-cols-2 items-start gap-4 mobile:grid-cols-1">
|
||||
{visibleTemplates.map((template) => {
|
||||
const TemplateIcon = nodeIcon(template.category);
|
||||
const selected = mode === "template" && selectedTemplateId === template.id;
|
||||
return (
|
||||
<div
|
||||
key={template.id}
|
||||
className={
|
||||
selected
|
||||
? "flex flex-col items-start gap-3 self-stretch rounded-md border-2 border-solid border-brand-brand-secondary-border-solid-default bg-surface-neutral-secondary px-4 py-4 shadow-sm"
|
||||
: "flex flex-col items-start gap-3 self-stretch rounded-md border border-solid border-border-default bg-surface-neutral-secondary px-4 py-4 shadow-sm hover:border-border-strong"
|
||||
}
|
||||
role="button"
|
||||
tabIndex={0}
|
||||
onClick={() => {
|
||||
setMode("template");
|
||||
setSelectedTemplateId(template.id);
|
||||
}}
|
||||
onKeyDown={(event) => {
|
||||
if (event.key === "Enter" || event.key === " ") {
|
||||
event.preventDefault();
|
||||
setMode("template");
|
||||
setSelectedTemplateId(template.id);
|
||||
}
|
||||
}}
|
||||
>
|
||||
<div className="flex w-full items-start gap-3">
|
||||
<IconWithBackground variant={template.isPlatform ? "information" : "neutral"} icon={<TemplateIcon />} />
|
||||
<div className="flex grow shrink-0 basis-0 flex-col items-start gap-0.5">
|
||||
<span className="w-full text-body-default-semibold-150 font-body-default-semibold-150 text-text-neutral-primary">
|
||||
{localizedValue(t, template.name, "automation.values.unknownTemplate")}
|
||||
</span>
|
||||
<span className="w-full text-body-small-regular-150 font-body-small-regular-150 text-text-neutral-tertiary">
|
||||
{localizedValue(t, `automation.templatesPage.categories.${template.category}`, "automation.values.unknownCategory")}
|
||||
</span>
|
||||
</div>
|
||||
<Tag_Label tone={template.isPlatform ? "sky-subtle" : "neutral-subtle"} noAction size="small">
|
||||
{template.isPlatform ? t("automation.templatesPage.platformTemplate") : t("automation.templatesPage.tenantTemplate")}
|
||||
</Tag_Label>
|
||||
</div>
|
||||
<div className="flex h-px w-full flex-none flex-col items-center bg-border-default" />
|
||||
<div className="flex w-full items-center justify-end gap-2">
|
||||
<Button
|
||||
type="button"
|
||||
variant={selected ? "primary" : "secondary"}
|
||||
size="small"
|
||||
iconRight={<FeatherArrowRight />}
|
||||
onClick={(event: React.MouseEvent<HTMLButtonElement>) => {
|
||||
event.stopPropagation();
|
||||
submitUseTemplate(template.id);
|
||||
}}
|
||||
>
|
||||
{t("automation.templatesPage.use")}
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="flex w-full items-center justify-end gap-2 border-t border-solid border-border-default bg-surface-neutral-secondary px-6 py-4 mobile:flex-col-reverse mobile:items-stretch mobile:px-4">
|
||||
<Button type="button" className="mobile:w-full" variant="tertiary" onClick={() => onOpenChange(false)}>
|
||||
{t("shared.cancel")}
|
||||
</Button>
|
||||
<Button
|
||||
type="button"
|
||||
className="mobile:w-full"
|
||||
iconRight={<FeatherArrowRight />}
|
||||
disabled={mode === "template" ? !selectedTemplateId : !ruleName.trim()}
|
||||
onClick={continueWithSelection}
|
||||
>
|
||||
{t("automation.list.dialogs.start.continue")}
|
||||
</Button>
|
||||
</div>
|
||||
</Dialog.Content>
|
||||
</Dialog>
|
||||
);
|
||||
}
|
||||
Reference in new issue
Block a user