mirror of
https://github.com/grafana/grafana.git
synced 2025-09-19 19:02:53 +08:00
Plugins: Support es5 plugins extending es6 core classes (#32664)
* Plugins: Support es5 plugins extending es6 core classes * Make all base classes backward compatible
This commit is contained in:
@ -11,6 +11,7 @@ import { ScopedVars } from './ScopedVars';
|
|||||||
import { CoreApp } from './app';
|
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';
|
||||||
|
|
||||||
export interface DataSourcePluginOptionsEditorProps<JSONData = DataSourceJsonData, SecureJSONData = {}> {
|
export interface DataSourcePluginOptionsEditorProps<JSONData = DataSourceJsonData, SecureJSONData = {}> {
|
||||||
options: DataSourceSettings<JSONData, SecureJSONData>;
|
options: DataSourceSettings<JSONData, SecureJSONData>;
|
||||||
@ -167,7 +168,7 @@ export interface DataSourceConstructor<
|
|||||||
* Although this is a class, datasource implementations do not *yet* need to extend it.
|
* Although this is a class, datasource implementations do not *yet* need to extend it.
|
||||||
* As such, we can not yet add functions with default implementations.
|
* As such, we can not yet add functions with default implementations.
|
||||||
*/
|
*/
|
||||||
export abstract class DataSourceApi<
|
abstract class DataSourceApi<
|
||||||
TQuery extends DataQuery = DataQuery,
|
TQuery extends DataQuery = DataQuery,
|
||||||
TOptions extends DataSourceJsonData = DataSourceJsonData
|
TOptions extends DataSourceJsonData = DataSourceJsonData
|
||||||
> {
|
> {
|
||||||
@ -631,3 +632,8 @@ export abstract class LanguageProvider {
|
|||||||
abstract start: () => Promise<Array<Promise<any>>>;
|
abstract start: () => Promise<Array<Promise<any>>>;
|
||||||
startTask?: Promise<any[]>;
|
startTask?: Promise<any[]>;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//@ts-ignore
|
||||||
|
DataSourceApi = makeClassES5Compatible(DataSourceApi);
|
||||||
|
|
||||||
|
export { DataSourceApi };
|
||||||
|
@ -17,3 +17,4 @@ export { locationUtil } from './location';
|
|||||||
export { urlUtil, UrlQueryMap, UrlQueryValue, serializeStateToUrlParam } from './url';
|
export { urlUtil, UrlQueryMap, UrlQueryValue, serializeStateToUrlParam } from './url';
|
||||||
export { DataLinkBuiltInVars, mapInternalLinkToExplore } from './dataLinks';
|
export { DataLinkBuiltInVars, mapInternalLinkToExplore } from './dataLinks';
|
||||||
export { DocsId } from './docs';
|
export { DocsId } from './docs';
|
||||||
|
export { makeClassES5Compatible } from './makeClassES5Compatible';
|
||||||
|
16
packages/grafana-data/src/utils/makeClassES5Compatible.ts
Normal file
16
packages/grafana-data/src/utils/makeClassES5Compatible.ts
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
/**
|
||||||
|
* @beta
|
||||||
|
* Proxies a ES6 class so that it can be used as a base class for an ES5 class
|
||||||
|
*/
|
||||||
|
export function makeClassES5Compatible<T>(ES6Class: T): T {
|
||||||
|
return (new Proxy(ES6Class as any, {
|
||||||
|
// ES5 code will call it like a function using super
|
||||||
|
apply(target, self, argumentsList) {
|
||||||
|
if (typeof Reflect === 'undefined' || !Reflect.construct) {
|
||||||
|
alert('Browser is too old');
|
||||||
|
}
|
||||||
|
|
||||||
|
return Reflect.construct(target, argumentsList, self.constructor);
|
||||||
|
},
|
||||||
|
}) as unknown) as T;
|
||||||
|
}
|
@ -6,6 +6,7 @@ import {
|
|||||||
DataQuery,
|
DataQuery,
|
||||||
DataSourceJsonData,
|
DataSourceJsonData,
|
||||||
ScopedVars,
|
ScopedVars,
|
||||||
|
makeClassES5Compatible,
|
||||||
} from '@grafana/data';
|
} from '@grafana/data';
|
||||||
import { Observable, of } from 'rxjs';
|
import { Observable, of } from 'rxjs';
|
||||||
import { map, catchError } from 'rxjs/operators';
|
import { map, catchError } from 'rxjs/operators';
|
||||||
@ -43,7 +44,7 @@ export interface HealthCheckResult {
|
|||||||
*
|
*
|
||||||
* @public
|
* @public
|
||||||
*/
|
*/
|
||||||
export class DataSourceWithBackend<
|
class DataSourceWithBackend<
|
||||||
TQuery extends DataQuery = DataQuery,
|
TQuery extends DataQuery = DataQuery,
|
||||||
TOptions extends DataSourceJsonData = DataSourceJsonData
|
TOptions extends DataSourceJsonData = DataSourceJsonData
|
||||||
> extends DataSourceApi<TQuery, TOptions> {
|
> extends DataSourceApi<TQuery, TOptions> {
|
||||||
@ -186,3 +187,8 @@ export class DataSourceWithBackend<
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//@ts-ignore
|
||||||
|
DataSourceWithBackend = makeClassES5Compatible(DataSourceWithBackend);
|
||||||
|
|
||||||
|
export { DataSourceWithBackend };
|
||||||
|
@ -1,8 +1,8 @@
|
|||||||
import _ from 'lodash';
|
import _ from 'lodash';
|
||||||
import { coreModule } from 'app/core/core';
|
import { coreModule } from 'app/core/core';
|
||||||
import { MetricsPanelCtrl } from 'app/plugins/sdk';
|
|
||||||
import { AnnotationEvent, dateTime } from '@grafana/data';
|
import { AnnotationEvent, dateTime } from '@grafana/data';
|
||||||
import { AnnotationsSrv } from './all';
|
import { AnnotationsSrv } from './all';
|
||||||
|
import { MetricsPanelCtrl } from '../panel/metrics_panel_ctrl';
|
||||||
|
|
||||||
export class EventEditorCtrl {
|
export class EventEditorCtrl {
|
||||||
panelCtrl: MetricsPanelCtrl;
|
panelCtrl: MetricsPanelCtrl;
|
||||||
|
@ -8,8 +8,8 @@ import {
|
|||||||
DEFAULT_ANNOTATION_COLOR,
|
DEFAULT_ANNOTATION_COLOR,
|
||||||
REGION_FILL_ALPHA,
|
REGION_FILL_ALPHA,
|
||||||
} from '@grafana/ui';
|
} from '@grafana/ui';
|
||||||
|
import { MetricsPanelCtrl } from '../panel/metrics_panel_ctrl';
|
||||||
|
|
||||||
import { MetricsPanelCtrl } from 'app/plugins/sdk';
|
|
||||||
import { AnnotationEvent } from '@grafana/data';
|
import { AnnotationEvent } from '@grafana/data';
|
||||||
|
|
||||||
export class EventManager {
|
export class EventManager {
|
||||||
|
@ -8,10 +8,10 @@ import { AngularComponent, getAngularLoader } from '@grafana/runtime';
|
|||||||
// Types
|
// Types
|
||||||
import { PanelModel, DashboardModel } from '../../state';
|
import { PanelModel, DashboardModel } from '../../state';
|
||||||
import { PanelPlugin, PanelPluginMeta } from '@grafana/data';
|
import { PanelPlugin, PanelPluginMeta } from '@grafana/data';
|
||||||
import { PanelCtrl } from 'app/plugins/sdk';
|
|
||||||
import { changePanelPlugin } from '../../state/actions';
|
import { changePanelPlugin } from '../../state/actions';
|
||||||
import { StoreState } from 'app/types';
|
import { StoreState } from 'app/types';
|
||||||
import { getSectionOpenState, saveSectionOpenState } from './state/utils';
|
import { getSectionOpenState, saveSectionOpenState } from './state/utils';
|
||||||
|
import { PanelCtrl } from 'app/features/panel/panel_ctrl';
|
||||||
|
|
||||||
interface OwnProps {
|
interface OwnProps {
|
||||||
panel: PanelModel;
|
panel: PanelModel;
|
||||||
|
@ -6,7 +6,6 @@ import './time_regions_form';
|
|||||||
import template from './template';
|
import template from './template';
|
||||||
import _ from 'lodash';
|
import _ from 'lodash';
|
||||||
|
|
||||||
import { MetricsPanelCtrl } from 'app/plugins/sdk';
|
|
||||||
import { DataProcessor } from './data_processor';
|
import { DataProcessor } from './data_processor';
|
||||||
import { axesEditorComponent } from './axes_editor';
|
import { axesEditorComponent } from './axes_editor';
|
||||||
import config from 'app/core/config';
|
import config from 'app/core/config';
|
||||||
@ -28,6 +27,7 @@ import { ThresholdMapper } from 'app/features/alerting/state/ThresholdMapper';
|
|||||||
import { getAnnotationsFromData } from 'app/features/annotations/standardAnnotationSupport';
|
import { getAnnotationsFromData } from 'app/features/annotations/standardAnnotationSupport';
|
||||||
import { appEvents } from '../../../core/core';
|
import { appEvents } from '../../../core/core';
|
||||||
import { ZoomOutEvent } from '../../../types/events';
|
import { ZoomOutEvent } from '../../../types/events';
|
||||||
|
import { MetricsPanelCtrl } from 'app/features/panel/metrics_panel_ctrl';
|
||||||
|
|
||||||
export class GraphCtrl extends MetricsPanelCtrl {
|
export class GraphCtrl extends MetricsPanelCtrl {
|
||||||
static template = template;
|
static template = template;
|
||||||
|
@ -1,7 +1,12 @@
|
|||||||
import { PanelCtrl } from 'app/features/panel/panel_ctrl';
|
import { makeClassES5Compatible } from '@grafana/data';
|
||||||
import { MetricsPanelCtrl } from 'app/features/panel/metrics_panel_ctrl';
|
|
||||||
import { QueryCtrl } from 'app/features/panel/query_ctrl';
|
|
||||||
import { alertTab } from 'app/features/alerting/AlertTabCtrl';
|
|
||||||
import { loadPluginCss } from '@grafana/runtime';
|
import { loadPluginCss } from '@grafana/runtime';
|
||||||
|
import { PanelCtrl as PanelCtrlES6 } from 'app/features/panel/panel_ctrl';
|
||||||
|
import { MetricsPanelCtrl as MetricsPanelCtrlES6 } from 'app/features/panel/metrics_panel_ctrl';
|
||||||
|
import { QueryCtrl as QueryCtrlES6 } from 'app/features/panel/query_ctrl';
|
||||||
|
import { alertTab } from 'app/features/alerting/AlertTabCtrl';
|
||||||
|
|
||||||
|
const PanelCtrl = makeClassES5Compatible(PanelCtrlES6);
|
||||||
|
const MetricsPanelCtrl = makeClassES5Compatible(MetricsPanelCtrlES6);
|
||||||
|
const QueryCtrl = makeClassES5Compatible(QueryCtrlES6);
|
||||||
|
|
||||||
export { PanelCtrl, MetricsPanelCtrl, QueryCtrl, alertTab, loadPluginCss };
|
export { PanelCtrl, MetricsPanelCtrl, QueryCtrl, alertTab, loadPluginCss };
|
||||||
|
@ -58,9 +58,11 @@ module.exports = (env = {}) =>
|
|||||||
options: {
|
options: {
|
||||||
cache: true,
|
cache: true,
|
||||||
},
|
},
|
||||||
|
memoryLimit: 4096,
|
||||||
},
|
},
|
||||||
typescript: {
|
typescript: {
|
||||||
mode: 'write-references',
|
mode: 'write-references',
|
||||||
|
memoryLimit: 4096,
|
||||||
diagnosticOptions: {
|
diagnosticOptions: {
|
||||||
semantic: true,
|
semantic: true,
|
||||||
syntactic: true,
|
syntactic: true,
|
||||||
|
Reference in New Issue
Block a user