diff --git a/src/webapp/pages/form-page/resources/mapResourceToInitialFormState.ts b/src/webapp/pages/form-page/resources/mapResourceToInitialFormState.ts index a2a30c9..1acda6c 100644 --- a/src/webapp/pages/form-page/resources/mapResourceToInitialFormState.ts +++ b/src/webapp/pages/form-page/resources/mapResourceToInitialFormState.ts @@ -26,7 +26,6 @@ export function mapResourceToInitialFormState( const fromIdsDictionary = (key: keyof typeof resourceFieldIds) => getFieldIdFromIdsDictionary(key, resourceFieldIds); - const { isAdmin } = resourcePermissions; return { @@ -37,58 +36,71 @@ export function mapResourceToInitialFormState( isValid: false, sections: [ { - title: "Resource type", - id: `${fromIdsDictionary("resourceType")}_section`, + title: "Resource name", + id: `${fromIdsDictionary("resourceLabel")}_section`, isVisible: true, required: true, fields: [ { - id: fromIdsDictionary("resourceType"), - placeholder: "Select a resource type", + id: fromIdsDictionary("resourceLabel"), isVisible: true, errors: [], - type: "select", - multiple: false, - options: resourceTypeOptions, - value: resource?.resourceType || "", + type: "text", + value: resource?.resourceLabel || "", required: true, }, ], }, { - title: "Resource name", - id: `${fromIdsDictionary("resourceLabel")}_section`, + title: "Resource type", + id: `${fromIdsDictionary("resourceType")}_section`, isVisible: true, required: true, fields: [ { - id: fromIdsDictionary("resourceLabel"), + id: fromIdsDictionary("resourceType"), + placeholder: "Select a resource type", isVisible: true, errors: [], - type: "text", - value: resource?.resourceLabel || "", + type: "select", + multiple: false, + options: resourceTypeOptions, + value: resource?.resourceType || "", required: true, }, ], }, + { title: "Resource folder", id: `${fromIdsDictionary("resourceFolder")}_section`, isVisible: isResourceDocument, required: true, - fields: [ - { - id: fromIdsDictionary("resourceFolder"), - isVisible: isResourceDocument, - errors: [], - type: "select", - options: resourceFolderOptions, - multiple: false, - addNewOption: isAdmin, - value: isResourceDocument ? resource.resourceFolder : "", - required: true, - }, - ], + fields: + resourceFolderOptions.length === 0 + ? [ + { + id: fromIdsDictionary("resourceFolder"), + isVisible: isResourceDocument, + errors: [], + type: "text", + value: isResourceDocument ? resource.resourceFolder : "", + required: true, + }, + ] + : [ + { + id: fromIdsDictionary("resourceFolder"), + isVisible: isResourceDocument, + errors: [], + type: "select", + options: resourceFolderOptions, + multiple: false, + addNewOption: isAdmin, + value: isResourceDocument ? resource.resourceFolder : "", + required: true, + }, + ], }, { title: "Resource file",