Browse Source

Merge pull request #6980 from nocodb/fix/dup-formula

fix: duplicate formula column after alias change
pull/6983/head
Raju Udava 1 year ago committed by GitHub
parent
commit
345177b18c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 14
      packages/nc-gui/components/dlg/ColumnDuplicate.vue
  2. 20
      packages/nc-gui/components/smartsheet/header/Menu.vue
  3. 20
      packages/nocodb/src/modules/jobs/jobs/export-import/duplicate.processor.ts
  4. 11
      packages/nocodb/src/modules/jobs/jobs/export-import/export.service.ts

14
packages/nc-gui/components/dlg/ColumnDuplicate.vue

@ -17,10 +17,6 @@ const dialogShow = useVModel(props, 'modelValue', emit)
const { $e, $poller } = useNuxtApp() const { $e, $poller } = useNuxtApp()
const basesStore = useBases()
const { createProject: _createProject } = basesStore
const { activeTable: _activeTable } = storeToRefs(useTablesStore()) const { activeTable: _activeTable } = storeToRefs(useTablesStore())
const reloadDataHook = inject(ReloadViewDataHookInj) const reloadDataHook = inject(ReloadViewDataHookInj)
@ -101,7 +97,9 @@ onKeyStroke('Enter', () => {
} }
}) })
const isEaster = ref(false) defineExpose({
duplicate: _duplicate,
})
</script> </script>
<template> <template>
@ -118,11 +116,9 @@ const isEaster = ref(false)
@keydown.esc="dialogShow = false" @keydown.esc="dialogShow = false"
> >
<div> <div>
<div class="prose-xl font-bold self-center" @dblclick="isEaster = !isEaster"> <div class="prose-xl font-bold self-center">{{ $t('general.duplicate') }} {{ $t('objects.column') }}</div>
{{ $t('general.duplicate') }} {{ $t('objects.column') }}
</div>
<div class="mt-4">{{ $t('msg.warning.duplicateProject') }}</div> <div class="mt-4">Are you sure you want to duplicate the field?</div>
<div class="prose-md self-center text-gray-500 mt-4">{{ $t('title.advancedSettings') }}</div> <div class="prose-md self-center text-gray-500 mt-4">{{ $t('title.advancedSettings') }}</div>

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

@ -111,8 +111,8 @@ const sortByColumn = async (direction: 'asc' | 'desc') => {
} }
const isDuplicateDlgOpen = ref(false) const isDuplicateDlgOpen = ref(false)
const selectedColumnToDuplicate = ref<ColumnType>()
const selectedColumnExtra = ref<any>() const selectedColumnExtra = ref<any>()
const duplicateDialogRef = ref<any>()
const duplicateVirtualColumn = async () => { const duplicateVirtualColumn = async () => {
let columnCreatePayload = {} let columnCreatePayload = {}
@ -165,7 +165,7 @@ const duplicateVirtualColumn = async () => {
const openDuplicateDlg = async () => { const openDuplicateDlg = async () => {
if (!column?.value) return if (!column?.value) return
if (column.value.uidt && [UITypes.Formula, UITypes.Lookup, UITypes.Rollup].includes(column.value.uidt as UITypes)) { if (column.value.uidt && [UITypes.Lookup, UITypes.Rollup].includes(column.value.uidt as UITypes)) {
duplicateVirtualColumn() duplicateVirtualColumn()
} else { } else {
const gridViewColumnList = (await $api.dbViewColumn.list(view.value?.id as string)).list const gridViewColumnList = (await $api.dbViewColumn.list(view.value?.id as string)).list
@ -186,8 +186,15 @@ const openDuplicateDlg = async () => {
view_id: view.value!.id as string, view_id: view.value!.id as string,
}, },
} }
selectedColumnToDuplicate.value = column.value
isDuplicateDlgOpen.value = true if (column.value.uidt === UITypes.Formula) {
nextTick(() => {
duplicateDialogRef?.value?.duplicate()
})
} else {
isDuplicateDlgOpen.value = true
}
isOpen.value = false isOpen.value = false
} }
} }
@ -373,9 +380,10 @@ const onInsertAfter = () => {
</a-dropdown> </a-dropdown>
<SmartsheetHeaderDeleteColumnModal v-model:visible="showDeleteColumnModal" /> <SmartsheetHeaderDeleteColumnModal v-model:visible="showDeleteColumnModal" />
<DlgColumnDuplicate <DlgColumnDuplicate
v-if="selectedColumnToDuplicate" v-if="column"
ref="duplicateDialogRef"
v-model="isDuplicateDlgOpen" v-model="isDuplicateDlgOpen"
:column="selectedColumnToDuplicate" :column="column"
:extra="selectedColumnExtra" :extra="selectedColumnExtra"
/> />
</template> </template>

20
packages/nocodb/src/modules/jobs/jobs/export-import/duplicate.processor.ts

@ -3,7 +3,7 @@ import { Process, Processor } from '@nestjs/bull';
import { Job } from 'bull'; import { Job } from 'bull';
import papaparse from 'papaparse'; import papaparse from 'papaparse';
import debug from 'debug'; import debug from 'debug';
import { isLinksOrLTAR } from 'nocodb-sdk'; import { isLinksOrLTAR, isVirtualCol } from 'nocodb-sdk';
import { Base, Column, Model, Source } from '~/models'; import { Base, Column, Model, Source } from '~/models';
import { BasesService } from '~/services/bases.service'; import { BasesService } from '~/services/bases.service';
import { import {
@ -373,14 +373,16 @@ export class DuplicateProcessor {
}); });
// update cdf // update cdf
await this.columnsService.columnUpdate({ if (!isVirtualCol(destColumn)) {
columnId: findWithIdentifier(idMap, sourceColumn.id), await this.columnsService.columnUpdate({
column: { columnId: findWithIdentifier(idMap, sourceColumn.id),
...destColumn, column: {
cdf: oldCdf, ...destColumn,
}, cdf: oldCdf,
user: req.user, },
}); user: req.user,
});
}
this.debugLog(`job completed for ${job.id} (${JobTypes.DuplicateModel})`); this.debugLog(`job completed for ${job.id} (${JobTypes.DuplicateModel})`);

11
packages/nocodb/src/modules/jobs/jobs/export-import/export.service.ts

@ -129,6 +129,17 @@ export class ExportService {
} }
break; break;
case 'formula': case 'formula':
// rewrite formula_raw with aliases
column.colOptions['formula_raw'] = column.colOptions[k].replace(
/\{\{.*?\}\}/gm,
(match) => {
const col = model.columns.find(
(c) => c.id === match.slice(2, -2),
);
return `{${col?.title}}`;
},
);
column.colOptions[k] = column.colOptions[k].replace( column.colOptions[k] = column.colOptions[k].replace(
/(?<=\{\{).*?(?=\}\})/gm, /(?<=\{\{).*?(?=\}\})/gm,
(match) => idMap.get(match), (match) => idMap.get(match),

Loading…
Cancel
Save