From 8f04a770f70ce6f3522cdea2acac62bde2ee966c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=A8=E5=9B=BD=E7=92=87?= <37972689+YangGuoXuan-0503@users.noreply.github.com> Date: Tue, 5 Nov 2024 10:24:29 +0800 Subject: [PATCH] fix: init new option (#6992) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: 杨国璇 --- .../popover/options-popover/index.js | 2 +- .../metadata/store/operations/constants.js | 1 + .../src/metadata/store/server-operator.js | 19 +++++++++++++++---- 3 files changed, 17 insertions(+), 5 deletions(-) diff --git a/frontend/src/metadata/components/popover/options-popover/index.js b/frontend/src/metadata/components/popover/options-popover/index.js index a32f6d14a7..0239bc2af6 100644 --- a/frontend/src/metadata/components/popover/options-popover/index.js +++ b/frontend/src/metadata/components/popover/options-popover/index.js @@ -75,7 +75,7 @@ const OptionsPopover = ({ target, column, onToggle, onSubmit }) => { const newOption = generateNewOption(options, newOptionName); const newOptions = options.slice(0); newOptions.push(newOption); - onChange(newOptions, COLUMN_DATA_OPERATION_TYPE.ADD_OPTION); + onChange(newOptions, COLUMN_DATA_OPERATION_TYPE.INIT_NEW_OPTION); setEditingOptionId(newOptionName ? '' : newOption.id); }, [searchValue, options, onChange]); diff --git a/frontend/src/metadata/store/operations/constants.js b/frontend/src/metadata/store/operations/constants.js index 0fc8d24b80..425425b33a 100644 --- a/frontend/src/metadata/store/operations/constants.js +++ b/frontend/src/metadata/store/operations/constants.js @@ -25,6 +25,7 @@ export const COLUMN_DATA_OPERATION_TYPE = { RENAME_OPTION: 'rename_option', MODIFY_OPTION_COLOR: 'modify_option_color', MOVE_OPTION: 'move_option', + INIT_NEW_OPTION: 'init_new_option', }; export const OPERATION_ATTRIBUTES = { diff --git a/frontend/src/metadata/store/server-operator.js b/frontend/src/metadata/store/server-operator.js index cc2e6c4192..60b3bfffc8 100644 --- a/frontend/src/metadata/store/server-operator.js +++ b/frontend/src/metadata/store/server-operator.js @@ -1,12 +1,13 @@ import { seafileAPI } from '../../utils/seafile-api'; import { gettext } from '../../utils/constants'; import { Utils } from '../../utils/utils'; -import { OPERATION_TYPE } from './operations'; +import { COLUMN_DATA_OPERATION_TYPE, OPERATION_TYPE } from './operations'; import { getColumnByKey } from '../utils/column'; import { getRowById } from '../utils/table'; import { checkIsDir } from '../utils/row'; -import { getFileNameFromRecord } from '../utils/cell'; +import { checkIsPredefinedOption, getFileNameFromRecord } from '../utils/cell'; import ObjectUtils from '../utils/object-utils'; +import { CellType } from '../constants'; const MAX_LOAD_RECORDS = 100; @@ -110,8 +111,18 @@ class ServerOperator { break; } case OPERATION_TYPE.MODIFY_COLUMN_DATA: { - const { repo_id, column_key, new_data } = operation; - window.sfMetadataContext.modifyColumnData(repo_id, column_key, new_data).then(res => { + const { repo_id, column_key, new_data, option_modify_type } = operation; + if (option_modify_type && option_modify_type === COLUMN_DATA_OPERATION_TYPE.INIT_NEW_OPTION) break; + const column = getColumnByKey(data.columns, column_key); + let origin_data = new_data; + + if (column.type === CellType.SINGLE_SELECT) { + origin_data.options = Array.isArray(origin_data.options) ? origin_data.options.map(option => { + if (checkIsPredefinedOption(column, option.id)) return { id: option.id, name: option.id }; + return option; + }) : []; + } + window.sfMetadataContext.modifyColumnData(repo_id, column_key, origin_data).then(res => { callback({ operation }); }).catch(error => { callback({ error: gettext('Failed to modify property data') });