From 43ca7e166713ee2b8a58a4b3bf825666d4e83924 Mon Sep 17 00:00:00 2001 From: alexm Date: Fri, 9 Aug 2024 11:40:05 +0200 Subject: [PATCH] fix(VnFilterPanel): emit userParams better --- src/components/VnTable/VnOrder.vue | 1 + src/components/VnTable/VnTable.vue | 4 ++-- src/components/ui/VnFilterPanel.vue | 15 ++++++++++----- 3 files changed, 13 insertions(+), 7 deletions(-) diff --git a/src/components/VnTable/VnOrder.vue b/src/components/VnTable/VnOrder.vue index 98c7ab392..f3cb74c1c 100644 --- a/src/components/VnTable/VnOrder.vue +++ b/src/components/VnTable/VnOrder.vue @@ -41,6 +41,7 @@ async function orderBy(name, direction) { break; } if (!direction) return await arrayData.deleteOrder(name); + console.log('name, direction: ', name, direction); await arrayData.addOrder(name, direction); } diff --git a/src/components/VnTable/VnTable.vue b/src/components/VnTable/VnTable.vue index be39570ee..dca30516f 100644 --- a/src/components/VnTable/VnTable.vue +++ b/src/components/VnTable/VnTable.vue @@ -154,7 +154,7 @@ watch( const isTableMode = computed(() => mode.value == TABLE_MODE); -function setUserParams(watchedParams) { +function setUserParams(watchedParams, watchedOrder) { if (!watchedParams) return; if (typeof watchedParams == 'string') watchedParams = JSON.parse(watchedParams); @@ -163,7 +163,7 @@ function setUserParams(watchedParams) { ? JSON.parse(watchedParams?.filter) : watchedParams?.filter; const where = filter?.where; - const order = filter?.order; + const order = watchedOrder ?? filter?.order; watchedParams = { ...watchedParams, ...where }; delete watchedParams.filter; diff --git a/src/components/ui/VnFilterPanel.vue b/src/components/ui/VnFilterPanel.vue index 430383e40..8adf25508 100644 --- a/src/components/ui/VnFilterPanel.vue +++ b/src/components/ui/VnFilterPanel.vue @@ -82,23 +82,28 @@ onMounted(() => { }); function setUserParams(watchedParams) { - if (!watchedParams) return; + if (!watchedParams || Object.keys(watchedParams).length == 0) return; if (typeof watchedParams == 'string') watchedParams = JSON.parse(watchedParams); + if (typeof watchedParams?.filter == 'string') + watchedParams.filter = JSON.parse(watchedParams.filter); + watchedParams = { ...watchedParams, ...watchedParams.filter?.where }; + const order = watchedParams.filter?.order; + delete watchedParams.filter; - userParams.value = { ...userParams.value, ...watchedParams }; - emit('setUserParams', userParams.value); + userParams.value = { ...userParams.value, ...sanitizer(watchedParams) }; + emit('setUserParams', userParams.value, order); } watch( () => route.query[$props.searchUrl], - (val) => setUserParams(val) + (val, oldValue) => (val || oldValue) && setUserParams(val) ); watch( () => arrayData.store.userParams, - (val) => setUserParams(val) + (val, oldValue) => (val || oldValue) && setUserParams(val) ); watch(