Skip to content

Commit 4a1460d

Browse files
Restart workflow action (#856)
* Restart workflow action * update icon * Update src/views/workflow-actions/config/workflow-actions.config.ts Co-authored-by: Adhitya Mamallan <[email protected]> * Lower case Restarted * add the before restarted --------- Co-authored-by: Adhitya Mamallan <[email protected]>
1 parent 3fde298 commit 4a1460d

File tree

8 files changed

+77
-18
lines changed

8 files changed

+77
-18
lines changed

src/config/dynamic/resolvers/schemas/resolver-schemas.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ const resolverSchemas: ResolverSchemas = {
3232
returnType: z.object({
3333
cancel: z.boolean(),
3434
terminate: z.boolean(),
35+
restart: z.boolean(),
3536
}),
3637
},
3738
};

src/config/dynamic/resolvers/workflow-actions-enabled.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,6 @@ export default async function workflowActionsEnabled(
1313
return {
1414
terminate: true,
1515
cancel: true,
16+
restart: true,
1617
};
1718
}

src/utils/config/__fixtures__/resolved-config-values.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ const mockResolvedConfigValues: LoadedConfigResolvedValues = {
3030
WORKFLOW_ACTIONS_ENABLED: {
3131
terminate: true,
3232
cancel: true,
33+
restart: true,
3334
},
3435
};
3536
export default mockResolvedConfigValues;

src/views/workflow-actions/config/workflow-actions.config.ts

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
1-
import { MdHighlightOff, MdPowerSettingsNew } from 'react-icons/md';
1+
import {
2+
MdHighlightOff,
3+
MdPowerSettingsNew,
4+
MdOutlineRestartAlt,
5+
} from 'react-icons/md';
26

37
import { type CancelWorkflowResponse } from '@/route-handlers/cancel-workflow/cancel-workflow.types';
8+
import { type RestartWorkflowResponse } from '@/route-handlers/restart-workflow/restart-workflow.types';
49
import { type TerminateWorkflowResponse } from '@/route-handlers/terminate-workflow/terminate-workflow.types';
510

611
import getWorkflowIsCompleted from '../../workflow-page/helpers/get-workflow-is-completed';
@@ -9,6 +14,7 @@ import { type WorkflowAction } from '../workflow-actions.types';
914
const workflowActionsConfig: [
1015
WorkflowAction<CancelWorkflowResponse>,
1116
WorkflowAction<TerminateWorkflowResponse>,
17+
WorkflowAction<RestartWorkflowResponse>,
1218
] = [
1319
{
1420
id: 'cancel',
@@ -48,6 +54,23 @@ const workflowActionsConfig: [
4854
apiRoute: 'terminate',
4955
getSuccessMessage: () => 'Workflow has been terminated.',
5056
},
57+
{
58+
id: 'restart',
59+
label: 'Restart',
60+
subtitle: 'Restart a workflow execution',
61+
modal: {
62+
text: [
63+
'Restarts a workflow by creating a new execution with a fresh Run ID while using the existing input. If the previous execution is still running, it will be terminated.',
64+
'What differentiates Restart from Reset is that the restarted workflow is not aware of the previous workflow execution.',
65+
],
66+
},
67+
icon: MdOutlineRestartAlt,
68+
getIsRunnable: () => true,
69+
apiRoute: 'restart',
70+
getSuccessMessage: (result) =>
71+
// TODO: change runid to a link (upcomming PR)
72+
`Workflow has been restarted with new run ID: ${result.runId}`,
73+
},
5174
] as const;
5275

5376
export default workflowActionsConfig;

src/views/workflow-actions/workflow-actions-menu/__tests__/workflow-actions-menu.test.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ describe(WorkflowActionsMenu.name, () => {
2020

2121
it('renders the menu items correctly', () => {
2222
setup({
23-
actionsEnabledConfig: { terminate: true, cancel: true },
23+
actionsEnabledConfig: { terminate: true, cancel: true, restart: true },
2424
});
2525

2626
const menuButtons = screen.getAllByRole('button');
@@ -43,7 +43,7 @@ describe(WorkflowActionsMenu.name, () => {
4343

4444
it('disables menu items if they are disabled from config', () => {
4545
setup({
46-
actionsEnabledConfig: { terminate: true, cancel: false },
46+
actionsEnabledConfig: { terminate: true, cancel: false, restart: true },
4747
});
4848

4949
const menuButtons = screen.getAllByRole('button');
@@ -89,7 +89,7 @@ describe(WorkflowActionsMenu.name, () => {
8989

9090
it('calls onActionSelect when the action button is clicked', async () => {
9191
const { user, mockOnActionSelect } = setup({
92-
actionsEnabledConfig: { terminate: true, cancel: true },
92+
actionsEnabledConfig: { terminate: true, cancel: true, restart: true },
9393
});
9494

9595
const menuButtons = screen.getAllByRole('button');

src/views/workflow-actions/workflow-actions-modal-content/__tests__/workflow-actions-modal-content.test.tsx

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,12 @@ import { HttpResponse } from 'msw';
33
import { render, screen, userEvent } from '@/test-utils/rtl';
44

55
import { type CancelWorkflowResponse } from '@/route-handlers/cancel-workflow/cancel-workflow.types';
6+
import { type RestartWorkflowResponse } from '@/route-handlers/restart-workflow/restart-workflow.types';
7+
import { type TerminateWorkflowResponse } from '@/route-handlers/terminate-workflow/terminate-workflow.types';
68
import { mockWorkflowDetailsParams } from '@/views/workflow-page/__fixtures__/workflow-details-params';
79

810
import { mockWorkflowActionsConfig } from '../../__fixtures__/workflow-actions-config';
11+
import { type WorkflowAction } from '../../workflow-actions.types';
912
import WorkflowActionsModalContent from '../workflow-actions-modal-content';
1013

1114
const mockEnqueue = jest.fn();
@@ -76,15 +79,37 @@ describe(WorkflowActionsModalContent.name, () => {
7679
).toBeInTheDocument();
7780
expect(mockOnClose).not.toHaveBeenCalled();
7881
});
82+
83+
it('renders array text correctly in modal content', () => {
84+
const cancelAction = {
85+
...mockWorkflowActionsConfig[0],
86+
modal: {
87+
text: ['First line of array text', 'Second line of array text'],
88+
},
89+
};
90+
91+
setup({ actionConfig: cancelAction });
92+
93+
expect(screen.getByText('First line of array text')).toBeInTheDocument();
94+
expect(screen.getByText('Second line of array text')).toBeInTheDocument();
95+
});
7996
});
8097

81-
function setup({ error }: { error?: boolean }) {
98+
function setup({
99+
error,
100+
actionConfig,
101+
}: {
102+
error?: boolean;
103+
actionConfig?: WorkflowAction<
104+
CancelWorkflowResponse | TerminateWorkflowResponse | RestartWorkflowResponse
105+
>;
106+
}) {
82107
const user = userEvent.setup();
83108
const mockOnClose = jest.fn();
84109

85110
render(
86111
<WorkflowActionsModalContent
87-
action={mockWorkflowActionsConfig[0]}
112+
action={actionConfig ?? mockWorkflowActionsConfig[0]}
88113
params={{ ...mockWorkflowDetailsParams }}
89114
onCloseModal={mockOnClose}
90115
/>,

src/views/workflow-actions/workflow-actions-modal-content/workflow-actions-modal-content.tsx

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -63,19 +63,27 @@ export default function WorkflowActionsModalContent<R>({
6363
queryClient
6464
);
6565

66+
const modalText = Array.isArray(action.modal.text) ? (
67+
action.modal.text.map((text, index) => <p key={index}>{text}</p>)
68+
) : (
69+
<p>{action.modal.text}</p>
70+
);
71+
6672
return (
6773
<>
6874
<styled.ModalHeader>{action.label} workflow</styled.ModalHeader>
6975
<styled.ModalBody>
70-
{action.modal.text}
71-
<styled.Link
72-
href={action.modal.docsLink.href}
73-
target="_blank"
74-
rel="noreferrer"
75-
>
76-
{action.modal.docsLink.text}
77-
<MdOpenInNew />
78-
</styled.Link>
76+
{modalText}
77+
{action.modal.docsLink && (
78+
<styled.Link
79+
href={action.modal.docsLink.href}
80+
target="_blank"
81+
rel="noreferrer"
82+
>
83+
{action.modal.docsLink.text}
84+
<MdOpenInNew />
85+
</styled.Link>
86+
)}
7987
{error && (
8088
<Banner
8189
hierarchy={HIERARCHY.low}

src/views/workflow-actions/workflow-actions.types.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,15 @@ export type WorkflowActionInputParams = {
1010
// TODO: add input here for extended workflow actions
1111
};
1212

13-
export type WorkflowActionID = 'cancel' | 'terminate';
13+
export type WorkflowActionID = 'cancel' | 'terminate' | 'restart';
1414

1515
export type WorkflowAction<R> = {
1616
id: WorkflowActionID;
1717
label: string;
1818
subtitle: string;
1919
modal: {
20-
text: string;
21-
docsLink: {
20+
text: string | string[];
21+
docsLink?: {
2222
text: string;
2323
href: string;
2424
};

0 commit comments

Comments
 (0)