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. 34
      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') if (expandedFormStore == null) throw new Error('Please call `useExpandedFormStore` on the appropriate parent component')
return expandedFormStore return expandedFormStore
} }
// todo: move to utils
function getPlainText(htmlString: string) {
const div = document.createElement('div')
div.textContent = htmlString || ''
return div.innerHTML
}

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

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

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

@ -17,3 +17,4 @@ export * from './viewUtils'
export * from './currencyUtils' export * from './currencyUtils'
export * from './dataUtils' export * from './dataUtils'
export * from './userUtils' 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