-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[UI v2] feat: Begins logic for creating UX based on an action type (#…
- Loading branch information
1 parent
adf1033
commit 16e85ce
Showing
5 changed files
with
197 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
93 changes: 93 additions & 0 deletions
93
ui-v2/src/components/automations/action-details/action-details.stories.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
import { Automation } from "@/api/automations"; | ||
import type { Meta, StoryObj } from "@storybook/react"; | ||
import { ActionDetails } from "./action-details"; | ||
|
||
const ACTIONS: Array<Automation["actions"][number]> = [ | ||
{ type: "do-nothing" }, | ||
{ type: "cancel-flow-run" }, | ||
{ type: "suspend-flow-run" }, | ||
{ type: "cancel-flow-run" }, | ||
{ type: "resume-flow-run" }, | ||
{ type: "run-deployment", deployment_id: null, source: "inferred" }, | ||
{ type: "run-deployment", deployment_id: "abc", source: "selected" }, | ||
{ type: "pause-deployment", deployment_id: null, source: "inferred" }, | ||
{ type: "resume-deployment", deployment_id: "abc", source: "selected" }, | ||
{ type: "pause-work-queue", work_queue_id: null, source: "inferred" }, | ||
{ type: "resume-work-queue", work_queue_id: "abc", source: "selected" }, | ||
{ type: "pause-work-pool", work_pool_id: null, source: "inferred" }, | ||
{ type: "resume-work-pool", work_pool_id: "abc", source: "selected" }, | ||
{ type: "pause-automation", automation_id: null, source: "inferred" }, | ||
{ type: "resume-automation", automation_id: "abc", source: "selected" }, | ||
{ | ||
type: "send-notification", | ||
block_document_id: "abc", | ||
body: "my_body", | ||
subject: "my_subject", | ||
}, | ||
{ | ||
type: "change-flow-run-state", | ||
state: "CANCELLED", | ||
}, | ||
{ | ||
type: "change-flow-run-state", | ||
state: "CANCELLING", | ||
}, | ||
{ | ||
type: "change-flow-run-state", | ||
state: "COMPLETED", | ||
}, | ||
{ | ||
type: "change-flow-run-state", | ||
state: "CRASHED", | ||
}, | ||
{ | ||
type: "change-flow-run-state", | ||
state: "FAILED", | ||
}, | ||
{ | ||
type: "change-flow-run-state", | ||
state: "PAUSED", | ||
}, | ||
{ | ||
type: "change-flow-run-state", | ||
state: "PENDING", | ||
}, | ||
{ | ||
type: "change-flow-run-state", | ||
state: "RUNNING", | ||
message: "My message", | ||
name: "My name", | ||
}, | ||
{ | ||
type: "change-flow-run-state", | ||
state: "SCHEDULED", | ||
}, | ||
{ | ||
type: "call-webhook", | ||
block_document_id: "abc", | ||
payload: "my_payload", | ||
}, | ||
]; | ||
|
||
const meta = { | ||
title: "Components/Automations/ActionDetails", | ||
component: ActionDetailsStory, | ||
} satisfies Meta<typeof ActionDetails>; | ||
|
||
export default meta; | ||
|
||
export const Story: StoryObj = { | ||
name: "ActionDetails", | ||
}; | ||
|
||
function ActionDetailsStory() { | ||
return ( | ||
<ul className="flex flex-col gap-4"> | ||
{ACTIONS.map((action, i) => ( | ||
<li key={i}> | ||
<ActionDetails key={i} action={action} /> | ||
</li> | ||
))} | ||
</ul> | ||
); | ||
} |
96 changes: 96 additions & 0 deletions
96
ui-v2/src/components/automations/action-details/action-details.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
import { Automation } from "@/api/automations"; | ||
import { Card } from "@/components/ui/card"; | ||
import { Typography } from "@/components/ui/typography"; | ||
type AutomationAction = Automation["actions"][number]; | ||
|
||
type ActionDetailsProps = { | ||
action: AutomationAction; | ||
}; | ||
export const ActionDetails = ({ action }: ActionDetailsProps) => ( | ||
<Card className="p-4 border-r-8"> | ||
<ActionDetailsType action={action} /> | ||
</Card> | ||
); | ||
|
||
export const ActionDetailsType = ({ action }: ActionDetailsProps) => { | ||
switch (action.type) { | ||
// Non-inferrable Actions | ||
case "do-nothing": | ||
case "cancel-flow-run": | ||
case "suspend-flow-run": | ||
case "resume-flow-run": | ||
return <NoninferredAction action={action} />; | ||
// Inferable actions | ||
case "run-deployment": | ||
return action.deployment_id && action.source == "selected" ? ( | ||
"TODO" | ||
) : ( | ||
<InferredAction action={action} /> | ||
); | ||
case "pause-deployment": | ||
case "resume-deployment": | ||
return action.deployment_id && action.source == "selected" ? ( | ||
"TODO" | ||
) : ( | ||
<InferredAction action={action} /> | ||
); | ||
case "pause-work-queue": | ||
case "resume-work-queue": | ||
return action.work_queue_id && action.source == "selected" ? ( | ||
"TODO" | ||
) : ( | ||
<InferredAction action={action} /> | ||
); | ||
case "pause-automation": | ||
case "resume-automation": | ||
return action.automation_id && action.source == "selected" ? ( | ||
"TODO" | ||
) : ( | ||
<InferredAction action={action} /> | ||
); | ||
case "pause-work-pool": | ||
case "resume-work-pool": | ||
return action.work_pool_id && action.source == "selected" ? ( | ||
"TODO" | ||
) : ( | ||
<InferredAction action={action} /> | ||
); | ||
// Other actions | ||
case "send-notification": | ||
return "TODO"; | ||
case "change-flow-run-state": | ||
return "TODO"; | ||
case "call-webhook": | ||
return "TODO"; | ||
} | ||
}; | ||
|
||
const ACTION_TYPE_TO_STRING: Record<AutomationAction["type"], string> = { | ||
"cancel-flow-run": "Cancel flow run", | ||
"suspend-flow-run": "Suspend flow run", | ||
"resume-flow-run": "Resume a flow run", | ||
"change-flow-run-state": "Change state of a flow run", | ||
"run-deployment": "Run deployment", | ||
"pause-deployment": "Pause deployment", | ||
"resume-deployment": "Resume deployment", | ||
"pause-work-queue": "Pause work queue", | ||
"resume-work-queue": "Resume work queue", | ||
"pause-work-pool": "Pause work queue", | ||
"resume-work-pool": "Resume work queue", | ||
"pause-automation": "Pause automation", | ||
"resume-automation": "Resume automation", | ||
"call-webhook": "Call a custom webhook notification", | ||
"send-notification": "Send a notification", | ||
"do-nothing": "Do nothing", | ||
} as const; | ||
|
||
const NoninferredAction = ({ action }: ActionDetailsProps) => ( | ||
<Typography variant="bodySmall"> | ||
{`${ACTION_TYPE_TO_STRING[action.type]} from the triggering event`} | ||
</Typography> | ||
); | ||
const InferredAction = ({ action }: ActionDetailsProps) => ( | ||
<Typography variant="bodySmall"> | ||
{`${ACTION_TYPE_TO_STRING[action.type]} inferred from the triggering event`} | ||
</Typography> | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export { ActionDetails } from "./action-details"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters