Commit eb326337 authored by Stefan Probst's avatar Stefan Probst
Browse files

fix: ignore empty recommended fields in workflow step validation

parent ccd52b61
Pipeline #293105 passed with stages
in 11 minutes and 49 seconds
......@@ -9,7 +9,7 @@ import { useCreateOrUpdateWorkflow } from '@/components/item-form/useCreateOrUpd
import { useWorkflowFormFields } from '@/components/item-form/useWorkflowFormFields'
import type { WorkflowFormPage } from '@/components/item-form/useWorkflowFormPage'
import { useWorkflowFormRecommendedFields } from '@/components/item-form/useWorkflowFormRecommendedFields'
import { useWorkflowValidationSchema } from '@/components/item-form/useWorkflowValidationSchema'
import { useWorkflowWithStepsValidationSchema } from '@/components/item-form/useWorkflowValidationSchema'
import { WorkflowForm } from '@/components/item-form/WorkflowForm'
import type { WorkflowInput } from '@/data/sshoc/api/workflow'
import type { WorkflowStepInput } from '@/data/sshoc/api/workflow-step'
......@@ -33,7 +33,7 @@ export function WorkflowCreateForm(props: WorkflowCreateFormProps): JSX.Element
const router = useRouter()
const formFields = useWorkflowFormFields()
const recommendedFields = useWorkflowFormRecommendedFields()
const validate = useWorkflowValidationSchema(removeEmptyItemFieldsOnSubmit)
const validate = useWorkflowWithStepsValidationSchema(removeEmptyItemFieldsOnSubmit)
const meta = useCreateItemMeta({ category })
const createOrUpdateWorkflow = useCreateOrUpdateWorkflow(undefined, { meta })
......
......@@ -15,9 +15,7 @@ import { MainFormSection } from '@/components/item-form/MainFormSection'
import { MediaFormSection } from '@/components/item-form/MediaFormSection'
import { PropertyFormSection } from '@/components/item-form/PropertyFormSection'
import { RelatedItemFormSection } from '@/components/item-form/RelatedItemFormSection'
import { removeEmptyItemFieldsOnSubmit } from '@/components/item-form/removeEmptyItemFieldsOnSubmit'
import { ThumbnailFormSection } from '@/components/item-form/ThumbnailFormSection'
import { useItemFormErrorMap } from '@/components/item-form/useItemFormErrorMap'
import type { ItemFormFields } from '@/components/item-form/useItemFormFields'
import { useWorkflowFormFields } from '@/components/item-form/useWorkflowFormFields'
import type { WorkflowFormPage } from '@/components/item-form/useWorkflowFormPage'
......@@ -28,12 +26,10 @@ import { WorkflowStepPreview } from '@/components/item-form/WorkflowStepPreview'
import { WorkflowTitle } from '@/components/item-form/WorkflowTitle'
import type { Workflow, WorkflowInput } from '@/data/sshoc/api/workflow'
import type { WorkflowStep, WorkflowStepInput } from '@/data/sshoc/api/workflow-step'
import { workflowWithStepsInputSchema } from '@/data/sshoc/validation-schemas/workflow'
import type { FormProps } from '@/lib/core/form/Form'
import { Form } from '@/lib/core/form/Form'
import { FormButton } from '@/lib/core/form/FormButton'
import { FormButtonLink } from '@/lib/core/form/FormButtonLink'
import { validateSchema } from '@/lib/core/form/validateSchema'
import { useI18n } from '@/lib/core/i18n/useI18n'
export type WorkflowFormValues = WorkflowInput & {
......@@ -100,17 +96,8 @@ export function WorkflowForm(props: WorkflowFormProps): JSX.Element {
setPage({ type: 'steps' })
}
// TODO: Avoid validating whole form for single step
// TODO: preprocess with removeEmptyFields only when creating new workflow
const errorMap = useItemFormErrorMap()
const _validate = validateSchema(
workflowWithStepsInputSchema,
errorMap,
removeEmptyItemFieldsOnSubmit,
)
return (
<Form initialValues={initialValues} name={name} onSubmit={onSubmitPage} validate={_validate}>
<Form initialValues={initialValues} name={name} onSubmit={onSubmitPage} validate={validate}>
<WorkflowFormNavigation onBeforeSubmit={onBeforeSubmit} page={page} setPage={setPage} />
{page.type === 'workflow' ? (
<WorkflowFormSections onBeforeSubmit={onBeforeSubmit} onCancel={onCancel} />
......@@ -208,7 +195,7 @@ function WorkflowStepsFormSection(props: WorkflowStepsFormSectionProps): JSX.Ele
fieldArray.fields.remove(index)
},
})
fieldArray.fields.push({ label: undefined, description: undefined })
fieldArray.fields.push({ ...recommendedFields, label: undefined, description: undefined })
}
return (
......
......@@ -19,7 +19,6 @@ import { RelatedReviewItemFormSection } from '@/components/item-form/RelatedRevi
import { ReviewFormMetadata } from '@/components/item-form/ReviewFormMetadata'
import { ThumbnailReviewFormSection } from '@/components/item-form/ThumbnailReviewFormSection'
import { useItemDiffFormInitialValues } from '@/components/item-form/useItemDiffFormInitialValues'
import { useItemFormErrorMap } from '@/components/item-form/useItemFormErrorMap'
import type { ItemFormFields } from '@/components/item-form/useItemFormFields'
import { useWorkflowFormFields } from '@/components/item-form/useWorkflowFormFields'
import type { WorkflowFormPage } from '@/components/item-form/useWorkflowFormPage'
......@@ -31,12 +30,10 @@ import { WorkflowTitle } from '@/components/item-form/WorkflowTitle'
import type { ItemsDiff } from '@/data/sshoc/api/item'
import type { Workflow, WorkflowInput } from '@/data/sshoc/api/workflow'
import type { WorkflowStep, WorkflowStepInput } from '@/data/sshoc/api/workflow-step'
import { workflowWithStepsInputSchema } from '@/data/sshoc/validation-schemas/workflow'
import type { FormProps } from '@/lib/core/form/Form'
import { Form } from '@/lib/core/form/Form'
import { FormButton } from '@/lib/core/form/FormButton'
import { FormButtonLink } from '@/lib/core/form/FormButtonLink'
import { validateSchema } from '@/lib/core/form/validateSchema'
import { useI18n } from '@/lib/core/i18n/useI18n'
export type WorkflowFormValues = WorkflowInput & {
......@@ -107,16 +104,12 @@ export function WorkflowReviewForm(props: WorkflowReviewFormProps): JSX.Element
// FIXME: Make ItemsDiff generic, fix initialValues type
useItemDiffFormInitialValues({ diff, item: initialValues }) ?? undefined
// TODO: Avoid validating whole form for single step
const errorMap = useItemFormErrorMap()
const _validate = validateSchema(workflowWithStepsInputSchema, errorMap)
return (
<Form
initialValues={initialValuesWithDeletedFields}
name={name}
onSubmit={onSubmitPage}
validate={_validate}
validate={validate}
>
<ReviewFormMetadata diff={diff}>
<WorkflowFormNavigation onBeforeSubmit={onBeforeSubmit} page={page} setPage={setPage} />
......@@ -219,7 +212,7 @@ function WorkflowStepsFormSection(props: WorkflowStepsFormSectionProps): JSX.Ele
fieldArray.fields.remove(index)
},
})
fieldArray.fields.push({ label: undefined, description: undefined })
fieldArray.fields.push({ ...recommendedFields, label: undefined, description: undefined })
}
return (
......
import { useItemFormErrorMap } from '@/components/item-form/useItemFormErrorMap'
import { workflowInputSchema as schema } from '@/data/sshoc/validation-schemas/workflow'
import {
workflowInputSchema,
workflowWithStepsInputSchema,
} from '@/data/sshoc/validation-schemas/workflow'
import type { Preprocessor } from '@/lib/core/form/validateSchema'
import { validateSchema } from '@/lib/core/form/validateSchema'
......@@ -7,5 +10,12 @@ import { validateSchema } from '@/lib/core/form/validateSchema'
export function useWorkflowValidationSchema(preprocess?: Preprocessor<any, any>) {
const errorMap = useItemFormErrorMap()
return validateSchema(schema, errorMap, preprocess)
return validateSchema(workflowInputSchema, errorMap, preprocess)
}
/* eslint-disable-next-line @typescript-eslint/explicit-module-boundary-types */
export function useWorkflowWithStepsValidationSchema(preprocess?: Preprocessor<any, any>) {
const errorMap = useItemFormErrorMap()
return validateSchema(workflowWithStepsInputSchema, errorMap, preprocess)
}
......@@ -20,7 +20,7 @@ import { useCreateOrUpdateWorkflow } from '@/components/item-form/useCreateOrUpd
import { useUpdateItemMeta } from '@/components/item-form/useUpdateItemMeta'
import { useWorkflowFormFields } from '@/components/item-form/useWorkflowFormFields'
import { useWorkflowFormPage } from '@/components/item-form/useWorkflowFormPage'
import { useWorkflowValidationSchema } from '@/components/item-form/useWorkflowValidationSchema'
import { useWorkflowWithStepsValidationSchema } from '@/components/item-form/useWorkflowValidationSchema'
import { WorkflowForm } from '@/components/item-form/WorkflowForm'
import type { Workflow, WorkflowInput } from '@/data/sshoc/api/workflow'
import { useWorkflow } from '@/data/sshoc/hooks/workflow'
......@@ -36,7 +36,6 @@ import { routes } from '@/lib/core/navigation/routes'
import { PageMainContent } from '@/lib/core/page/PageMainContent'
import { Centered } from '@/lib/core/ui/Centered/Centered'
import { FullPage } from '@/lib/core/ui/FullPage/FullPage'
import { LoadingIndicator } from '@/lib/core/ui/LoadingIndicator/LoadingIndicator'
import { ProgressSpinner } from '@/lib/core/ui/ProgressSpinner/ProgressSpinner'
export type UpdateWorkflowFormValues = ItemFormValues<WorkflowInput>
......@@ -113,7 +112,7 @@ export default function EditWorkflowPage(props: EditWorkflowPage.Props): JSX.Ele
})
const formFields = useWorkflowFormFields()
const validate = useWorkflowValidationSchema()
const validate = useWorkflowWithStepsValidationSchema()
const meta = useUpdateItemMeta({ category })
const createOrUpdateWorkflow = useCreateOrUpdateWorkflow(undefined, { meta })
......
......@@ -20,7 +20,7 @@ import { useCreateOrUpdateWorkflow } from '@/components/item-form/useCreateOrUpd
import { useUpdateItemMeta } from '@/components/item-form/useUpdateItemMeta'
import { useWorkflowFormFields } from '@/components/item-form/useWorkflowFormFields'
import { useWorkflowFormPage } from '@/components/item-form/useWorkflowFormPage'
import { useWorkflowValidationSchema } from '@/components/item-form/useWorkflowValidationSchema'
import { useWorkflowWithStepsValidationSchema } from '@/components/item-form/useWorkflowValidationSchema'
import { WorkflowForm } from '@/components/item-form/WorkflowForm'
import type { Workflow, WorkflowInput } from '@/data/sshoc/api/workflow'
import { useWorkflow, useWorkflowVersion } from '@/data/sshoc/hooks/workflow'
......@@ -37,7 +37,6 @@ import { useSearchParams } from '@/lib/core/navigation/useSearchParams'
import { PageMainContent } from '@/lib/core/page/PageMainContent'
import { Centered } from '@/lib/core/ui/Centered/Centered'
import { FullPage } from '@/lib/core/ui/FullPage/FullPage'
import { LoadingIndicator } from '@/lib/core/ui/LoadingIndicator/LoadingIndicator'
import { ProgressSpinner } from '@/lib/core/ui/ProgressSpinner/ProgressSpinner'
export type UpdateWorkflowFormValues = ItemFormValues<WorkflowInput>
......@@ -131,7 +130,7 @@ export default function EditWorkflowVersionPage(props: EditWorkflowVersionPage.P
})
const formFields = useWorkflowFormFields()
const validate = useWorkflowValidationSchema()
const validate = useWorkflowWithStepsValidationSchema()
const meta = useUpdateItemMeta({ category })
const createOrUpdateWorkflow = useCreateOrUpdateWorkflow(undefined, { meta })
......
......@@ -20,7 +20,7 @@ import { useCreateOrUpdateWorkflow } from '@/components/item-form/useCreateOrUpd
import { useReviewItemMeta } from '@/components/item-form/useReviewItemMeta'
import { useWorkflowFormFields } from '@/components/item-form/useWorkflowFormFields'
import { useWorkflowFormPage } from '@/components/item-form/useWorkflowFormPage'
import { useWorkflowValidationSchema } from '@/components/item-form/useWorkflowValidationSchema'
import { useWorkflowWithStepsValidationSchema } from '@/components/item-form/useWorkflowValidationSchema'
import { WorkflowReviewForm } from '@/components/item-form/WorkflowReviewForm'
import type { Workflow, WorkflowInput } from '@/data/sshoc/api/workflow'
import {
......@@ -144,7 +144,7 @@ export default function ReviewWorkflowPage(props: ReviewWorkflowPage.Props): JSX
})
const formFields = useWorkflowFormFields()
const validate = useWorkflowValidationSchema()
const validate = useWorkflowWithStepsValidationSchema()
const meta = useReviewItemMeta({ category })
const createOrUpdateWorkflow = useCreateOrUpdateWorkflow(undefined, { meta: meta.approve })
const rejectWorkflowVersion = useRejectWorkflowVersion({ persistentId, versionId }, undefined, {
......
Markdown is supported
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