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

feat: add initial recommended fields in create item form

parent e04d7ae0
Pipeline #218464 passed with stages
in 8 minutes and 13 seconds
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
"tool": { "tool": {
"required": ["label", "description"], "required": ["label", "description"],
"recommended": [ "recommended": [
"actors", "contributors",
"accessibleAt", "accessibleAt",
"externalIds", "externalIds",
"media", "media",
...@@ -32,7 +32,7 @@ ...@@ -32,7 +32,7 @@
"trainingMaterial": { "trainingMaterial": {
"required": ["label", "description"], "required": ["label", "description"],
"recommended": [ "recommended": [
"actors", "contributors",
"accessibleAt", "accessibleAt",
"externalIds", "externalIds",
"media", "media",
...@@ -58,7 +58,7 @@ ...@@ -58,7 +58,7 @@
"publication": { "publication": {
"required": ["label", "description"], "required": ["label", "description"],
"recommended": [ "recommended": [
"actors", "contributors",
"accessibleAt", "accessibleAt",
"externalIds", "externalIds",
"media", "media",
...@@ -90,7 +90,7 @@ ...@@ -90,7 +90,7 @@
"dataset": { "dataset": {
"required": ["label", "description"], "required": ["label", "description"],
"recommended": [ "recommended": [
"actors", "contributors",
"accessibleAt", "accessibleAt",
"externalIds", "externalIds",
"media", "media",
...@@ -116,7 +116,7 @@ ...@@ -116,7 +116,7 @@
"workflow": { "workflow": {
"required": ["label", "description"], "required": ["label", "description"],
"recommended": [ "recommended": [
"actors", "contributors",
"externalIds", "externalIds",
"media", "media",
"thumbnail", "thumbnail",
......
...@@ -12,6 +12,8 @@ import type { ...@@ -12,6 +12,8 @@ import type {
WorkflowCore, WorkflowCore,
WorkflowDto, WorkflowDto,
} from '@/api/sshoc' } from '@/api/sshoc'
import type { Item } from '@/api/sshoc/types'
import allowedPropertyTypes from '@/utils/propertyTypes.preval'
export function convertToInitialFormValues(item: DatasetDto): DatasetCore export function convertToInitialFormValues(item: DatasetDto): DatasetCore
export function convertToInitialFormValues( export function convertToInitialFormValues(
...@@ -135,3 +137,47 @@ export function convertToInitialFormValues( ...@@ -135,3 +137,47 @@ export function convertToInitialFormValues(
return initialValues return initialValues
} }
/**
* Populates recommended form fields with empty values.
*/
export function createInitialRecommendedFields({
required,
recommended,
recommendedProperties,
}: {
required: Array<string>
recommended: Array<string>
recommendedProperties: Array<string>
}): Record<string, unknown> {
const fieldTypes: Partial<Item> = {
label: '',
version: '',
description: '',
contributors: [{ role: { code: 'contributor' } }],
accessibleAt: [''],
externalIds: [{}],
media: [{}],
thumbnail: {},
relatedItems: [{}],
}
const initialValues: any = {}
;(required as Array<keyof Item>).forEach((fieldName) => {
initialValues[fieldName] = fieldTypes[fieldName]
})
;(recommended as Array<keyof Item>).forEach((fieldName) => {
initialValues[fieldName] = fieldTypes[fieldName]
})
initialValues.properties = []
recommendedProperties
.filter((id) => allowedPropertyTypes.includes(id))
.forEach((id) => {
initialValues.properties.push({ type: { code: id } })
})
return initialValues
}
import { Fragment } from 'react' import { Fragment } from 'react'
import { createInitialRecommendedFields } from '@/api/sshoc/helpers'
import { ItemForm } from '@/components/item/DatasetCreateForm/DatasetCreateForm' import { ItemForm } from '@/components/item/DatasetCreateForm/DatasetCreateForm'
import ContentColumn from '@/modules/layout/ContentColumn' import ContentColumn from '@/modules/layout/ContentColumn'
import GridLayout from '@/modules/layout/GridLayout' import GridLayout from '@/modules/layout/GridLayout'
import Metadata from '@/modules/metadata/Metadata' import Metadata from '@/modules/metadata/Metadata'
import { Title } from '@/modules/ui/typography/Title' import { Title } from '@/modules/ui/typography/Title'
import forms from '@@/config/forms.json'
/** /**
* Create dataset screen. * Create dataset screen.
...@@ -19,7 +21,10 @@ export default function DatasetCreateScreen(): JSX.Element { ...@@ -19,7 +21,10 @@ export default function DatasetCreateScreen(): JSX.Element {
style={{ gridColumn: '4 / span 8' }} style={{ gridColumn: '4 / span 8' }}
> >
<Title>Create dataset</Title> <Title>Create dataset</Title>
<ItemForm category="dataset" initialValues={{}} /> <ItemForm
category="dataset"
initialValues={createInitialRecommendedFields(forms.dataset)}
/>
</ContentColumn> </ContentColumn>
</GridLayout> </GridLayout>
</Fragment> </Fragment>
......
import { Fragment } from 'react' import { Fragment } from 'react'
import { createInitialRecommendedFields } from '@/api/sshoc/helpers'
import { ItemForm } from '@/components/item/PublicationCreateForm/PublicationCreateForm' import { ItemForm } from '@/components/item/PublicationCreateForm/PublicationCreateForm'
import ContentColumn from '@/modules/layout/ContentColumn' import ContentColumn from '@/modules/layout/ContentColumn'
import GridLayout from '@/modules/layout/GridLayout' import GridLayout from '@/modules/layout/GridLayout'
import Metadata from '@/modules/metadata/Metadata' import Metadata from '@/modules/metadata/Metadata'
import { Title } from '@/modules/ui/typography/Title' import { Title } from '@/modules/ui/typography/Title'
import forms from '@@/config/forms.json'
/** /**
* Create publication screen. * Create publication screen.
...@@ -19,7 +21,10 @@ export default function PublicationCreateScreen(): JSX.Element { ...@@ -19,7 +21,10 @@ export default function PublicationCreateScreen(): JSX.Element {
style={{ gridColumn: '4 / span 8' }} style={{ gridColumn: '4 / span 8' }}
> >
<Title>Create publication</Title> <Title>Create publication</Title>
<ItemForm category="publication" initialValues={{}} /> <ItemForm
category="publication"
initialValues={createInitialRecommendedFields(forms.publication)}
/>
</ContentColumn> </ContentColumn>
</GridLayout> </GridLayout>
</Fragment> </Fragment>
......
import { Fragment } from 'react' import { Fragment } from 'react'
import { createInitialRecommendedFields } from '@/api/sshoc/helpers'
import { ItemForm } from '@/components/item/ToolCreateForm/ToolCreateForm' import { ItemForm } from '@/components/item/ToolCreateForm/ToolCreateForm'
import ContentColumn from '@/modules/layout/ContentColumn' import ContentColumn from '@/modules/layout/ContentColumn'
import GridLayout from '@/modules/layout/GridLayout' import GridLayout from '@/modules/layout/GridLayout'
import Metadata from '@/modules/metadata/Metadata' import Metadata from '@/modules/metadata/Metadata'
import { Title } from '@/modules/ui/typography/Title' import { Title } from '@/modules/ui/typography/Title'
import forms from '@@/config/forms.json'
/** /**
* Create tool screen. * Create tool screen.
...@@ -19,7 +21,10 @@ export default function ToolCreateScreen(): JSX.Element { ...@@ -19,7 +21,10 @@ export default function ToolCreateScreen(): JSX.Element {
style={{ gridColumn: '4 / span 8' }} style={{ gridColumn: '4 / span 8' }}
> >
<Title>Create tool</Title> <Title>Create tool</Title>
<ItemForm category="tool-or-service" initialValues={{}} /> <ItemForm
category="tool-or-service"
initialValues={createInitialRecommendedFields(forms.tool)}
/>
</ContentColumn> </ContentColumn>
</GridLayout> </GridLayout>
</Fragment> </Fragment>
......
import { Fragment } from 'react' import { Fragment } from 'react'
import { createInitialRecommendedFields } from '@/api/sshoc/helpers'
import { ItemForm } from '@/components/item/TrainingMaterialCreateForm/TrainingMaterialCreateForm' import { ItemForm } from '@/components/item/TrainingMaterialCreateForm/TrainingMaterialCreateForm'
import ContentColumn from '@/modules/layout/ContentColumn' import ContentColumn from '@/modules/layout/ContentColumn'
import GridLayout from '@/modules/layout/GridLayout' import GridLayout from '@/modules/layout/GridLayout'
import Metadata from '@/modules/metadata/Metadata' import Metadata from '@/modules/metadata/Metadata'
import { Title } from '@/modules/ui/typography/Title' import { Title } from '@/modules/ui/typography/Title'
import forms from '@@/config/forms.json'
/** /**
* Create training material screen. * Create training material screen.
...@@ -19,7 +21,12 @@ export default function TrainingMaterialCreateScreen(): JSX.Element { ...@@ -19,7 +21,12 @@ export default function TrainingMaterialCreateScreen(): JSX.Element {
style={{ gridColumn: '4 / span 8' }} style={{ gridColumn: '4 / span 8' }}
> >
<Title>Create training material</Title> <Title>Create training material</Title>
<ItemForm category="training-material" initialValues={{}} /> <ItemForm
category="training-material"
initialValues={createInitialRecommendedFields(
forms.trainingMaterial,
)}
/>
</ContentColumn> </ContentColumn>
</GridLayout> </GridLayout>
</Fragment> </Fragment>
......
import { Fragment } from 'react' import { Fragment } from 'react'
import { createInitialRecommendedFields } from '@/api/sshoc/helpers'
import { ItemForm } from '@/components/item/WorkflowCreateForm/WorkflowCreateForm' import { ItemForm } from '@/components/item/WorkflowCreateForm/WorkflowCreateForm'
import ContentColumn from '@/modules/layout/ContentColumn' import ContentColumn from '@/modules/layout/ContentColumn'
import GridLayout from '@/modules/layout/GridLayout' import GridLayout from '@/modules/layout/GridLayout'
import Metadata from '@/modules/metadata/Metadata' import Metadata from '@/modules/metadata/Metadata'
import forms from '@@/config/forms.json'
/** /**
* Create workflow screen. * Create workflow screen.
...@@ -17,7 +19,10 @@ export default function WorkflowCreateScreen(): JSX.Element { ...@@ -17,7 +19,10 @@ export default function WorkflowCreateScreen(): JSX.Element {
className="px-6 py-12 space-y-12" className="px-6 py-12 space-y-12"
style={{ gridColumn: '4 / span 8' }} style={{ gridColumn: '4 / span 8' }}
> >
<ItemForm category="workflow" initialValues={{}} /> <ItemForm
category="workflow"
initialValues={createInitialRecommendedFields(forms.workflow)}
/>
</ContentColumn> </ContentColumn>
</GridLayout> </GridLayout>
</Fragment> </Fragment>
......
import preval from 'next-plugin-preval'
import { getPropertyTypes } from '@/api/sshoc'
/**
* Retrieves allowed property-types at build-time, so we can filter out
* property types which are unknown in a sshoc instance when populating
* initial recommended form fields.
*/
export default preval(
getPropertyTypes({}).then(({ propertyTypes }) => {
return propertyTypes!.map((propertyType) => propertyType.code)
}),
)
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