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' && typeof parsedVal === 'object' &&
!Array.isArray(parsedVal) && !Array.isArray(parsedVal) &&
// eslint-disable-next-line no-prototype-builtins // 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 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({ return JSON.stringify({
rowId: extractPkFromRow(rowObj.row, meta.value?.columns as ColumnType[]), rowId: extractPkFromRow(rowObj.row, meta.value?.columns as ColumnType[]),
columnId: columnObj.id,
fk_related_model_id: (columnObj.colOptions as LinkToAnotherRecordType).fk_related_model_id, fk_related_model_id: (columnObj.colOptions as LinkToAnotherRecordType).fk_related_model_id,
value: !isNaN(+textToCopy) ? +textToCopy : 0, value: !isNaN(+textToCopy) ? +textToCopy : 0,
}) })
@ -923,16 +924,20 @@ export function useMultiSelect(
let result let result
console.log('column', columnObj.id)
try { try {
result = await api.dbDataTableRow.nestedLinkUnlink(meta.value?.id as string, columnObj.id as string, [ result = await api.dbDataTableRow.nestedLinkUnlink(meta.value?.id as string, columnObj.id as string, [
{ {
operation: 'copy', operation: 'copy',
rowId: pasteVal.rowId, rowId: pasteVal.rowId,
columnId: pasteVal.columnId,
fk_related_model_id: pasteVal.fk_related_model_id, fk_related_model_id: pasteVal.fk_related_model_id,
}, },
{ {
operation: 'paste', operation: 'paste',
rowId: pasteRowPk, rowId: pasteRowPk,
columnId: pasteVal.columnId,
fk_related_model_id: fk_related_model_id:
(columnObj.colOptions as LinkToAnotherRecordType).fk_related_model_id || pasteVal.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 && 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({ addUndo({
redo: { redo: {
fn: async ( fn: async (

1
packages/nocodb/src/controllers/data-table.controller.ts

@ -206,6 +206,7 @@ export class DataTableController {
data: { data: {
operation: 'copy' | 'paste'; operation: 'copy' | 'paste';
rowId: string; rowId: string;
columnId: string;
fk_related_model_id: string; fk_related_model_id: string;
}[], }[],
) { ) {

5
packages/nocodb/src/schema/swagger.json

@ -23249,11 +23249,14 @@
"rowId": { "rowId": {
"type": "string" "type": "string"
}, },
"columnId":{
"type": "string"
},
"fk_related_model_id":{ "fk_related_model_id":{
"type": "string" "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: { data: {
operation: 'copy' | 'paste'; operation: 'copy' | 'paste';
rowId: string; rowId: string;
columnId: string;
fk_related_model_id: string; fk_related_model_id: string;
}[]; }[];
}) { }) {
@ -480,6 +481,7 @@ export class DataTableService {
{ {
operation: 'copy' | 'paste'; operation: 'copy' | 'paste';
rowId: string; rowId: string;
columnId: string;
fk_related_model_id: string; fk_related_model_id: string;
} }
>, >,
@ -538,7 +540,7 @@ export class DataTableService {
const [copiedCellNestedList, pasteCellNestedList] = await Promise.all([ const [copiedCellNestedList, pasteCellNestedList] = await Promise.all([
baseModel.mmList( baseModel.mmList(
{ {
colId: column.id, colId: operationMap.copy.columnId,
parentId: operationMap.copy.rowId, parentId: operationMap.copy.rowId,
}, },
listArgs as any, listArgs as any,
@ -567,18 +569,20 @@ export class DataTableService {
); );
await Promise.all([ await Promise.all([
baseModel.addLinks({ filteredRowsToLink.length &&
colId: column.id, baseModel.addLinks({
childIds: filteredRowsToLink, colId: column.id,
rowId: operationMap.paste.rowId, childIds: filteredRowsToLink,
cookie: param.cookie, rowId: operationMap.paste.rowId,
}), cookie: param.cookie,
baseModel.removeLinks({ }),
colId: column.id, filteredRowsToUnlink.length &&
childIds: filteredRowsToUnlink, baseModel.removeLinks({
rowId: operationMap.paste.rowId, colId: column.id,
cookie: param.cookie, childIds: filteredRowsToUnlink,
}), rowId: operationMap.paste.rowId,
cookie: param.cookie,
}),
]); ]);
return { link: filteredRowsToLink, unlink: filteredRowsToUnlink }; return { link: filteredRowsToLink, unlink: filteredRowsToUnlink };

Loading…
Cancel
Save