From 7bd817e3dfe02ff9f51a4893a50fa24e8253af14 Mon Sep 17 00:00:00 2001 From: rick Date: Wed, 10 Jul 2024 02:41:41 +0000 Subject: [PATCH] feat: support test case nav via shortcut --- console/atest-ui/src/views/TestingPanel.vue | 35 ++++++++++++++++++++- console/atest-ui/src/views/magicKeys.ts | 4 +-- 2 files changed, 36 insertions(+), 3 deletions(-) diff --git a/console/atest-ui/src/views/TestingPanel.vue b/console/atest-ui/src/views/TestingPanel.vue index 78281875..ebc753c7 100644 --- a/console/atest-ui/src/views/TestingPanel.vue +++ b/console/atest-ui/src/views/TestingPanel.vue @@ -10,6 +10,7 @@ import type { Suite } from './types' import { API } from './net' import { Cache } from './cache' import { useI18n } from 'vue-i18n' +import { Magic } from './magicKeys' const { t } = useI18n() @@ -61,6 +62,39 @@ const handleTreeClick = (data: Tree) => { } } +Magic.Keys((k) => { + const currentKey = currentNodekey.value + + if (treeRef.value) { + treeRef.value.data.forEach((n) => { + if (n.children) { + n.children.forEach((c, index) => { + if (c.id === currentKey) { + var nextIndex = -1 + if (k.endsWith('Up')) { + if (index > 0) { + nextIndex = index - 1 + } + } else { + if (index < n.children.length - 1) { + nextIndex = index + 1 + } + } + + if (nextIndex >= 0 < n.children.length) { + const next = n.children[nextIndex] + currentNodekey.value = next.id + treeRef.value!.setCurrentKey(next.id) + treeRef.value!.setCheckedKeys([next.id], false) + } + return + } + }) + } + }) + } +}, ['Alt+ArrowUp', 'Alt+ArrowDown']) + const treeData = ref([] as Tree[]) const treeRef = ref>() const currentNodekey = ref('') @@ -327,7 +361,6 @@ const suiteKinds = [{ ref="treeRef" node-key="id" :filter-node-method="filterTestCases" - @node-click="handleTreeClick" @current-change="handleTreeClick" data-intro="This is the test suite tree. You can click the test suite to edit it." > diff --git a/console/atest-ui/src/views/magicKeys.ts b/console/atest-ui/src/views/magicKeys.ts index 832d5545..e607b52d 100644 --- a/console/atest-ui/src/views/magicKeys.ts +++ b/console/atest-ui/src/views/magicKeys.ts @@ -17,11 +17,11 @@ limitations under the License. import { watch } from 'vue' import { useMagicKeys } from '@vueuse/core' -function Keys(func: () => void, keys: string[]) { +function Keys(func: (() => void) | ((k: string) => void), keys: string[]) { const magicKeys = useMagicKeys() keys.forEach(k => { watch(magicKeys[k], (v) => { - if (v) func() + if (v) func(k) }) }) }