Browse Source

fix(gui): pass Row ref to insert method

Signed-off-by: Pranav C <pranavxc@gmail.com>
pull/4088/head
Pranav C 2 years ago
parent
commit
f9cab933b8
  1. 2
      packages/nc-gui/components/smartsheet/Form.vue
  2. 37
      packages/nc-gui/composables/useViewData.ts

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

@ -117,7 +117,7 @@ async function submitForm() {
if (e.errorFields.length) return if (e.errorFields.length) return
} }
const insertedRowData = await insertRow(formState) const insertedRowData = await insertRow({ row: formState, oldRow: {}, rowMeta: { new: true } })
if (insertedRowData) { if (insertedRowData) {
await syncLTARRefs(insertedRowData) await syncLTARRefs(insertedRowData)

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

@ -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
@ -201,15 +201,13 @@ export function useViewData(
} }
async function insertRow( async function insertRow(
row: Record<string, any>, currentRow: Row,
rowIndex = formattedData.value?.length, rowIndex = formattedData.value?.length,
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 } = {},
) { ) {
if (formattedData.value[rowIndex].rowMeta) formattedData.value[rowIndex].rowMeta.saving = true const row = currentRow
if (currentRow.rowMeta) currentRow.rowMeta.saving = true
try { try {
const { missingRequiredColumns, insertObj } = await populateInsertObject({ const { missingRequiredColumns, insertObj } = await populateInsertObject({
meta: metaValue!, meta: metaValue!,
@ -228,9 +226,9 @@ export function useViewData(
insertObj, insertObj,
) )
Object.assign(formattedData.value[rowIndex], { Object.assign(currentRow, {
row: { ...insertedData, ...row }, row: { ...insertedData, ...row },
rowMeta: { ...(row.rowMeta || {}), new: undefined }, rowMeta: { ...(currentRow.rowMeta || {}), new: undefined },
oldRow: { ...insertedData }, oldRow: { ...insertedData },
}) })
@ -239,17 +237,14 @@ export function useViewData(
} catch (error: any) { } catch (error: any) {
message.error(await extractSdkResponseErrorMsg(error)) message.error(await extractSdkResponseErrorMsg(error))
} finally { } finally {
if (formattedData.value[rowIndex].rowMeta) formattedData.value[rowIndex].rowMeta.saving = false if (currentRow.rowMeta) currentRow.rowMeta.saving = false
} }
} }
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 {
@ -298,7 +293,7 @@ export function useViewData(
await until(() => !(row.rowMeta?.new && row.rowMeta?.saving)).toMatch((v) => v) await until(() => !(row.rowMeta?.new && row.rowMeta?.saving)).toMatch((v) => v)
if (row.rowMeta.new) { if (row.rowMeta.new) {
return await insertRow(row.row, formattedData.value.indexOf(row), ltarState, args) return await insertRow(row, formattedData.value.indexOf(row), ltarState, args)
} else { } else {
await updateRowProperty(row, property!, args) await updateRowProperty(row, property!, args)
} }
@ -315,7 +310,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