mirror of
https://github.com/grafana/grafana.git
synced 2024-11-25 10:20:29 -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 { ComponentType } from 'react';
|
||||
|
||||
import { DataQuery, QueryEditorProps } from './datasource';
|
||||
import { QueryEditorProps } from './datasource';
|
||||
import { DataFrame } from './dataFrame';
|
||||
import { DataQuery, DatasourceRef } from './query';
|
||||
|
||||
/**
|
||||
* This JSON object is stored in the dashboard json model.
|
||||
*/
|
||||
export interface AnnotationQuery<TQuery extends DataQuery = DataQuery> {
|
||||
datasource?: string | null;
|
||||
datasource?: DatasourceRef | string | null;
|
||||
|
||||
enable: boolean;
|
||||
name: string;
|
||||
iconColor: string;
|
||||
|
@ -1,5 +1,40 @@
|
||||
import { FieldConfigSource } from './fieldOverrides';
|
||||
import { DataQuery, DatasourceRef } from './query';
|
||||
|
||||
export enum DashboardCursorSync {
|
||||
Off,
|
||||
Crosshair,
|
||||
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 { ApplyFieldOverrideOptions } from './fieldOverrides';
|
||||
import { PanelPluginDataSupport } from '.';
|
||||
import { DataTopic } from './query';
|
||||
|
||||
export type KeyValue<T = any> = Record<string, T>;
|
||||
|
||||
@ -17,10 +18,6 @@ export enum LoadingState {
|
||||
Error = 'Error',
|
||||
}
|
||||
|
||||
export enum DataTopic {
|
||||
Annotations = 'annotations',
|
||||
}
|
||||
|
||||
// Should be kept in sync with grafana-plugin-sdk-go/data/frame_meta.go
|
||||
export type PreferredVisualisationType = 'graph' | 'table' | 'logs' | 'trace' | 'nodeGraph';
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
import { DataQuery } from './datasource';
|
||||
import { DataQuery } from './query';
|
||||
import { InterpolateFunction } from './panel';
|
||||
|
||||
/**
|
||||
|
@ -4,7 +4,7 @@ import { GrafanaPlugin, PluginMeta } from './plugin';
|
||||
import { PanelData } from './panel';
|
||||
import { LogRowModel } from './logs';
|
||||
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 { RawTimeRange, TimeRange } from './time';
|
||||
import { ScopedVars } from './ScopedVars';
|
||||
@ -12,6 +12,7 @@ import { CoreApp } from './app';
|
||||
import { LiveChannelSupport } from './live';
|
||||
import { CustomVariableSupport, DataSourceVariableSupport, StandardVariableSupport } from './variables';
|
||||
import { makeClassES5Compatible } from '../utils/makeClassES5Compatible';
|
||||
import { DataQuery } from './query';
|
||||
|
||||
export interface DataSourcePluginOptionsEditorProps<JSONData = DataSourceJsonData, SecureJSONData = {}> {
|
||||
options: DataSourceSettings<JSONData, SecureJSONData>;
|
||||
@ -205,6 +206,9 @@ abstract class DataSourceApi<
|
||||
this.type = instanceSettings.type;
|
||||
this.meta = {} as DataSourcePluginMeta;
|
||||
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;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 {
|
||||
Cancelled = 'cancelled',
|
||||
Timeout = 'timeout',
|
||||
|
@ -2,6 +2,7 @@ export * from './data';
|
||||
export * from './dataFrame';
|
||||
export * from './dataLink';
|
||||
export * from './dashboard';
|
||||
export * from './query';
|
||||
export * from './annotations';
|
||||
export * from './logs';
|
||||
export * from './navModel';
|
||||
|
@ -1,7 +1,7 @@
|
||||
import { Labels } from './data';
|
||||
import { DataFrame } from './dataFrame';
|
||||
import { DataQuery } from './query';
|
||||
import { AbsoluteTimeRange } from './time';
|
||||
import { DataQuery } from './datasource';
|
||||
|
||||
/**
|
||||
* Mapping of log level abbreviation to canonical log level.
|
||||
|
@ -11,6 +11,7 @@ import { StandardEditorProps } from '../field';
|
||||
import { OptionsEditorItem } from './OptionsUIRegistryBuilder';
|
||||
import { OptionEditorConfig } from './options';
|
||||
import { AlertStateInfo } from './alerts';
|
||||
import { PanelModel } from './dashboard';
|
||||
|
||||
export type InterpolateFunction = (value: string, scopedVars?: ScopedVars, format?: string | Function) => string;
|
||||
|
||||
@ -121,19 +122,6 @@ export interface PanelEditorProps<T = any> {
|
||||
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
|
||||
*/
|
||||
|
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 { DataQuery, DataSourceApi } from './datasource';
|
||||
import { DataQuery, DatasourceRef } from './query';
|
||||
import { DataSourceApi } from './datasource';
|
||||
import { PanelData } from './panel';
|
||||
import { ScopedVars } from './ScopedVars';
|
||||
import { TimeRange, TimeZone } from './time';
|
||||
@ -10,7 +11,7 @@ import { TimeRange, TimeZone } from './time';
|
||||
* @internal
|
||||
*/
|
||||
export interface QueryRunnerOptions {
|
||||
datasource: string | DataSourceApi | null;
|
||||
datasource: DatasourceRef | DataSourceApi | null;
|
||||
queries: DataQuery[];
|
||||
panelId?: number;
|
||||
dashboardId?: number;
|
||||
|
@ -1,8 +1,8 @@
|
||||
import { ComponentType } from 'react';
|
||||
import { Observable } from 'rxjs';
|
||||
import { DataQuery } from './query';
|
||||
|
||||
import {
|
||||
DataQuery,
|
||||
DataQueryRequest,
|
||||
DataQueryResponse,
|
||||
DataSourceApi,
|
||||
|
@ -17,6 +17,8 @@ import {
|
||||
PanelPluginDataSupport,
|
||||
ScopedVars,
|
||||
urlUtil,
|
||||
PanelModel as IPanelModel,
|
||||
DatasourceRef,
|
||||
} from '@grafana/data';
|
||||
import { EDIT_PANEL_ID } from 'app/core/constants';
|
||||
import config from 'app/core/config';
|
||||
@ -124,7 +126,7 @@ const defaults: any = {
|
||||
title: '',
|
||||
};
|
||||
|
||||
export class PanelModel implements DataConfigSource {
|
||||
export class PanelModel implements DataConfigSource, IPanelModel {
|
||||
/* persisted id, used in URL to identify a panel */
|
||||
id!: number;
|
||||
editSourceId?: number;
|
||||
@ -144,7 +146,7 @@ export class PanelModel implements DataConfigSource {
|
||||
panels?: any;
|
||||
declare targets: DataQuery[];
|
||||
transformations?: DataTransformerConfig[];
|
||||
datasource: string | null = null;
|
||||
datasource: DatasourceRef | null = null;
|
||||
thresholds?: any;
|
||||
pluginVersion?: string;
|
||||
|
||||
|
@ -8,6 +8,7 @@ import {
|
||||
DataQueryResponse,
|
||||
DataSourceApi,
|
||||
DataSourceInstanceSettings,
|
||||
DatasourceRef,
|
||||
isValidLiveChannelAddress,
|
||||
parseLiveChannelAddress,
|
||||
StreamingFrameOptions,
|
||||
@ -17,6 +18,7 @@ import {
|
||||
import { GrafanaAnnotationQuery, GrafanaAnnotationType, GrafanaQuery, GrafanaQueryType } from './types';
|
||||
import AnnotationQueryEditor from './components/AnnotationQueryEditor';
|
||||
import { getDashboardSrv } from '../../../features/dashboard/services/DashboardSrv';
|
||||
import { isString } from 'lodash';
|
||||
|
||||
let counter = 100;
|
||||
|
||||
@ -37,7 +39,11 @@ export class GrafanaDatasource extends DataSourceApi<GrafanaQuery> {
|
||||
return json;
|
||||
},
|
||||
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';
|
||||
|
||||
describe('Graph Panel Migrations', () => {
|
||||
@ -52,7 +52,7 @@ describe('Graph Panel Migrations', () => {
|
||||
spaceLength: 10,
|
||||
stack: false,
|
||||
steppedLine: false,
|
||||
targets: [
|
||||
targets: ([
|
||||
{
|
||||
alias: 'Foo datacenter',
|
||||
labels: 'datacenter=foo,region=us-east-1',
|
||||
@ -71,7 +71,7 @@ describe('Graph Panel Migrations', () => {
|
||||
refId: 'C',
|
||||
scenarioId: 'random_walk',
|
||||
},
|
||||
],
|
||||
] as unknown) as DataQuery[],
|
||||
thresholds: [],
|
||||
timeFrom: null,
|
||||
timeRegions: [],
|
||||
|
Loading…
Reference in New Issue
Block a user