Skip to content

πŸ”₯ πŸ”₯ πŸ”₯ A Free & Self-hostable Airtable Alternative

fix(nc-gui): on trigger ai button data is directly getting saved in db #5042

Ramesh Mane8d18ffe81380
diff --git a/packages/nc-gui/components/virtual-cell/Button.vue b/packages/nc-gui/components/virtual-cell/Button.vue
index a0bc236a93..c0552fde0c 100644
--- a/packages/nc-gui/components/virtual-cell/Button.vue
+++ b/packages/nc-gui/components/virtual-cell/Button.vue
@@ -10,7 +10,7 @@ const column = inject(ColumnInj) as Ref<
const cellValue = inject(CellValueInj, ref())
-const { currentRow, displayValue } = useSmartsheetRowStoreOrThrow()
+const { currentRow, displayValue, changedColumns } = useSmartsheetRowStoreOrThrow()
const { generateRows, generatingRows, generatingColumnRows, generatingColumns, aiIntegrations } = useNocoAi()
@@ -75,7 +75,8 @@ const generate = async () => {
generatingColumns.value.push(...(outputColumnIds ?? []))
- const res = await generateRows(meta.value.id, column.value.id, [pk.value])
+ // In expanded form get preview data and update local state so that expanded form save btn works properly
+ const res = await generateRows(meta.value.id, column.value.id, [pk.value], false, isExpandedForm.value)
if (res?.length) {
const resRow = res[0]
@@ -83,6 +84,8 @@ const generate = async () => {
if (outputColumnIds) {
for (const col of outputColumns) {
if (col && currentRow.value.row) {
+ changedColumns.value.add(col.title!)
+
currentRow.value.row[col.title!] = resRow[col.title!]
}
}
diff --git a/packages/nc-gui/composables/useExpandedFormStore.ts b/packages/nc-gui/composables/useExpandedFormStore.ts
index 9f6df8c583..860de6dda9 100644
--- a/packages/nc-gui/composables/useExpandedFormStore.ts
+++ b/packages/nc-gui/composables/useExpandedFormStore.ts
@@ -45,7 +45,7 @@ const [useProvideExpandedFormStore, useExpandedFormStore] = useInjectionState(
const saveRowAndStay = ref(0)
- const changedColumns = ref(new Set<string>())
+ const changedColumns = ref<Set<string>>(new Set<string>())
const localOnlyChanges = ref<Record<string, any>>({})
@@ -71,7 +71,7 @@ const [useProvideExpandedFormStore, useExpandedFormStore] = useInjectionState(
if (row.value?.rowMeta?.fromExpandedForm) {
row.value.rowMeta.fromExpandedForm = true
}
- const rowStore = useProvideSmartsheetRowStore(row)
+ const rowStore = useProvideSmartsheetRowStore(row, changedColumns)
const activeView = inject(ActiveViewInj, ref())
diff --git a/packages/nc-gui/composables/useSmartsheetRowStore.ts b/packages/nc-gui/composables/useSmartsheetRowStore.ts
index fb14e902e3..82e53d39d6 100644
--- a/packages/nc-gui/composables/useSmartsheetRowStore.ts
+++ b/packages/nc-gui/composables/useSmartsheetRowStore.ts
@@ -1,54 +1,58 @@
import type { MaybeRef } from '@vueuse/core'
-const [useProvideSmartsheetRowStore, useSmartsheetRowStore] = useInjectionState((row: MaybeRef<Row>) => {
- const currentRow = ref(row)
-
- // state
- const state = computed({
- get: () => currentRow.value?.rowMeta?.ltarState ?? {},
- set: (value) => {
- if (currentRow.value) {
- if (!currentRow.value.rowMeta) {
- currentRow.value.rowMeta = {}
+const [useProvideSmartsheetRowStore, useSmartsheetRowStore] = useInjectionState(
+ (row: MaybeRef<Row>, changedColumns: Ref<Set<string>> = ref(new Set<string>())) => {
+ const currentRow = ref(row)
+
+ // state
+ const state = computed({
+ get: () => currentRow.value?.rowMeta?.ltarState ?? {},
+ set: (value) => {
+ if (currentRow.value) {
+ if (!currentRow.value.rowMeta) {
+ currentRow.value.rowMeta = {}
+ }
+ currentRow.value.rowMeta.ltarState = value
}
- currentRow.value.rowMeta.ltarState = value
- }
- },
- })
-
- const meta = inject(MetaInj, ref())
-
- const pk = computed(() => extractPkFromRow(currentRow.value.row, meta.value?.columns ?? []))
-
- // getters
- const isNew = computed(() => unref(row).rowMeta?.new ?? false)
-
- const displayValue = computed(() => {
- const row = unref(currentRow)
-
- const column = meta.value?.columns.find((col) => col.pv) || meta.value?.columns.find((col) => col.pk)
-
- return row.row[column?.title]
- })
-
- const { addLTARRef, removeLTARRef, syncLTARRefs, loadRow, clearLTARCell, cleaMMCell } = useSmartsheetLtarHelpersOrThrow()
-
- return {
- pk,
- row,
- state,
- isNew,
- displayValue,
- // todo: use better name
- addLTARRef: (...args: any) => addLTARRef(currentRow.value, ...args),
- removeLTARRef: (...args: any) => removeLTARRef(currentRow.value, ...args),
- syncLTARRefs: (...args: any) => syncLTARRefs(currentRow.value, ...args),
- loadRow: (...args: any) => loadRow(currentRow.value, ...args),
- currentRow,
- clearLTARCell: (...args: any) => clearLTARCell(currentRow.value, ...args),
- cleaMMCell: (...args: any) => cleaMMCell(currentRow.value, ...args),
- }
-}, 'smartsheet-row-store')
+ },
+ })
+
+ const meta = inject(MetaInj, ref())
+
+ const pk = computed(() => extractPkFromRow(currentRow.value.row, meta.value?.columns ?? []))
+
+ // getters
+ const isNew = computed(() => unref(row).rowMeta?.new ?? false)
+
+ const displayValue = computed(() => {
+ const row = unref(currentRow)
+
+ const column = meta.value?.columns.find((col) => col.pv) || meta.value?.columns.find((col) => col.pk)
+
+ return row.row[column?.title]
+ })
+
+ const { addLTARRef, removeLTARRef, syncLTARRefs, loadRow, clearLTARCell, cleaMMCell } = useSmartsheetLtarHelpersOrThrow()
+
+ return {
+ pk,
+ row,
+ changedColumns,
+ state,
+ isNew,
+ displayValue,
+ // todo: use better name
+ addLTARRef: (...args: any) => addLTARRef(currentRow.value, ...args),
+ removeLTARRef: (...args: any) => removeLTARRef(currentRow.value, ...args),
+ syncLTARRefs: (...args: any) => syncLTARRefs(currentRow.value, ...args),
+ loadRow: (...args: any) => loadRow(currentRow.value, ...args),
+ currentRow,
+ clearLTARCell: (...args: any) => clearLTARCell(currentRow.value, ...args),
+ cleaMMCell: (...args: any) => cleaMMCell(currentRow.value, ...args),
+ }
+ },
+ 'smartsheet-row-store',
+)
export { useProvideSmartsheetRowStore }