Improve node management when using search bar
gitea/salix-front/pipeline/pr-dev This commit looks good Details

This commit is contained in:
William Buezas 2024-05-22 10:20:36 -03:00
parent 990e3f6e75
commit f4807d887f
1 changed files with 19 additions and 1 deletions

View File

@ -82,10 +82,28 @@ const onSelected = async (val, node) => {
}
};
function getNodeIds(node) {
let ids = [];
if (node.id) ids.push(node.id);
if (node.childs) {
node.childs.forEach((child) => {
ids = ids.concat(getNodeIds(child));
});
}
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];
await fetchNodeLeaves(1);
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];
});
onMounted(async (n) => {