Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
SSHOC
sshoc-marketplace-frontend
Commits
19a89698
Commit
19a89698
authored
Mar 09, 2021
by
Stefan Probst
Browse files
fix: filter out nulls from arrays
parent
d9260a7b
Pipeline
#179326
canceled with stage
in 4 minutes and 39 seconds
Changes
10
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
src/components/item/ActorsFormSection/ActorsFormSection.tsx
View file @
19a89698
...
...
@@ -212,12 +212,14 @@ function CreateActorForm(props: CreateActorFormProps) {
const
queryClient
=
useQueryClient
()
const
toast
=
useToast
()
function
onSubmit
(
values
:
ActorFormValues
)
{
function
onSubmit
(
unsanitized
:
ActorFormValues
)
{
if
(
auth
.
session
?.
accessToken
===
undefined
)
{
toast
.
error
(
'
Authentication required.
'
)
return
Promise
.
reject
()
}
const
values
=
sanitizeActorFormValues
(
unsanitized
)
return
createActor
.
mutateAsync
(
[
values
,
{
token
:
auth
.
session
.
accessToken
}],
{
...
...
@@ -331,3 +333,10 @@ function CreateActorForm(props: CreateActorFormProps) {
</
Form
>
)
}
function
sanitizeActorFormValues
(
values
:
ActorFormValues
)
{
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
values
.
affiliations
=
values
.
affiliations
?.
filter
((
v
)
=>
v
!=
null
)
return
values
}
src/components/item/DatasetCreateForm/DatasetCreateForm.tsx
View file @
19a89698
...
...
@@ -12,6 +12,7 @@ import { RelatedItemsFormSection } from '@/components/item/RelatedItemsFormSecti
import
{
SourceFormSection
}
from
'
@/components/item/SourceFormSection/SourceFormSection
'
import
{
Button
}
from
'
@/elements/Button/Button
'
import
{
useToast
}
from
'
@/elements/Toast/useToast
'
import
{
sanitizeFormValues
}
from
'
@/lib/sshoc/sanitizeFormValues
'
import
{
validateCommonFormFields
}
from
'
@/lib/sshoc/validateCommonFormFields
'
import
{
validateDateFormFields
}
from
'
@/lib/sshoc/validateDateFormFields
'
import
{
useAuth
}
from
'
@/modules/auth/AuthContext
'
...
...
@@ -87,18 +88,13 @@ export function ItemForm(props: ItemFormProps<ItemFormValues>): JSX.Element {
},
})
function
onSubmit
({
draft
,
...
values
}:
ItemFormValues
)
{
function
onSubmit
({
draft
,
...
unsanitized
}:
ItemFormValues
)
{
if
(
auth
.
session
?.
accessToken
==
null
)
{
toast
.
error
(
'
Authentication required.
'
)
return
Promise
.
reject
()
}
/**
* Backend crashes with `source: {}`.
*/
if
(
values
.
source
&&
values
.
source
.
id
===
undefined
)
{
delete
values
.
source
}
const
values
=
sanitizeFormValues
(
unsanitized
)
return
create
.
mutateAsync
([
{
draft
},
...
...
src/components/item/DatasetEditForm/DatasetEditForm.tsx
View file @
19a89698
...
...
@@ -12,6 +12,7 @@ import { RelatedItemsFormSection } from '@/components/item/RelatedItemsFormSecti
import
{
SourceFormSection
}
from
'
@/components/item/SourceFormSection/SourceFormSection
'
import
{
Button
}
from
'
@/elements/Button/Button
'
import
{
useToast
}
from
'
@/elements/Toast/useToast
'
import
{
sanitizeFormValues
}
from
'
@/lib/sshoc/sanitizeFormValues
'
import
{
validateCommonFormFields
}
from
'
@/lib/sshoc/validateCommonFormFields
'
import
{
validateDateFormFields
}
from
'
@/lib/sshoc/validateDateFormFields
'
import
{
useAuth
}
from
'
@/modules/auth/AuthContext
'
...
...
@@ -89,18 +90,13 @@ export function ItemForm(props: ItemFormProps<ItemFormValues>): JSX.Element {
},
})
function
onSubmit
({
draft
,
...
values
}:
ItemFormValues
)
{
function
onSubmit
({
draft
,
...
unsanitized
}:
ItemFormValues
)
{
if
(
auth
.
session
?.
accessToken
==
null
)
{
toast
.
error
(
'
Authentication required.
'
)
return
Promise
.
reject
()
}
/**
* Backend crashes with `source: {}`.
*/
if
(
values
.
source
&&
values
.
source
.
id
===
undefined
)
{
delete
values
.
source
}
const
values
=
sanitizeFormValues
(
unsanitized
)
return
create
.
mutateAsync
([
{
id
},
...
...
src/components/item/PublicationCreateForm/PublicationCreateForm.tsx
View file @
19a89698
...
...
@@ -12,6 +12,7 @@ import { RelatedItemsFormSection } from '@/components/item/RelatedItemsFormSecti
import
{
SourceFormSection
}
from
'
@/components/item/SourceFormSection/SourceFormSection
'
import
{
Button
}
from
'
@/elements/Button/Button
'
import
{
useToast
}
from
'
@/elements/Toast/useToast
'
import
{
sanitizeFormValues
}
from
'
@/lib/sshoc/sanitizeFormValues
'
import
{
validateCommonFormFields
}
from
'
@/lib/sshoc/validateCommonFormFields
'
import
{
validateDateFormFields
}
from
'
@/lib/sshoc/validateDateFormFields
'
import
{
useAuth
}
from
'
@/modules/auth/AuthContext
'
...
...
@@ -87,18 +88,13 @@ export function ItemForm(props: ItemFormProps<ItemFormValues>): JSX.Element {
},
})
function
onSubmit
({
draft
,
...
values
}:
ItemFormValues
)
{
function
onSubmit
({
draft
,
...
unsanitized
}:
ItemFormValues
)
{
if
(
auth
.
session
?.
accessToken
==
null
)
{
toast
.
error
(
'
Authentication required.
'
)
return
Promise
.
reject
()
}
/**
* Backend crashes with `source: {}`.
*/
if
(
values
.
source
&&
values
.
source
.
id
===
undefined
)
{
delete
values
.
source
}
const
values
=
sanitizeFormValues
(
unsanitized
)
return
create
.
mutateAsync
([
{
draft
},
...
...
src/components/item/PublicationEditForm/PublicationEditForm.tsx
View file @
19a89698
...
...
@@ -12,6 +12,7 @@ import { RelatedItemsFormSection } from '@/components/item/RelatedItemsFormSecti
import
{
SourceFormSection
}
from
'
@/components/item/SourceFormSection/SourceFormSection
'
import
{
Button
}
from
'
@/elements/Button/Button
'
import
{
useToast
}
from
'
@/elements/Toast/useToast
'
import
{
sanitizeFormValues
}
from
'
@/lib/sshoc/sanitizeFormValues
'
import
{
validateCommonFormFields
}
from
'
@/lib/sshoc/validateCommonFormFields
'
import
{
validateDateFormFields
}
from
'
@/lib/sshoc/validateDateFormFields
'
import
{
useAuth
}
from
'
@/modules/auth/AuthContext
'
...
...
@@ -89,18 +90,13 @@ export function ItemForm(props: ItemFormProps<ItemFormValues>): JSX.Element {
},
})
function
onSubmit
({
draft
,
...
values
}:
ItemFormValues
)
{
function
onSubmit
({
draft
,
...
unsanitized
}:
ItemFormValues
)
{
if
(
auth
.
session
?.
accessToken
==
null
)
{
toast
.
error
(
'
Authentication required.
'
)
return
Promise
.
reject
()
}
/**
* Backend crashes with `source: {}`.
*/
if
(
values
.
source
&&
values
.
source
.
id
===
undefined
)
{
delete
values
.
source
}
const
values
=
sanitizeFormValues
(
unsanitized
)
return
create
.
mutateAsync
([
{
id
},
...
...
src/components/item/ToolCreateForm/ToolCreateForm.tsx
View file @
19a89698
...
...
@@ -11,6 +11,7 @@ import { RelatedItemsFormSection } from '@/components/item/RelatedItemsFormSecti
import
{
SourceFormSection
}
from
'
@/components/item/SourceFormSection/SourceFormSection
'
import
{
Button
}
from
'
@/elements/Button/Button
'
import
{
useToast
}
from
'
@/elements/Toast/useToast
'
import
{
sanitizeFormValues
}
from
'
@/lib/sshoc/sanitizeFormValues
'
import
{
validateCommonFormFields
}
from
'
@/lib/sshoc/validateCommonFormFields
'
import
{
useAuth
}
from
'
@/modules/auth/AuthContext
'
import
{
Form
}
from
'
@/modules/form/Form
'
...
...
@@ -85,18 +86,13 @@ export function ItemForm(props: ItemFormProps<ItemFormValues>): JSX.Element {
},
})
function
onSubmit
({
draft
,
...
values
}:
ItemFormValues
)
{
function
onSubmit
({
draft
,
...
unsanitized
}:
ItemFormValues
)
{
if
(
auth
.
session
?.
accessToken
==
null
)
{
toast
.
error
(
'
Authentication required.
'
)
return
Promise
.
reject
()
}
/**
* Backend crashes with `source: {}`.
*/
if
(
values
.
source
&&
values
.
source
.
id
===
undefined
)
{
delete
values
.
source
}
const
values
=
sanitizeFormValues
(
unsanitized
)
return
create
.
mutateAsync
([
{
draft
},
...
...
src/components/item/ToolEditForm/ToolEditForm.tsx
View file @
19a89698
...
...
@@ -11,6 +11,7 @@ import { RelatedItemsFormSection } from '@/components/item/RelatedItemsFormSecti
import
{
SourceFormSection
}
from
'
@/components/item/SourceFormSection/SourceFormSection
'
import
{
Button
}
from
'
@/elements/Button/Button
'
import
{
useToast
}
from
'
@/elements/Toast/useToast
'
import
{
sanitizeFormValues
}
from
'
@/lib/sshoc/sanitizeFormValues
'
import
{
validateCommonFormFields
}
from
'
@/lib/sshoc/validateCommonFormFields
'
import
{
useAuth
}
from
'
@/modules/auth/AuthContext
'
import
{
Form
}
from
'
@/modules/form/Form
'
...
...
@@ -87,18 +88,13 @@ export function ItemForm(props: ItemFormProps<ItemFormValues>): JSX.Element {
},
})
function
onSubmit
({
draft
,
...
values
}:
ItemFormValues
)
{
function
onSubmit
({
draft
,
...
unsanitized
}:
ItemFormValues
)
{
if
(
auth
.
session
?.
accessToken
==
null
)
{
toast
.
error
(
'
Authentication required.
'
)
return
Promise
.
reject
()
}
/**
* Backend crashes with `source: {}`.
*/
if
(
values
.
source
&&
values
.
source
.
id
===
undefined
)
{
delete
values
.
source
}
const
values
=
sanitizeFormValues
(
unsanitized
)
return
create
.
mutateAsync
([
{
id
},
...
...
src/components/item/TrainingMaterialCreateForm/TrainingMaterialCreateForm.tsx
View file @
19a89698
...
...
@@ -11,6 +11,7 @@ import { RelatedItemsFormSection } from '@/components/item/RelatedItemsFormSecti
import
{
SourceFormSection
}
from
'
@/components/item/SourceFormSection/SourceFormSection
'
import
{
Button
}
from
'
@/elements/Button/Button
'
import
{
useToast
}
from
'
@/elements/Toast/useToast
'
import
{
sanitizeFormValues
}
from
'
@/lib/sshoc/sanitizeFormValues
'
import
{
validateCommonFormFields
}
from
'
@/lib/sshoc/validateCommonFormFields
'
import
{
useAuth
}
from
'
@/modules/auth/AuthContext
'
import
{
Form
}
from
'
@/modules/form/Form
'
...
...
@@ -85,18 +86,13 @@ export function ItemForm(props: ItemFormProps<ItemFormValues>): JSX.Element {
},
})
function
onSubmit
({
draft
,
...
values
}:
ItemFormValues
)
{
function
onSubmit
({
draft
,
...
unsanitized
}:
ItemFormValues
)
{
if
(
auth
.
session
?.
accessToken
==
null
)
{
toast
.
error
(
'
Authentication required.
'
)
return
Promise
.
reject
()
}
/**
* Backend crashes with `source: {}`.
*/
if
(
values
.
source
&&
values
.
source
.
id
===
undefined
)
{
delete
values
.
source
}
const
values
=
sanitizeFormValues
(
unsanitized
)
return
create
.
mutateAsync
([
{
draft
},
...
...
src/components/item/TrainingMaterialEditForm/TrainingMaterialEditForm.tsx
View file @
19a89698
...
...
@@ -11,6 +11,7 @@ import { RelatedItemsFormSection } from '@/components/item/RelatedItemsFormSecti
import
{
SourceFormSection
}
from
'
@/components/item/SourceFormSection/SourceFormSection
'
import
{
Button
}
from
'
@/elements/Button/Button
'
import
{
useToast
}
from
'
@/elements/Toast/useToast
'
import
{
sanitizeFormValues
}
from
'
@/lib/sshoc/sanitizeFormValues
'
import
{
validateCommonFormFields
}
from
'
@/lib/sshoc/validateCommonFormFields
'
import
{
useAuth
}
from
'
@/modules/auth/AuthContext
'
import
{
Form
}
from
'
@/modules/form/Form
'
...
...
@@ -87,18 +88,13 @@ export function ItemForm(props: ItemFormProps<ItemFormValues>): JSX.Element {
},
})
function
onSubmit
({
draft
,
...
values
}:
ItemFormValues
)
{
function
onSubmit
({
draft
,
...
unsanitized
}:
ItemFormValues
)
{
if
(
auth
.
session
?.
accessToken
==
null
)
{
toast
.
error
(
'
Authentication required.
'
)
return
Promise
.
reject
()
}
/**
* Backend crashes with `source: {}`.
*/
if
(
values
.
source
&&
values
.
source
.
id
===
undefined
)
{
delete
values
.
source
}
const
values
=
sanitizeFormValues
(
unsanitized
)
return
create
.
mutateAsync
([
{
id
},
...
...
src/lib/sshoc/sanitizeFormValues.ts
0 → 100644
View file @
19a89698
import
type
{
DatasetCore
,
PublicationCore
,
StepCore
,
ToolCore
,
TrainingMaterialCore
,
WorkflowCore
,
}
from
'
@/api/sshoc
'
export
function
sanitizeFormValues
<
T
extends
|
DatasetCore
|
PublicationCore
|
ToolCore
|
TrainingMaterialCore
|
WorkflowCore
|
StepCore
>
(
values
:
T
):
T
{
/**
* Backend crashes with `[null]`
*/
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
values
.
accessibleAt
=
values
.
accessibleAt
?.
filter
((
v
)
=>
v
!=
null
)
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
values
.
contributors
=
values
.
contributors
?.
filter
((
v
)
=>
v
!=
null
)
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
values
.
properties
=
values
.
properties
?.
filter
((
v
)
=>
v
!=
null
)
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
values
.
relatedItems
=
values
.
relatedItems
?.
filter
((
v
)
=>
v
!=
null
)
/**
* Backend crashes with `source: {}`.
*/
if
(
values
.
source
&&
values
.
source
.
id
===
undefined
)
{
delete
values
.
source
}
return
values
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a 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