Skip to content

Commit cf22768

Browse files
committed
feat: support to query verify functions
1 parent 9e4259f commit cf22768

File tree

7 files changed

+447
-414
lines changed

7 files changed

+447
-414
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@
4747
"welcome": "Welcome",
4848
"secrets": "Secrets",
4949
"stores": "Stores",
50-
"templateQuery": "Template Functions Query",
50+
"functionQuery": "Functions Query",
5151
"output": "Output"
5252
},
5353
"tip": {

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
"secrets": "凭据",
4343
"stores": "存储",
4444
"parameter": "参数",
45-
"templateQuery": "模板函数查询",
45+
"functionQuery": "函数查询",
4646
"output": "输出"
4747
},
4848
"tip": {

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

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,13 @@ import { Magic } from './magicKeys'
77
88
const { t } = useI18n()
99
10+
const functionKind = ref('template')
1011
const dialogVisible = ref(false)
1112
const query = ref('')
1213
const funcs = ref([] as Pair[])
1314
1415
function queryFuncs() {
15-
API.FunctionsQuery(query.value, (d) => {
16+
API.FunctionsQuery(query.value, functionKind.value, (d) => {
1617
funcs.value = d.data
1718
})
1819
}
@@ -28,12 +29,20 @@ Magic.Keys(() => {
2829
data-intro="You can search your desired template functions.">{{ t('button.toolbox') }}</el-button>
2930
</el-affix>
3031

31-
<el-dialog v-model="dialogVisible" :title="t('title.templateQuery')" width="50%" draggable destroy-on-close>
32+
<el-dialog v-model="dialogVisible" :title="t('title.functionQuery')" width="50%" draggable destroy-on-close>
3233
<el-input
3334
v-model="query" placeholder="Query after enter" v-on:keyup.enter="queryFuncs">
3435
<template #append v-if="funcs.length > 0">
3536
{{ funcs.length }}
3637
</template>
38+
<template #prepend>
39+
<el-select
40+
v-model="functionKind"
41+
>
42+
<el-option label="Template" value="template" />
43+
<el-option label="Verify" value="verify" />
44+
</el-select>
45+
</template>
3746
</el-input>
3847
<span class="dialog-footer">
3948
<el-table :data="funcs">

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -556,14 +556,14 @@ function GetSecrets(callback: (d: any) => void, errHandle?: (e: any) => void | n
556556
.catch(emptyOrDefault(errHandle))
557557
}
558558

559-
function FunctionsQuery(filter: string,
559+
function FunctionsQuery(filter: string, kind: string,
560560
callback: (d: any) => void, errHandle?: (e: any) => (PromiseLike<void | null | undefined> | void | null | undefined) | undefined | null) {
561561
const requestOptions = {
562562
headers: {
563563
'X-Auth': getToken()
564564
}
565565
}
566-
fetch(`/api/v1/functions?name=${filter}`, requestOptions)
566+
fetch(`/api/v1/functions?name=${filter}&kind=${kind}`, requestOptions)
567567
.then(DefaultResponseProcess)
568568
.then(callback).catch(emptyOrDefault(errHandle))
569569
}

pkg/server/remote_server.go

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import (
2121
"context"
2222
"errors"
2323
"fmt"
24+
"github.com/expr-lang/expr/builtin"
2425
"io"
2526
"mime"
2627
"net/http"
@@ -1077,14 +1078,26 @@ func (s *server) FunctionsQuery(ctx context.Context, in *SimpleQuery) (reply *Pa
10771078
reply = &Pairs{}
10781079
in.Name = strings.ToLower(in.Name)
10791080

1080-
for name, fn := range render.FuncMap() {
1081-
lowerCaseName := strings.ToLower(name)
1082-
if in.Name == "" || strings.Contains(lowerCaseName, in.Name) {
1083-
reply.Data = append(reply.Data, &Pair{
1084-
Key: name,
1085-
Value: fmt.Sprintf("%v", reflect.TypeOf(fn)),
1086-
Description: render.FuncUsage(name),
1087-
})
1081+
if in.Kind == "verify" {
1082+
for _, fn := range builtin.Builtins {
1083+
lowerName := strings.ToLower(fn.Name)
1084+
if in.Name == "" || strings.Contains(lowerName, in.Name) {
1085+
reply.Data = append(reply.Data, &Pair{
1086+
Key: fn.Name,
1087+
Value: fmt.Sprintf("%v", reflect.TypeOf(fn.Func)),
1088+
})
1089+
}
1090+
}
1091+
} else {
1092+
for name, fn := range render.FuncMap() {
1093+
lowerName := strings.ToLower(name)
1094+
if in.Name == "" || strings.Contains(lowerName, in.Name) {
1095+
reply.Data = append(reply.Data, &Pair{
1096+
Key: name,
1097+
Value: fmt.Sprintf("%v", reflect.TypeOf(fn)),
1098+
Description: render.FuncUsage(name),
1099+
})
1100+
}
10881101
}
10891102
}
10901103
return

0 commit comments

Comments
 (0)