Browse Source

fix(gui): only overwrite Rollup and Formula cell on row update

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

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

@ -1,4 +1,4 @@
import { ViewTypes, isVirtualCol } from 'nocodb-sdk' import { ViewTypes, isVirtualCol, UITypes } 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 {
@ -180,12 +180,12 @@ export function useViewData(
if ((!project?.value?.id || !meta.value?.id || !viewMeta.value?.id) && !isPublic.value) return if ((!project?.value?.id || !meta.value?.id || !viewMeta.value?.id) && !isPublic.value) return
const response = !isPublic.value const response = !isPublic.value
? await api.dbViewRow.list('noco', project.value.id!, meta.value!.id!, viewMeta.value!.id!, { ? await api.dbViewRow.list('noco', project.value.id!, meta.value!.id!, viewMeta.value!.id!, {
...queryParams.value, ...queryParams.value,
...params, ...params,
...(isUIAllowed('sortSync') ? {} : { sortArrJson: JSON.stringify(sorts.value) }), ...(isUIAllowed('sortSync') ? {} : { sortArrJson: JSON.stringify(sorts.value) }),
...(isUIAllowed('filterSync') ? {} : { filterArrJson: JSON.stringify(nestedFilters.value) }), ...(isUIAllowed('filterSync') ? {} : { filterArrJson: JSON.stringify(nestedFilters.value) }),
where: where?.value, where: where?.value,
}) })
: await fetchSharedViewData({ sortsArr: sorts.value, filtersArr: nestedFilters.value }) : await fetchSharedViewData({ sortsArr: sorts.value, filtersArr: nestedFilters.value })
formattedData.value = formatData(response.list) formattedData.value = formatData(response.list)
paginationData.value = response.pageInfo paginationData.value = response.pageInfo
@ -203,7 +203,10 @@ export function useViewData(
async function insertRow( async function insertRow(
currentRow: Row, currentRow: Row,
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
@ -243,7 +246,10 @@ export function useViewData(
async function updateRowProperty( async function updateRowProperty(
toUpdate: Row, toUpdate: Row,
property: string, property: string,
{ metaValue = meta.value, viewMetaValue = viewMeta.value }: { metaValue?: TableType; viewMetaValue?: ViewType } = {}, {
metaValue = meta.value,
viewMetaValue = viewMeta.value,
}: { metaValue?: TableType; viewMetaValue?: ViewType } = {},
) { ) {
if (toUpdate.rowMeta) toUpdate.rowMeta.saving = true if (toUpdate.rowMeta) toUpdate.rowMeta.saving = true
try { try {
@ -278,7 +284,7 @@ export function useViewData(
Object.assign( Object.assign(
toUpdate.row, toUpdate.row,
metaValue!.columns!.reduce<Record<string, any>>((acc: Record<string, any>, col: ColumnType) => { metaValue!.columns!.reduce<Record<string, any>>((acc: Record<string, any>, col: ColumnType) => {
if (isVirtualCol(col)) acc[col.title!] = updatedRowData[col.title!] if (col.uidt === UITypes.Formula || col.uidt === UITypes.Rollup) acc[col.title!] = updatedRowData[col.title!]
return acc return acc
}, {} as Record<string, any>), }, {} as Record<string, any>),
) )
@ -317,7 +323,7 @@ export function useViewData(
async function deleteRowById(id: string) { async function deleteRowById(id: string) {
if (!id) { if (!id) {
throw new Error("Delete not allowed for table which doesn't have primary Key") throw new Error('Delete not allowed for table which doesn\'t have primary Key')
} }
const res: any = await $api.dbViewRow.delete( const res: any = await $api.dbViewRow.delete(

Loading…
Cancel
Save