mirror of
https://github.com/grafana/grafana.git
synced 2025-02-15 01:53:33 -06:00
* Narrow Variable editor state using selector functions - Explicitly type "extended" editor state in editor/reducter.ts using a union - Create selectors to narrow the types, using unique properties from each extended state to discriminate the union - Update DataSourceVariableEditor to use new style of redux connector - Update variable editor components to use new selectors * fix tests * Make adhoc variable infoText optional, because it is! * Add AdHocVariableEditor tests * DataSourceVariableEditor tests * comment * reset * Wrote tests for selectors \(that actually caught a bug, whodathunkit) * fix stray types and lint issues * Rename selector functions
42 lines
1.2 KiB
TypeScript
42 lines
1.2 KiB
TypeScript
import {
|
|
AdHocVariableEditorState,
|
|
DataSourceVariableEditorState,
|
|
QueryVariableEditorState,
|
|
VariableEditorState,
|
|
} from './reducer';
|
|
|
|
/**
|
|
* Narrows generic variable editor state down to specific Adhoc variable extended editor state
|
|
*/
|
|
export function getAdhocVariableEditorState(editorState: VariableEditorState): AdHocVariableEditorState | null {
|
|
if (editorState.extended && 'dataSources' in editorState.extended) {
|
|
return editorState.extended;
|
|
}
|
|
|
|
return null;
|
|
}
|
|
|
|
/**
|
|
* Narrows generic variable editor state down to specific Datasource variable extended editor state
|
|
*/
|
|
export function getDatasourceVariableEditorState(
|
|
editorState: VariableEditorState
|
|
): DataSourceVariableEditorState | null {
|
|
if (editorState.extended && 'dataSourceTypes' in editorState.extended) {
|
|
return editorState.extended;
|
|
}
|
|
|
|
return null;
|
|
}
|
|
|
|
/**
|
|
* Narrows generic variable editor state down to specific Query variable extended editor state
|
|
*/
|
|
export function getQueryVariableEditorState(editorState: VariableEditorState): QueryVariableEditorState | null {
|
|
if (editorState.extended && 'dataSource' in editorState.extended) {
|
|
return editorState.extended;
|
|
}
|
|
|
|
return null;
|
|
}
|