forked from cadence-workflow/cadence-web
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathschedule-actions-config.tsx
More file actions
82 lines (76 loc) · 2.41 KB
/
Copy pathschedule-actions-config.tsx
File metadata and controls
82 lines (76 loc) · 2.41 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
import {
MdOutlineWarningAmber,
MdPauseCircleOutline,
MdPlayCircleOutline,
} from 'react-icons/md';
import { z } from 'zod';
import { type PauseScheduleResponse } from '@/route-handlers/pause-schedule/pause-schedule.types';
import { type UnpauseScheduleResponse } from '@/route-handlers/unpause-schedule/unpause-schedule.types';
import {
type ScheduleAction,
type ScheduleActionInputParams,
} from '../schedule-actions.types';
const mockActionApiRoute =
(action: string) => (params: ScheduleActionInputParams) =>
`/api/domains/${params.domain}/${params.cluster}/schedules/${params.scheduleId}/${action}`;
export const mockPauseActionConfig: ScheduleAction<
PauseScheduleResponse,
{ reason: string },
{ reason: string }
> = {
id: 'pause',
label: 'Mock pause',
subtitle: 'Mock pause a schedule',
modal: {
banner: {
kind: 'warning',
icon: ({ size }) => <MdOutlineWarningAmber size={size} />,
render: () => 'Mock pause banner message',
},
withForm: true,
form: ({ control, fieldErrors }) => (
<div data-testid="mock-pause-form">
<input
data-testid="mock-pause-reason"
aria-label="Reason"
aria-invalid={!!fieldErrors.reason}
{...control.register('reason')}
/>
</div>
),
formSchema: z.object({
reason: z.string().trim().min(1, 'Reason for pausing is required'),
}),
transformFormDataToSubmission: (formData) => formData,
initialFormValues: { reason: '' },
},
icon: MdPauseCircleOutline,
getRunnableStatus: (schedule) =>
schedule.state?.paused
? 'NOT_RUNNABLE_SCHEDULE_ALREADY_PAUSED'
: 'RUNNABLE',
apiRoute: mockActionApiRoute('pause'),
renderSuccessMessage: () => 'Mock pause notification',
};
export const mockResumeActionConfig: ScheduleAction<UnpauseScheduleResponse> = {
id: 'resume',
label: 'Mock resume',
subtitle: 'Mock resume a schedule',
modal: {
text: 'Mock modal text to resume a schedule',
docsLink: {
text: 'Mock docs link',
href: 'https://mock.docs.link',
},
withForm: false,
},
icon: MdPlayCircleOutline,
getRunnableStatus: (schedule) =>
schedule.state?.paused ? 'RUNNABLE' : 'NOT_RUNNABLE_SCHEDULE_NOT_PAUSED',
apiRoute: mockActionApiRoute('unpause'),
renderSuccessMessage: () => 'Mock resume notification',
};
export const mockScheduleActionsConfig = [
mockPauseActionConfig,
mockResumeActionConfig,
] as const;