From 6d716b389651f346b94a5c0765eb220f15e962c7 Mon Sep 17 00:00:00 2001 From: mertmit Date: Wed, 15 Nov 2023 12:19:07 +0300 Subject: [PATCH] fix: duplicate formula column after alias change Signed-off-by: mertmit --- .../nc-gui/components/dlg/ColumnDuplicate.vue | 14 +++++-------- .../components/smartsheet/header/Menu.vue | 20 +++++++++++++------ .../jobs/export-import/duplicate.processor.ts | 20 ++++++++++--------- .../jobs/jobs/export-import/export.service.ts | 11 ++++++++++ 4 files changed, 41 insertions(+), 24 deletions(-) diff --git a/packages/nc-gui/components/dlg/ColumnDuplicate.vue b/packages/nc-gui/components/dlg/ColumnDuplicate.vue index 82dd82612c..2c87a60ca0 100644 --- a/packages/nc-gui/components/dlg/ColumnDuplicate.vue +++ b/packages/nc-gui/components/dlg/ColumnDuplicate.vue @@ -17,10 +17,6 @@ const dialogShow = useVModel(props, 'modelValue', emit) const { $e, $poller } = useNuxtApp() -const basesStore = useBases() - -const { createProject: _createProject } = basesStore - const { activeTable: _activeTable } = storeToRefs(useTablesStore()) const reloadDataHook = inject(ReloadViewDataHookInj) @@ -101,7 +97,9 @@ onKeyStroke('Enter', () => { } }) -const isEaster = ref(false) +defineExpose({ + duplicate: _duplicate, +}) diff --git a/packages/nocodb/src/modules/jobs/jobs/export-import/duplicate.processor.ts b/packages/nocodb/src/modules/jobs/jobs/export-import/duplicate.processor.ts index 34c0da3e59..090f199688 100644 --- a/packages/nocodb/src/modules/jobs/jobs/export-import/duplicate.processor.ts +++ b/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 papaparse from 'papaparse'; import debug from 'debug'; -import { isLinksOrLTAR } from 'nocodb-sdk'; +import { isLinksOrLTAR, isVirtualCol } from 'nocodb-sdk'; import { Base, Column, Model, Source } from '~/models'; import { BasesService } from '~/services/bases.service'; import { @@ -373,14 +373,16 @@ export class DuplicateProcessor { }); // update cdf - await this.columnsService.columnUpdate({ - columnId: findWithIdentifier(idMap, sourceColumn.id), - column: { - ...destColumn, - cdf: oldCdf, - }, - user: req.user, - }); + if (!isVirtualCol(destColumn)) { + await this.columnsService.columnUpdate({ + columnId: findWithIdentifier(idMap, sourceColumn.id), + column: { + ...destColumn, + cdf: oldCdf, + }, + user: req.user, + }); + } this.debugLog(`job completed for ${job.id} (${JobTypes.DuplicateModel})`); diff --git a/packages/nocodb/src/modules/jobs/jobs/export-import/export.service.ts b/packages/nocodb/src/modules/jobs/jobs/export-import/export.service.ts index c34ae99cf0..885d279989 100644 --- a/packages/nocodb/src/modules/jobs/jobs/export-import/export.service.ts +++ b/packages/nocodb/src/modules/jobs/jobs/export-import/export.service.ts @@ -129,6 +129,17 @@ export class ExportService { } break; 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( /(?<=\{\{).*?(?=\}\})/gm, (match) => idMap.get(match),