From f302f63759c11013e1470ae81cd331f49715900c Mon Sep 17 00:00:00 2001 From: Pranav C Date: Wed, 30 Nov 2022 11:34:07 +0530 Subject: [PATCH] fix(gui): duplicating single/multiselect column Signed-off-by: Pranav C --- .../components/smartsheet/header/Menu.vue | 41 +++++++++++++++---- packages/nc-gui/lang/en.json | 1 + 2 files changed, 33 insertions(+), 9 deletions(-) diff --git a/packages/nc-gui/components/smartsheet/header/Menu.vue b/packages/nc-gui/components/smartsheet/header/Menu.vue index e27ed735ec..eaa22a88d7 100644 --- a/packages/nc-gui/components/smartsheet/header/Menu.vue +++ b/packages/nc-gui/components/smartsheet/header/Menu.vue @@ -112,31 +112,47 @@ const getUniqueColumnName = (initName: string, columns: ColumnType[]) => { const duplicateColumn = async () => { let columnCreatePayload = {} + // generate duplicate column name const duplicateColumnName = getUniqueColumnName(`${column!.value.title}_copy`, meta!.value!.columns!) + // construct column create payload switch (column.value.uidt) { - // LTAR - // Formula - // Lookup - // Rollup - case UITypes.LinkToAnotherRecord: case UITypes.Lookup: case UITypes.Rollup: case UITypes.Formula: return message.info('Not available at the moment') + case UITypes.SingleSelect: + case UITypes.MultiSelect: + columnCreatePayload = { + ...column!.value!, + title: duplicateColumnName, + column_name: duplicateColumnName, + id: undefined, + order: undefined, + colOptions: { + options: + column.value.colOptions?.options?.map((option: Record) => ({ + ...option, + id: undefined, + })) ?? [], + }, + } + break default: columnCreatePayload = { ...column!.value!, - ...column!.value.colOptions, + ...(column!.value.colOptions ?? {}), title: duplicateColumnName, column_name: duplicateColumnName, id: undefined, colOptions: undefined, + order: undefined, } break } + try { const gridViewColumnList = await $api.dbViewColumn.list(view.value?.id as string) @@ -158,6 +174,8 @@ const duplicateColumn = async () => { await getMeta(meta!.value!.id!, true) eventBus.emit(SmartsheetStoreEvents.FIELD_RELOAD) + + message.success(t('msg.success.columnDuplicated')) } catch (e) { message.error(await extractSdkResponseErrorMsg(e)) } @@ -204,7 +222,8 @@ const hideField = async () => {