Browse Source

fix(nc-gui): prevent paste bt cell value to different fk_related_model_id cell

pull/7558/head
Ramesh Mane 9 months ago
parent
commit
aed6b95bc1
  1. 17
      packages/nc-gui/composables/useMultiSelect/convertCellData.ts
  2. 14
      packages/nc-gui/composables/useMultiSelect/index.ts

17
packages/nc-gui/composables/useMultiSelect/convertCellData.ts

@ -251,12 +251,20 @@ export default function convertCellData(
return undefined
}
const parsedVal = typeof value === 'string' ? JSON.parse(value) : value
if (!(parsedVal && typeof parsedVal === 'object' && !Array.isArray(parsedVal) && Object.keys(parsedVal))) {
if ((column.colOptions as LinkToAnotherRecordType)?.type === RelationTypes.MANY_TO_MANY) {
const parsedVal = typeof value === 'string' ? JSON.parse(value) : value
if (
!(parsedVal && typeof parsedVal === 'object' && !Array.isArray(parsedVal) && Object.keys(parsedVal)) ||
parsedVal?.fk_related_model_id !== (column.colOptions as LinkToAnotherRecordType)?.fk_related_model_id
) {
throw new Error(`Unsupported conversion for ${to}`)
}
return parsedVal
} else {
throw new Error(`Unsupported conversion for ${to}`)
}
return parsedVal
}
case UITypes.Links: {
if (isMultiple) {
@ -265,6 +273,7 @@ export default function convertCellData(
if ((column.colOptions as LinkToAnotherRecordType)?.type === RelationTypes.MANY_TO_MANY) {
const parsedVal = typeof value === 'string' ? JSON.parse(value) : value
if (
!(
parsedVal &&

14
packages/nc-gui/composables/useMultiSelect/index.ts

@ -137,6 +137,15 @@ export function useMultiSelect(
}
}
if (
typeof textToCopy === 'object' &&
columnObj.uidt === UITypes.LinkToAnotherRecord &&
(columnObj.colOptions as LinkToAnotherRecordType).type === RelationTypes.BELONGS_TO
) {
// fk_related_model_id is used to prevent paste operation in different fk_related_model_id cell
textToCopy = { ...textToCopy, fk_related_model_id: (columnObj.colOptions as LinkToAnotherRecordType).fk_related_model_id }
}
if (typeof textToCopy === 'object') {
textToCopy = JSON.stringify(textToCopy)
} else {
@ -871,10 +880,9 @@ export function useMultiSelect(
columnObj.uidt === UITypes.LinkToAnotherRecord &&
(columnObj.colOptions as LinkToAnotherRecordType)?.type === RelationTypes.BELONGS_TO
) {
const clipboardContext = JSON.parse(clipboardData!)
const pasteVal = convertCellData(
{
value: clipboardContext,
value: clipboardData,
to: columnObj.uidt as UITypes,
column: columnObj,
appInfo: unref(appInfo),
@ -894,7 +902,7 @@ export function useMultiSelect(
if (!foreignKeyColumn) return
rowObj.row[foreignKeyColumn.title!] = extractPkFromRow(clipboardContext, (relatedTableMeta as any)!.columns!)
rowObj.row[foreignKeyColumn.title!] = extractPkFromRow(pasteVal, (relatedTableMeta as any)!.columns!)
return await syncCellData?.({ ...activeCell, updatedColumnTitle: foreignKeyColumn.title })
}

Loading…
Cancel
Save