Skip to content

Commit eb311a5

Browse files
committed
support etcd key-value query
1 parent b687b06 commit eb311a5

File tree

4 files changed

+101
-40
lines changed

4 files changed

+101
-40
lines changed

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,8 @@
5050
"functionQuery": "Functions Query",
5151
"output": "Output",
5252
"proxy": "Proxy",
53-
"secure": "Secure"
53+
"secure": "Secure",
54+
"data": "Data"
5455
},
5556
"tip": {
5657
"filter": "Filter Keyword",

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,8 @@
4545
"functionQuery": "函数查询",
4646
"output": "输出",
4747
"proxy": "代理",
48-
"secure": "安全"
48+
"secure": "安全",
49+
"data": "数据"
4950
},
5051
"tip": {
5152
"filter": "过滤",
Lines changed: 76 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,36 @@
11
<script setup lang="ts">
2-
import { ref } from 'vue'
2+
import { ref, watch } from 'vue'
33
import { API } from './net'
4-
import { Cache } from './cache'
54
import { ElMessage } from 'element-plus'
65
76
const stores = ref([])
7+
const kind = ref('')
88
const store = ref('')
9-
const sqlQuery = ref('select * from t_sys_global_config')
9+
const sqlQuery = ref('')
1010
const queryResult = ref([])
1111
const columns = ref([])
12+
const queryTip = ref('')
13+
14+
watch(store, (s) => {
15+
stores.value.forEach((e: Store) => {
16+
if (e.name === s) {
17+
kind.value = e.kind.name
18+
return
19+
}
20+
})
21+
})
22+
watch(kind, (k) => {
23+
switch (k) {
24+
case 'atest-store-orm':
25+
sqlQuery.value = 'show tables'
26+
queryTip.value = 'Enter SQL query'
27+
break;
28+
case 'atest-store-etcd':
29+
sqlQuery.value = ''
30+
queryTip.value = 'Enter key'
31+
break;
32+
}
33+
})
1234
1335
API.GetStores((data) => {
1436
stores.value = data.data
@@ -20,33 +42,62 @@ API.GetStores((data) => {
2042
});
2143
})
2244
23-
const executeQuery = async () => {
24-
API.DataQuery(store.value, sqlQuery.value, (data) => {
45+
const ormDataHandler = (data) => {
2546
const result = []
2647
const cols = new Set()
2748
2849
data.items.forEach(e => {
29-
const obj = {}
30-
e.data.forEach(item => {
31-
obj[item.key] = item.value
32-
cols.add(item.key)
33-
})
34-
result.push(obj)
50+
const obj = {}
51+
e.data.forEach(item => {
52+
obj[item.key] = item.value
53+
cols.add(item.key)
54+
})
55+
result.push(obj)
3556
})
3657
3758
queryResult.value = result
3859
columns.value = Array.from(cols).sort((a, b) => {
39-
if (a === 'id') return -1;
40-
if (b === 'id') return 1;
41-
return a.localeCompare(b);
60+
if (a === 'id') return -1;
61+
if (b === 'id') return 1;
62+
return a.localeCompare(b);
63+
})
64+
}
65+
66+
const keyValueDataHandler = (data) => {
67+
queryResult.value = []
68+
data.data.forEach(e => {
69+
const obj = {}
70+
obj['key'] = e.key
71+
obj['value'] = e.value
72+
queryResult.value.push(obj)
73+
74+
columns.value = ['key', 'value']
75+
})
76+
}
77+
78+
const executeQuery = async () => {
79+
API.DataQuery(store.value, kind.value, sqlQuery.value, (data) => {
80+
switch (kind.value) {
81+
case 'atest-store-orm':
82+
ormDataHandler(data)
83+
break;
84+
case 'atest-store-etcd':
85+
keyValueDataHandler(data)
86+
break;
87+
default:
88+
ElMessage({
89+
showClose: true,
90+
message: 'Unsupported store kind',
91+
type: 'error'
92+
});
93+
}
94+
}, (e) => {
95+
ElMessage({
96+
showClose: true,
97+
message: e.message,
98+
type: 'error'
99+
});
42100
})
43-
}, (e) => {
44-
ElMessage({
45-
showClose: true,
46-
message: e.message,
47-
type: 'error'
48-
});
49-
})
50101
}
51102
</script>
52103

@@ -57,13 +108,14 @@ const executeQuery = async () => {
57108
<el-col :span="2">
58109
<el-form-item>
59110
<el-select v-model="store" placeholder="Select store">
60-
<el-option v-for="item in stores" :key="item.name" :label="item.name" :value="item.name"></el-option>
111+
<el-option v-for="item in stores" :key="item.name" :label="item.name"
112+
:value="item.name" :disabled="!item.ready" :kind="item.kind.name"></el-option>
61113
</el-select>
62114
</el-form-item>
63115
</el-col>
64116
<el-col :span="18">
65117
<el-form-item>
66-
<el-input v-model="sqlQuery" placeholder="Enter SQL query"></el-input>
118+
<el-input v-model="sqlQuery" :placeholder="queryTip"></el-input>
67119
</el-form-item>
68120
</el-col>
69121
<el-col :span="2">
@@ -77,4 +129,4 @@ const executeQuery = async () => {
77129
<el-table-column v-for="col in columns" :key="col" :prop="col" :label="col"></el-table-column>
78130
</el-table>
79131
</div>
80-
</template>
132+
</template>

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

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -773,20 +773,27 @@ var SBOM = (callback: (d: any) => void) => {
773773
.then(callback)
774774
}
775775

776-
var DataQuery = (store: string, query: string, callback: (d: any) => void, errHandler: (d: any) => void) => {
777-
const requestOptions = {
778-
method: 'POST',
779-
headers: {
780-
'X-Store-Name': store
781-
},
782-
body: JSON.stringify({
783-
sql: query
784-
})
785-
}
786-
fetch(`/api/v1/data/query`, requestOptions)
787-
.then(DefaultResponseProcess)
788-
.then(callback)
789-
.catch(errHandler)
776+
var DataQuery = (store: string, kind: string, query: string, callback: (d: any) => void, errHandler: (d: any) => void) => {
777+
const queryObj = {}
778+
switch (kind) {
779+
case 'atest-store-orm':
780+
queryObj['sql'] = query;
781+
break;
782+
case 'atest-store-etcd':
783+
queryObj['key'] = query;
784+
break;
785+
}
786+
const requestOptions = {
787+
method: 'POST',
788+
headers: {
789+
'X-Store-Name': store
790+
},
791+
body: JSON.stringify(queryObj)
792+
}
793+
fetch(`/api/v1/data/query`, requestOptions)
794+
.then(DefaultResponseProcess)
795+
.then(callback)
796+
.catch(errHandler)
790797
}
791798

792799
export const API = {

0 commit comments

Comments
 (0)