mirror of
https://github.com/grafana/grafana.git
synced 2025-02-13 09:05:45 -06:00
* Move xss and sanitize packages to grafana-data
* Move text, url and location utils to grafana-data
* Move grafana config types to grafana-data
* Move field display value proxy to grafana-data
* Fix
* Move data links built in vars to grafana-data
* Attach links supplier to when applying field overrides
* Prep tests
* Use links suppliers attached via field overrides
* locationUtil dependencies type
* Move sanitize-url declaration to grafana-data
* Revert "Move sanitize-url declaration to grafana-data"
This reverts commit 11db9f5e55
.
* Fix typo
* fix ts vol1
* Remove import from runtime in data.... Make TS happy at the same time ;)
* Lovely TS, please shut up
* Lovely TS, please shut up vol2
* fix tests
* Fixes
* minor refactor
* Attach get links to FieldDisplayValue for seamless usage
* Update packages/grafana-data/src/field/fieldOverrides.ts
* Make storybook build
64 lines
2.4 KiB
TypeScript
64 lines
2.4 KiB
TypeScript
import { ComponentType } from 'react';
|
|
import { Reducer } from 'redux';
|
|
import { Registry, UrlQueryValue, VariableType } from '@grafana/data';
|
|
|
|
import {
|
|
AdHocVariableModel,
|
|
ConstantVariableModel,
|
|
CustomVariableModel,
|
|
DataSourceVariableModel,
|
|
IntervalVariableModel,
|
|
QueryVariableModel,
|
|
TextBoxVariableModel,
|
|
VariableModel,
|
|
VariableOption,
|
|
} from '../templating/types';
|
|
import { VariableEditorProps } from './editor/types';
|
|
import { VariablesState } from './state/variablesReducer';
|
|
import { VariablePickerProps } from './pickers/types';
|
|
import { createQueryVariableAdapter } from './query/adapter';
|
|
import { createCustomVariableAdapter } from './custom/adapter';
|
|
import { createTextBoxVariableAdapter } from './textbox/adapter';
|
|
import { createConstantVariableAdapter } from './constant/adapter';
|
|
import { createDataSourceVariableAdapter } from './datasource/adapter';
|
|
import { createIntervalVariableAdapter } from './interval/adapter';
|
|
import { createAdHocVariableAdapter } from './adhoc/adapter';
|
|
|
|
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) => Partial<Model>;
|
|
getValueForUrl: (variable: Model) => string | string[];
|
|
picker: ComponentType<VariablePickerProps>;
|
|
editor: ComponentType<VariableEditorProps>;
|
|
reducer: Reducer<VariablesState>;
|
|
}
|
|
|
|
export type VariableModels =
|
|
| QueryVariableModel
|
|
| CustomVariableModel
|
|
| TextBoxVariableModel
|
|
| ConstantVariableModel
|
|
| DataSourceVariableModel
|
|
| IntervalVariableModel
|
|
| AdHocVariableModel;
|
|
export type VariableTypeRegistry<Model extends VariableModel = VariableModel> = Registry<VariableAdapter<Model>>;
|
|
|
|
export const getDefaultVariableAdapters = () => [
|
|
createQueryVariableAdapter(),
|
|
createCustomVariableAdapter(),
|
|
createTextBoxVariableAdapter(),
|
|
createConstantVariableAdapter(),
|
|
createDataSourceVariableAdapter(),
|
|
createIntervalVariableAdapter(),
|
|
createAdHocVariableAdapter(),
|
|
];
|
|
|
|
export const variableAdapters: VariableTypeRegistry = new Registry<VariableAdapter<VariableModels>>();
|