console/filter: add filtering support for custom columns

Some of the code is based on #870.
This commit is contained in:
Vincent Bernat
2023-09-16 17:18:57 +02:00
parent e3fdd6bcc8
commit 6dc0b512c6
10 changed files with 152 additions and 117 deletions

View File

@@ -6,6 +6,7 @@ package console
import (
"fmt"
"net/http"
"sort"
"strconv"
"strings"
@@ -84,21 +85,22 @@ func (c *Component) filterCompleteHandlerFunc(gc *gin.Context) {
completions := []filterCompletion{}
switch input.What {
case "column":
_, err := filter.Parse("", []byte{},
filter.Entrypoint("ConditionExpr"), filter.GlobalStore("meta", &filter.Meta{Schema: c.d.Schema}))
if err != nil {
for _, candidate := range filter.Expected(err) {
if !strings.HasSuffix(candidate, `"i`) {
continue
}
candidate = candidate[1 : len(candidate)-2]
if column, ok := c.d.Schema.LookupColumnByName(candidate); ok && !column.Disabled {
completions = append(completions, filterCompletion{
Label: candidate,
Detail: "column name",
})
}
// We use the schema directly.
columns := []string{}
for _, column := range c.d.Schema.Columns() {
if column.Disabled {
continue
}
if strings.HasPrefix(strings.ToLower(column.Name), strings.ToLower(input.Prefix)) {
columns = append(columns, column.Name)
}
}
sort.Strings(columns)
for _, column := range columns {
completions = append(completions, filterCompletion{
Label: column,
Detail: "column name",
})
}
case "operator":
_, err := filter.Parse("",