Skip to content

Commit

Permalink
feat(editor-content): create const for actions #29871
Browse files Browse the repository at this point in the history
  • Loading branch information
nicobytes committed Sep 17, 2024
1 parent 20d63f5 commit 522a042
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 19 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import { INPUT_TYPES } from "./models";

type Actions = {
allowExistingFile: boolean,
allowURLImport: boolean,
allowCreateFile: boolean,
allowGenerateImg: boolean
}

type ConfigActions = Record<INPUT_TYPES, Actions>;

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
}
};
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -59,26 +60,13 @@ export const FileFieldStore = signalStore(
}) => {
const { inputType, uiMessage } = initState;

const state: Partial<FileFieldState> = {
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
});
}
}))
);

0 comments on commit 522a042

Please sign in to comment.