Skip to content

Commit 55329c7

Browse files
committed
2423: Create scheduled task form WIP
1 parent 46505e0 commit 55329c7

File tree

5 files changed

+157
-6
lines changed

5 files changed

+157
-6
lines changed

packages/orchestrator-ui-components/src/components/WfoPageTemplate/paths.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ export const PATH_METADATA_RESOURCE_TYPES = '/metadata/resource-types';
1010
export const PATH_METADATA_WORKFLOWS = '/metadata/workflows';
1111
export const PATH_METADATA_TASKS = '/metadata/tasks';
1212
export const PATH_METADATA_SCHEDULED_TASKS = '/metadata/scheduled-tasks';
13-
export const PATH_METADATA_ADD_SCHEDULED_TASK_FORM =
14-
'/metadata/scheduled-tasks-form';
13+
export const PATH_METADATA_ADD_SCHEDULE_TASK_FORM =
14+
'/metadata/schedule-task-form';
1515
export const PATH_TASKS = '/tasks';
1616
export const PATH_SETTINGS = '/settings';
Lines changed: 150 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,150 @@
1+
import React, { useMemo } from 'react';
2+
3+
import _ from 'lodash';
4+
import { useTranslations } from 'next-intl';
5+
import { useRouter } from 'next/router';
6+
import {
7+
Locale,
8+
PydanticForm,
9+
PydanticFormApiResponseType,
10+
PydanticFormFieldFormat,
11+
PydanticFormFieldType,
12+
} from 'pydantic-forms';
13+
import type {
14+
PydanticFormApiProvider,
15+
PydanticFormConfig,
16+
PydanticFormDefinitionResponse,
17+
PydanticFormSuccessResponse,
18+
} from 'pydantic-forms';
19+
20+
import { EuiSpacer } from '@elastic/eui';
21+
22+
import { WfoContentHeader, WfoLoading } from '@/components';
23+
24+
export const WfoScheduleTaskFormPage = () => {
25+
const t = useTranslations('metadata.scheduledTasks');
26+
const router = useRouter();
27+
const onSuccess = () => {
28+
console.log('SUCCESS!!!');
29+
};
30+
31+
const createScheduledTask = (
32+
formInput: unknown,
33+
): PydanticFormSuccessResponse => ({
34+
type: PydanticFormApiResponseType.SUCCESS,
35+
data: formInput as object,
36+
status: 222,
37+
});
38+
39+
const validateForm = (formInput: unknown): boolean => {
40+
if (
41+
!_.isEmpty(formInput) &&
42+
_.isArray(formInput) &&
43+
formInput.length === 2
44+
) {
45+
return true;
46+
}
47+
return false;
48+
};
49+
50+
const validateStep1 = (formInput: unknown): boolean => {
51+
return !_.isEmpty(formInput);
52+
};
53+
54+
const formStep1: PydanticFormDefinitionResponse = {
55+
type: PydanticFormApiResponseType.FORM_DEFINITION,
56+
form: {
57+
type: PydanticFormFieldType.OBJECT,
58+
properties: {
59+
task: {
60+
type: PydanticFormFieldType.STRING,
61+
format: PydanticFormFieldFormat.DROPDOWN,
62+
$ref: '',
63+
},
64+
taskType: {
65+
type: PydanticFormFieldType.STRING,
66+
format: PydanticFormFieldFormat.RADIO,
67+
$ref: '',
68+
},
69+
},
70+
},
71+
meta: {
72+
hasNext: true,
73+
},
74+
};
75+
76+
const formStep2: PydanticFormDefinitionResponse = {
77+
type: PydanticFormApiResponseType.FORM_DEFINITION,
78+
form: {
79+
type: PydanticFormFieldType.OBJECT,
80+
properties: {
81+
firstDate: {
82+
type: PydanticFormFieldType.DATETIME,
83+
format: PydanticFormFieldFormat.LONG,
84+
$ref: '',
85+
},
86+
schedule: {
87+
type: PydanticFormFieldType.STRING,
88+
format: PydanticFormFieldFormat.DROPDOWN,
89+
$ref: '',
90+
},
91+
},
92+
},
93+
meta: {
94+
hasNext: false,
95+
},
96+
};
97+
98+
const pydanticFormProvider: PydanticFormApiProvider = ({
99+
_,
100+
requestBody = [],
101+
}) => {
102+
return new Promise<Record<string, unknown>>((resolve) => {
103+
if (validateForm(requestBody)) {
104+
const successResponse = createScheduledTask(requestBody);
105+
console.log('successPresone', successResponse);
106+
return resolve(successResponse);
107+
} else if (validateStep1(requestBody)) {
108+
resolve(formStep2);
109+
}
110+
resolve(formStep1);
111+
}).then((formDefinition) => {
112+
return formDefinition;
113+
});
114+
};
115+
116+
const getConfig = (): PydanticFormConfig => {
117+
const getLocale = () => {
118+
if (router.locale) {
119+
return router.locale as Locale;
120+
}
121+
return Locale.enGB; // Default to enGB if no locale is set
122+
};
123+
124+
return {
125+
apiProvider: pydanticFormProvider,
126+
// footerRenderer: (props) => <Footer {...props} isTask={isTask} />,
127+
// headerRenderer: Header,
128+
// componentMatcherExtender: wfoComponentMatcherExtender,
129+
// labelProvider: pydanticLabelProvider,
130+
// rowRenderer: Row,
131+
// customTranslations: customTranslations,
132+
loadingComponent: <WfoLoading />,
133+
locale: getLocale(),
134+
};
135+
};
136+
137+
return (
138+
<>
139+
<WfoContentHeader title={t('addSchedule')} />
140+
<EuiSpacer size="l" />
141+
<PydanticForm
142+
formKey="add-schedule"
143+
formId="add-schedule"
144+
onSuccess={onSuccess}
145+
title="TEMP TITLE"
146+
config={getConfig()}
147+
/>
148+
</>
149+
);
150+
};

packages/orchestrator-ui-components/src/pages/metadata/WfoScheduledTasksPage.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ import {
2121
getDataSortHandler,
2222
getQueryStringHandler,
2323
} from '@/components';
24-
import { PATH_METADATA_ADD_SCHEDULED_TASK_FORM } from '@/components';
24+
import { PATH_METADATA_ADD_SCHEDULE_TASK_FORM } from '@/components';
2525
import { WfoAdvancedTable } from '@/components/WfoTable/WfoAdvancedTable';
2626
import { WfoAdvancedTableColumnConfig } from '@/components/WfoTable/WfoAdvancedTable/types';
2727
import { ColumnType, Pagination } from '@/components/WfoTable/WfoTable';
@@ -251,7 +251,7 @@ export const WfoScheduledTasksPage = () => {
251251
extraButtons={
252252
<EuiButton
253253
onClick={() => {
254-
router.push(PATH_METADATA_ADD_SCHEDULED_TASK_FORM);
254+
router.push(PATH_METADATA_ADD_SCHEDULE_TASK_FORM);
255255
}}
256256
>
257257
{t('addSchedule')}

packages/orchestrator-ui-components/src/pages/metadata/WfoTasksPage.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ import {
2323
WfoProductBlockBadge,
2424
} from '@/components';
2525
import { getDataSortHandler, getQueryStringHandler } from '@/components';
26-
import { PATH_METADATA_ADD_SCHEDULED_TASK_FORM } from '@/components';
26+
import { PATH_METADATA_ADD_SCHEDULE_TASK_FORM } from '@/components';
2727
import { WfoDateTime } from '@/components/WfoDateTime/WfoDateTime';
2828
import { WfoMetadataDescriptionField } from '@/components/WfoMetadata/WfoMetadataDescriptionField';
2929
import { WfoAdvancedTable } from '@/components/WfoTable/WfoAdvancedTable';
@@ -134,7 +134,7 @@ const SetScheduleButton = ({
134134
onClick={() => {
135135
closePopover();
136136
router.push(
137-
`${PATH_METADATA_ADD_SCHEDULED_TASK_FORM}/${workflowId}`,
137+
`${PATH_METADATA_ADD_SCHEDULE_TASK_FORM}/${workflowId}`,
138138
);
139139
}}
140140
>

packages/orchestrator-ui-components/src/pages/metadata/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,4 @@ export * from './WfoTasksPage';
66
export * from './WfoMetadataPageLayout';
77
export * from './WfoScheduledTasksPage';
88
export * from './workflowListObjectMapper';
9+
export * from './WfoScheduleTaskFormPage';

0 commit comments

Comments
 (0)