Skip to content

Commit 5063db2

Browse files
authored
simplfy the buttons (#668)
* chore: provide a way to toggle button as icon mode or not * using goroutine to check store status * support to duplicate a store on ui --------- Co-authored-by: rick <[email protected]>
1 parent 9abb703 commit 5063db2

File tree

12 files changed

+132
-82
lines changed

12 files changed

+132
-82
lines changed

console/atest-ui/src/App.vue

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,9 @@ API.GetVersion((d) => {
5151
})
5252
5353
const isCollapse = ref(true)
54+
watch(isCollapse, (v: boolean) => {
55+
window.localStorage.setItem('button.style', v ? 'simple' : '')
56+
})
5457
const lastActiveMenu = window.localStorage.getItem('activeMenu')
5558
const activeMenu = ref(lastActiveMenu === '' ? 'welcome' : lastActiveMenu)
5659
const panelName = ref(activeMenu)
@@ -64,7 +67,7 @@ i18nLocale.value = locale.value
6467
6568
watch(locale, (e: string) =>{
6669
Cache.WithLocale(e)
67-
i18nLocale.value = locale
70+
i18nLocale.value = e
6871
})
6972
7073
const handleChangeLan = (command: string) => {
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<script setup lang="ts">
2+
import { ref } from 'vue'
3+
4+
const simpleButton = ref(localStorage.getItem('button.style') === 'simple')
5+
</script>
6+
7+
<template>
8+
<el-button v-bind="$attrs">
9+
<slot v-if="!simpleButton || !($attrs.icon)"></slot>
10+
</el-button>
11+
</template>

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
"toolbox": "Tool Box",
1717
"refresh": "Refresh",
1818
"newtestcase": "New TestCase",
19-
"viewYaml":"View YAML",
19+
"viewYaml": "View YAML",
2020
"verify": "Verify",
2121
"duplicate": "Duplicate",
2222
"generateCode": "Generate Code",
@@ -32,6 +32,7 @@
3232
"createTestSuite": "Create Test Suite",
3333
"createTestCase": "Create Test Case",
3434
"createStore": "Create Store",
35+
"updateStore": "Update Store",
3536
"createSecret": "Create Secret",
3637
"secretManager": "Secret Manager",
3738
"protoContent": "Proto Content",

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
"createTestSuite": "创建测试用例集",
3333
"createTestCase": "创建测试用例",
3434
"createStore": "创建存储",
35+
"updateStore": "更新存储",
3536
"createSecret": "创建凭据",
3637
"secretManager": "凭据管理",
3738
"apiRequestParameter": "API 请求参数",
@@ -63,6 +64,7 @@
6364
"plugin": "插件",
6465
"pluginName": "插件名称",
6566
"pluginURL": "插件地址",
67+
"disabled": "禁用",
6668
"status": "状态",
6769
"operations": "操作",
6870
"storageLocation": "保存位置",

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

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,14 @@ const executeQuery = async () => {
179179
return executeWithQuery(sqlQuery.value)
180180
}
181181
const executeWithQuery = async (sql: string) => {
182+
switch (kind.value) {
183+
case 'atest-store-etcd':
184+
sqlQuery.value = '*'
185+
break;
186+
case '':
187+
return;
188+
}
189+
182190
let success = false
183191
query.value.store = store.value
184192
query.value.key = queryDataMeta.value.currentDatabase
@@ -268,7 +276,7 @@ const nextPage = () => {
268276
</el-col>
269277
<el-col :span="2">
270278
<el-form-item>
271-
<el-button type="primary" @click="executeQuery">Execute</el-button>
279+
<el-button type="primary" @click="executeQuery" :disabled="kind === ''">Execute</el-button>
272280
</el-form-item>
273281
</el-col>
274282
<el-col :span="2">

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

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
<script setup lang="ts">
22
import { ElMessage } from 'element-plus'
33
import { reactive, ref, watch } from 'vue'
4-
import { Edit, Delete, QuestionFilled, Help } from '@element-plus/icons-vue'
4+
import { Edit, Delete, QuestionFilled, Help, Refresh } from '@element-plus/icons-vue'
55
import type { FormInstance, FormRules } from 'element-plus'
66
import type { Pair } from './types'
77
import { API } from './net'
88
import { UIAPI } from './net-vue'
99
import { SupportedExtensions, SupportedExtension } from './store'
1010
import { useI18n } from 'vue-i18n'
1111
import { Magic } from './magicKeys'
12+
import Button from '../components/Button.vue'
1213
1314
const { t } = useI18n()
1415
@@ -69,7 +70,7 @@ loadStores()
6970
Magic.Keys(loadStores, ['Alt+KeyR'])
7071
7172
function deleteStore(name: string) {
72-
API.DeleteStore(name, (e) => {
73+
API.DeleteStore(name, () => {
7374
ElMessage({
7475
message: 'Deleted.',
7576
type: 'success'
@@ -191,6 +192,11 @@ function storeVerify(formEl: FormInstance | undefined) {
191192
})
192193
}
193194
195+
const storeDuplicate = async (formEl: FormInstance | undefined) => {
196+
createAction.value = true
197+
storeForm.name += '-copy'
198+
}
199+
194200
function updateKeys() {
195201
const props = storeForm.properties
196202
if (props.findIndex(p => p.key === '') === -1) {
@@ -207,8 +213,8 @@ const storeExtLink = ref('')
207213
<template>
208214
<div>Store Manager</div>
209215
<div>
210-
<el-button type="primary" @click="addStore" :icon="Edit">{{t('button.new')}}</el-button>
211-
<el-button type="primary" @click="loadStores">{{t('button.refresh')}}</el-button>
216+
<Button type="primary" @click="addStore" :icon="Edit">{{t('button.new')}}</Button>
217+
<Button type="primary" @click="loadStores" :icon="Refresh">{{t('button.refresh')}}</Button>
212218
</div>
213219
<el-table :data="stores" style="width: 100%" v-loading=storesLoading>
214220
<el-table-column :label="t('field.name')" width="180">
@@ -254,8 +260,8 @@ const storeExtLink = ref('')
254260
<el-table-column :label="t('field.operations')" width="220">
255261
<template #default="scope">
256262
<div style="display: flex; align-items: center" v-if="scope.row.name !== 'local'">
257-
<el-button type="primary" @click="deleteStore(scope.row.name)" :icon="Delete">{{t('button.delete')}}</el-button>
258-
<el-button type="primary" @click="editStore(scope.row.name)" :icon="Edit">{{t('button.edit')}}</el-button>
263+
<Button type="primary" @click="deleteStore(scope.row.name)" :icon="Delete">{{t('button.delete')}}</Button>
264+
<Button type="primary" @click="editStore(scope.row.name)" :icon="Edit">{{t('button.edit')}}</Button>
259265
</div>
260266
</template>
261267
</el-table-column>
@@ -265,7 +271,7 @@ const storeExtLink = ref('')
265271
Follow <el-link href="https://linuxsuren.github.io/api-testing/#storage" target="_blank">the instructions</el-link> to configure the storage plugins.
266272
</div>
267273

268-
<el-dialog v-model="dialogVisible" :title="t('title.createStore')" width="30%" draggable>
274+
<el-dialog v-model="dialogVisible" :title="t(createAction? 'title.createStore': 'title.updateStore')" width="30%" draggable>
269275
<template #footer>
270276
<span class="dialog-footer">
271277
<el-form
@@ -274,7 +280,7 @@ const storeExtLink = ref('')
274280
ref="storeFormRef"
275281
status-icon label-width="120px">
276282
<el-form-item :label="t('field.name')" prop="name">
277-
<el-input v-model="storeForm.name" test-id="store-form-name" />
283+
<el-input v-model="storeForm.name" test-id="store-form-name" :disabled="!createAction"/>
278284
</el-form-item>
279285
<el-form-item label="URL" prop="url">
280286
<el-input v-model="storeForm.url" placeholder="http://foo" test-id="store-form-url" />
@@ -341,18 +347,23 @@ const storeExtLink = ref('')
341347
</el-table>
342348
</el-form-item>
343349
<el-form-item>
344-
<el-button
350+
<Button
345351
type="primary"
346352
@click="storeVerify(storeFormRef)"
347353
test-id="store-form-verify"
348-
>{{t('button.verify')}}</el-button
354+
>{{t('button.verify')}}</Button
349355
>
350-
<el-button
356+
<Button
357+
type="primary"
358+
v-if="!createAction"
359+
@click="storeDuplicate(storeFormRef)"
360+
>{{t('button.duplicate')}}</Button>
361+
<Button
351362
type="primary"
352363
@click="submitForm(storeFormRef)"
353364
v-loading="creatingLoading"
354365
test-id="store-form-submit"
355-
>{{t('button.submit')}}</el-button
366+
>{{t('button.submit')}}</Button
356367
>
357368
</el-form-item>
358369
</el-form>

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

Lines changed: 29 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
<script setup lang="ts">
22
import { ref, watch, reactive } from 'vue'
33
import { ElMessage } from 'element-plus'
4-
import { Edit, Delete, Search, CopyDocument } from '@element-plus/icons-vue'
4+
import { Edit, Delete, Search, CopyDocument, Help } from '@element-plus/icons-vue'
55
import JsonViewer from 'vue-json-viewer'
66
import type { Pair, TestResult, TestCaseWithSuite, TestCase } from './types'
77
import { NewSuggestedAPIsQuery, CreateFilter, GetHTTPMethods, FlattenObject } from './types'
8+
import Button from '../components/Button.vue'
89
import { Cache } from './cache'
910
import { API } from './net'
1011
import EditButton from '../components/EditButton.vue'
@@ -125,6 +126,7 @@ const handleTestResult = (e: any) => {
125126
testResult.value.bodyLength = e.body.length
126127
testResult.value.bodyObject = JSON.parse(e.body);
127128
testResult.value.originBodyObject = JSON.parse(e.body);
129+
responseBodyFilter()
128130
}
129131
130132
Cache.SetTestCaseResponseCache(suite + '-' + name, {
@@ -162,7 +164,7 @@ function responseBodyFilter() {
162164
json: testResult.value.originBodyObject,
163165
resultType: 'value'
164166
})
165-
testResult.value.bodyObject = query[0]
167+
testResult.value.bodyObject = query
166168
}
167169
}
168170
@@ -905,16 +907,16 @@ const renameTestCase = (name: string) => {
905907
<el-container style="height: 100%;">
906908
<el-header style="padding-left: 5px;">
907909
<div style="margin-bottom: 5px">
908-
<el-button type="primary" @click="saveTestCase" :icon="Edit" v-loading="saveLoading"
910+
<Button type="primary" @click="saveTestCase" :icon="Edit" v-loading="saveLoading"
909911
disabled v-if="Cache.GetCurrentStore().readOnly || isHistoryTestCase"
910-
>{{ t('button.save') }}</el-button>
911-
<el-button type="primary" @click="saveTestCase" :icon="Edit" v-loading="saveLoading"
912+
>{{ t('button.save') }}</Button>
913+
<Button type="primary" @click="saveTestCase" :icon="Edit" v-loading="saveLoading"
912914
v-if="!Cache.GetCurrentStore().readOnly && !isHistoryTestCase"
913-
>{{ t('button.save') }}</el-button>
914-
<el-button type="danger" @click="deleteCase" :icon="Delete">{{ t('button.delete') }}</el-button>
915-
<el-button type="primary" @click="openDuplicateTestCaseDialog" :icon="CopyDocument" v-if="!isHistoryTestCase">{{ t('button.duplicate') }}</el-button>
916-
<el-button type="primary" @click="openCodeDialog">{{ t('button.generateCode') }}</el-button>
917-
<el-button type="primary" v-if="!isHistoryTestCase && Cache.GetCurrentStore().kind.name == 'atest-store-orm'" @click="openHistoryDialog">{{ t('button.viewHistory') }}</el-button>
915+
>{{ t('button.save') }}</Button>
916+
<Button type="danger" @click="deleteCase" :icon="Delete">{{ t('button.delete') }}</Button>
917+
<Button type="primary" @click="openDuplicateTestCaseDialog" :icon="CopyDocument" v-if="!isHistoryTestCase">{{ t('button.duplicate') }}</Button>
918+
<Button type="primary" @click="openCodeDialog">{{ t('button.generateCode') }}</Button>
919+
<Button type="primary" v-if="!isHistoryTestCase && Cache.GetCurrentStore().kind.name == 'atest-store-orm'" @click="openHistoryDialog">{{ t('button.viewHistory') }}</Button>
918920
<span v-if="isHistoryTestCase" style="margin-left: 15px;">{{ t('tip.runningAt') }}{{ HistoryTestCaseCreateTime }}</span>
919921
<EditButton :value="props.name" @changed="renameTestCase"/>
920922
</div>
@@ -1060,8 +1062,8 @@ const renameTestCase = (name: string) => {
10601062

10611063
<el-tab-pane name="body">
10621064
<span style="margin-right: 10px; padding-right: 5px;">
1063-
<el-button type="primary" @click="jsonFormat(4)">Beautify</el-button>
1064-
<el-button type="primary" @click="jsonFormat(0)">Minify</el-button>
1065+
<Button type="primary" @click="jsonFormat(4)">Beautify</Button>
1066+
<Button type="primary" @click="jsonFormat(0)">Minify</Button>
10651067
<el-text class="mx-1">Choose the body format</el-text>
10661068
</span>
10671069
<template #label>
@@ -1221,8 +1223,8 @@ const renameTestCase = (name: string) => {
12211223
:value="item.key"
12221224
/>
12231225
</el-select>
1224-
<el-button type="primary" @click="generateCode">{{ t('button.refresh') }}</el-button>
1225-
<el-button type="primary" @click="copyCode">{{ t('button.copy') }}</el-button>
1226+
<Button type="primary" @click="generateCode">{{ t('button.refresh') }}</Button>
1227+
<Button type="primary" @click="copyCode">{{ t('button.copy') }}</Button>
12261228
</div>
12271229
<Codemirror v-model="currentCodeContent"/>
12281230
</template>
@@ -1257,24 +1259,24 @@ const renameTestCase = (name: string) => {
12571259
</el-col>
12581260
<el-col :span="4">
12591261
<div style="display: flex;flex-wrap: nowrap;justify-content: flex-end;">
1260-
<el-button
1262+
<Button
12611263
type="primary"
12621264
@click="submitForm(viewHistoryRef)"
12631265
:loading="caseRevertLoading"
12641266
>{{ t('button.revert') }}
1265-
</el-button>
1266-
<el-button
1267+
</Button>
1268+
<Button
12671269
type="primary"
12681270
@click="goToHistory(viewHistoryRef)"
12691271
:loading="caseRevertLoading"
12701272
>{{ t('button.goToHistory') }}
1271-
</el-button>
1272-
<el-button
1273+
</Button>
1274+
<Button
12731275
type="primary"
12741276
@click="deleteAllHistory(viewHistoryRef)"
12751277
:loading="caseRevertLoading"
12761278
>{{ t('button.deleteAllHistory') }}
1277-
</el-button>
1279+
</Button>
12781280
</div>
12791281
</el-col>
12801282
</el-row>
@@ -1322,7 +1324,7 @@ const renameTestCase = (name: string) => {
13221324
</el-table-column>
13231325
</el-table>
13241326

1325-
<el-button type="primary" @click="sendRequestWithParameter">{{ t('button.send') }}</el-button>
1327+
<Button type="primary" @click="sendRequestWithParameter">{{ t('button.send') }}</Button>
13261328
</template>
13271329
</el-drawer>
13281330
</el-main>
@@ -1341,8 +1343,11 @@ const renameTestCase = (name: string) => {
13411343
<el-tab-pane label="Body" name="body">
13421344
<div v-if="testResult.bodyObject">
13431345
<el-input :prefix-icon="Search" @change="responseBodyFilter" v-model="responseBodyFilterText"
1344-
clearable placeholder="$.key">
1346+
clearable placeholder="$.data[?(@.status==='SUCCEED')]">
13451347
<template #prepend v-if="testResult.bodyLength > 0">Body Size: {{testResult.bodyLength}}</template>
1348+
<template #suffix>
1349+
<a href="https://www.npmjs.com/package/jsonpath-plus" target="_blank"><el-icon><Help /></el-icon></a>
1350+
</template>
13461351
</el-input>
13471352
<JsonViewer :value="testResult.bodyObject" :expand-depth="5" copyable boxed sort />
13481353
</div>
@@ -1354,7 +1359,7 @@ const renameTestCase = (name: string) => {
13541359
<div>Response body is too large, please download to view.</div>
13551360
</el-col>
13561361
<el-col :span="2">
1357-
<el-button type="primary" @click="downloadResponseFile">Download</el-button>
1362+
<Button type="primary" @click="downloadResponseFile">Download</Button>
13581363
</el-col>
13591364
</el-row>
13601365
</div>
@@ -1389,7 +1394,7 @@ const renameTestCase = (name: string) => {
13891394
New Test Case Name:<el-input v-model="targetTestCaseName" />
13901395
</template>
13911396
<template #footer>
1392-
<el-button type="primary" @click="duplicateTestCase">{{ t('button.ok') }}</el-button>
1397+
<Button type="primary" @click="duplicateTestCase">{{ t('button.ok') }}</Button>
13931398
</template>
13941399
</el-drawer>
13951400
</template>

0 commit comments

Comments
 (0)