mirror of https://github.com/grafana/grafana.git
with selectable fields
This commit is contained in:
parent
a24398a876
commit
b5857ea669
|
@ -13,6 +13,9 @@ correlationsv0alpha1: {
|
|||
type: CorrelationType
|
||||
}
|
||||
}
|
||||
selectableFields: [
|
||||
"spec.datasource.name"
|
||||
]
|
||||
}
|
||||
|
||||
DataSourceRef: {
|
||||
|
|
|
@ -5,13 +5,25 @@
|
|||
package v0alpha1
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/grafana/grafana-app-sdk/resource"
|
||||
)
|
||||
|
||||
// schema is unexported to prevent accidental overwrites
|
||||
var (
|
||||
schemaCorrelation = resource.NewSimpleSchema("correlations.grafana.app", "v0alpha1", &Correlation{}, &CorrelationList{}, resource.WithKind("Correlation"),
|
||||
resource.WithPlural("correlations"), resource.WithScope(resource.NamespacedScope))
|
||||
resource.WithPlural("correlations"), resource.WithScope(resource.NamespacedScope), resource.WithSelectableFields([]resource.SelectableField{{
|
||||
FieldSelector: "spec.datasource.name",
|
||||
FieldValueFunc: func(o resource.Object) (string, error) {
|
||||
cast, ok := o.(*Correlation)
|
||||
if !ok {
|
||||
return "", fmt.Errorf("provided object must be of type *Correlation")
|
||||
}
|
||||
return cast.Spec.Datasource.Name, nil
|
||||
},
|
||||
},
|
||||
}))
|
||||
kindCorrelation = resource.Kind{
|
||||
Schema: schemaCorrelation,
|
||||
Codecs: map[resource.KindEncoding]resource.Codec{
|
||||
|
|
|
@ -39,6 +39,9 @@ var appManifestData = app.ManifestData{
|
|||
Scope: "Namespaced",
|
||||
Conversion: false,
|
||||
Schema: &versionSchemaCorrelationv0alpha1,
|
||||
SelectableFields: []string{
|
||||
"spec.datasource.name",
|
||||
},
|
||||
},
|
||||
},
|
||||
Routes: app.ManifestVersionRoutes{
|
||||
|
|
|
@ -65,12 +65,12 @@ func (s *legacyStorage) List(ctx context.Context, options *internalversion.ListO
|
|||
if options.FieldSelector != nil {
|
||||
for _, r := range options.FieldSelector.Requirements() {
|
||||
switch r.Field {
|
||||
case "spec.datasource":
|
||||
case "spec.datasource.name":
|
||||
switch r.Operator {
|
||||
case selection.Equals, selection.DoubleEquals:
|
||||
uids = []string{r.Value}
|
||||
case selection.In:
|
||||
uids = strings.Split(r.Value, ";")
|
||||
uids = strings.Split(r.Value, ";") // ??? not sure how/if this supports multiple values
|
||||
default:
|
||||
return nil, fmt.Errorf("unsupported operation")
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue