Browse Source

Merge pull request #4295 from nocodb/fix/4291-tab-switching-update-error

Fix: Grid view - tab switching error
pull/4299/head
Raju Udava 2 years ago committed by GitHub
parent
commit
5c1c54be00
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 2
      packages/nc-gui/components/smartsheet/Grid.vue
  2. 13
      packages/nc-gui/composables/useViewData.ts

2
packages/nc-gui/components/smartsheet/Grid.vue

@ -384,7 +384,7 @@ const saveOrUpdateRecords = async (args: { metaValue?: TableType; viewMetaValue?
for (const field of (args.metaValue || meta.value)?.columns ?? []) {
if (isVirtualCol(field)) continue
if (currentRow.row[field.title!] !== currentRow.oldRow[field.title!]) {
await updateOrSaveRow(currentRow, field.title!, args)
await updateOrSaveRow(currentRow, field.title!, {}, args)
}
}
}

13
packages/nc-gui/composables/useViewData.ts

@ -240,14 +240,17 @@ export function useViewData(
}
}
// inside this method use metaValue and viewMetaValue to refer meta
// since sometimes we need to pass old metas
async function updateRowProperty(
toUpdate: Row,
property: string,
{ metaValue = meta.value, viewMetaValue = viewMeta.value }: { metaValue?: TableType; viewMetaValue?: ViewType } = {},
) {
if (toUpdate.rowMeta) toUpdate.rowMeta.saving = true
try {
const id = extractPkFromRow(toUpdate.row, meta.value?.columns as ColumnType[])
const id = extractPkFromRow(toUpdate.row, metaValue?.columns as ColumnType[])
const updatedRowData = await $api.dbViewRow.update(
NOCO,
@ -256,7 +259,8 @@ export function useViewData(
viewMetaValue?.id as string,
id,
{
[property]: toUpdate.row[property],
// if value is undefined treat it as null
[property]: toUpdate.row[property] ?? null,
},
// todo:
// {
@ -303,7 +307,10 @@ export function useViewData(
if (row.rowMeta.new) {
return await insertRow(row, ltarState, args)
} else {
await updateRowProperty(row, property!, args)
// if the field name is missing skip update
if (property) {
await updateRowProperty(row, property, args)
}
}
}

Loading…
Cancel
Save