diff --git a/packages/nc-gui/components/smartsheet/Form.vue b/packages/nc-gui/components/smartsheet/Form.vue index 683e4550d0..9b941404cb 100644 --- a/packages/nc-gui/components/smartsheet/Form.vue +++ b/packages/nc-gui/components/smartsheet/Form.vue @@ -117,7 +117,7 @@ async function submitForm() { if (e.errorFields.length) return } - const insertedRowData = await insertRow(formState) + const insertedRowData = await insertRow({ row: formState, oldRow: {}, rowMeta: { new: true } }) if (insertedRowData) { await syncLTARRefs(insertedRowData) diff --git a/packages/nc-gui/components/smartsheet/Grid.vue b/packages/nc-gui/components/smartsheet/Grid.vue index 0f63ea2919..b0a882ade4 100644 --- a/packages/nc-gui/components/smartsheet/Grid.vue +++ b/packages/nc-gui/components/smartsheet/Grid.vue @@ -479,24 +479,27 @@ watch(
- - {{ row.rowMeta.commentCount }} - -
- +
diff --git a/packages/nc-gui/composables/useViewData.ts b/packages/nc-gui/composables/useViewData.ts index 0b21448f7c..a190818557 100644 --- a/packages/nc-gui/composables/useViewData.ts +++ b/packages/nc-gui/composables/useViewData.ts @@ -11,6 +11,7 @@ import { message, populateInsertObject, ref, + until, useApi, useGlobal, useI18n, @@ -200,11 +201,13 @@ export function useViewData( } async function insertRow( - row: Record, + currentRow: Row, rowIndex = formattedData.value?.length, ltarState: Record = {}, { metaValue = meta.value, viewMetaValue = viewMeta.value }: { metaValue?: TableType; viewMetaValue?: ViewType } = {}, ) { + const row = currentRow.row; + if (currentRow.rowMeta) currentRow.rowMeta.saving = true try { const { missingRequiredColumns, insertObj } = await populateInsertObject({ meta: metaValue!, @@ -223,9 +226,9 @@ export function useViewData( insertObj, ) - formattedData.value?.splice(rowIndex ?? 0, 1, { - row: insertedData, - rowMeta: {}, + Object.assign(currentRow, { + row: { ...insertedData, ...row }, + rowMeta: { ...(currentRow.rowMeta || {}), new: undefined }, oldRow: { ...insertedData }, }) @@ -233,6 +236,8 @@ export function useViewData( return insertedData } catch (error: any) { message.error(await extractSdkResponseErrorMsg(error)) + } finally { + if (currentRow.rowMeta) currentRow.rowMeta.saving = false } } @@ -241,6 +246,7 @@ export function useViewData( 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[]) @@ -272,6 +278,8 @@ export function useViewData( Object.assign(toUpdate.oldRow, updatedRowData) } catch (e: any) { message.error(`${t('msg.error.rowUpdateFailed')} ${await extractSdkResponseErrorMsg(e)}`) + } finally { + if (toUpdate.rowMeta) toUpdate.rowMeta.saving = false } } @@ -281,8 +289,11 @@ export function useViewData( ltarState?: Record, args: { metaValue?: TableType; viewMetaValue?: ViewType } = {}, ) { + // if new row and save is in progress then wait until the save is complete + await until(() => !(row.rowMeta?.new && row.rowMeta?.saving)).toMatch((v) => v) + 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 { await updateRowProperty(row, property!, args) } diff --git a/packages/nc-gui/lib/types.ts b/packages/nc-gui/lib/types.ts index 80345a0766..127e811491 100644 --- a/packages/nc-gui/lib/types.ts +++ b/packages/nc-gui/lib/types.ts @@ -57,6 +57,7 @@ export interface Row { selected?: boolean commentCount?: number changed?: boolean + saving?: boolean } } diff --git a/packages/nc-gui/pages/[projectType]/[projectId]/index/index/[type]/[title]/[[viewTitle]].vue b/packages/nc-gui/pages/[projectType]/[projectId]/index/index/[type]/[title]/[[viewTitle]].vue index a05c1740f4..71ddda5dcb 100644 --- a/packages/nc-gui/pages/[projectType]/[projectId]/index/index/[type]/[title]/[[viewTitle]].vue +++ b/packages/nc-gui/pages/[projectType]/[projectId]/index/index/[type]/[title]/[[viewTitle]].vue @@ -22,6 +22,7 @@ watch( until(tables) .toMatch((tables) => tables.length > 0) .then(() => { + loading.value = true getMeta(tableTitle as string, true).finally(() => (loading.value = false)) }) }, @@ -30,7 +31,13 @@ watch(