diff --git a/core-web/libs/edit-content/src/lib/fields/dot-edit-content-file-field/dot-edit-content-file-field.const.ts b/core-web/libs/edit-content/src/lib/fields/dot-edit-content-file-field/dot-edit-content-file-field.const.ts new file mode 100644 index 000000000000..50c53307d4be --- /dev/null +++ b/core-web/libs/edit-content/src/lib/fields/dot-edit-content-file-field/dot-edit-content-file-field.const.ts @@ -0,0 +1,31 @@ +import { INPUT_TYPES } from "./models"; + +type Actions = { + allowExistingFile: boolean, + allowURLImport: boolean, + allowCreateFile: boolean, + allowGenerateImg: boolean +} + +type ConfigActions = Record; + +export const INPUT_CONFIG_ACTIONS: ConfigActions = { + File: { + allowExistingFile: true, + allowURLImport: true, + allowCreateFile: true, + allowGenerateImg: false + }, + Image: { + allowExistingFile: true, + allowURLImport: true, + allowCreateFile: false, + allowGenerateImg: true + }, + Binary: { + allowExistingFile: false, + allowURLImport: true, + allowCreateFile: true, + allowGenerateImg: true + } +}; \ No newline at end of file diff --git a/core-web/libs/edit-content/src/lib/fields/dot-edit-content-file-field/store/file-field.store.ts b/core-web/libs/edit-content/src/lib/fields/dot-edit-content-file-field/store/file-field.store.ts index 164acae09570..bc82b878d76e 100644 --- a/core-web/libs/edit-content/src/lib/fields/dot-edit-content-file-field/store/file-field.store.ts +++ b/core-web/libs/edit-content/src/lib/fields/dot-edit-content-file-field/store/file-field.store.ts @@ -4,6 +4,7 @@ import { computed } from '@angular/core'; import { DotCMSContentlet, DotCMSTempFile } from '@dotcms/dotcms-models'; +import { INPUT_CONFIG_ACTIONS } from '../dot-edit-content-file-field.const'; import { INPUT_TYPES, FILE_STATUS, UIMessage } from '../models'; export interface FileFieldState { @@ -59,26 +60,13 @@ export const FileFieldStore = signalStore( }) => { const { inputType, uiMessage } = initState; - const state: Partial = { - inputType, - uiMessage - }; - - if (inputType === 'File') { - state.allowExistingFile = true; - state.allowURLImport = true; - state.allowCreateFile = true; - } else if (inputType === 'Image') { - state.allowExistingFile = true; - state.allowURLImport = true; - state.allowGenerateImg = true; - } else if (inputType === 'Binary') { - state.allowCreateFile = true; - state.allowURLImport = true; - state.allowGenerateImg = true; - } + const actions = INPUT_CONFIG_ACTIONS[inputType] || {}; - patchState(store, state); + patchState(store, { + inputType, + uiMessage, + ...actions + }); } })) );