|
| 1 | +import { Automation } from "@/api/automations"; |
| 2 | +import { Card } from "@/components/ui/card"; |
| 3 | +import { Typography } from "@/components/ui/typography"; |
| 4 | +type AutomationAction = Automation["actions"][number]; |
| 5 | + |
| 6 | +type ActionDetailsProps = { |
| 7 | + action: AutomationAction; |
| 8 | +}; |
| 9 | +export const ActionDetails = ({ action }: ActionDetailsProps) => ( |
| 10 | + <Card className="p-4 border-r-8"> |
| 11 | + <ActionDetailsType action={action} /> |
| 12 | + </Card> |
| 13 | +); |
| 14 | + |
| 15 | +export const ActionDetailsType = ({ action }: ActionDetailsProps) => { |
| 16 | + switch (action.type) { |
| 17 | + // Non-inferrable Actions |
| 18 | + case "do-nothing": |
| 19 | + case "cancel-flow-run": |
| 20 | + case "suspend-flow-run": |
| 21 | + case "resume-flow-run": |
| 22 | + return <NoninferredAction action={action} />; |
| 23 | + // Inferable actions |
| 24 | + case "run-deployment": |
| 25 | + return action.deployment_id && action.source == "selected" ? ( |
| 26 | + "TODO" |
| 27 | + ) : ( |
| 28 | + <InferredAction action={action} /> |
| 29 | + ); |
| 30 | + case "pause-deployment": |
| 31 | + case "resume-deployment": |
| 32 | + return action.deployment_id && action.source == "selected" ? ( |
| 33 | + "TODO" |
| 34 | + ) : ( |
| 35 | + <InferredAction action={action} /> |
| 36 | + ); |
| 37 | + case "pause-work-queue": |
| 38 | + case "resume-work-queue": |
| 39 | + return action.work_queue_id && action.source == "selected" ? ( |
| 40 | + "TODO" |
| 41 | + ) : ( |
| 42 | + <InferredAction action={action} /> |
| 43 | + ); |
| 44 | + case "pause-automation": |
| 45 | + case "resume-automation": |
| 46 | + return action.automation_id && action.source == "selected" ? ( |
| 47 | + "TODO" |
| 48 | + ) : ( |
| 49 | + <InferredAction action={action} /> |
| 50 | + ); |
| 51 | + case "pause-work-pool": |
| 52 | + case "resume-work-pool": |
| 53 | + return action.work_pool_id && action.source == "selected" ? ( |
| 54 | + "TODO" |
| 55 | + ) : ( |
| 56 | + <InferredAction action={action} /> |
| 57 | + ); |
| 58 | + // Other actions |
| 59 | + case "send-notification": |
| 60 | + return "TODO"; |
| 61 | + case "change-flow-run-state": |
| 62 | + return "TODO"; |
| 63 | + case "call-webhook": |
| 64 | + return "TODO"; |
| 65 | + } |
| 66 | +}; |
| 67 | + |
| 68 | +const ACTION_TYPE_TO_STRING: Record<AutomationAction["type"], string> = { |
| 69 | + "cancel-flow-run": "Cancel flow run", |
| 70 | + "suspend-flow-run": "Suspend flow run", |
| 71 | + "resume-flow-run": "Resume a flow run", |
| 72 | + "change-flow-run-state": "Change state of a flow run", |
| 73 | + "run-deployment": "Run deployment", |
| 74 | + "pause-deployment": "Pause deployment", |
| 75 | + "resume-deployment": "Resume deployment", |
| 76 | + "pause-work-queue": "Pause work queue", |
| 77 | + "resume-work-queue": "Resume work queue", |
| 78 | + "pause-work-pool": "Pause work queue", |
| 79 | + "resume-work-pool": "Resume work queue", |
| 80 | + "pause-automation": "Pause automation", |
| 81 | + "resume-automation": "Resume automation", |
| 82 | + "call-webhook": "Call a custom webhook notification", |
| 83 | + "send-notification": "Send a notification", |
| 84 | + "do-nothing": "Do nothing", |
| 85 | +} as const; |
| 86 | + |
| 87 | +const NoninferredAction = ({ action }: ActionDetailsProps) => ( |
| 88 | + <Typography variant="bodySmall"> |
| 89 | + {`${ACTION_TYPE_TO_STRING[action.type]} from the triggering event`} |
| 90 | + </Typography> |
| 91 | +); |
| 92 | +const InferredAction = ({ action }: ActionDetailsProps) => ( |
| 93 | + <Typography variant="bodySmall"> |
| 94 | + {`${ACTION_TYPE_TO_STRING[action.type]} inferred from the triggering event`} |
| 95 | + </Typography> |
| 96 | +); |
0 commit comments