From b65240b6b25b813b0c3d6bedacf1cc4e703f702f Mon Sep 17 00:00:00 2001 From: Ramesh Mane <101566080+rameshmane7218@users.noreply.github.com> Date: Mon, 19 Feb 2024 03:41:21 +0000 Subject: [PATCH] fix: copy paste mm cell from different where relatedTableModelId is same --- .../useMultiSelect/convertCellData.ts | 2 +- .../composables/useMultiSelect/index.ts | 9 ++++++ .../src/controllers/data-table.controller.ts | 1 + packages/nocodb/src/schema/swagger.json | 5 +++- .../nocodb/src/services/data-table.service.ts | 30 +++++++++++-------- 5 files changed, 32 insertions(+), 15 deletions(-) diff --git a/packages/nc-gui/composables/useMultiSelect/convertCellData.ts b/packages/nc-gui/composables/useMultiSelect/convertCellData.ts index 2b3abf2eac..5a6c01530a 100644 --- a/packages/nc-gui/composables/useMultiSelect/convertCellData.ts +++ b/packages/nc-gui/composables/useMultiSelect/convertCellData.ts @@ -271,7 +271,7 @@ export default function convertCellData( typeof parsedVal === 'object' && !Array.isArray(parsedVal) && // eslint-disable-next-line no-prototype-builtins - ['rowId', 'fk_related_model_id', 'value'].every((key) => (parsedVal as Object).hasOwnProperty(key)) + ['rowId', 'columnId', 'fk_related_model_id', 'value'].every((key) => (parsedVal as Object).hasOwnProperty(key)) ) || parsedVal?.fk_related_model_id !== (column.colOptions as LinkToAnotherRecordType).fk_related_model_id ) { diff --git a/packages/nc-gui/composables/useMultiSelect/index.ts b/packages/nc-gui/composables/useMultiSelect/index.ts index 04a367d375..d41ac0f826 100644 --- a/packages/nc-gui/composables/useMultiSelect/index.ts +++ b/packages/nc-gui/composables/useMultiSelect/index.ts @@ -232,6 +232,7 @@ export function useMultiSelect( ) { return JSON.stringify({ rowId: extractPkFromRow(rowObj.row, meta.value?.columns as ColumnType[]), + columnId: columnObj.id, fk_related_model_id: (columnObj.colOptions as LinkToAnotherRecordType).fk_related_model_id, value: !isNaN(+textToCopy) ? +textToCopy : 0, }) @@ -923,16 +924,20 @@ export function useMultiSelect( let result + console.log('column', columnObj.id) + try { result = await api.dbDataTableRow.nestedLinkUnlink(meta.value?.id as string, columnObj.id as string, [ { operation: 'copy', rowId: pasteVal.rowId, + columnId: pasteVal.columnId, fk_related_model_id: pasteVal.fk_related_model_id, }, { operation: 'paste', rowId: pasteRowPk, + columnId: pasteVal.columnId, fk_related_model_id: (columnObj.colOptions as LinkToAnotherRecordType).fk_related_model_id || pasteVal.fk_related_model_id, }, @@ -942,6 +947,10 @@ export function useMultiSelect( } if (result && result?.link && result?.unlink && Array.isArray(result.link) && Array.isArray(result.unlink)) { + if (!result.link.length && !result.unlink.length) { + rowObj.row[columnObj.title!] = oldCellValue + return + } addUndo({ redo: { fn: async ( diff --git a/packages/nocodb/src/controllers/data-table.controller.ts b/packages/nocodb/src/controllers/data-table.controller.ts index 1d3e424fee..acf72af3e5 100644 --- a/packages/nocodb/src/controllers/data-table.controller.ts +++ b/packages/nocodb/src/controllers/data-table.controller.ts @@ -206,6 +206,7 @@ export class DataTableController { data: { operation: 'copy' | 'paste'; rowId: string; + columnId: string; fk_related_model_id: string; }[], ) { diff --git a/packages/nocodb/src/schema/swagger.json b/packages/nocodb/src/schema/swagger.json index d71179ea71..a5d9db01ed 100644 --- a/packages/nocodb/src/schema/swagger.json +++ b/packages/nocodb/src/schema/swagger.json @@ -23249,11 +23249,14 @@ "rowId": { "type": "string" }, + "columnId":{ + "type": "string" + }, "fk_related_model_id":{ "type": "string" } }, - "required": ["operation", "rowId", "fk_related_model_id"] + "required": ["operation", "rowId", "columnId", "fk_related_model_id"] } } }, diff --git a/packages/nocodb/src/services/data-table.service.ts b/packages/nocodb/src/services/data-table.service.ts index 26471ae61c..f0be837e52 100644 --- a/packages/nocodb/src/services/data-table.service.ts +++ b/packages/nocodb/src/services/data-table.service.ts @@ -454,6 +454,7 @@ export class DataTableService { data: { operation: 'copy' | 'paste'; rowId: string; + columnId: string; fk_related_model_id: string; }[]; }) { @@ -480,6 +481,7 @@ export class DataTableService { { operation: 'copy' | 'paste'; rowId: string; + columnId: string; fk_related_model_id: string; } >, @@ -538,7 +540,7 @@ export class DataTableService { const [copiedCellNestedList, pasteCellNestedList] = await Promise.all([ baseModel.mmList( { - colId: column.id, + colId: operationMap.copy.columnId, parentId: operationMap.copy.rowId, }, listArgs as any, @@ -567,18 +569,20 @@ export class DataTableService { ); await Promise.all([ - baseModel.addLinks({ - colId: column.id, - childIds: filteredRowsToLink, - rowId: operationMap.paste.rowId, - cookie: param.cookie, - }), - baseModel.removeLinks({ - colId: column.id, - childIds: filteredRowsToUnlink, - rowId: operationMap.paste.rowId, - cookie: param.cookie, - }), + filteredRowsToLink.length && + baseModel.addLinks({ + colId: column.id, + childIds: filteredRowsToLink, + rowId: operationMap.paste.rowId, + cookie: param.cookie, + }), + filteredRowsToUnlink.length && + baseModel.removeLinks({ + colId: column.id, + childIds: filteredRowsToUnlink, + rowId: operationMap.paste.rowId, + cookie: param.cookie, + }), ]); return { link: filteredRowsToLink, unlink: filteredRowsToUnlink };