Browse Source

fix(gui-v2): on cell update use response data to update row

Signed-off-by: Pranav C <pranavxc@gmail.com>
pull/3338/head
Pranav C 2 years ago
parent
commit
49d6fa2170
  1. 7
      packages/nc-gui-v2/composables/useExpandedFormStore.ts
  2. 40
      packages/nc-gui-v2/composables/useViewData.ts
  3. 1
      packages/nc-gui-v2/utils/index.ts
  4. 5
      packages/nc-gui-v2/utils/stringUtils.ts

7
packages/nc-gui-v2/composables/useExpandedFormStore.ts

@ -205,10 +205,3 @@ export function useExpandedFormStoreOrThrow() {
if (expandedFormStore == null) throw new Error('Please call `useExpandedFormStore` on the appropriate parent component')
return expandedFormStore
}
// todo: move to utils
function getPlainText(htmlString: string) {
const div = document.createElement('div')
div.textContent = htmlString || ''
return div.innerHTML
}

40
packages/nc-gui-v2/composables/useViewData.ts

@ -11,6 +11,7 @@ import {
useProject,
useUIPermission,
} from '#imports'
import { getHTMLEncodedText } from '~/utils'
const formatData = (list: Record<string, any>[]) =>
list.map((row) => ({
@ -166,43 +167,41 @@ export function useViewData(
}
}
const updateRowProperty = async (row: Record<string, any>, property: string) => {
const updateRowProperty = async (row: Row, property: string) => {
try {
const id = meta?.value?.columns
?.filter((c) => c.pk)
.map((c) => row[c.title as string])
.map((c) => row.row[c.title as string])
.join('___') as string
return await $api.dbViewRow.update(
const updatedRowData = await $api.dbViewRow.update(
NOCO,
project?.value.id as string,
meta?.value.id as string,
viewMeta?.value?.id as string,
id,
{
[property]: row[property],
[property]: row.row[property],
},
// todo:
// {
// query: { ignoreWebhook: !saved }
// }
)
// audit
$api.utils
.auditRowUpdate(id, {
fk_model_id: meta?.value.id as string,
column_name: property,
row_id: id,
value: getHTMLEncodedText(row.row[property]),
prev_value: getHTMLEncodedText(row.oldRow[property]),
})
.catch(() => {})
/*
todo: audit
// audit
this.$api.utils
.auditRowUpdate(id, {
fk_model_id: this.meta.id,
column_name: column.title,
row_id: id,
value: getPlainText(rowObj[column.title]),
prev_value: getPlainText(oldRow[column.title])
})
.then(() => {})
*/
/** update row data(to sync formula and other related columns) */
Object.assign(row.row, updatedRowData)
Object.assign(row.oldRow, updatedRowData)
} catch (e: any) {
message.error(`Row update failed ${await extractSdkResponseErrorMsg(e)}`)
}
@ -212,9 +211,8 @@ export function useViewData(
if (row.rowMeta.new) {
await insertRow(row.row, formattedData.value.indexOf(row))
} else {
await updateRowProperty(row.row, property)
await updateRowProperty(row, property)
}
reloadHook.trigger()
}
const changePage = async (page: number) => {
paginationData.value.page = page

1
packages/nc-gui-v2/utils/index.ts

@ -17,3 +17,4 @@ export * from './viewUtils'
export * from './currencyUtils'
export * from './dataUtils'
export * from './userUtils'
export * from './stringUtils'

5
packages/nc-gui-v2/utils/stringUtils.ts

@ -0,0 +1,5 @@
export function getHTMLEncodedText(htmlString: string) {
const div = document.createElement('div')
div.textContent = htmlString || ''
return div.innerHTML
}
Loading…
Cancel
Save