|
|
|
@ -11,6 +11,7 @@ import {
|
|
|
|
|
message, |
|
|
|
|
populateInsertObject, |
|
|
|
|
ref, |
|
|
|
|
until, |
|
|
|
|
useApi, |
|
|
|
|
useGlobal, |
|
|
|
|
useI18n, |
|
|
|
@ -200,11 +201,13 @@ export function useViewData(
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
async function insertRow( |
|
|
|
|
row: Record<string, any>, |
|
|
|
|
currentRow: Row, |
|
|
|
|
rowIndex = formattedData.value?.length, |
|
|
|
|
ltarState: Record<string, any> = {}, |
|
|
|
|
{ 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<string, any>, |
|
|
|
|
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) |
|
|
|
|
} |
|
|
|
|