Skip to content

Commit

Permalink
fix: update workflow and workflow steps forms (#193)
Browse files Browse the repository at this point in the history
closes #192
  • Loading branch information
stefanprobst authored Oct 17, 2024
2 parents 145d9a7 + 42b0bfc commit 1d4c7bd
Show file tree
Hide file tree
Showing 5 changed files with 90 additions and 10 deletions.
8 changes: 4 additions & 4 deletions src/components/item-form/WorkflowForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import { FormSections } from '@/components/common/FormSections'
import { ActorFormSection } from '@/components/item-form/ActorFormSection'
import { DateFormSection } from '@/components/item-form/DateFormSection'
import { ItemFormControls } from '@/components/item-form/ItemFormControls'
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'
Expand All @@ -22,6 +21,8 @@ import type { WorkflowFormPage } from '@/components/item-form/useWorkflowFormPag
import { useWorkflowStepFormFields } from '@/components/item-form/useWorkflowStepFormFields'
import { useWorkflowStepFormRecommendedFields } from '@/components/item-form/useWorkflowStepFormRecommendedFields'
import { WorkflowFormNavigation } from '@/components/item-form/WorkflowFormNavigation'
import { WorkflowMainFormSection } from '@/components/item-form/WorkflowMainFormSection'
import { WorkflowStepMainFormSection } from '@/components/item-form/WorkflowStepMainFormSection'
import { WorkflowStepPreview } from '@/components/item-form/WorkflowStepPreview'
import { WorkflowTitle } from '@/components/item-form/WorkflowTitle'
import type { Workflow, WorkflowInput } from '@/data/sshoc/api/workflow'
Expand Down Expand Up @@ -151,7 +152,7 @@ function WorkflowFormSections(props: WorkflowFormSectionsProps): JSX.Element {

return (
<FormSections>
<MainFormSection formFields={formFields} />
<WorkflowMainFormSection formFields={formFields} />
<DateFormSection formFields={formFields} />
<ActorFormSection formFields={formFields} />
<PropertyFormSection formFields={formFields} />
Expand Down Expand Up @@ -279,9 +280,8 @@ function WorkflowStepFormSections(props: WorkflowStepFormSectionsProps): JSX.Ele

return (
<FormSections>
<MainFormSection formFields={formFields} />
<WorkflowStepMainFormSection formFields={formFields} />
<PropertyFormSection formFields={formFields} />
<MediaFormSection formFields={formFields} />
<RelatedItemFormSection formFields={formFields} />

<FormControls>
Expand Down
31 changes: 31 additions & 0 deletions src/components/item-form/WorkflowMainFormSection.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import { VisuallyHidden } from '@react-aria/visually-hidden'

import { FormSection } from '@/components/common/FormSection'
import { FormSectionTitle } from '@/components/common/FormSectionTitle'
import { ExternalIdsFormFieldArray } from '@/components/item-form/ExternalIdsFormFieldArray'
import type { ItemFormFields } from '@/components/item-form/useItemFormFields'
import { FormTextArea } from '@/lib/core/form/FormTextArea'
import { FormTextField } from '@/lib/core/form/FormTextField'
import { useI18n } from '@/lib/core/i18n/useI18n'

export interface WorkflowMainFormSectionProps {
formFields: ItemFormFields
}

export function WorkflowMainFormSection(props: WorkflowMainFormSectionProps): JSX.Element {
const { fields } = props.formFields

const { t } = useI18n<'authenticated' | 'common'>()

return (
<FormSection>
<VisuallyHidden>
<FormSectionTitle>{t(['authenticated', 'forms', 'main-section'])}</FormSectionTitle>
</VisuallyHidden>
<FormTextField {...fields.label} />
<FormTextField {...fields.version} />
<FormTextArea {...fields.description} rows={6} />
<ExternalIdsFormFieldArray field={fields.externalIds} />
</FormSection>
)
}
28 changes: 28 additions & 0 deletions src/components/item-form/WorkflowStepMainFormSection.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { VisuallyHidden } from '@react-aria/visually-hidden'

import { FormSection } from '@/components/common/FormSection'
import { FormSectionTitle } from '@/components/common/FormSectionTitle'
import type { ItemFormFields } from '@/components/item-form/useItemFormFields'
import { FormTextArea } from '@/lib/core/form/FormTextArea'
import { FormTextField } from '@/lib/core/form/FormTextField'
import { useI18n } from '@/lib/core/i18n/useI18n'

export interface WorkflowMainFormSectionProps {
formFields: ItemFormFields
}

export function WorkflowMainFormSection(props: WorkflowMainFormSectionProps): JSX.Element {
const { fields } = props.formFields

const { t } = useI18n<'authenticated' | 'common'>()

return (
<FormSection>
<VisuallyHidden>
<FormSectionTitle>{t(['authenticated', 'forms', 'main-section'])}</FormSectionTitle>
</VisuallyHidden>
<FormTextField {...fields.label} />
<FormTextArea {...fields.description} rows={6} />
</FormSection>
)
}
8 changes: 3 additions & 5 deletions src/components/item-form/useWorkflowFormRecommendedFields.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const recommendedFields = {
// label: '',
// description: '',
contributors: [{ role: { code: undefined }, actor: { id: undefined } }],
accessibleAt: [undefined],
// accessibleAt: [undefined],
externalIds: [{ identifier: undefined, identifierService: { code: undefined } }],
relatedItems: [{ relation: { code: undefined }, persistentId: undefined }],
}
Expand All @@ -19,12 +19,10 @@ const recommendedProperties = [
'keyword',
'discipline',
'language',
'intended-audience',
'see-also',
'license',
'terms-of-use-url',
'standard',
'resource-category',
'see-also',
'license',
]

const properties: Array<
Expand Down
25 changes: 24 additions & 1 deletion src/components/item-form/useWorkflowStepFormRecommendedFields.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,35 @@
import type { StaticResult as PropertyTypes } from '@/components/item-form/property-types.static'
import _propertyTypes from '@/components/item-form/property-types.static'
import type { PropertyTypeConcept, PropertyTypeScalar } from '@/data/sshoc/api/property'
import type { WorkflowStepInput } from '@/data/sshoc/api/workflow-step'

const propertyTypes = _propertyTypes as unknown as PropertyTypes

const recommendedFields = {
// label: '',
// description: '',
relatedItems: [{ relation: { code: undefined }, persistentId: undefined }],
}

const fields = { ...recommendedFields }
const recommendedProperties = ['activity', 'keyword', 'inputformat', 'outputformat']

const properties: Array<
| { type: PropertyTypeConcept; concept: { uri: undefined } }
| { type: PropertyTypeScalar; value: undefined }
> = []

recommendedProperties.forEach((id) => {
const propertyType = propertyTypes[id]
if (propertyType != null) {
if (propertyType.type === 'concept') {
properties.push({ type: propertyType, concept: { uri: undefined } })
} else {
properties.push({ type: propertyType, value: undefined })
}
}
})

const fields = { ...recommendedFields, properties }

export function useWorkflowStepFormRecommendedFields(): Partial<WorkflowStepInput> {
return fields as unknown as Partial<WorkflowStepInput>
Expand Down

0 comments on commit 1d4c7bd

Please sign in to comment.