-
Notifications
You must be signed in to change notification settings - Fork 4
Add WFO Object and Array field #1980
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
54a0657
ea8fb82
8b4b6cc
9e3d82b
4fa0568
3ba7f0e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
'@orchestrator-ui/orchestrator-ui-components': patch | ||
--- | ||
|
||
WfoArrayField, WfoObjectField, fix some import and types for the forms |
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,18 +15,24 @@ import { | |
zodValidationPresets, | ||
} from 'pydantic-forms'; | ||
|
||
import { FetchBaseQueryError } from '@reduxjs/toolkit/query'; | ||
|
||
import { PATH_TASKS, PATH_WORKFLOWS, WfoLoading } from '@/components'; | ||
import { StartWorkflowPayload } from '@/pages/processes/WfoStartProcessPage'; | ||
import { HttpStatus } from '@/rtk'; | ||
import { HttpStatus, isFetchBaseQueryError, isRecord } from '@/rtk'; | ||
import { useStartProcessMutation } from '@/rtk/endpoints/forms'; | ||
import { useAppSelector } from '@/rtk/hooks'; | ||
import { FormValidationError } from '@/types'; | ||
|
||
import { Footer } from './Footer'; | ||
import { Row } from './Row'; | ||
import { Checkbox, Divider, Label, Summary, Text, TextArea } from './fields'; | ||
import { | ||
Checkbox, | ||
Divider, | ||
Label, | ||
Summary, | ||
Text, | ||
TextArea, | ||
WfoArrayField, | ||
WfoObjectField, | ||
} from './fields'; | ||
|
||
interface WfoPydanticFormProps { | ||
processName: string; | ||
|
@@ -46,7 +52,7 @@ export const WfoPydanticForm = ({ | |
const [startProcess] = useStartProcessMutation(); | ||
const router = useRouter(); | ||
const t = useTranslations('pydanticForms.userInputForm'); | ||
const componentMatcher = useAppSelector( | ||
const componentMatcherExtender = useAppSelector( | ||
(state) => state.pydanticForm?.componentMatcher, | ||
); | ||
|
||
|
@@ -81,40 +87,26 @@ export const WfoPydanticForm = ({ | |
userInputs: [{ ...startProcessPayload }, ...requestBody], | ||
}); | ||
return response | ||
.then((result) => { | ||
return new Promise<Record<string, object | string>>( | ||
(resolve) => { | ||
if (result.error) { | ||
const error = | ||
result.error as FetchBaseQueryError; | ||
if ( | ||
error.status === HttpStatus.FormNotComplete | ||
) { | ||
const data = error.data as Record< | ||
string, | ||
object | string | ||
>; | ||
resolve(data); | ||
} else if ( | ||
typeof error === 'object' && | ||
error !== null | ||
) { | ||
const validationError = | ||
error as FormValidationError; | ||
if (validationError?.status === 400) { | ||
resolve({ | ||
...validationError.data, | ||
status: validationError.status.toString(), | ||
}); | ||
} | ||
} | ||
} else if (result.data) { | ||
resolve(result.data); | ||
.then(({ error, data }) => { | ||
return new Promise<Record<string, unknown>>((resolve) => { | ||
if ( | ||
isFetchBaseQueryError(error) && | ||
isRecord(error.data) | ||
) { | ||
if (error.status === HttpStatus.FormNotComplete) { | ||
resolve(error.data); | ||
} else if (error.status === HttpStatus.BadRequest) { | ||
resolve({ | ||
...error.data, | ||
status: error.status, | ||
}); | ||
} | ||
} else if (data) { | ||
resolve(data); | ||
} | ||
|
||
resolve({}); | ||
}, | ||
); | ||
resolve({}); | ||
}); | ||
}) | ||
.catch((error) => { | ||
return new Promise<Record<string, object>>( | ||
|
@@ -146,6 +138,10 @@ export const WfoPydanticForm = ({ | |
|
||
const wfoComponentMatcher: ComponentMatcher = (currentMatchers) => { | ||
const wfoMatchers: PydanticComponentMatcher[] = [ | ||
...currentMatchers | ||
.filter((matcher) => matcher.id !== 'text') | ||
.filter((matcher) => matcher.id !== 'array') | ||
.filter((matcher) => matcher.id !== 'object'), | ||
{ | ||
id: 'textarea', | ||
ElementMatch: { | ||
|
@@ -159,6 +155,26 @@ export const WfoPydanticForm = ({ | |
); | ||
}, | ||
}, | ||
{ | ||
id: 'object', | ||
ElementMatch: { | ||
isControlledElement: false, | ||
Element: WfoObjectField, | ||
}, | ||
matcher: (field) => { | ||
return field.type === PydanticFormFieldType.OBJECT; | ||
}, | ||
}, | ||
{ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In the defaultComponentMatcher in the pydantic-forms lib there are some other fields that match on field type array like the MultiSelectField. This matcher should be after defaut matchers or else they will hijack matches that should end up there There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is now the default object field matcher. |
||
id: 'array', | ||
ElementMatch: { | ||
isControlledElement: true, | ||
Element: WfoArrayField, | ||
}, | ||
matcher: (field) => { | ||
return field.type === PydanticFormFieldType.ARRAY; | ||
}, | ||
}, | ||
{ | ||
id: 'summary', | ||
ElementMatch: { | ||
|
@@ -208,7 +224,6 @@ export const WfoPydanticForm = ({ | |
return field.type === PydanticFormFieldType.BOOLEAN; | ||
}, | ||
}, | ||
...currentMatchers.filter((matcher) => matcher.id !== 'text'), | ||
{ | ||
id: 'text', | ||
ElementMatch: { | ||
|
@@ -221,8 +236,9 @@ export const WfoPydanticForm = ({ | |
validator: zodValidationPresets.string, | ||
}, | ||
]; | ||
|
||
return componentMatcher ? componentMatcher(wfoMatchers) : wfoMatchers; | ||
return componentMatcherExtender | ||
? componentMatcherExtender(wfoMatchers) | ||
: wfoMatchers; | ||
}; | ||
|
||
const handleCancel = () => { | ||
|
Uh oh!
There was an error while loading. Please reload this page.