Browse Source

fix: copy paste mm cell from different where relatedTableModelId is same

pull/7558/head
Ramesh Mane 9 months ago
parent
commit
b65240b6b2
  1. 2
      packages/nc-gui/composables/useMultiSelect/convertCellData.ts
  2. 9
      packages/nc-gui/composables/useMultiSelect/index.ts
  3. 1
      packages/nocodb/src/controllers/data-table.controller.ts
  4. 5
      packages/nocodb/src/schema/swagger.json
  5. 30
      packages/nocodb/src/services/data-table.service.ts

2
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
) {

9
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 (

1
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;
}[],
) {

5
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"]
}
}
},

30
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 };

Loading…
Cancel
Save