|
@@ -26,9 +26,18 @@ export interface PanelEditorProps<T = any> {
|
|
|
onOptionsChange: (options: T) => void;
|
|
onOptionsChange: (options: T) => void;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+/**
|
|
|
|
|
+ * Checks the existing model before the component is loaded
|
|
|
|
|
+ * This is useful for fixing options as configuration changes
|
|
|
|
|
+ * The object passed in is the panel model.... but not typed
|
|
|
|
|
+ * since that is not in grafana ui
|
|
|
|
|
+ */
|
|
|
|
|
+export type PanelOptionsValidator<T = any> = (panelModel: any) => T;
|
|
|
|
|
+
|
|
|
export class ReactPanelPlugin<TOptions = any> {
|
|
export class ReactPanelPlugin<TOptions = any> {
|
|
|
panel: ComponentClass<PanelProps<TOptions>>;
|
|
panel: ComponentClass<PanelProps<TOptions>>;
|
|
|
editor?: ComponentClass<PanelEditorProps<TOptions>>;
|
|
editor?: ComponentClass<PanelEditorProps<TOptions>>;
|
|
|
|
|
+ optionsValidator?: PanelOptionsValidator<TOptions>;
|
|
|
defaults?: TOptions;
|
|
defaults?: TOptions;
|
|
|
|
|
|
|
|
constructor(panel: ComponentClass<PanelProps<TOptions>>) {
|
|
constructor(panel: ComponentClass<PanelProps<TOptions>>) {
|
|
@@ -39,6 +48,10 @@ export class ReactPanelPlugin<TOptions = any> {
|
|
|
this.editor = editor;
|
|
this.editor = editor;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ setOptionsValidator(validator: PanelOptionsValidator<TOptions>) {
|
|
|
|
|
+ this.optionsValidator = validator;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
setDefaults(defaults: TOptions) {
|
|
setDefaults(defaults: TOptions) {
|
|
|
this.defaults = defaults;
|
|
this.defaults = defaults;
|
|
|
}
|
|
}
|