From 1347e4ec4041dcf8c314071eeacf8425f36dff5d Mon Sep 17 00:00:00 2001 From: wbuezas Date: Wed, 22 May 2024 10:56:37 -0300 Subject: [PATCH] Handle params search on mounted --- src/pages/Zone/Card/ZoneLocationsTree.vue | 32 ++++++++++++++--------- 1 file changed, 20 insertions(+), 12 deletions(-) diff --git a/src/pages/Zone/Card/ZoneLocationsTree.vue b/src/pages/Zone/Card/ZoneLocationsTree.vue index e520398b2..2a13365b4 100644 --- a/src/pages/Zone/Card/ZoneLocationsTree.vue +++ b/src/pages/Zone/Card/ZoneLocationsTree.vue @@ -94,19 +94,27 @@ function getNodeIds(node) { return ids; } -watch(storeData, async (val) => { - // Se triggerea cuando se actualiza el store.data, el cual es el resultado del fetch de la searchbar - nodes.value[0].children = [...val]; - const fetchedNodeKeys = val.flatMap(getNodeIds); - state.set('Tree', [...fetchedNodeKeys]); - const tree = state.get('Tree'); - for (let n of tree) { - await fetchNodeLeaves(n); - } - expanded.value = [null, 1, ...fetchedNodeKeys]; -}); +watch( + storeData, + async (val) => { + // Se triggerea cuando se actualiza el store.data, el cual es el resultado del fetch de la searchbar + nodes.value[0].children = [...val]; + const fetchedNodeKeys = val.flatMap(getNodeIds); + state.set('Tree', [...fetchedNodeKeys]); + const tree = state.get('Tree'); + for (let n of tree) { + await fetchNodeLeaves(n); + } + expanded.value = [null, 1, ...fetchedNodeKeys]; + }, + { immediate: true } +); -onMounted(async (n) => { +onMounted(async () => { + if (store.userParams?.search) { + await arrayData.fetch({ append: false }); + return; + } const tree = [...state.get('Tree'), 1]; const lastStateTree = state.get('TreeState'); if (tree) {