grafana/public/app/features/variables/adapters.ts
Hugo Häggmark 4b4afc7b2c
Chore: reduces circular dependencies for variables/utils.ts (#44087)
* Chore: move constants to own file

* Chore: moves safe* functions to grafana/data

* Chore: moves safe* functions to grafana/data

* Chore: adds VariableQueryEditorProps and deprecates VariableQueryProps

* Chore: remove getDefaultVariableAdapters function

* Chore: moves transaction status to types

* Chore: fix tests that do not initialise TemplateSrv

* Chore: change space when stringifying

* Chore: revert safe* func move

* Chore: remove circular dependency in Explore utils
2022-01-17 12:48:26 +01:00

28 lines
1.2 KiB
TypeScript

import { ComponentType } from 'react';
import { Reducer } from 'redux';
import { Registry, UrlQueryValue, VariableType } from '@grafana/data';
import { VariableModel, VariableOption } from './types';
import { VariableEditorProps } from './editor/types';
import { VariablePickerProps } from './pickers/types';
import { VariablesState } from './state/types';
export interface VariableAdapter<Model extends VariableModel> {
id: VariableType;
description: string;
name: string;
initialState: Model;
dependsOn: (variable: Model, variableToTest: Model) => boolean;
setValue: (variable: Model, option: VariableOption, emitChanges?: boolean) => Promise<void>;
setValueFromUrl: (variable: Model, urlValue: UrlQueryValue) => Promise<void>;
updateOptions: (variable: Model, searchFilter?: string) => Promise<void>;
getSaveModel: (variable: Model, saveCurrentAsDefault?: boolean) => Partial<Model>;
getValueForUrl: (variable: Model) => string | string[];
picker: ComponentType<VariablePickerProps<Model>>;
editor: ComponentType<VariableEditorProps<Model>>;
reducer: Reducer<VariablesState>;
beforeAdding?: (model: any) => any;
}
export const variableAdapters = new Registry<VariableAdapter<any>>();