From 918dd498d434e8743a1b96b58fff86421f52b725 Mon Sep 17 00:00:00 2001 From: Alex <49969959+alexzhang1030@users.noreply.github.com> Date: Tue, 7 Jan 2025 21:10:55 +0800 Subject: [PATCH] feat(applet): support filter on router page (#762) --- .../router/components/routes/Index.vue | 33 ++++++++++++++++--- 1 file changed, 29 insertions(+), 4 deletions(-) diff --git a/packages/applet/src/modules/router/components/routes/Index.vue b/packages/applet/src/modules/router/components/routes/Index.vue index 0736f38d2..a3d944a28 100644 --- a/packages/applet/src/modules/router/components/routes/Index.vue +++ b/packages/applet/src/modules/router/components/routes/Index.vue @@ -2,7 +2,8 @@ import type { CustomInspectorNode, CustomInspectorState } from '@vue/devtools-kit' import { DevToolsMessagingEvents, rpc } from '@vue/devtools-core' import { parse } from '@vue/devtools-kit' -import { until } from '@vueuse/core' +import { VueInput } from '@vue/devtools-ui' +import { until, useToggle, watchDebounced } from '@vueuse/core' import { Pane, Splitpanes } from 'splitpanes' import { computed, onUnmounted, ref, watch } from 'vue' import DevToolsHeader from '~/components/basic/DevToolsHeader.vue' @@ -21,6 +22,8 @@ const customInspectState = useCustomInspectorState() const inspectorId = computed(() => customInspectState.value.id!) const selected = ref('') +const filterKey = ref('') +const [filtered, toggleFiltered] = useToggle(true) const tree = ref([]) const treeNodeLinkedList = computed(() => tree.value?.length ? dfs(tree.value?.[0]) : []) const flattenedTreeNodes = computed(() => flattenTreeNodes(tree.value)) @@ -92,8 +95,8 @@ watch(selected, () => { getRoutesState(selected.value) }) -const getRoutesInspectorTree = () => { - rpc.value.getInspectorTree({ inspectorId: inspectorId.value, filter: '' }).then((_data) => { +const getRoutesInspectorTree = async (filter = '') => { + await rpc.value.getInspectorTree({ inspectorId: inspectorId.value, filter }).then((_data) => { const data = parse(_data!) tree.value = data if (!selected.value && data.length) { @@ -145,6 +148,18 @@ onUnmounted(() => { rpc.functions.off(DevToolsMessagingEvents.INSPECTOR_TREE_UPDATED, onInspectorTreeUpdated) rpc.functions.off(DevToolsMessagingEvents.INSPECTOR_STATE_UPDATED, onInspectorStateUpdated) }) + +function search(v: string) { + const value = v.trim().toLowerCase() + toggleFiltered() + getRoutesInspectorTree(value).then(() => { + toggleFiltered() + }) +} + +watchDebounced(filterKey, (v) => { + search(v) +}, { debounce: 300 })