Browse Source

fix(gui): duplicating single/multiselect column

Signed-off-by: Pranav C <pranavxc@gmail.com>
pull/4504/head
Pranav C 2 years ago
parent
commit
f302f63759
  1. 41
      packages/nc-gui/components/smartsheet/header/Menu.vue
  2. 1
      packages/nc-gui/lang/en.json

41
packages/nc-gui/components/smartsheet/header/Menu.vue

@ -112,31 +112,47 @@ const getUniqueColumnName = (initName: string, columns: ColumnType[]) => {
const duplicateColumn = async () => { const duplicateColumn = async () => {
let columnCreatePayload = {} let columnCreatePayload = {}
// generate duplicate column name
const duplicateColumnName = getUniqueColumnName(`${column!.value.title}_copy`, meta!.value!.columns!) const duplicateColumnName = getUniqueColumnName(`${column!.value.title}_copy`, meta!.value!.columns!)
// construct column create payload
switch (column.value.uidt) { switch (column.value.uidt) {
// LTAR
// Formula
// Lookup
// Rollup
case UITypes.LinkToAnotherRecord: case UITypes.LinkToAnotherRecord:
case UITypes.Lookup: case UITypes.Lookup:
case UITypes.Rollup: case UITypes.Rollup:
case UITypes.Formula: case UITypes.Formula:
return message.info('Not available at the moment') 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<string, any>) => ({
...option,
id: undefined,
})) ?? [],
},
}
break
default: default:
columnCreatePayload = { columnCreatePayload = {
...column!.value!, ...column!.value!,
...column!.value.colOptions, ...(column!.value.colOptions ?? {}),
title: duplicateColumnName, title: duplicateColumnName,
column_name: duplicateColumnName, column_name: duplicateColumnName,
id: undefined, id: undefined,
colOptions: undefined, colOptions: undefined,
order: undefined,
} }
break break
} }
try { try {
const gridViewColumnList = await $api.dbViewColumn.list(view.value?.id as string) const gridViewColumnList = await $api.dbViewColumn.list(view.value?.id as string)
@ -158,6 +174,8 @@ const duplicateColumn = async () => {
await getMeta(meta!.value!.id!, true) await getMeta(meta!.value!.id!, true)
eventBus.emit(SmartsheetStoreEvents.FIELD_RELOAD) eventBus.emit(SmartsheetStoreEvents.FIELD_RELOAD)
message.success(t('msg.success.columnDuplicated'))
} catch (e) { } catch (e) {
message.error(await extractSdkResponseErrorMsg(e)) message.error(await extractSdkResponseErrorMsg(e))
} }
@ -204,7 +222,8 @@ const hideField = async () => {
</script> </script>
<template> <template>
<a-dropdown v-if="!isLocked" placement="bottomRight" :trigger="['click']" overlay-class-name="nc-dropdown-column-operations"> <a-dropdown v-if="!isLocked" placement="bottomRight" :trigger="['click']"
overlay-class-name="nc-dropdown-column-operations">
<MdiMenuDown class="h-full text-grey nc-ui-dt-dropdown cursor-pointer outline-0" /> <MdiMenuDown class="h-full text-grey nc-ui-dt-dropdown cursor-pointer outline-0" />
<template #overlay> <template #overlay>
@ -216,7 +235,8 @@ const hideField = async () => {
{{ $t('general.edit') }} {{ $t('general.edit') }}
</div> </div>
</a-menu-item> </a-menu-item>
<template v-if="column.uidt !== UITypes.LinkToAnotherRecord || column.colOptions.type !== RelationTypes.BELONGS_TO"> <template
v-if="column.uidt !== UITypes.LinkToAnotherRecord || column.colOptions.type !== RelationTypes.BELONGS_TO">
<a-divider class="!my-0" /> <a-divider class="!my-0" />
<a-menu-item @click="sortByColumn('asc')"> <a-menu-item @click="sortByColumn('asc')">
<div class="nc-column-insert-after nc-header-menu-item"> <div class="nc-column-insert-after nc-header-menu-item">
@ -241,7 +261,10 @@ const hideField = async () => {
<a-divider class="!my-0" /> <a-divider class="!my-0" />
<a-menu-item @click="duplicateColumn"> <a-menu-item
v-if="column.uidt !== UITypes.LinkToAnotherRecord && column.uidt !== UITypes.Lookup && !column.pk"
@click="duplicateColumn"
>
<div class="nc-column-duplicate nc-header-menu-item"> <div class="nc-column-duplicate nc-header-menu-item">
<MdiFileReplaceOutline class="text-primary" /> <MdiFileReplaceOutline class="text-primary" />
Duplicate Duplicate

1
packages/nc-gui/lang/en.json

@ -695,6 +695,7 @@
"futureRelease": "Coming soon!" "futureRelease": "Coming soon!"
}, },
"success": { "success": {
"columnDuplicated": "Column duplicated successfully",
"updatedUIACL": "Updated UI ACL for tables successfully", "updatedUIACL": "Updated UI ACL for tables successfully",
"pluginUninstalled": "Plugin uninstalled successfully", "pluginUninstalled": "Plugin uninstalled successfully",
"pluginSettingsSaved": "Plugin settings saved successfully", "pluginSettingsSaved": "Plugin settings saved successfully",

Loading…
Cancel
Save