Skip to content

Commit a39ce50

Browse files
committed
support to show the key binding on each page
1 parent 0f947c4 commit a39ce50

File tree

8 files changed

+98
-30
lines changed

8 files changed

+98
-30
lines changed

console/atest-ui/src/App.vue

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import {
99
Guide,
1010
DataAnalysis, Help, Setting
1111
} from '@element-plus/icons-vue'
12-
import { ref, watch } from 'vue'
12+
import { ref, watch, onMounted, onBeforeUnmount } from 'vue'
1313
import { API } from './views/net'
1414
import { Cache } from './views/cache'
1515
import TestingPanel from './views/TestingPanel.vue'
@@ -98,6 +98,21 @@ const theme = ref(getTheme())
9898
watch(theme, (e) => {
9999
setTheme(e)
100100
})
101+
102+
const keyBindingsDialogVisible = ref(false)
103+
const keyBindings = ref([])
104+
const showKeyBindingsDialog = (keys: any) => {
105+
keyBindingsDialogVisible.value = true
106+
keyBindings.value = keys.detail || []
107+
}
108+
109+
onMounted(() => {
110+
window.addEventListener('show-key-bindings-dialog', showKeyBindingsDialog)
111+
})
112+
113+
onBeforeUnmount(() => {
114+
window.removeEventListener('show-key-bindings-dialog', showKeyBindingsDialog)
115+
})
101116
</script>
102117

103118
<template>
@@ -212,6 +227,18 @@ watch(theme, (e) => {
212227
</el-col>
213228
</el-row>
214229
</el-dialog>
230+
231+
<el-drawer v-model="keyBindingsDialogVisible" size="50%">
232+
<template #header>
233+
<h4>{{ t('title.keyBindings') }}</h4>
234+
</template>
235+
<template #default>
236+
<el-table :data="keyBindings">
237+
<el-table-column prop="keys" label="Key" />
238+
<el-table-column prop="description" label="Description" />
239+
</el-table>
240+
</template>
241+
</el-drawer>
215242
</template>
216243

217244
<style>

console/atest-ui/src/locales/en.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,8 @@
5454
"proxy": "Proxy",
5555
"secure": "Secure",
5656
"data": "Data",
57-
"setting": "Setting"
57+
"setting": "Setting",
58+
"keyBindings": "Key Bindings"
5859
},
5960
"tip": {
6061
"filter": "Filter Keyword",

console/atest-ui/src/locales/zh.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,8 @@
4949
"proxy": "代理",
5050
"secure": "安全",
5151
"data": "数据",
52-
"setting": "设置"
52+
"setting": "设置",
53+
"keyBindings": "按键绑定"
5354
},
5455
"tip": {
5556
"filter": "过滤",

console/atest-ui/src/views/StoreManager.vue

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,10 +110,12 @@ function addStore() {
110110
111111
Magic.AdvancedKeys([{
112112
Keys: ['Alt+KeyE', 'ctrl+n'],
113-
Func: addStore
113+
Func: addStore,
114+
Description: 'Add a new store'
114115
}, {
115116
Keys: ['Alt+KeyR'],
116-
Func: loadStores
117+
Func: loadStores,
118+
Description: 'Refresh the store list'
117119
}])
118120
119121
const rules = reactive<FormRules<Store>>({

console/atest-ui/src/views/TemplateFunctions.vue

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,13 @@ function queryFuncs() {
1818
})
1919
}
2020
21-
Magic.Keys(() => {
22-
dialogVisible.value = true
23-
}, ['Alt+KeyT'])
21+
Magic.AdvancedKeys([{
22+
Keys: ['Alt+KeyT'],
23+
Func: () => {
24+
dialogVisible.value = true
25+
},
26+
Description: 'Open template functions dialog',
27+
}])
2428
</script>
2529

2630
<template>

console/atest-ui/src/views/TestCase.vue

Lines changed: 37 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,6 @@ const emit = defineEmits(['updated','toHistoryPanel'])
4444
let querySuggestedAPIs = NewSuggestedAPIsQuery(Cache.GetCurrentStore().name!, props.suite!)
4545
const testResultActiveTab = ref(Cache.GetPreference().responseActiveTab)
4646
watch(testResultActiveTab, Cache.WithResponseActiveTab)
47-
Magic.Keys(() => {
48-
testResultActiveTab.value = 'output'
49-
}, ['Alt+KeyO'])
5047
5148
const parameters = ref([] as Pair[])
5249
const requestLoading = ref(false)
@@ -59,7 +56,6 @@ const sendRequest = async () => {
5956
runTestCase()
6057
}
6158
}
62-
Magic.Keys(sendRequest, ['Alt+S', 'Alt+ß'])
6359
6460
const runTestCaseResultHandler = (e: any) => {
6561
requestLoading.value = false
@@ -712,15 +708,6 @@ const deleteAllHistory = async (formEl) => {
712708
const options = GetHTTPMethods()
713709
const requestActiveTab = ref(Cache.GetPreference().requestActiveTab)
714710
watch(requestActiveTab, Cache.WatchRequestActiveTab)
715-
Magic.Keys(() => {
716-
requestActiveTab.value = 'query'
717-
}, ['Alt+KeyQ'])
718-
Magic.Keys(() => {
719-
requestActiveTab.value = 'header'
720-
}, ['Alt+KeyH'])
721-
Magic.Keys(() => {
722-
requestActiveTab.value = 'body'
723-
}, ['Alt+KeyB'])
724711
725712
function bodyFiledExpectChange() {
726713
const data = testCaseWithSuite.value.data.response.bodyFieldsExpect
@@ -910,7 +897,6 @@ const openDuplicateTestCaseDialog = () => {
910897
duplicateTestCaseDialog.value = true
911898
targetTestCaseName.value = props.name + '-copy'
912899
}
913-
Magic.Keys(openDuplicateTestCaseDialog, ['Alt+KeyD'])
914900
const duplicateTestCase = () => {
915901
API.DuplicateTestCase(props.suite, props.suite, props.name, targetTestCaseName.value,(d) => {
916902
duplicateTestCaseDialog.value = false
@@ -922,18 +908,50 @@ const duplicateTestCase = () => {
922908
emit('updated')
923909
})
924910
}
925-
Magic.Keys(() => {
926-
if (duplicateTestCaseDialog.value) {
927-
duplicateTestCase()
928-
}
929-
}, ['Alt+KeyO'])
930911
931912
const renameTestCase = (name: string) => {
932913
const suiteName = props.suite
933914
API.RenameTestCase(suiteName, suiteName, props.name, name, (d) => {
934915
emit('updated', suiteName, name)
935916
})
936917
}
918+
919+
Magic.AdvancedKeys([{
920+
Keys: ['Alt+S', 'Alt+ß'],
921+
Func: sendRequest,
922+
Description: 'Send the request'
923+
}, {
924+
Keys: ['Alt+KeyD'],
925+
Func: openDuplicateTestCaseDialog,
926+
Description: 'Duplicate the test case'
927+
}, {
928+
Keys: ['Alt+KeyO'],
929+
Func: () => {
930+
if (duplicateTestCaseDialog.value) {
931+
duplicateTestCase()
932+
}
933+
testResultActiveTab.value = 'output'
934+
},
935+
Description: 'Open the output tab'
936+
}, {
937+
Keys: ['Alt+KeyB'],
938+
Func: () => {
939+
testResultActiveTab.value = 'body'
940+
},
941+
Description: 'Open the body tab'
942+
}, {
943+
Keys: ['Alt+KeyH'],
944+
Func: () => {
945+
testResultActiveTab.value = 'header'
946+
},
947+
Description: 'Open the header tab'
948+
}, {
949+
Keys: ['Alt+KeyQ'],
950+
Func: () => {
951+
testResultActiveTab.value = 'query'
952+
},
953+
Description: 'Open the query tab'
954+
}])
937955
</script>
938956

939957
<template>

console/atest-ui/src/views/TestSuite.vue

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,6 @@ const saveTestSuite = () => {
131131
}
132132
)
133133
}
134-
Magic.Keys(saveTestSuite, ['Alt+S', 'Alt+ß'])
135134
136135
const isFullScreen = ref(false)
137136
const dialogVisible = ref(false)
@@ -153,7 +152,16 @@ function openNewTestCaseDialog() {
153152
dialogVisible.value = true
154153
querySuggestedAPIs = NewSuggestedAPIsQuery(Cache.GetCurrentStore().name!, props.name!)
155154
}
156-
Magic.Keys(openNewTestCaseDialog, ['Alt+N', 'Alt+dead'])
155+
156+
Magic.AdvancedKeys([{
157+
Keys: ['Alt+N', 'Alt+dead'],
158+
Func: openNewTestCaseDialog,
159+
Description: 'Open new test case dialog',
160+
}, {
161+
Keys: ['Alt+S', 'Alt+ß'],
162+
Func: saveTestSuite,
163+
Description: 'Save test suite',
164+
}])
157165
158166
const submitTestCaseForm = async (formEl: FormInstance | undefined) => {
159167
if (!formEl) return

console/atest-ui/src/views/magicKeys.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,15 @@ const AdvancedKeys = (keys: MagicKey[]) => {
3737
keys.push({
3838
Keys: ['ctrl+/'],
3939
Func: () => {
40-
console.log('Advanced keys dialog opened')
40+
const event = new CustomEvent('show-key-bindings-dialog', {
41+
detail: keys.map((k) => ({
42+
keys: k.Keys.join(', '),
43+
description: k.Description ?? 'No description',
44+
})),
45+
})
46+
window.dispatchEvent(event)
4147
},
48+
Description: 'Show key bindings dialog',
4249
})
4350

4451
keys.forEach((key: MagicKey) => {

0 commit comments

Comments
 (0)