Skip to content

Commit

Permalink
Schema: Clean up dashboard variables schema (grafana#76121)
Browse files Browse the repository at this point in the history
* Cleanup variable schema model

* minor fix

* remove type ignores that are no longer type errors
  • Loading branch information
torkelo authored Oct 9, 2023
1 parent 69142bf commit fc0933d
Show file tree
Hide file tree
Showing 18 changed files with 120 additions and 113 deletions.
31 changes: 15 additions & 16 deletions docs/sources/developers/kinds/core/dashboard/schema-reference.md

Large diffs are not rendered by default.

14 changes: 4 additions & 10 deletions kinds/dashboard/dashboard_kind.cue
Original file line number Diff line number Diff line change
Expand Up @@ -183,33 +183,31 @@ lineage: schemas: [{

// A variable is a placeholder for a value. You can use variables in metric queries and in panel titles.
#VariableModel: {
// Unique numeric identifier for the variable.
id: string | *"00000000-0000-0000-0000-000000000000"
// Type of variable
type: #VariableType
// Name of variable
name: string
// Optional display name
label?: string
// Visibility configuration for the variable
hide: #VariableHide
hide?: #VariableHide
// Whether the variable value should be managed by URL query params or not
skipUrlSync: bool | *false
skipUrlSync?: bool | *false
// Description of variable. It can be defined but `null`.
description?: string
// Query used to fetch values for a variable
query?: string | {...}
// Data source used to fetch values for a variable. It can be defined but `null`.
datasource?: #DataSourceRef
// Format to use while fetching all values from data source, eg: wildcard, glob, regex, pipe, etc.
allFormat?: string
// Shows current selected variable text/value on the dashboard
current?: #VariableOption
// Whether multiple values can be selected or not from variable value list
multi?: bool | *false
// Options that can be selected for a variable.
options?: [...#VariableOption]
refresh?: #VariableRefresh
// Options sort order
sort?: #VariableSort
...
} @cuetsy(kind="interface") @grafana(TSVeneer="type") @grafanamaturity(NeedsExpertReview)

Expand Down Expand Up @@ -244,10 +242,6 @@ lineage: schemas: [{
// `6`: Alphabetical Case Insensitive DESC
#VariableSort: 0 | 1 | 2 | 3 | 4 | 5 | 6 @cuetsy(kind="enum",memberNames="disabled|alphabeticalAsc|alphabeticalDesc|numericalAsc|numericalDesc|alphabeticalCaseInsensitiveAsc|alphabeticalCaseInsensitiveDesc")

// Loading status
// Accepted values are `NotStarted` (the request is not started), `Loading` (waiting for response), `Streaming` (pulling continuous data), `Done` (response received successfully) or `Error` (failed request).
#LoadingState: "NotStarted" | "Loading" | "Streaming" | "Done" | "Error" @cuetsy(kind="enum")

// Ref to a DataSource instance
#DataSourceRef: {
// The plugin type-id
Expand Down
1 change: 0 additions & 1 deletion packages/grafana-schema/src/index.gen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ export {
defaultAnnotationPanelFilter,
VariableRefresh,
VariableSort,
LoadingState,
defaultDashboardLink,
FieldColorModeId,
defaultGridPos,
Expand Down
29 changes: 6 additions & 23 deletions packages/grafana-schema/src/raw/dashboard/x/dashboard_types.gen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,10 +121,6 @@ export const defaultAnnotationQuery: Partial<AnnotationQuery> = {
* A variable is a placeholder for a value. You can use variables in metric queries and in panel titles.
*/
export interface VariableModel {
/**
* Format to use while fetching all values from data source, eg: wildcard, glob, regex, pipe, etc.
*/
allFormat?: string;
/**
* Shows current selected variable text/value on the dashboard
*/
Expand All @@ -140,11 +136,7 @@ export interface VariableModel {
/**
* Visibility configuration for the variable
*/
hide: VariableHide;
/**
* Unique numeric identifier for the variable.
*/
id: string;
hide?: VariableHide;
/**
* Optional display name
*/
Expand All @@ -169,15 +161,18 @@ export interface VariableModel {
/**
* Whether the variable value should be managed by URL query params or not
*/
skipUrlSync: boolean;
skipUrlSync?: boolean;
/**
* Options sort order
*/
sort?: VariableSort;
/**
* Type of variable
*/
type: VariableType;
}

export const defaultVariableModel: Partial<VariableModel> = {
id: '00000000-0000-0000-0000-000000000000',
multi: false,
options: [],
skipUrlSync: false,
Expand Down Expand Up @@ -244,18 +239,6 @@ export enum VariableSort {
numericalDesc = 4,
}

/**
* Loading status
* Accepted values are `NotStarted` (the request is not started), `Loading` (waiting for response), `Streaming` (pulling continuous data), `Done` (response received successfully) or `Error` (failed request).
*/
export enum LoadingState {
Done = 'Done',
Error = 'Error',
Loading = 'Loading',
NotStarted = 'NotStarted',
Streaming = 'Streaming',
}

/**
* Ref to a DataSource instance
*/
Expand Down
12 changes: 12 additions & 0 deletions packages/grafana-schema/src/veneer/common.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,15 @@ export const defaultTableFieldOptions: raw.TableFieldOptions = {
type: raw.TableCellDisplayMode.Auto,
},
};

/**
* Represent panel data loading state.
* @deprecated Please use LoadingState from @grafana/data
*/
export enum LoadingState {
NotStarted = 'NotStarted',
Loading = 'Loading',
Streaming = 'Streaming',
Done = 'Done',
Error = 'Error',
}
9 changes: 2 additions & 7 deletions packages/grafana-schema/src/veneer/dashboard.types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,8 @@ export enum VariableHide {
hideVariable,
}

export interface VariableModel extends Omit<raw.VariableModel, 'hide' | 'description' | 'datasource'> {
hide: VariableHide;
description?: string | null;
datasource: DataSourceRef | null;
export interface VariableModel extends Omit<raw.VariableModel, 'datasource'> {
datasource?: DataSourceRef | null;
}

export interface Dashboard extends Omit<raw.Dashboard, 'templating' | 'annotations' | 'panels'> {
Expand Down Expand Up @@ -63,9 +61,6 @@ export interface DataTransformerConfig<TOptions = any> extends raw.DataTransform
export const defaultDashboard = raw.defaultDashboard as Dashboard;
export const defaultVariableModel = {
...raw.defaultVariableModel,
description: null,
hide: VariableHide.dontHide,
datasource: null,
} as VariableModel;
export const defaultPanel: Partial<Panel> = raw.defaultPanel;
export const defaultRowPanel: Partial<Panel> = raw.defaultRowPanel;
Expand Down
43 changes: 35 additions & 8 deletions pkg/kinds/dashboard/dashboard_spec_gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ import { css } from '@emotion/css';
import React, { FC, useEffect, useState } from 'react';
import { useAsync } from 'react-use';

import { PanelData, CoreApp, GrafanaTheme2 } from '@grafana/data';
import { PanelData, CoreApp, GrafanaTheme2, LoadingState } from '@grafana/data';
import { getDataSourceSrv } from '@grafana/runtime';
import { DataQuery, LoadingState } from '@grafana/schema';
import { DataQuery } from '@grafana/schema';
import { useStyles2 } from '@grafana/ui';
import { getTimeSrv } from 'app/features/dashboard/services/TimeSrv';
import { AlertQuery } from 'app/types/unified-alerting-dto';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,15 @@
import { xor } from 'lodash';
import { ValidateResult } from 'react-hook-form';

import { DataFrame, ThresholdsConfig, ThresholdsMode, isTimeSeriesFrames, PanelData } from '@grafana/data';
import { GraphTresholdsStyleMode, LoadingState } from '@grafana/schema';
import {
DataFrame,
ThresholdsConfig,
ThresholdsMode,
isTimeSeriesFrames,
PanelData,
LoadingState,
} from '@grafana/data';
import { GraphTresholdsStyleMode } from '@grafana/schema';
import { config } from 'app/core/config';
import { EvalFunction } from 'app/features/alerting/state/alertDef';
import { isExpressionQuery } from 'app/features/expressions/guards';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { map, of } from 'rxjs';

import { DataSourceApi, DataQueryRequest, PanelData } from '@grafana/data';
import { LoadingState } from '@grafana/schema';
import { DataSourceApi, DataQueryRequest, PanelData, LoadingState } from '@grafana/data';
import { PublicAnnotationsDataSource } from 'app/features/query/state/DashboardQueryRunner/PublicAnnotationsDataSource';

import { DashboardAnnotationsDataLayer } from './DashboardAnnotationsDataLayer';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
import { AnnotationEvent, arrayToDataFrame, DataTopic, getDefaultTimeRange, PanelData } from '@grafana/data';
import {
AnnotationEvent,
arrayToDataFrame,
DataTopic,
getDefaultTimeRange,
PanelData,
LoadingState,
} from '@grafana/data';
import { config } from '@grafana/runtime';
import { dataLayers } from '@grafana/scenes';
import { AnnotationQuery, LoadingState } from '@grafana/schema';
import { AnnotationQuery } from '@grafana/schema';
import { PublicAnnotationsDataSource } from 'app/features/query/state/DashboardQueryRunner/PublicAnnotationsDataSource';

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { Observable, ReplaySubject, Unsubscribable } from 'rxjs';

import { getDefaultTimeRange } from '@grafana/data';
import { getDefaultTimeRange, LoadingState } from '@grafana/data';
import {
SceneDataProvider,
SceneDataProviderResult,
Expand All @@ -10,7 +10,6 @@ import {
SceneObject,
SceneObjectBase,
} from '@grafana/scenes';
import { LoadingState } from '@grafana/schema';
import { DashboardQuery } from 'app/plugins/datasource/dashboard/types';

import { getVizPanelKeyForPanelId } from '../utils/utils';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { LoadingState } from '@grafana/data';
import { getPanelPlugin } from '@grafana/data/test/__mocks__/pluginMocks';
import { config } from '@grafana/runtime';
import {
Expand All @@ -14,7 +15,7 @@ import {
SceneQueryRunner,
VizPanel,
} from '@grafana/scenes';
import { DashboardCursorSync, defaultDashboard, LoadingState, Panel, RowPanel, VariableType } from '@grafana/schema';
import { DashboardCursorSync, defaultDashboard, Panel, RowPanel, VariableType } from '@grafana/schema';
import { DashboardModel, PanelModel } from 'app/features/dashboard/state';
import { createPanelJSONFixture } from 'app/features/dashboard/state/__fixtures__/dashboardFixtures';
import { SHARED_DASHBOARD_QUERY } from 'app/plugins/datasource/dashboard';
Expand Down
Loading

0 comments on commit fc0933d

Please sign in to comment.