Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

[UI v2] feat: Adds action details for send-notification type #16849

Merged
merged 1 commit into from
Jan 26, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import type { Automation } from "@/api/automations";
import type { BlockDocument } from "@/api/block-documents";
import type { Deployment } from "@/api/deployments";
import type { components } from "@/api/prefect";
import type { WorkPool } from "@/api/work-pools";
Expand All @@ -18,6 +19,7 @@ import { StateBadge } from "@/components/ui/state-badge";
import { Typography } from "@/components/ui/typography";
import {
createFakeAutomation,
createFakeBlockDocument,
createFakeDeployment,
createFakeWorkPool,
createFakeWorkQueue,
Expand All @@ -39,7 +41,8 @@ const ACTION_TYPE_TO_STRING = {
"pause-automation": "Pause automation",
"resume-automation": "Resume automation",
"call-webhook": "Call a custom webhook notification",
"send-notification": "Send a notification",
/** Default string if `block_type_name` is not found. */
"send-notification": "Send a notification using",
"do-nothing": "Do nothing",
} as const;
type ActionLabel =
Expand All @@ -60,10 +63,11 @@ export const ActionDetailsType = ({ action }: ActionDetailsProps) => {
const label = ACTION_TYPE_TO_STRING[action.type];
switch (action.type) {
// Non-inferrable Actions
case "do-nothing":
case "cancel-flow-run":
case "suspend-flow-run":
case "resume-flow-run":
case "call-webhook": // Not used
case "do-nothing": // not used
return <NoninferredAction label={label} />;
// Inferable actions
case "run-deployment":
Expand Down Expand Up @@ -120,7 +124,15 @@ export const ActionDetailsType = ({ action }: ActionDetailsProps) => {
);
// Other actions
case "send-notification":
return "TODO";
// TODO: Pass a real block document from API
return (
<BlockDocumentActionDetails
label={label}
blockDocument={createFakeBlockDocument({
block_type_name: "Mattermost Webhook",
})}
/>
);
case "change-flow-run-state":
return (
<ChangeFlowRunStateActionDetails
Expand All @@ -129,8 +141,8 @@ export const ActionDetailsType = ({ action }: ActionDetailsProps) => {
name={action.name}
/>
);
case "call-webhook":
return "TODO";
default:
return null;
}
};

Expand Down Expand Up @@ -262,6 +274,36 @@ export const AutomationActionDetails = ({
);
};

type BlockDocumentActionDetailsProps = {
label: ActionLabel;
blockDocument: BlockDocument;
};
export const BlockDocumentActionDetails = ({
label,
blockDocument,
}: BlockDocumentActionDetailsProps) => {
if (!blockDocument.name) {
return <Typography>Block not found</Typography>;
}

const _label = blockDocument.block_type_name
? `Send a ${blockDocument.block_type_name.toLowerCase()} using`
: label;

return (
<ActionResource>
<label>{_label}</label>
<Link
to="/blocks/block/$id"
params={{ id: blockDocument.id }}
aria-label={blockDocument.name}
>
<ActionResourceName iconId="Box" name={blockDocument.name} />
</Link>
</ActionResource>
);
};

type WorkPoolActionDetailsProps = {
label: ActionLabel;
workPool: WorkPool;
Expand Down
2 changes: 2 additions & 0 deletions ui-v2/src/components/ui/icons/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import {
AlignVerticalJustifyStart,
Ban,
Bot,
Box,
Calendar,
Check,
ChevronDown,
Expand Down Expand Up @@ -35,6 +36,7 @@ export const ICONS = {
AlignVerticalJustifyStart,
Ban,
Bot,
Box,
Calendar,
Check,
ChevronDown,
Expand Down
Loading