Skip to content

Commit

Permalink
feat: support to query verify functions
Browse files Browse the repository at this point in the history
  • Loading branch information
LinuxSuRen committed Nov 11, 2024
1 parent 9e4259f commit cf22768
Show file tree
Hide file tree
Showing 7 changed files with 447 additions and 414 deletions.
2 changes: 1 addition & 1 deletion console/atest-ui/src/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
"welcome": "Welcome",
"secrets": "Secrets",
"stores": "Stores",
"templateQuery": "Template Functions Query",
"functionQuery": "Functions Query",
"output": "Output"
},
"tip": {
Expand Down
2 changes: 1 addition & 1 deletion console/atest-ui/src/locales/zh.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
"secrets": "凭据",
"stores": "存储",
"parameter": "参数",
"templateQuery": "模板函数查询",
"functionQuery": "函数查询",
"output": "输出"
},
"tip": {
Expand Down
13 changes: 11 additions & 2 deletions console/atest-ui/src/views/TemplateFunctions.vue
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,13 @@ import { Magic } from './magicKeys'
const { t } = useI18n()
const functionKind = ref('template')
const dialogVisible = ref(false)
const query = ref('')
const funcs = ref([] as Pair[])
function queryFuncs() {
API.FunctionsQuery(query.value, (d) => {
API.FunctionsQuery(query.value, functionKind.value, (d) => {
funcs.value = d.data
})
}
Expand All @@ -28,12 +29,20 @@ Magic.Keys(() => {
data-intro="You can search your desired template functions.">{{ t('button.toolbox') }}</el-button>
</el-affix>

<el-dialog v-model="dialogVisible" :title="t('title.templateQuery')" width="50%" draggable destroy-on-close>
<el-dialog v-model="dialogVisible" :title="t('title.functionQuery')" width="50%" draggable destroy-on-close>
<el-input
v-model="query" placeholder="Query after enter" v-on:keyup.enter="queryFuncs">
<template #append v-if="funcs.length > 0">
{{ funcs.length }}
</template>
<template #prepend>
<el-select
v-model="functionKind"
>
<el-option label="Template" value="template" />
<el-option label="Verify" value="verify" />
</el-select>
</template>
</el-input>
<span class="dialog-footer">
<el-table :data="funcs">
Expand Down
4 changes: 2 additions & 2 deletions console/atest-ui/src/views/net.ts
Original file line number Diff line number Diff line change
Expand Up @@ -556,14 +556,14 @@ function GetSecrets(callback: (d: any) => void, errHandle?: (e: any) => void | n
.catch(emptyOrDefault(errHandle))
}

function FunctionsQuery(filter: string,
function FunctionsQuery(filter: string, kind: string,
callback: (d: any) => void, errHandle?: (e: any) => (PromiseLike<void | null | undefined> | void | null | undefined) | undefined | null) {
const requestOptions = {
headers: {
'X-Auth': getToken()
}
}
fetch(`/api/v1/functions?name=${filter}`, requestOptions)
fetch(`/api/v1/functions?name=${filter}&kind=${kind}`, requestOptions)
.then(DefaultResponseProcess)
.then(callback).catch(emptyOrDefault(errHandle))
}
Expand Down
29 changes: 21 additions & 8 deletions pkg/server/remote_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"context"
"errors"
"fmt"
"github.com/expr-lang/expr/builtin"
"io"
"mime"
"net/http"
Expand Down Expand Up @@ -1077,14 +1078,26 @@ func (s *server) FunctionsQuery(ctx context.Context, in *SimpleQuery) (reply *Pa
reply = &Pairs{}
in.Name = strings.ToLower(in.Name)

for name, fn := range render.FuncMap() {
lowerCaseName := strings.ToLower(name)
if in.Name == "" || strings.Contains(lowerCaseName, in.Name) {
reply.Data = append(reply.Data, &Pair{
Key: name,
Value: fmt.Sprintf("%v", reflect.TypeOf(fn)),
Description: render.FuncUsage(name),
})
if in.Kind == "verify" {
for _, fn := range builtin.Builtins {
lowerName := strings.ToLower(fn.Name)
if in.Name == "" || strings.Contains(lowerName, in.Name) {
reply.Data = append(reply.Data, &Pair{
Key: fn.Name,
Value: fmt.Sprintf("%v", reflect.TypeOf(fn.Func)),
})
}
}
} else {
for name, fn := range render.FuncMap() {
lowerName := strings.ToLower(name)
if in.Name == "" || strings.Contains(lowerName, in.Name) {
reply.Data = append(reply.Data, &Pair{
Key: name,
Value: fmt.Sprintf("%v", reflect.TypeOf(fn)),
Description: render.FuncUsage(name),
})
}
}
}
return
Expand Down
Loading

0 comments on commit cf22768

Please sign in to comment.