Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
SSHOC
sshoc-marketplace-frontend
Commits
e665c1da
Commit
e665c1da
authored
Aug 05, 2021
by
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
Changes
8
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
config/forms.json
View file @
e665c1da
...
...
@@ -2,7 +2,7 @@
"tool"
:
{
"required"
:
[
"label"
,
"description"
],
"recommended"
:
[
"
a
ctors"
,
"c
ontribu
tors"
,
"accessibleAt"
,
"externalIds"
,
"media"
,
...
...
@@ -32,7 +32,7 @@
"trainingMaterial"
:
{
"required"
:
[
"label"
,
"description"
],
"recommended"
:
[
"
a
ctors"
,
"c
ontribu
tors"
,
"accessibleAt"
,
"externalIds"
,
"media"
,
...
...
@@ -58,7 +58,7 @@
"publication"
:
{
"required"
:
[
"label"
,
"description"
],
"recommended"
:
[
"
a
ctors"
,
"c
ontribu
tors"
,
"accessibleAt"
,
"externalIds"
,
"media"
,
...
...
@@ -90,7 +90,7 @@
"dataset"
:
{
"required"
:
[
"label"
,
"description"
],
"recommended"
:
[
"
a
ctors"
,
"c
ontribu
tors"
,
"accessibleAt"
,
"externalIds"
,
"media"
,
...
...
@@ -116,7 +116,7 @@
"workflow"
:
{
"required"
:
[
"label"
,
"description"
],
"recommended"
:
[
"
a
ctors"
,
"c
ontribu
tors"
,
"externalIds"
,
"media"
,
"thumbnail"
,
...
...
src/api/sshoc/helpers.ts
View file @
e665c1da
...
...
@@ -12,6 +12,8 @@ import type {
WorkflowCore
,
WorkflowDto
,
}
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
(
...
...
@@ -135,3 +137,47 @@ export function convertToInitialFormValues(
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
}
src/screens/item/dataset/DatasetCreateScreen.tsx
View file @
e665c1da
import
{
Fragment
}
from
'
react
'
import
{
createInitialRecommendedFields
}
from
'
@/api/sshoc/helpers
'
import
{
ItemForm
}
from
'
@/components/item/DatasetCreateForm/DatasetCreateForm
'
import
ContentColumn
from
'
@/modules/layout/ContentColumn
'
import
GridLayout
from
'
@/modules/layout/GridLayout
'
import
Metadata
from
'
@/modules/metadata/Metadata
'
import
{
Title
}
from
'
@/modules/ui/typography/Title
'
import
forms
from
'
@@/config/forms.json
'
/**
* Create dataset screen.
...
...
@@ -19,7 +21,10 @@ export default function DatasetCreateScreen(): JSX.Element {
style
=
{
{
gridColumn
:
'
4 / span 8
'
}
}
>
<
Title
>
Create dataset
</
Title
>
<
ItemForm
category
=
"dataset"
initialValues
=
{
{}
}
/>
<
ItemForm
category
=
"dataset"
initialValues
=
{
createInitialRecommendedFields
(
forms
.
dataset
)
}
/>
</
ContentColumn
>
</
GridLayout
>
</
Fragment
>
...
...
src/screens/item/publication/PublicationCreateScreen.tsx
View file @
e665c1da
import
{
Fragment
}
from
'
react
'
import
{
createInitialRecommendedFields
}
from
'
@/api/sshoc/helpers
'
import
{
ItemForm
}
from
'
@/components/item/PublicationCreateForm/PublicationCreateForm
'
import
ContentColumn
from
'
@/modules/layout/ContentColumn
'
import
GridLayout
from
'
@/modules/layout/GridLayout
'
import
Metadata
from
'
@/modules/metadata/Metadata
'
import
{
Title
}
from
'
@/modules/ui/typography/Title
'
import
forms
from
'
@@/config/forms.json
'
/**
* Create publication screen.
...
...
@@ -19,7 +21,10 @@ export default function PublicationCreateScreen(): JSX.Element {
style
=
{
{
gridColumn
:
'
4 / span 8
'
}
}
>
<
Title
>
Create publication
</
Title
>
<
ItemForm
category
=
"publication"
initialValues
=
{
{}
}
/>
<
ItemForm
category
=
"publication"
initialValues
=
{
createInitialRecommendedFields
(
forms
.
publication
)
}
/>
</
ContentColumn
>
</
GridLayout
>
</
Fragment
>
...
...
src/screens/item/tool/ToolCreateScreen.tsx
View file @
e665c1da
import
{
Fragment
}
from
'
react
'
import
{
createInitialRecommendedFields
}
from
'
@/api/sshoc/helpers
'
import
{
ItemForm
}
from
'
@/components/item/ToolCreateForm/ToolCreateForm
'
import
ContentColumn
from
'
@/modules/layout/ContentColumn
'
import
GridLayout
from
'
@/modules/layout/GridLayout
'
import
Metadata
from
'
@/modules/metadata/Metadata
'
import
{
Title
}
from
'
@/modules/ui/typography/Title
'
import
forms
from
'
@@/config/forms.json
'
/**
* Create tool screen.
...
...
@@ -19,7 +21,10 @@ export default function ToolCreateScreen(): JSX.Element {
style
=
{
{
gridColumn
:
'
4 / span 8
'
}
}
>
<
Title
>
Create tool
</
Title
>
<
ItemForm
category
=
"tool-or-service"
initialValues
=
{
{}
}
/>
<
ItemForm
category
=
"tool-or-service"
initialValues
=
{
createInitialRecommendedFields
(
forms
.
tool
)
}
/>
</
ContentColumn
>
</
GridLayout
>
</
Fragment
>
...
...
src/screens/item/training-material/TrainingMaterialCreateScreen.tsx
View file @
e665c1da
import
{
Fragment
}
from
'
react
'
import
{
createInitialRecommendedFields
}
from
'
@/api/sshoc/helpers
'
import
{
ItemForm
}
from
'
@/components/item/TrainingMaterialCreateForm/TrainingMaterialCreateForm
'
import
ContentColumn
from
'
@/modules/layout/ContentColumn
'
import
GridLayout
from
'
@/modules/layout/GridLayout
'
import
Metadata
from
'
@/modules/metadata/Metadata
'
import
{
Title
}
from
'
@/modules/ui/typography/Title
'
import
forms
from
'
@@/config/forms.json
'
/**
* Create training material screen.
...
...
@@ -19,7 +21,12 @@ export default function TrainingMaterialCreateScreen(): JSX.Element {
style
=
{
{
gridColumn
:
'
4 / span 8
'
}
}
>
<
Title
>
Create training material
</
Title
>
<
ItemForm
category
=
"training-material"
initialValues
=
{
{}
}
/>
<
ItemForm
category
=
"training-material"
initialValues
=
{
createInitialRecommendedFields
(
forms
.
trainingMaterial
,
)
}
/>
</
ContentColumn
>
</
GridLayout
>
</
Fragment
>
...
...
src/screens/item/workflow/WorkflowCreateScreen.tsx
View file @
e665c1da
import
{
Fragment
}
from
'
react
'
import
{
createInitialRecommendedFields
}
from
'
@/api/sshoc/helpers
'
import
{
ItemForm
}
from
'
@/components/item/WorkflowCreateForm/WorkflowCreateForm
'
import
ContentColumn
from
'
@/modules/layout/ContentColumn
'
import
GridLayout
from
'
@/modules/layout/GridLayout
'
import
Metadata
from
'
@/modules/metadata/Metadata
'
import
forms
from
'
@@/config/forms.json
'
/**
* Create workflow screen.
...
...
@@ -17,7 +19,10 @@ export default function WorkflowCreateScreen(): JSX.Element {
className
=
"px-6 py-12 space-y-12"
style
=
{
{
gridColumn
:
'
4 / span 8
'
}
}
>
<
ItemForm
category
=
"workflow"
initialValues
=
{
{}
}
/>
<
ItemForm
category
=
"workflow"
initialValues
=
{
createInitialRecommendedFields
(
forms
.
workflow
)
}
/>
</
ContentColumn
>
</
GridLayout
>
</
Fragment
>
...
...
src/utils/propertyTypes.preval.ts
0 → 100644
View file @
e665c1da
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
)
}),
)
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment