From 6ebf49a383d31e6da9c9f03d97004eaac6bcb16f Mon Sep 17 00:00:00 2001 From: Collin Fingar Date: Fri, 9 May 2025 12:46:19 -0400 Subject: [PATCH] QueryLibrary: Added IsVisibility property to Query data (#104579) * QueryLibrary: Added IsVisibility property to Query data * Added asserts for unit test * generated openapi changes --- pkg/apis/query/v0alpha1/template/types.go | 3 + .../query/v0alpha1/zz_generated.openapi.go | 7 ++ .../features/explore/spec/helper/assert.ts | 11 +++ .../spec/helper/testdata/testQueryList.ts | 68 +++++++++++++++++++ 4 files changed, 89 insertions(+) diff --git a/pkg/apis/query/v0alpha1/template/types.go b/pkg/apis/query/v0alpha1/template/types.go index 07ef8949336..4ab0170fa89 100644 --- a/pkg/apis/query/v0alpha1/template/types.go +++ b/pkg/apis/query/v0alpha1/template/types.go @@ -14,6 +14,9 @@ type QueryTemplate struct { // Longer description for why it is interesting Description string `json:"description,omitempty"` + // Toggle for visible/hidden queries + IsVisible bool `json:"isVisible,omitempty"` + // The variables that can be used to render // +listType=map // +listMapKey=key diff --git a/pkg/apis/query/v0alpha1/zz_generated.openapi.go b/pkg/apis/query/v0alpha1/zz_generated.openapi.go index fafe2ffc26e..bfb8e1ea075 100644 --- a/pkg/apis/query/v0alpha1/zz_generated.openapi.go +++ b/pkg/apis/query/v0alpha1/zz_generated.openapi.go @@ -400,6 +400,13 @@ func schema_apis_query_v0alpha1_template_QueryTemplate(ref common.ReferenceCallb Format: "", }, }, + "isVisible": { + SchemaProps: spec.SchemaProps{ + Description: "Toggle for visible/hidden queries", + Type: []string{"boolean"}, + Format: "", + }, + }, "vars": { VendorExtensible: spec.VendorExtensible{ Extensions: spec.Extensions{ diff --git a/public/app/features/explore/spec/helper/assert.ts b/public/app/features/explore/spec/helper/assert.ts index 9046747e7fa..84da5c925ba 100644 --- a/public/app/features/explore/spec/helper/assert.ts +++ b/public/app/features/explore/spec/helper/assert.ts @@ -33,6 +33,17 @@ export const assertQueryLibraryTemplateExists = async (datasource: string, descr }); }; +export const assertQueryLibraryTemplateDoesNotExists = async (description: string) => { + const selector = withinQueryLibrary(); + await waitFor(() => { + const cell = selector.queryByRole('radio', { + name: description, + }); + + expect(cell).not.toBeInTheDocument(); + }); +}; + export const assertAddToQueryLibraryButtonExists = async (value = true) => { await waitFor(() => { // ensures buttons for the card have been loaded to avoid false positives diff --git a/public/app/features/explore/spec/helper/testdata/testQueryList.ts b/public/app/features/explore/spec/helper/testdata/testQueryList.ts index 7a730bb2c6c..0f5d634490f 100644 --- a/public/app/features/explore/spec/helper/testdata/testQueryList.ts +++ b/public/app/features/explore/spec/helper/testdata/testQueryList.ts @@ -120,5 +120,73 @@ export const getTestQueryList = () => ({ ], }, }, + { + kind: 'QueryTemplate', + apiVersion: 'querylibrary.grafana.app/v0alpha1', + metadata: { + name: 'ALoki296tj', + generateName: 'ALoki', + namespace: 'default', + uid: '3e71de65-efa7-40e3-8f23-124212cca456', + resourceVersion: '1783214217151647744', + creationTimestamp: '2024-04-25T11:05:55Z', + annotations: { 'grafana.app/createdBy': 'user:u000000002' }, + }, + spec: { + title: 'Loki Query Template Hidden', + isVisible: false, + vars: [ + { + key: '__value', + defaultValues: [''], + valueListDefinition: { + customValues: '', + }, + }, + ], + targets: [ + { + variables: { + __value: [ + { + path: '$.datasource.jsonData.derivedFields.0.url', + position: { + start: 0, + end: 14, + }, + format: 'raw', + }, + { + path: '$.datasource.jsonData.derivedFields.1.url', + position: { + start: 0, + end: 14, + }, + format: 'raw', + }, + { + path: '$.datasource.jsonData.derivedFields.2.url', + position: { + start: 0, + end: 14, + }, + format: 'raw', + }, + ], + }, + properties: { + refId: 'A', + datasource: { + type: 'loki', + uid: 'loki-uid', + }, + queryType: 'range', + editorMode: 'code', + expr: '{test="test"}', + }, + }, + ], + }, + }, ], });