Commit 39bc0647 authored by Stefan Probst's avatar Stefan Probst
Browse files

fix: allow saving workflow step when workflow has empty fields

parent c7096684
Pipeline #289297 failed with stages
in 13 seconds
...@@ -108,7 +108,7 @@ export function WorkflowForm(props: WorkflowFormProps): JSX.Element { ...@@ -108,7 +108,7 @@ export function WorkflowForm(props: WorkflowFormProps): JSX.Element {
return ( return (
<Form initialValues={initialValues} name={name} onSubmit={onSubmitPage} validate={_validate}> <Form initialValues={initialValues} name={name} onSubmit={onSubmitPage} validate={_validate}>
{page.type === 'workflow' ? ( {page.type === 'workflow' ? (
<WorkflowFormSections onCancel={onCancel} onBeforeSubmit={onBeforeSubmit} /> <WorkflowFormSections onBeforeSubmit={onBeforeSubmit} onCancel={onCancel} />
) : null} ) : null}
{page.type === 'steps' ? ( {page.type === 'steps' ? (
<FormSections> <FormSections>
...@@ -122,15 +122,19 @@ export function WorkflowForm(props: WorkflowFormProps): JSX.Element { ...@@ -122,15 +122,19 @@ export function WorkflowForm(props: WorkflowFormProps): JSX.Element {
</FormSections> </FormSections>
) : null} ) : null}
{page.type === 'step' ? ( {page.type === 'step' ? (
<WorkflowStepFormSections index={page.index} onCancel={onCancelStep} /> <WorkflowStepFormSections
index={page.index}
onBeforeSubmit={onBeforeSubmit}
onCancel={onCancelStep}
/>
) : null} ) : null}
</Form> </Form>
) )
} }
interface WorkflowFormSectionsProps { interface WorkflowFormSectionsProps {
onCancel: () => void
onBeforeSubmit?: (form: FormApi<WorkflowFormValues>) => void onBeforeSubmit?: (form: FormApi<WorkflowFormValues>) => void
onCancel: () => void
} }
function WorkflowFormSections(props: WorkflowFormSectionsProps): JSX.Element { function WorkflowFormSections(props: WorkflowFormSectionsProps): JSX.Element {
...@@ -206,6 +210,7 @@ function WorkflowStepsFormSection(props: WorkflowStepsFormSectionProps): JSX.Ele ...@@ -206,6 +210,7 @@ function WorkflowStepsFormSection(props: WorkflowStepsFormSectionProps): JSX.Ele
<FormFieldList> <FormFieldList>
{fieldArray.fields.map((name, index) => { {fieldArray.fields.map((name, index) => {
function onEdit() { function onEdit() {
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
const value = fieldArray.fields.value[index]! const value = fieldArray.fields.value[index]!
setPage({ setPage({
type: 'step', type: 'step',
...@@ -262,6 +267,7 @@ function WorkflowStepsFormSection(props: WorkflowStepsFormSectionProps): JSX.Ele ...@@ -262,6 +267,7 @@ function WorkflowStepsFormSection(props: WorkflowStepsFormSectionProps): JSX.Ele
interface WorkflowStepFormSectionsProps { interface WorkflowStepFormSectionsProps {
index: number index: number
onBeforeSubmit?: (form: FormApi<WorkflowFormValues>) => void
onCancel: () => void onCancel: () => void
} }
...@@ -270,8 +276,13 @@ function WorkflowStepFormSections(props: WorkflowStepFormSectionsProps): JSX.Ele ...@@ -270,8 +276,13 @@ function WorkflowStepFormSections(props: WorkflowStepFormSectionsProps): JSX.Ele
const { t } = useI18n<'authenticated' | 'common'>() const { t } = useI18n<'authenticated' | 'common'>()
const name = `composedOf[${index}]` const name = `composedOf[${index}]`
const form = useForm<WorkflowFormValues>()
const formFields = useWorkflowStepFormFields(name) const formFields = useWorkflowStepFormFields(name)
function onBeforeSubmit() {
props.onBeforeSubmit?.(form)
}
return ( return (
<FormSections> <FormSections>
<MainFormSection formFields={formFields} /> <MainFormSection formFields={formFields} />
...@@ -283,7 +294,9 @@ function WorkflowStepFormSections(props: WorkflowStepFormSectionsProps): JSX.Ele ...@@ -283,7 +294,9 @@ function WorkflowStepFormSections(props: WorkflowStepFormSectionsProps): JSX.Ele
<FormButtonLink onPress={onCancel}> <FormButtonLink onPress={onCancel}>
{t(['authenticated', 'controls', 'cancel'])} {t(['authenticated', 'controls', 'cancel'])}
</FormButtonLink> </FormButtonLink>
<FormButton type="submit">{t(['authenticated', 'controls', 'save'])}</FormButton> <FormButton onPress={onBeforeSubmit} type="submit">
{t(['authenticated', 'controls', 'save'])}
</FormButton>
</FormControls> </FormControls>
</FormSections> </FormSections>
) )
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment