Browse Source

fix(gui): tab switch row insert/update bug

- pass correct column list to get primary key
- handle undefined as null in update

Signed-off-by: Pranav C <pranavxc@gmail.com>
pull/4295/head
Pranav C 2 years ago
parent
commit
cfaa7b64e7
  1. 2
      packages/nc-gui/components/smartsheet/Grid.vue
  2. 11
      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)
}
}
}

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

@ -240,14 +240,20 @@ 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
// if the field name is missing return
if (!property) return
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 +262,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:
// {

Loading…
Cancel
Save