Browse Source

feat: use nested insert for row insert

Signed-off-by: Pranav C <pranavxc@gmail.com>
pull/6817/head
Pranav C 11 months ago
parent
commit
faaaff3a90
  1. 12
      packages/nc-gui/components/smartsheet/Row.vue
  2. 6
      packages/nc-gui/components/smartsheet/expanded-form/index.vue
  3. 2
      packages/nc-gui/components/smartsheet/grid/Table.vue
  4. 2
      packages/nc-gui/composables/useData.ts
  5. 2
      packages/nc-gui/composables/useExpandedFormStore.ts
  6. 21
      packages/nocodb/src/db/BaseModelSqlv2.ts

12
packages/nc-gui/components/smartsheet/Row.vue

@ -26,12 +26,12 @@ const { isNew, state, syncLTARRefs, clearLTARCell, addLTARRef } = useProvideSmar
// on changing isNew(new record insert) status sync LTAR cell values
watch(isNew, async (nextVal, prevVal) => {
if (prevVal && !nextVal) {
await syncLTARRefs(currentRow.value.row)
// update row values without invoking api
currentRow.value.row = { ...currentRow.value.row, ...state.value }
currentRow.value.oldRow = { ...currentRow.value.row, ...state.value }
}
// if (prevVal && !nextVal) {
// await syncLTARRefs(currentRow.value.row)
// // update row values without invoking api
// currentRow.value.row = { ...currentRow.value.row, ...state.value }
// currentRow.value.oldRow = { ...currentRow.value.row, ...state.value }
// }
})
const reloadViewDataTrigger = inject(ReloadViewDataHookInj)!

6
packages/nc-gui/components/smartsheet/expanded-form/index.vue

@ -185,7 +185,7 @@ const onDuplicateRow = () => {
const save = async () => {
if (isNew.value) {
const data = await _save(rowState.value)
await syncLTARRefs(data)
// await syncLTARRefs(data)
reloadTrigger?.trigger()
} else {
let kanbanClbk
@ -341,7 +341,7 @@ useActiveKeyupListener(
if (isNew.value) {
const data = await _save(rowState.value)
await syncLTARRefs(data)
// await syncLTARRefs(data)
reloadHook?.trigger(null)
} else {
await save()
@ -376,7 +376,7 @@ useActiveKeyupListener(
cancelText: t('labels.discard'),
onOk: async () => {
const data = await _save(rowState.value)
await syncLTARRefs(data)
// await syncLTARRefs(data)
reloadHook?.trigger(null)
addNewRow()
},

2
packages/nc-gui/components/smartsheet/grid/Table.vue

@ -1454,6 +1454,8 @@ const loaderText = computed(() => {
:style="{ height: rowHeight ? `${rowHeight * 1.8}rem` : `1.8rem` }"
:data-testid="`grid-row-${rowIndex}`"
>
<td>{{
row.row}}</td>
<td
key="row-index"
class="caption nc-grid-cell pl-5 pr-1"

2
packages/nc-gui/composables/useData.ts

@ -91,7 +91,7 @@ export function useData(args: {
base?.value.id as string,
metaValue?.id as string,
viewMetaValue?.id as string,
insertObj,
{ ...insertObj, ...(ltarState ||{}) },
)
if (!undo) {

2
packages/nc-gui/composables/useExpandedFormStore.ts

@ -180,7 +180,7 @@ const [useProvideExpandedFormStore, useExpandedFormStore] = useInjectionState((m
if (missingRequiredColumns.size) return
data = await $api.dbTableRow.create('noco', base.value.id as string, meta.value.id, insertObj)
data = await $api.dbTableRow.create('noco', base.value.id as string, meta.value.id, { ...insertObj, ...(ltarState ||{}) })
Object.assign(row.value, {
row: data,

21
packages/nocodb/src/db/BaseModelSqlv2.ts

@ -2590,23 +2590,22 @@ class BaseModelSqlv2 {
!response ||
(typeof response?.[0] !== 'object' && response?.[0] !== null)
) {
let id;
if (response?.length) {
id = response[0];
rowId = response[0];
} else {
id = (await query)[0];
rowId = (await query)[0];
}
if (ai) {
if (this.isSqlite) {
// sqlite doesnt return id after insert
id = (
rowId = (
await this.dbDriver(this.tnPath)
.select(ai.column_name)
.max(ai.column_name, { as: 'id' })
)[0].id;
} else if (this.isSnowflake) {
id = (
rowId = (
(await this.dbDriver(this.tnPath).max(ai.column_name, {
as: 'id',
})) as any
@ -2622,19 +2621,19 @@ class BaseModelSqlv2 {
response = data;
}
} else if (ai) {
id = Array.isArray(response)
? response?.[0]?.[ai.title]
: response?.[ai.title];
rowId = Array.isArray(response)
? response?.[0]?.[ai.title]
: response?.[ai.title];
}
rowId = id;
await Promise.all(postInsertOps.map((f) => f()));
const response = this.readByPk(rowId,
response = this.readByPk(
rowId,
false,
{},
{ ignoreView: true, getHiddenColumn: true },
);
);
await this.afterInsert(response, this.dbDriver, cookie);

Loading…
Cancel
Save