From 833781c998cce062aafab02fb1bda5df1bed69d5 Mon Sep 17 00:00:00 2001 From: Pranav C Date: Sat, 8 Oct 2022 11:08:08 +0530 Subject: [PATCH] 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,