From 49d6fa217013cb420fffa7bc10787a042d09d1a5 Mon Sep 17 00:00:00 2001 From: Pranav C Date: Thu, 25 Aug 2022 11:48:35 +0530 Subject: [PATCH] fix(gui-v2): on cell update use response data to update row Signed-off-by: Pranav C --- .../composables/useExpandedFormStore.ts | 7 ---- packages/nc-gui-v2/composables/useViewData.ts | 40 +++++++++---------- packages/nc-gui-v2/utils/index.ts | 1 + packages/nc-gui-v2/utils/stringUtils.ts | 5 +++ 4 files changed, 25 insertions(+), 28 deletions(-) create mode 100644 packages/nc-gui-v2/utils/stringUtils.ts diff --git a/packages/nc-gui-v2/composables/useExpandedFormStore.ts b/packages/nc-gui-v2/composables/useExpandedFormStore.ts index eefa9c87ef..19d186593b 100644 --- a/packages/nc-gui-v2/composables/useExpandedFormStore.ts +++ b/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 -} diff --git a/packages/nc-gui-v2/composables/useViewData.ts b/packages/nc-gui-v2/composables/useViewData.ts index cc60dccb67..7b63412727 100644 --- a/packages/nc-gui-v2/composables/useViewData.ts +++ b/packages/nc-gui-v2/composables/useViewData.ts @@ -11,6 +11,7 @@ import { useProject, useUIPermission, } from '#imports' +import { getHTMLEncodedText } from '~/utils' const formatData = (list: Record[]) => list.map((row) => ({ @@ -166,43 +167,41 @@ export function useViewData( } } - const updateRowProperty = async (row: Record, 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 diff --git a/packages/nc-gui-v2/utils/index.ts b/packages/nc-gui-v2/utils/index.ts index 2b2e7fa724..642feed20c 100644 --- a/packages/nc-gui-v2/utils/index.ts +++ b/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' diff --git a/packages/nc-gui-v2/utils/stringUtils.ts b/packages/nc-gui-v2/utils/stringUtils.ts new file mode 100644 index 0000000000..ca75abf996 --- /dev/null +++ b/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 +}