adapters.ts 1.2 KB

12345678910111213141516171819202122232425262728
  1. import { ComponentType } from 'react';
  2. import { Reducer } from 'redux';
  3. import { Registry, UrlQueryValue, VariableType } from '@grafana/data';
  4. import { VariableEditorProps } from './editor/types';
  5. import { VariablePickerProps } from './pickers/types';
  6. import { VariablesState } from './state/types';
  7. import { VariableModel, VariableOption } from './types';
  8. export interface VariableAdapter<Model extends VariableModel> {
  9. id: VariableType;
  10. description: string;
  11. name: string;
  12. initialState: Model;
  13. dependsOn: (variable: Model, variableToTest: Model) => boolean;
  14. setValue: (variable: Model, option: VariableOption, emitChanges?: boolean) => Promise<void>;
  15. setValueFromUrl: (variable: Model, urlValue: UrlQueryValue) => Promise<void>;
  16. updateOptions: (variable: Model, searchFilter?: string) => Promise<void>;
  17. getSaveModel: (variable: Model, saveCurrentAsDefault?: boolean) => Partial<Model>;
  18. getValueForUrl: (variable: Model) => string | string[];
  19. picker: ComponentType<VariablePickerProps<Model>>;
  20. editor: ComponentType<VariableEditorProps<Model>>;
  21. reducer: Reducer<VariablesState>;
  22. beforeAdding?: (model: any) => any;
  23. }
  24. export const variableAdapters = new Registry<VariableAdapter<any>>();