From 5daac02ced5e994321adc35eb2cdc2536874e0b1 Mon Sep 17 00:00:00 2001 From: Pranav C Date: Fri, 7 Oct 2022 20:07:16 +0530 Subject: [PATCH 1/5] fix(api): avoid unnecessary filter reload Signed-off-by: Pranav C --- .../smartsheet/toolbar/ColumnFilterMenu.vue | 11 +++++++---- .../components/smartsheet/toolbar/FieldsMenu.vue | 2 +- .../components/smartsheet/toolbar/SortListMenu.vue | 4 ++-- packages/nc-gui/composables/useViewColumns.ts | 2 +- packages/nc-gui/composables/useViewFilters.ts | 2 +- 5 files changed, 12 insertions(+), 9 deletions(-) diff --git a/packages/nc-gui/components/smartsheet/toolbar/ColumnFilterMenu.vue b/packages/nc-gui/components/smartsheet/toolbar/ColumnFilterMenu.vue index 47b2356963..b23fa2bd13 100644 --- a/packages/nc-gui/components/smartsheet/toolbar/ColumnFilterMenu.vue +++ b/packages/nc-gui/components/smartsheet/toolbar/ColumnFilterMenu.vue @@ -42,9 +42,11 @@ const filtersLength = ref(0) watch( () => activeView?.value, - async () => { - await loadFilters() - filtersLength.value = filters.value.length || 0 + async (view) => { + if (view?.id) { + await loadFilters() + filtersLength.value = filters.value.length || 0 + } }, { immediate: true }, ) @@ -83,7 +85,8 @@ const filterAutoSaveLoc = computed({ @update:filters-length="filtersLength = $event" >
- + {{ $t('msg.info.filterAutoApply') }} diff --git a/packages/nc-gui/components/smartsheet/toolbar/FieldsMenu.vue b/packages/nc-gui/components/smartsheet/toolbar/FieldsMenu.vue index f03944b4d1..581df98a31 100644 --- a/packages/nc-gui/components/smartsheet/toolbar/FieldsMenu.vue +++ b/packages/nc-gui/components/smartsheet/toolbar/FieldsMenu.vue @@ -51,7 +51,7 @@ const { watch( () => activeView.value?.id, async (newVal, oldVal) => { - if (newVal !== oldVal && meta.value) { + if (newVal && newVal !== oldVal && meta.value) { await loadViewColumns() } }, diff --git a/packages/nc-gui/components/smartsheet/toolbar/SortListMenu.vue b/packages/nc-gui/components/smartsheet/toolbar/SortListMenu.vue index 1a35292606..3112d08d20 100644 --- a/packages/nc-gui/components/smartsheet/toolbar/SortListMenu.vue +++ b/packages/nc-gui/components/smartsheet/toolbar/SortListMenu.vue @@ -32,8 +32,8 @@ const columnByID = computed(() => watch( () => view.value?.id, - () => { - loadSorts() + (viewId) => { + if(viewId)loadSorts() }, { immediate: true }, ) diff --git a/packages/nc-gui/composables/useViewColumns.ts b/packages/nc-gui/composables/useViewColumns.ts index 27e9e1641d..e97312d0bc 100644 --- a/packages/nc-gui/composables/useViewColumns.ts +++ b/packages/nc-gui/composables/useViewColumns.ts @@ -207,7 +207,7 @@ export function useViewColumns( // reload view columns when table meta changes watch(meta, async (newVal, oldVal) => { - if (newVal !== oldVal && meta.value) { + if (newVal !== oldVal && newVal) { await loadViewColumns() } }) diff --git a/packages/nc-gui/composables/useViewFilters.ts b/packages/nc-gui/composables/useViewFilters.ts index 06098fdecb..8df90d85e8 100644 --- a/packages/nc-gui/composables/useViewFilters.ts +++ b/packages/nc-gui/composables/useViewFilters.ts @@ -218,7 +218,7 @@ export function useViewFilters( return metas?.value?.[view?.value?.fk_model_id as string]?.columns?.length || 0 }, async (nextColsLength, oldColsLength) => { - if (nextColsLength < oldColsLength) await loadFilters() + if (nextColsLength && nextColsLength < oldColsLength) await loadFilters() }, ) From 833781c998cce062aafab02fb1bda5df1bed69d5 Mon Sep 17 00:00:00 2001 From: Pranav C Date: Sat, 8 Oct 2022 11:08:08 +0530 Subject: [PATCH 2/5] fix(gui): avoid duplicate watch and only trigger when active view id changes Signed-off-by: Pranav C --- .../components/smartsheet/toolbar/ColumnFilterMenu.vue | 6 +++--- .../components/smartsheet/toolbar/FieldsMenu.vue | 10 ---------- packages/nc-gui/composables/useViewColumns.ts | 6 +++--- 3 files changed, 6 insertions(+), 16 deletions(-) diff --git a/packages/nc-gui/components/smartsheet/toolbar/ColumnFilterMenu.vue b/packages/nc-gui/components/smartsheet/toolbar/ColumnFilterMenu.vue index b23fa2bd13..af4f87aa31 100644 --- a/packages/nc-gui/components/smartsheet/toolbar/ColumnFilterMenu.vue +++ b/packages/nc-gui/components/smartsheet/toolbar/ColumnFilterMenu.vue @@ -41,9 +41,9 @@ const { filters, loadFilters } = useViewFilters( const filtersLength = ref(0) watch( - () => activeView?.value, - async (view) => { - if (view?.id) { + () => activeView?.value?.id, + async (viewId) => { + if (viewId) { await loadFilters() filtersLength.value = filters.value.length || 0 } diff --git a/packages/nc-gui/components/smartsheet/toolbar/FieldsMenu.vue b/packages/nc-gui/components/smartsheet/toolbar/FieldsMenu.vue index 581df98a31..f6b74584bf 100644 --- a/packages/nc-gui/components/smartsheet/toolbar/FieldsMenu.vue +++ b/packages/nc-gui/components/smartsheet/toolbar/FieldsMenu.vue @@ -48,16 +48,6 @@ const { metaColumnById, } = useViewColumns(activeView, meta, () => reloadDataHook.trigger()) -watch( - () => activeView.value?.id, - async (newVal, oldVal) => { - if (newVal && newVal !== oldVal && meta.value) { - await loadViewColumns() - } - }, - { immediate: true }, -) - watch( sortedAndFilteredFields, (v) => { diff --git a/packages/nc-gui/composables/useViewColumns.ts b/packages/nc-gui/composables/useViewColumns.ts index e97312d0bc..c754325bc4 100644 --- a/packages/nc-gui/composables/useViewColumns.ts +++ b/packages/nc-gui/composables/useViewColumns.ts @@ -206,11 +206,11 @@ export function useViewColumns( }) // reload view columns when table meta changes - watch(meta, async (newVal, oldVal) => { - if (newVal !== oldVal && newVal) { + watch(() => view?.value?.id, async (newVal) => { + if (newVal) { await loadViewColumns() } - }) + }, { immediate: true }) return { fields, From bee72fc5bea1baae9c89e34d8562aa706ed54607 Mon Sep 17 00:00:00 2001 From: Pranav C Date: Sat, 8 Oct 2022 11:09:49 +0530 Subject: [PATCH 3/5] fix(gui): reload column width data when column create/delete or when view changes Signed-off-by: Pranav C --- packages/nc-gui/composables/useGridViewColumnWidth.ts | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/packages/nc-gui/composables/useGridViewColumnWidth.ts b/packages/nc-gui/composables/useGridViewColumnWidth.ts index b73f58bf12..adca292855 100644 --- a/packages/nc-gui/composables/useGridViewColumnWidth.ts +++ b/packages/nc-gui/composables/useGridViewColumnWidth.ts @@ -50,8 +50,9 @@ export function useGridViewColumnWidth(view: Ref) { loadCss() } - /** when columns changes(create/delete) reload grid columns */ - watch(columns, loadGridViewColumns) + /** when columns changes(create/delete) reload grid columns + * or when view changes reload columns width */ + watch([() => columns.value?.length, () => view?.value?.id ], loadGridViewColumns) const updateWidth = async (id: string, width: string) => { if (gridViewCols?.value?.[id]) { From 81d191406d2f8acfca3402fba9a3ea094e9fd1a1 Mon Sep 17 00:00:00 2001 From: Pranav C Date: Sat, 8 Oct 2022 11:13:25 +0530 Subject: [PATCH 4/5] chore(gui): lint Signed-off-by: Pranav C --- .../smartsheet/toolbar/ColumnFilterMenu.vue | 3 +-- .../components/smartsheet/toolbar/FieldsMenu.vue | 1 - .../components/smartsheet/toolbar/SortListMenu.vue | 2 +- .../nc-gui/composables/useGridViewColumnWidth.ts | 2 +- packages/nc-gui/composables/useViewColumns.ts | 14 +++++++++----- 5 files changed, 12 insertions(+), 10 deletions(-) diff --git a/packages/nc-gui/components/smartsheet/toolbar/ColumnFilterMenu.vue b/packages/nc-gui/components/smartsheet/toolbar/ColumnFilterMenu.vue index af4f87aa31..37bca9be79 100644 --- a/packages/nc-gui/components/smartsheet/toolbar/ColumnFilterMenu.vue +++ b/packages/nc-gui/components/smartsheet/toolbar/ColumnFilterMenu.vue @@ -85,8 +85,7 @@ const filterAutoSaveLoc = computed({ @update:filters-length="filtersLength = $event" >
- + {{ $t('msg.info.filterAutoApply') }} diff --git a/packages/nc-gui/components/smartsheet/toolbar/FieldsMenu.vue b/packages/nc-gui/components/smartsheet/toolbar/FieldsMenu.vue index f6b74584bf..d7492bc50e 100644 --- a/packages/nc-gui/components/smartsheet/toolbar/FieldsMenu.vue +++ b/packages/nc-gui/components/smartsheet/toolbar/FieldsMenu.vue @@ -39,7 +39,6 @@ const { showSystemFields, sortedAndFilteredFields, fields, - loadViewColumns, filteredFieldList, filterQuery, showAll, diff --git a/packages/nc-gui/components/smartsheet/toolbar/SortListMenu.vue b/packages/nc-gui/components/smartsheet/toolbar/SortListMenu.vue index 3112d08d20..041b80ff8c 100644 --- a/packages/nc-gui/components/smartsheet/toolbar/SortListMenu.vue +++ b/packages/nc-gui/components/smartsheet/toolbar/SortListMenu.vue @@ -33,7 +33,7 @@ const columnByID = computed(() => watch( () => view.value?.id, (viewId) => { - if(viewId)loadSorts() + if (viewId) loadSorts() }, { immediate: true }, ) diff --git a/packages/nc-gui/composables/useGridViewColumnWidth.ts b/packages/nc-gui/composables/useGridViewColumnWidth.ts index adca292855..27f3855298 100644 --- a/packages/nc-gui/composables/useGridViewColumnWidth.ts +++ b/packages/nc-gui/composables/useGridViewColumnWidth.ts @@ -52,7 +52,7 @@ export function useGridViewColumnWidth(view: Ref) { /** when columns changes(create/delete) reload grid columns * or when view changes reload columns width */ - watch([() => columns.value?.length, () => view?.value?.id ], loadGridViewColumns) + watch([() => columns.value?.length, () => view?.value?.id], loadGridViewColumns) const updateWidth = async (id: string, width: string) => { if (gridViewCols?.value?.[id]) { diff --git a/packages/nc-gui/composables/useViewColumns.ts b/packages/nc-gui/composables/useViewColumns.ts index c754325bc4..ed7b4f0dad 100644 --- a/packages/nc-gui/composables/useViewColumns.ts +++ b/packages/nc-gui/composables/useViewColumns.ts @@ -206,11 +206,15 @@ export function useViewColumns( }) // reload view columns when table meta changes - watch(() => view?.value?.id, async (newVal) => { - if (newVal) { - await loadViewColumns() - } - }, { immediate: true }) + watch( + () => view?.value?.id, + async (newVal) => { + if (newVal) { + await loadViewColumns() + } + }, + { immediate: true }, + ) return { fields, From 2c63324d9c35472dd9c9c9d21f8279e7800f5deb Mon Sep 17 00:00:00 2001 From: Pranav C Date: Sat, 8 Oct 2022 12:24:05 +0530 Subject: [PATCH 5/5] fix(gui): within watch verify view belongs to the table or not Signed-off-by: Pranav C --- packages/nc-gui/composables/useViewColumns.ts | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/packages/nc-gui/composables/useViewColumns.ts b/packages/nc-gui/composables/useViewColumns.ts index ed7b4f0dad..0922527003 100644 --- a/packages/nc-gui/composables/useViewColumns.ts +++ b/packages/nc-gui/composables/useViewColumns.ts @@ -205,11 +205,13 @@ export function useViewColumns( ?.map((field: Field) => metaColumnById?.value?.[field.fk_column_id!]) || []) as ColumnType[] }) - // reload view columns when table meta changes + // reload view columns when active view changes + // or when columns count changes(delete/add) watch( - () => view?.value?.id, - async (newVal) => { - if (newVal) { + [() => view?.value?.id, () => meta.value?.columns?.length], + async ([newViewId]) => { + // reload only if view belongs to current table + if (newViewId && view.value?.fk_model_id === meta.value?.id) { await loadViewColumns() } },