Browse Source

fix(gui): avoid overwriting cell value after update

Signed-off-by: Pranav C <pranavxc@gmail.com>
pull/4118/head
Pranav C 2 years ago
parent
commit
96db6145fc
  1. 18
      packages/nc-gui/composables/useViewData.ts

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

@ -1,4 +1,4 @@
import { ViewTypes } from 'nocodb-sdk' import { ViewTypes, isVirtualCol } from 'nocodb-sdk'
import type { Api, ColumnType, FormType, GalleryType, PaginatedType, TableType, ViewType } from 'nocodb-sdk' import type { Api, ColumnType, FormType, GalleryType, PaginatedType, TableType, ViewType } from 'nocodb-sdk'
import type { ComputedRef, Ref } from 'vue' import type { ComputedRef, Ref } from 'vue'
import { import {
@ -206,7 +206,7 @@ export function useViewData(
ltarState: Record<string, any> = {}, ltarState: Record<string, any> = {},
{ metaValue = meta.value, viewMetaValue = viewMeta.value }: { metaValue?: TableType; viewMetaValue?: ViewType } = {}, { metaValue = meta.value, viewMetaValue = viewMeta.value }: { metaValue?: TableType; viewMetaValue?: ViewType } = {},
) { ) {
const row = currentRow.row; const row = currentRow.row
if (currentRow.rowMeta) currentRow.rowMeta.saving = true if (currentRow.rowMeta) currentRow.rowMeta.saving = true
try { try {
const { missingRequiredColumns, insertObj } = await populateInsertObject({ const { missingRequiredColumns, insertObj } = await populateInsertObject({
@ -266,15 +266,23 @@ export function useViewData(
) )
// audit // audit
$api.utils.auditRowUpdate(id, { $api.utils.auditRowUpdate(id, {
fk_model_id: meta.value?.id as string, fk_model_id: metaValue?.id as string,
column_name: property, column_name: property,
row_id: id, row_id: id,
value: getHTMLEncodedText(toUpdate.row[property]), value: getHTMLEncodedText(toUpdate.row[property]),
prev_value: getHTMLEncodedText(toUpdate.oldRow[property]), prev_value: getHTMLEncodedText(toUpdate.oldRow[property]),
}) })
/** update row data(to sync formula and other related columns) */ /** update row data(to sync formula and other related columns)
Object.assign(toUpdate.row, updatedRowData) * update only virtual columns data to avoid overwriting any changes made by user
*/
Object.assign(
toUpdate.row,
metaValue!.columns!.reduce<Record<string, any>>((acc: Record<string, any>, col: ColumnType) => {
if (isVirtualCol(col)) acc[col.title!] = updatedRowData[col.title!]
return acc
}, {} as Record<string, any>),
)
Object.assign(toUpdate.oldRow, updatedRowData) Object.assign(toUpdate.oldRow, updatedRowData)
} catch (e: any) { } catch (e: any) {
message.error(`${t('msg.error.rowUpdateFailed')} ${await extractSdkResponseErrorMsg(e)}`) message.error(`${t('msg.error.rowUpdateFailed')} ${await extractSdkResponseErrorMsg(e)}`)

Loading…
Cancel
Save