Commit 927ac48a authored by Stefan Probst's avatar Stefan Probst
Browse files

fix: adjust to objectid=>persistentId change, pass dto to workflow edit form

parent fa3ebff7
Pipeline #188014 failed with stage
in 13 seconds
......@@ -74,28 +74,32 @@ export function convertToInitialFormValues(
}
}),
/**
* `persistentId` => `objectId`
* Only ids needed.
*/
relatedItems: item.relatedItems?.map((relation) => {
return {
...relation,
objectId: relation.persistentId,
id: relation.id,
persistentId: relation.persistentId,
relation: relation.relation && { code: relation.relation.code },
}
}),
/**
* Only ids needed. Also, fields are non-null.
*/
externalIds: item.externalIds?.map((id) => {
return {
serviceIdentifier: id.identifierService?.code ?? '',
identifier: id.identifier ?? '',
const identifierService = { code: id.identifierService?.code }
const identifier = id.identifier!
const externalId = {
identifier,
serviceIdentifier: identifierService,
}
return externalId
}),
/**
* Only id needed.
*/
source: {
id: item.source?.id,
source: item.source && {
id: item.source.id,
},
sourceItemId: item.sourceItemId,
}
......
This diff is collapsed.
......@@ -263,7 +263,7 @@ function CreateActorForm(props: CreateActorFormProps) {
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
id != null &&
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
id.serviceIdentifier != null &&
id.serviceIdentifier?.code != null &&
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
id.identifier == null
) {
......@@ -285,13 +285,13 @@ function CreateActorForm(props: CreateActorFormProps) {
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
id.identifier != null &&
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
id.serviceIdentifier == null
id.serviceIdentifier?.code == null
) {
if (errors.externalIds === undefined) {
errors.externalIds = []
}
errors.externalIds[index] = {
serviceIdentifier: 'Please select an ID service.',
serviceIdentifier: { code: 'Please select an ID service.' },
}
}
})
......
......@@ -88,7 +88,7 @@ export function MainFormSection(props: MainFormSectionProps): JSX.Element {
}
>
<ExternalIdServiceSelect
name={`${name}.serviceIdentifier`}
name={`${name}.serviceIdentifier.code`}
label="ID Service"
/>
<FormTextField
......
......@@ -46,7 +46,7 @@ export function RelatedItemsFormSection(
label={'Relation type'}
/>
<RelatedItemComboBox
name={`${name}.objectId`}
name={`${name}.persistentId`}
label={'Item'}
initialValues={props.initialValues}
index={index}
......
......@@ -440,7 +440,11 @@ export function ItemForm(props: ItemFormProps<ItemFormValues>): JSX.Element {
</div>
) : null}
</div>
<Page onSetPage={onSetPage} prefix={state.prefix} />
<Page
onSetPage={onSetPage}
prefix={state.prefix}
item={props.item}
/>
<div className="flex items-center justify-end space-x-6">
<Button onPress={onCancel} variant="link">
Cancel
......@@ -523,15 +527,16 @@ export function ItemForm(props: ItemFormProps<ItemFormValues>): JSX.Element {
interface FormPageProps {
onSetPage: (page: PageKey, prefix?: string, onReset?: () => void) => void
prefix?: string
item?: WorkflowDto
}
function WorkflowPage() {
function WorkflowPage(props: FormPageProps) {
return (
<Fragment>
<MainFormSection />
<ActorsFormSection />
<PropertiesFormSection />
<RelatedItemsFormSection />
<ActorsFormSection initialValues={props.item} />
<PropertiesFormSection initialValues={props.item} />
<RelatedItemsFormSection initialValues={props.item} />
<SourceFormSection />
</Fragment>
)
......
......@@ -170,13 +170,13 @@ export function validateCommonFormFields<
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
item != null &&
item.relation !== undefined &&
item.objectId === undefined
item.persistentId === undefined
) {
if (errors.relatedItems === undefined) {
/* @ts-expect-error Untyped empty array. */
errors.relatedItems = []
}
errors.relatedItems[index] = { objectId: 'Please select an item.' }
errors.relatedItems[index] = { persistentId: 'Please select an item.' }
}
})
}
......@@ -187,7 +187,7 @@ export function validateCommonFormFields<
if (
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
item != null &&
item.objectId !== undefined &&
item.persistentId !== undefined &&
item.relation === undefined
) {
if (errors.relatedItems === undefined) {
......@@ -207,7 +207,7 @@ export function validateCommonFormFields<
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
id != null &&
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
id.serviceIdentifier != null &&
id.serviceIdentifier?.code != null &&
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
id.identifier == null
) {
......@@ -230,14 +230,14 @@ export function validateCommonFormFields<
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
id.identifier != null &&
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
id.serviceIdentifier == null
id.serviceIdentifier?.code == null
) {
if (errors.externalIds === undefined) {
/* @ts-expect-error Untyped empty array. */
errors.externalIds = []
}
errors.externalIds[index] = {
serviceIdentifier: 'Please select an ID service.',
serviceIdentifier: { code: 'Please select an ID service.' },
}
}
})
......
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