mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Chore: define base panel type in @grafana/data (#37766)
This commit is contained in:
parent
7a8e861c1f
commit
36c798eb2f
@ -1,14 +1,16 @@
|
|||||||
import { Observable } from 'rxjs';
|
import { Observable } from 'rxjs';
|
||||||
import { ComponentType } from 'react';
|
import { ComponentType } from 'react';
|
||||||
|
|
||||||
import { DataQuery, QueryEditorProps } from './datasource';
|
import { QueryEditorProps } from './datasource';
|
||||||
import { DataFrame } from './dataFrame';
|
import { DataFrame } from './dataFrame';
|
||||||
|
import { DataQuery, DatasourceRef } from './query';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This JSON object is stored in the dashboard json model.
|
* This JSON object is stored in the dashboard json model.
|
||||||
*/
|
*/
|
||||||
export interface AnnotationQuery<TQuery extends DataQuery = DataQuery> {
|
export interface AnnotationQuery<TQuery extends DataQuery = DataQuery> {
|
||||||
datasource?: string | null;
|
datasource?: DatasourceRef | string | null;
|
||||||
|
|
||||||
enable: boolean;
|
enable: boolean;
|
||||||
name: string;
|
name: string;
|
||||||
iconColor: string;
|
iconColor: string;
|
||||||
|
@ -1,5 +1,40 @@
|
|||||||
|
import { FieldConfigSource } from './fieldOverrides';
|
||||||
|
import { DataQuery, DatasourceRef } from './query';
|
||||||
|
|
||||||
export enum DashboardCursorSync {
|
export enum DashboardCursorSync {
|
||||||
Off,
|
Off,
|
||||||
Crosshair,
|
Crosshair,
|
||||||
Tooltip,
|
Tooltip,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @public
|
||||||
|
*/
|
||||||
|
export interface PanelModel<TOptions = any, TCustomFieldConfig extends object = any> {
|
||||||
|
/** ID of the panel within the current dashboard */
|
||||||
|
id: number;
|
||||||
|
|
||||||
|
/** Panel title */
|
||||||
|
title?: string;
|
||||||
|
|
||||||
|
/** Description */
|
||||||
|
description?: string;
|
||||||
|
|
||||||
|
/** Panel options */
|
||||||
|
options: TOptions;
|
||||||
|
|
||||||
|
/** Field options configuration */
|
||||||
|
fieldConfig: FieldConfigSource<TCustomFieldConfig>;
|
||||||
|
|
||||||
|
/** Version of the panel plugin */
|
||||||
|
pluginVersion?: string;
|
||||||
|
|
||||||
|
/** The datasource used in all targets */
|
||||||
|
datasource?: DatasourceRef | null;
|
||||||
|
|
||||||
|
/** The queries in a panel */
|
||||||
|
targets?: DataQuery[];
|
||||||
|
|
||||||
|
/** alerting v1 object */
|
||||||
|
alert?: any;
|
||||||
|
}
|
||||||
|
@ -2,6 +2,7 @@ import { FieldConfig } from './dataFrame';
|
|||||||
import { DataTransformerConfig } from './transformations';
|
import { DataTransformerConfig } from './transformations';
|
||||||
import { ApplyFieldOverrideOptions } from './fieldOverrides';
|
import { ApplyFieldOverrideOptions } from './fieldOverrides';
|
||||||
import { PanelPluginDataSupport } from '.';
|
import { PanelPluginDataSupport } from '.';
|
||||||
|
import { DataTopic } from './query';
|
||||||
|
|
||||||
export type KeyValue<T = any> = Record<string, T>;
|
export type KeyValue<T = any> = Record<string, T>;
|
||||||
|
|
||||||
@ -17,10 +18,6 @@ export enum LoadingState {
|
|||||||
Error = 'Error',
|
Error = 'Error',
|
||||||
}
|
}
|
||||||
|
|
||||||
export enum DataTopic {
|
|
||||||
Annotations = 'annotations',
|
|
||||||
}
|
|
||||||
|
|
||||||
// Should be kept in sync with grafana-plugin-sdk-go/data/frame_meta.go
|
// Should be kept in sync with grafana-plugin-sdk-go/data/frame_meta.go
|
||||||
export type PreferredVisualisationType = 'graph' | 'table' | 'logs' | 'trace' | 'nodeGraph';
|
export type PreferredVisualisationType = 'graph' | 'table' | 'logs' | 'trace' | 'nodeGraph';
|
||||||
|
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
import { DataQuery } from './datasource';
|
import { DataQuery } from './query';
|
||||||
import { InterpolateFunction } from './panel';
|
import { InterpolateFunction } from './panel';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -4,7 +4,7 @@ import { GrafanaPlugin, PluginMeta } from './plugin';
|
|||||||
import { PanelData } from './panel';
|
import { PanelData } from './panel';
|
||||||
import { LogRowModel } from './logs';
|
import { LogRowModel } from './logs';
|
||||||
import { AnnotationEvent, AnnotationQuery, AnnotationSupport } from './annotations';
|
import { AnnotationEvent, AnnotationQuery, AnnotationSupport } from './annotations';
|
||||||
import { DataTopic, KeyValue, LoadingState, TableData, TimeSeries } from './data';
|
import { KeyValue, LoadingState, TableData, TimeSeries } from './data';
|
||||||
import { DataFrame, DataFrameDTO } from './dataFrame';
|
import { DataFrame, DataFrameDTO } from './dataFrame';
|
||||||
import { RawTimeRange, TimeRange } from './time';
|
import { RawTimeRange, TimeRange } from './time';
|
||||||
import { ScopedVars } from './ScopedVars';
|
import { ScopedVars } from './ScopedVars';
|
||||||
@ -12,6 +12,7 @@ import { CoreApp } from './app';
|
|||||||
import { LiveChannelSupport } from './live';
|
import { LiveChannelSupport } from './live';
|
||||||
import { CustomVariableSupport, DataSourceVariableSupport, StandardVariableSupport } from './variables';
|
import { CustomVariableSupport, DataSourceVariableSupport, StandardVariableSupport } from './variables';
|
||||||
import { makeClassES5Compatible } from '../utils/makeClassES5Compatible';
|
import { makeClassES5Compatible } from '../utils/makeClassES5Compatible';
|
||||||
|
import { DataQuery } from './query';
|
||||||
|
|
||||||
export interface DataSourcePluginOptionsEditorProps<JSONData = DataSourceJsonData, SecureJSONData = {}> {
|
export interface DataSourcePluginOptionsEditorProps<JSONData = DataSourceJsonData, SecureJSONData = {}> {
|
||||||
options: DataSourceSettings<JSONData, SecureJSONData>;
|
options: DataSourceSettings<JSONData, SecureJSONData>;
|
||||||
@ -205,6 +206,9 @@ abstract class DataSourceApi<
|
|||||||
this.type = instanceSettings.type;
|
this.type = instanceSettings.type;
|
||||||
this.meta = {} as DataSourcePluginMeta;
|
this.meta = {} as DataSourcePluginMeta;
|
||||||
this.uid = instanceSettings.uid;
|
this.uid = instanceSettings.uid;
|
||||||
|
if (!this.uid) {
|
||||||
|
this.uid = this.name; // Internal datasources do not have a UID (-- Grafana --)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -430,44 +434,6 @@ export interface DataQueryResponse {
|
|||||||
state?: LoadingState;
|
state?: LoadingState;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* These are the common properties available to all queries in all datasources
|
|
||||||
* Specific implementations will extend this interface adding the required properties
|
|
||||||
* for the given context
|
|
||||||
*/
|
|
||||||
export interface DataQuery {
|
|
||||||
/**
|
|
||||||
* A - Z
|
|
||||||
*/
|
|
||||||
refId: string;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* true if query is disabled (ie should not be returned to the dashboard)
|
|
||||||
*/
|
|
||||||
hide?: boolean;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Unique, guid like, string used in explore mode
|
|
||||||
*/
|
|
||||||
key?: string;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Specify the query flavor
|
|
||||||
*/
|
|
||||||
queryType?: string;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* The data topic results should be attached to
|
|
||||||
*/
|
|
||||||
dataTopic?: DataTopic;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* For mixed data sources the selected datasource is on the query level.
|
|
||||||
* For non mixed scenarios this is undefined.
|
|
||||||
*/
|
|
||||||
datasource?: string | null;
|
|
||||||
}
|
|
||||||
|
|
||||||
export enum DataQueryErrorType {
|
export enum DataQueryErrorType {
|
||||||
Cancelled = 'cancelled',
|
Cancelled = 'cancelled',
|
||||||
Timeout = 'timeout',
|
Timeout = 'timeout',
|
||||||
|
@ -2,6 +2,7 @@ export * from './data';
|
|||||||
export * from './dataFrame';
|
export * from './dataFrame';
|
||||||
export * from './dataLink';
|
export * from './dataLink';
|
||||||
export * from './dashboard';
|
export * from './dashboard';
|
||||||
|
export * from './query';
|
||||||
export * from './annotations';
|
export * from './annotations';
|
||||||
export * from './logs';
|
export * from './logs';
|
||||||
export * from './navModel';
|
export * from './navModel';
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
import { Labels } from './data';
|
import { Labels } from './data';
|
||||||
import { DataFrame } from './dataFrame';
|
import { DataFrame } from './dataFrame';
|
||||||
|
import { DataQuery } from './query';
|
||||||
import { AbsoluteTimeRange } from './time';
|
import { AbsoluteTimeRange } from './time';
|
||||||
import { DataQuery } from './datasource';
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Mapping of log level abbreviation to canonical log level.
|
* Mapping of log level abbreviation to canonical log level.
|
||||||
|
@ -11,6 +11,7 @@ import { StandardEditorProps } from '../field';
|
|||||||
import { OptionsEditorItem } from './OptionsUIRegistryBuilder';
|
import { OptionsEditorItem } from './OptionsUIRegistryBuilder';
|
||||||
import { OptionEditorConfig } from './options';
|
import { OptionEditorConfig } from './options';
|
||||||
import { AlertStateInfo } from './alerts';
|
import { AlertStateInfo } from './alerts';
|
||||||
|
import { PanelModel } from './dashboard';
|
||||||
|
|
||||||
export type InterpolateFunction = (value: string, scopedVars?: ScopedVars, format?: string | Function) => string;
|
export type InterpolateFunction = (value: string, scopedVars?: ScopedVars, format?: string | Function) => string;
|
||||||
|
|
||||||
@ -121,19 +122,6 @@ export interface PanelEditorProps<T = any> {
|
|||||||
data?: PanelData;
|
data?: PanelData;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface PanelModel<TOptions = any> {
|
|
||||||
/** ID of the panel within the current dashboard */
|
|
||||||
id: number;
|
|
||||||
alert?: any;
|
|
||||||
/** Panel options */
|
|
||||||
options: TOptions;
|
|
||||||
/** Field options configuration */
|
|
||||||
fieldConfig: FieldConfigSource;
|
|
||||||
/** Version of the panel plugin */
|
|
||||||
pluginVersion?: string;
|
|
||||||
scopedVars?: ScopedVars;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Called when a panel is first loaded with current panel model
|
* Called when a panel is first loaded with current panel model
|
||||||
*/
|
*/
|
||||||
|
50
packages/grafana-data/src/types/query.ts
Normal file
50
packages/grafana-data/src/types/query.ts
Normal file
@ -0,0 +1,50 @@
|
|||||||
|
/**
|
||||||
|
* Attached to query results (not persisted)
|
||||||
|
*
|
||||||
|
* @public
|
||||||
|
*/
|
||||||
|
export enum DataTopic {
|
||||||
|
Annotations = 'annotations',
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* In 8.2, this will become an interface
|
||||||
|
*
|
||||||
|
* @public
|
||||||
|
*/
|
||||||
|
export type DatasourceRef = string;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* These are the common properties available to all queries in all datasources
|
||||||
|
* Specific implementations will *extend* this interface adding the required properties
|
||||||
|
* for the given context
|
||||||
|
*
|
||||||
|
* @public
|
||||||
|
*/
|
||||||
|
export interface DataQuery {
|
||||||
|
/**
|
||||||
|
* A - Z
|
||||||
|
*/
|
||||||
|
refId: string;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* true if query is disabled (ie should not be returned to the dashboard)
|
||||||
|
*/
|
||||||
|
hide?: boolean;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Unique, guid like, string used in explore mode
|
||||||
|
*/
|
||||||
|
key?: string;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Specify the query flavor
|
||||||
|
*/
|
||||||
|
queryType?: string;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* For mixed data sources the selected datasource is on the query level.
|
||||||
|
* For non mixed scenarios this is undefined.
|
||||||
|
*/
|
||||||
|
datasource?: DatasourceRef;
|
||||||
|
}
|
@ -1,5 +1,6 @@
|
|||||||
import { Observable } from 'rxjs';
|
import { Observable } from 'rxjs';
|
||||||
import { DataQuery, DataSourceApi } from './datasource';
|
import { DataQuery, DatasourceRef } from './query';
|
||||||
|
import { DataSourceApi } from './datasource';
|
||||||
import { PanelData } from './panel';
|
import { PanelData } from './panel';
|
||||||
import { ScopedVars } from './ScopedVars';
|
import { ScopedVars } from './ScopedVars';
|
||||||
import { TimeRange, TimeZone } from './time';
|
import { TimeRange, TimeZone } from './time';
|
||||||
@ -10,7 +11,7 @@ import { TimeRange, TimeZone } from './time';
|
|||||||
* @internal
|
* @internal
|
||||||
*/
|
*/
|
||||||
export interface QueryRunnerOptions {
|
export interface QueryRunnerOptions {
|
||||||
datasource: string | DataSourceApi | null;
|
datasource: DatasourceRef | DataSourceApi | null;
|
||||||
queries: DataQuery[];
|
queries: DataQuery[];
|
||||||
panelId?: number;
|
panelId?: number;
|
||||||
dashboardId?: number;
|
dashboardId?: number;
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
import { ComponentType } from 'react';
|
import { ComponentType } from 'react';
|
||||||
import { Observable } from 'rxjs';
|
import { Observable } from 'rxjs';
|
||||||
|
import { DataQuery } from './query';
|
||||||
|
|
||||||
import {
|
import {
|
||||||
DataQuery,
|
|
||||||
DataQueryRequest,
|
DataQueryRequest,
|
||||||
DataQueryResponse,
|
DataQueryResponse,
|
||||||
DataSourceApi,
|
DataSourceApi,
|
||||||
|
@ -17,6 +17,8 @@ import {
|
|||||||
PanelPluginDataSupport,
|
PanelPluginDataSupport,
|
||||||
ScopedVars,
|
ScopedVars,
|
||||||
urlUtil,
|
urlUtil,
|
||||||
|
PanelModel as IPanelModel,
|
||||||
|
DatasourceRef,
|
||||||
} from '@grafana/data';
|
} from '@grafana/data';
|
||||||
import { EDIT_PANEL_ID } from 'app/core/constants';
|
import { EDIT_PANEL_ID } from 'app/core/constants';
|
||||||
import config from 'app/core/config';
|
import config from 'app/core/config';
|
||||||
@ -124,7 +126,7 @@ const defaults: any = {
|
|||||||
title: '',
|
title: '',
|
||||||
};
|
};
|
||||||
|
|
||||||
export class PanelModel implements DataConfigSource {
|
export class PanelModel implements DataConfigSource, IPanelModel {
|
||||||
/* persisted id, used in URL to identify a panel */
|
/* persisted id, used in URL to identify a panel */
|
||||||
id!: number;
|
id!: number;
|
||||||
editSourceId?: number;
|
editSourceId?: number;
|
||||||
@ -144,7 +146,7 @@ export class PanelModel implements DataConfigSource {
|
|||||||
panels?: any;
|
panels?: any;
|
||||||
declare targets: DataQuery[];
|
declare targets: DataQuery[];
|
||||||
transformations?: DataTransformerConfig[];
|
transformations?: DataTransformerConfig[];
|
||||||
datasource: string | null = null;
|
datasource: DatasourceRef | null = null;
|
||||||
thresholds?: any;
|
thresholds?: any;
|
||||||
pluginVersion?: string;
|
pluginVersion?: string;
|
||||||
|
|
||||||
|
@ -8,6 +8,7 @@ import {
|
|||||||
DataQueryResponse,
|
DataQueryResponse,
|
||||||
DataSourceApi,
|
DataSourceApi,
|
||||||
DataSourceInstanceSettings,
|
DataSourceInstanceSettings,
|
||||||
|
DatasourceRef,
|
||||||
isValidLiveChannelAddress,
|
isValidLiveChannelAddress,
|
||||||
parseLiveChannelAddress,
|
parseLiveChannelAddress,
|
||||||
StreamingFrameOptions,
|
StreamingFrameOptions,
|
||||||
@ -17,6 +18,7 @@ import {
|
|||||||
import { GrafanaAnnotationQuery, GrafanaAnnotationType, GrafanaQuery, GrafanaQueryType } from './types';
|
import { GrafanaAnnotationQuery, GrafanaAnnotationType, GrafanaQuery, GrafanaQueryType } from './types';
|
||||||
import AnnotationQueryEditor from './components/AnnotationQueryEditor';
|
import AnnotationQueryEditor from './components/AnnotationQueryEditor';
|
||||||
import { getDashboardSrv } from '../../../features/dashboard/services/DashboardSrv';
|
import { getDashboardSrv } from '../../../features/dashboard/services/DashboardSrv';
|
||||||
|
import { isString } from 'lodash';
|
||||||
|
|
||||||
let counter = 100;
|
let counter = 100;
|
||||||
|
|
||||||
@ -37,7 +39,11 @@ export class GrafanaDatasource extends DataSourceApi<GrafanaQuery> {
|
|||||||
return json;
|
return json;
|
||||||
},
|
},
|
||||||
prepareQuery(anno: AnnotationQuery<GrafanaAnnotationQuery>): GrafanaQuery {
|
prepareQuery(anno: AnnotationQuery<GrafanaAnnotationQuery>): GrafanaQuery {
|
||||||
return { ...anno, refId: anno.name, queryType: GrafanaQueryType.Annotations };
|
let datasource: DatasourceRef | undefined | null = undefined;
|
||||||
|
if (isString(anno.datasource)) {
|
||||||
|
datasource = anno.datasource as DatasourceRef;
|
||||||
|
}
|
||||||
|
return { ...anno, refId: anno.name, queryType: GrafanaQueryType.Annotations, datasource };
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
import { PanelModel, FieldConfigSource } from '@grafana/data';
|
import { PanelModel, FieldConfigSource, DataQuery } from '@grafana/data';
|
||||||
import { graphPanelMigrationHandler } from './GraphMigrations';
|
import { graphPanelMigrationHandler } from './GraphMigrations';
|
||||||
|
|
||||||
describe('Graph Panel Migrations', () => {
|
describe('Graph Panel Migrations', () => {
|
||||||
@ -52,7 +52,7 @@ describe('Graph Panel Migrations', () => {
|
|||||||
spaceLength: 10,
|
spaceLength: 10,
|
||||||
stack: false,
|
stack: false,
|
||||||
steppedLine: false,
|
steppedLine: false,
|
||||||
targets: [
|
targets: ([
|
||||||
{
|
{
|
||||||
alias: 'Foo datacenter',
|
alias: 'Foo datacenter',
|
||||||
labels: 'datacenter=foo,region=us-east-1',
|
labels: 'datacenter=foo,region=us-east-1',
|
||||||
@ -71,7 +71,7 @@ describe('Graph Panel Migrations', () => {
|
|||||||
refId: 'C',
|
refId: 'C',
|
||||||
scenarioId: 'random_walk',
|
scenarioId: 'random_walk',
|
||||||
},
|
},
|
||||||
],
|
] as unknown) as DataQuery[],
|
||||||
thresholds: [],
|
thresholds: [],
|
||||||
timeFrom: null,
|
timeFrom: null,
|
||||||
timeRegions: [],
|
timeRegions: [],
|
||||||
|
Loading…
Reference in New Issue
Block a user