mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Variables: breaks variable.ts into 2 separate files utils and types (#22884)
This commit is contained in:
parent
7d9b6a0dee
commit
05b6d38374
@ -9,7 +9,7 @@ import { e2e } from '@grafana/e2e';
|
||||
|
||||
import coreModule from '../core_module';
|
||||
import { GrafanaRootScope } from 'app/routes/GrafanaCtrl';
|
||||
import { containsSearchFilter } from '../../features/templating/variable';
|
||||
import { containsSearchFilter } from '../../features/templating/utils';
|
||||
|
||||
export class ValueSelectDropdownCtrl {
|
||||
dropdownVisible: any;
|
||||
|
@ -2,7 +2,7 @@ import React, { PureComponent } from 'react';
|
||||
import { connect, MapStateToProps } from 'react-redux';
|
||||
import { StoreState } from '../../../../types';
|
||||
import { getVariableClones } from '../../../variables/state/selectors';
|
||||
import { VariableHide, VariableModel } from '../../../templating/variable';
|
||||
import { VariableHide, VariableModel } from '../../../templating/types';
|
||||
import { DashboardModel } from '../../state';
|
||||
import { AngularDashboardLinks } from './AngularDashboardLinks';
|
||||
import { Annotations } from './Annotations';
|
||||
|
@ -1,5 +1,5 @@
|
||||
import React, { FunctionComponent, useEffect, useState } from 'react';
|
||||
import { VariableHide, VariableModel } from '../../../templating/variable';
|
||||
import { VariableHide, VariableModel } from '../../../templating/types';
|
||||
import { e2e } from '@grafana/e2e';
|
||||
import { PickerRenderer } from '../../../variables/pickers/PickerRenderer';
|
||||
|
||||
|
@ -13,7 +13,7 @@ import { DashboardMigrator } from './DashboardMigrator';
|
||||
import { AppEvent, dateTime, DateTimeInput, isDateTime, PanelEvents, TimeRange, TimeZone, toUtc } from '@grafana/data';
|
||||
import { UrlQueryValue } from '@grafana/runtime';
|
||||
import { CoreEvents, DashboardMeta, KIOSK_MODE_TV } from 'app/types';
|
||||
import { VariableModel } from '../../templating/variable';
|
||||
import { VariableModel } from '../../templating/types';
|
||||
import { getConfig } from '../../../core/config';
|
||||
import { getVariableClones, getVariables } from 'app/features/variables/state/selectors';
|
||||
import { variableAdapters } from 'app/features/variables/adapters';
|
||||
|
@ -6,7 +6,7 @@ import {
|
||||
VariableOption,
|
||||
VariableType,
|
||||
variableTypes,
|
||||
} from './variable';
|
||||
} from './types';
|
||||
import { VariableSrv } from './variable_srv';
|
||||
|
||||
export class TextBoxVariable implements TextBoxVariableModel, VariableActions {
|
||||
|
@ -7,7 +7,7 @@ import {
|
||||
VariableHide,
|
||||
VariableType,
|
||||
variableTypes,
|
||||
} from './variable';
|
||||
} from './types';
|
||||
|
||||
export class AdhocVariable implements AdHocVariableModel, VariableActions {
|
||||
type: VariableType;
|
||||
|
@ -6,7 +6,7 @@ import {
|
||||
VariableOption,
|
||||
VariableType,
|
||||
variableTypes,
|
||||
} from './variable';
|
||||
} from './types';
|
||||
import { VariableSrv } from './all';
|
||||
|
||||
export class ConstantVariable implements ConstantVariableModel, VariableActions {
|
||||
|
@ -7,7 +7,7 @@ import {
|
||||
VariableOption,
|
||||
VariableType,
|
||||
variableTypes,
|
||||
} from './variable';
|
||||
} from './types';
|
||||
import { VariableSrv } from './variable_srv';
|
||||
|
||||
export class CustomVariable implements CustomVariableModel, VariableActions {
|
||||
|
@ -1,6 +1,5 @@
|
||||
import {
|
||||
assignModelProperties,
|
||||
containsVariable,
|
||||
DataSourceVariableModel,
|
||||
VariableActions,
|
||||
VariableHide,
|
||||
@ -8,12 +7,13 @@ import {
|
||||
VariableRefresh,
|
||||
VariableType,
|
||||
variableTypes,
|
||||
} from './variable';
|
||||
} from './types';
|
||||
import { stringToJsRegex } from '@grafana/data';
|
||||
import { VariableSrv } from './variable_srv';
|
||||
import { TemplateSrv } from './template_srv';
|
||||
import { DatasourceSrv } from '../plugins/datasource_srv';
|
||||
import { config } from '@grafana/runtime';
|
||||
import { containsVariable } from './utils';
|
||||
|
||||
export class DatasourceVariable implements DataSourceVariableModel, VariableActions {
|
||||
type: VariableType;
|
||||
|
@ -3,7 +3,7 @@ import { AppEvents } from '@grafana/data';
|
||||
import { e2e } from '@grafana/e2e';
|
||||
|
||||
import coreModule from 'app/core/core_module';
|
||||
import { variableTypes } from './variable';
|
||||
import { variableTypes } from './types';
|
||||
import appEvents from 'app/core/app_events';
|
||||
import DatasourceSrv from '../plugins/datasource_srv';
|
||||
import { VariableSrv } from './all';
|
||||
|
@ -9,7 +9,7 @@ import {
|
||||
VariableRefresh,
|
||||
VariableType,
|
||||
variableTypes,
|
||||
} from './variable';
|
||||
} from './types';
|
||||
import { TimeSrv } from '../dashboard/services/TimeSrv';
|
||||
import { TemplateSrv } from './template_srv';
|
||||
import { VariableSrv } from './variable_srv';
|
||||
|
@ -1,7 +1,6 @@
|
||||
import _ from 'lodash';
|
||||
import {
|
||||
assignModelProperties,
|
||||
containsVariable,
|
||||
QueryVariableModel,
|
||||
VariableActions,
|
||||
VariableHide,
|
||||
@ -11,12 +10,13 @@ import {
|
||||
VariableTag,
|
||||
VariableType,
|
||||
variableTypes,
|
||||
} from './variable';
|
||||
} from './types';
|
||||
import { DataSourceApi, stringToJsRegex } from '@grafana/data';
|
||||
import DatasourceSrv from '../plugins/datasource_srv';
|
||||
import { TemplateSrv } from './template_srv';
|
||||
import { VariableSrv } from './variable_srv';
|
||||
import { TimeSrv } from '../dashboard/services/TimeSrv';
|
||||
import { containsVariable } from './utils';
|
||||
|
||||
function getNoneOption(): VariableOption {
|
||||
return { text: 'None', value: '', isNone: true, selected: false };
|
||||
|
@ -1,11 +1,6 @@
|
||||
import {
|
||||
assignModelProperties,
|
||||
containsSearchFilter,
|
||||
containsVariable,
|
||||
getSearchFilterScopedVar,
|
||||
SEARCH_FILTER_VARIABLE,
|
||||
} from '../variable';
|
||||
import { assignModelProperties } from '../types';
|
||||
import { ScopedVars } from '@grafana/data';
|
||||
import { containsSearchFilter, containsVariable, getSearchFilterScopedVar, SEARCH_FILTER_VARIABLE } from '../utils';
|
||||
|
||||
describe('containsVariable', () => {
|
||||
describe('when checking if a string contains a variable', () => {
|
@ -1,10 +1,10 @@
|
||||
import kbn from 'app/core/utils/kbn';
|
||||
import _ from 'lodash';
|
||||
import { variableRegex } from 'app/features/templating/variable';
|
||||
import { escapeHtml } from 'app/core/utils/text';
|
||||
import { ScopedVars, TimeRange } from '@grafana/data';
|
||||
import { getVariableWithName, getFilteredVariables } from '../variables/state/selectors';
|
||||
import { getConfig } from 'app/core/config';
|
||||
import { variableRegex } from './utils';
|
||||
import { isAdHoc } from '../variables/guard';
|
||||
|
||||
function luceneEscape(value: string) {
|
||||
|
@ -1,51 +1,6 @@
|
||||
import _ from 'lodash';
|
||||
import { ScopedVars } from '@grafana/data';
|
||||
|
||||
import { assignModelProperties } from 'app/core/utils/model_utils';
|
||||
import { Deferred } from '../../core/utils/deferred';
|
||||
|
||||
/*
|
||||
* This regex matches 3 types of variable reference with an optional format specifier
|
||||
* \$(\w+) $var1
|
||||
* \[\[([\s\S]+?)(?::(\w+))?\]\] [[var2]] or [[var2:fmt2]]
|
||||
* \${(\w+)(?::(\w+))?} ${var3} or ${var3:fmt3}
|
||||
*/
|
||||
export const variableRegex = /\$(\w+)|\[\[([\s\S]+?)(?::(\w+))?\]\]|\${(\w+)(?:\.([^:^\}]+))?(?::(\w+))?}/g;
|
||||
|
||||
// Helper function since lastIndex is not reset
|
||||
export const variableRegexExec = (variableString: string) => {
|
||||
variableRegex.lastIndex = 0;
|
||||
return variableRegex.exec(variableString);
|
||||
};
|
||||
|
||||
export const SEARCH_FILTER_VARIABLE = '__searchFilter';
|
||||
|
||||
export const containsSearchFilter = (query: string | unknown): boolean =>
|
||||
query && typeof query === 'string' ? query.indexOf(SEARCH_FILTER_VARIABLE) !== -1 : false;
|
||||
|
||||
export const getSearchFilterScopedVar = (args: {
|
||||
query: string;
|
||||
wildcardChar: string;
|
||||
options: { searchFilter?: string };
|
||||
}): ScopedVars => {
|
||||
const { query, wildcardChar } = args;
|
||||
if (!containsSearchFilter(query)) {
|
||||
return {};
|
||||
}
|
||||
|
||||
let { options } = args;
|
||||
|
||||
options = options || { searchFilter: '' };
|
||||
const value = options.searchFilter ? `${options.searchFilter}${wildcardChar}` : `${wildcardChar}`;
|
||||
|
||||
return {
|
||||
__searchFilter: {
|
||||
value,
|
||||
text: '',
|
||||
},
|
||||
};
|
||||
};
|
||||
|
||||
export enum VariableRefresh {
|
||||
never,
|
||||
onDashboardLoad,
|
||||
@ -172,19 +127,3 @@ export interface VariableTypes {
|
||||
|
||||
export let variableTypes: VariableTypes = {};
|
||||
export { assignModelProperties };
|
||||
|
||||
export function containsVariable(...args: any[]) {
|
||||
const variableName = args[args.length - 1];
|
||||
args[0] = _.isString(args[0]) ? args[0] : Object['values'](args[0]).join(' ');
|
||||
const variableString = args.slice(0, -1).join(' ');
|
||||
const matches = variableString.match(variableRegex);
|
||||
const isMatchingVariable =
|
||||
matches !== null
|
||||
? matches.find(match => {
|
||||
const varMatch = variableRegexExec(match);
|
||||
return varMatch !== null && varMatch.indexOf(variableName) > -1;
|
||||
})
|
||||
: false;
|
||||
|
||||
return !!isMatchingVariable;
|
||||
}
|
60
public/app/features/templating/utils.ts
Normal file
60
public/app/features/templating/utils.ts
Normal file
@ -0,0 +1,60 @@
|
||||
import isString from 'lodash/isString';
|
||||
import { ScopedVars } from '@grafana/data';
|
||||
|
||||
/*
|
||||
* This regex matches 3 types of variable reference with an optional format specifier
|
||||
* \$(\w+) $var1
|
||||
* \[\[([\s\S]+?)(?::(\w+))?\]\] [[var2]] or [[var2:fmt2]]
|
||||
* \${(\w+)(?::(\w+))?} ${var3} or ${var3:fmt3}
|
||||
*/
|
||||
export const variableRegex = /\$(\w+)|\[\[([\s\S]+?)(?::(\w+))?\]\]|\${(\w+)(?:\.([^:^\}]+))?(?::(\w+))?}/g;
|
||||
|
||||
// Helper function since lastIndex is not reset
|
||||
export const variableRegexExec = (variableString: string) => {
|
||||
variableRegex.lastIndex = 0;
|
||||
return variableRegex.exec(variableString);
|
||||
};
|
||||
|
||||
export const SEARCH_FILTER_VARIABLE = '__searchFilter';
|
||||
|
||||
export const containsSearchFilter = (query: string | unknown): boolean =>
|
||||
query && typeof query === 'string' ? query.indexOf(SEARCH_FILTER_VARIABLE) !== -1 : false;
|
||||
|
||||
export const getSearchFilterScopedVar = (args: {
|
||||
query: string;
|
||||
wildcardChar: string;
|
||||
options: { searchFilter?: string };
|
||||
}): ScopedVars => {
|
||||
const { query, wildcardChar } = args;
|
||||
if (!containsSearchFilter(query)) {
|
||||
return {};
|
||||
}
|
||||
|
||||
let { options } = args;
|
||||
|
||||
options = options || { searchFilter: '' };
|
||||
const value = options.searchFilter ? `${options.searchFilter}${wildcardChar}` : `${wildcardChar}`;
|
||||
|
||||
return {
|
||||
__searchFilter: {
|
||||
value,
|
||||
text: '',
|
||||
},
|
||||
};
|
||||
};
|
||||
|
||||
export function containsVariable(...args: any[]) {
|
||||
const variableName = args[args.length - 1];
|
||||
args[0] = isString(args[0]) ? args[0] : Object['values'](args[0]).join(' ');
|
||||
const variableString = args.slice(0, -1).join(' ');
|
||||
const matches = variableString.match(variableRegex);
|
||||
const isMatchingVariable =
|
||||
matches !== null
|
||||
? matches.find(match => {
|
||||
const varMatch = variableRegexExec(match);
|
||||
return varMatch !== null && varMatch.indexOf(variableName) > -1;
|
||||
})
|
||||
: false;
|
||||
|
||||
return !!isMatchingVariable;
|
||||
}
|
@ -3,7 +3,7 @@ import angular, { auto, ILocationService, IPromise, IQService } from 'angular';
|
||||
import _ from 'lodash';
|
||||
// Utils & Services
|
||||
import coreModule from 'app/core/core_module';
|
||||
import { variableTypes } from './variable';
|
||||
import { variableTypes } from './types';
|
||||
import { Graph } from 'app/core/utils/dag';
|
||||
import { TemplateSrv } from 'app/features/templating/template_srv';
|
||||
import { TimeSrv } from 'app/features/dashboard/services/TimeSrv';
|
||||
|
@ -13,7 +13,7 @@ import {
|
||||
VariableModel,
|
||||
VariableOption,
|
||||
VariableType,
|
||||
} from '../templating/variable';
|
||||
} from '../templating/types';
|
||||
import { VariableEditorProps } from './editor/types';
|
||||
import { VariablesState } from './state/variablesReducer';
|
||||
import { VariablePickerProps } from './pickers/types';
|
||||
|
@ -1,11 +1,12 @@
|
||||
import React, { PureComponent } from 'react';
|
||||
import { AdHocVariableModel } from '../../templating/variable';
|
||||
import { MapDispatchToProps, MapStateToProps } from 'react-redux';
|
||||
|
||||
import { AdHocVariableModel } from '../../templating/types';
|
||||
import { VariableEditorProps } from '../editor/types';
|
||||
import { VariableEditorState } from '../editor/reducer';
|
||||
import { AdHocVariableEditorState } from './reducer';
|
||||
import { initAdHocVariableEditor, changeVariableDatasource } from './actions';
|
||||
import { changeVariableDatasource, initAdHocVariableEditor } from './actions';
|
||||
import { connectWithStore } from 'app/core/utils/connectWithReduxStore';
|
||||
import { MapDispatchToProps, MapStateToProps } from 'react-redux';
|
||||
import { StoreState } from 'app/types';
|
||||
|
||||
export interface OwnProps extends VariableEditorProps<AdHocVariableModel> {}
|
||||
|
@ -20,7 +20,7 @@ import { filterAdded, filterRemoved, filtersRestored, filterUpdated } from './re
|
||||
import { addVariable, changeVariableProp } from '../state/sharedReducer';
|
||||
import { updateLocation } from 'app/core/actions';
|
||||
import { DashboardState, LocationState } from 'app/types';
|
||||
import { VariableModel } from 'app/features/templating/variable';
|
||||
import { VariableModel } from 'app/features/templating/types';
|
||||
import { changeVariableEditorExtended, setIdInEditor } from '../editor/reducer';
|
||||
import { adHocBuilder } from '../shared/testing/builders';
|
||||
|
||||
|
@ -13,7 +13,7 @@ import {
|
||||
filterUpdated,
|
||||
initialAdHocVariableModelState,
|
||||
} from './reducer';
|
||||
import { AdHocVariableFilter, AdHocVariableModel } from 'app/features/templating/variable';
|
||||
import { AdHocVariableFilter, AdHocVariableModel } from 'app/features/templating/types';
|
||||
import { variableUpdated } from '../state/actions';
|
||||
import { isAdHoc } from '../guard';
|
||||
|
||||
|
@ -1,5 +1,6 @@
|
||||
import cloneDeep from 'lodash/cloneDeep';
|
||||
import { AdHocVariableModel } from '../../templating/variable';
|
||||
|
||||
import { AdHocVariableModel } from '../../templating/types';
|
||||
import { dispatch } from '../../../store/store';
|
||||
import { VariableAdapter } from '../adapters';
|
||||
import { AdHocPicker } from './picker/AdHocPicker';
|
||||
|
@ -1,7 +1,7 @@
|
||||
import React, { FC, useState, ReactElement } from 'react';
|
||||
import React, { FC, ReactElement, useState } from 'react';
|
||||
import { SegmentAsync } from '@grafana/ui';
|
||||
import { OperatorSegment } from './OperatorSegment';
|
||||
import { AdHocVariableFilter } from 'app/features/templating/variable';
|
||||
import { AdHocVariableFilter } from 'app/features/templating/types';
|
||||
import { SelectableValue } from '@grafana/data';
|
||||
|
||||
interface Props {
|
||||
|
@ -1,7 +1,7 @@
|
||||
import React, { PureComponent, ReactNode } from 'react';
|
||||
import { connect, MapDispatchToProps, MapStateToProps } from 'react-redux';
|
||||
import { StoreState } from 'app/types';
|
||||
import { AdHocVariableFilter, AdHocVariableModel } from 'app/features/templating/variable';
|
||||
import { AdHocVariableFilter, AdHocVariableModel } from 'app/features/templating/types';
|
||||
import { SegmentAsync } from '@grafana/ui';
|
||||
import { VariablePickerProps } from '../../pickers/types';
|
||||
import { OperatorSegment } from './OperatorSegment';
|
||||
|
@ -4,7 +4,7 @@ import { getVariableTestContext } from '../state/helpers';
|
||||
import { toVariablePayload } from '../state/types';
|
||||
import { adHocVariableReducer, filterAdded, filterRemoved, filtersRestored, filterUpdated } from './reducer';
|
||||
import { VariablesState } from '../state/variablesReducer';
|
||||
import { AdHocVariableFilter, AdHocVariableModel } from '../../templating/variable';
|
||||
import { AdHocVariableFilter, AdHocVariableModel } from '../../templating/types';
|
||||
import { createAdHocVariableAdapter } from './adapter';
|
||||
|
||||
describe('adHocVariableReducer', () => {
|
||||
|
@ -1,4 +1,4 @@
|
||||
import { AdHocVariableFilter, AdHocVariableModel, VariableHide } from 'app/features/templating/variable';
|
||||
import { AdHocVariableFilter, AdHocVariableModel, VariableHide } from 'app/features/templating/types';
|
||||
import { getInstanceState, NEW_VARIABLE_ID, VariablePayload } from '../state/types';
|
||||
import { createSlice, PayloadAction } from '@reduxjs/toolkit';
|
||||
import { initialVariablesState, VariablesState } from '../state/variablesReducer';
|
||||
|
@ -1,5 +1,5 @@
|
||||
import { toUrl, toFilters } from './urlParser';
|
||||
import { AdHocVariableFilter } from 'app/features/templating/variable';
|
||||
import { toFilters, toUrl } from './urlParser';
|
||||
import { AdHocVariableFilter } from 'app/features/templating/types';
|
||||
import { UrlQueryValue } from '@grafana/runtime';
|
||||
|
||||
describe('urlParser', () => {
|
||||
|
@ -1,6 +1,6 @@
|
||||
import { AdHocVariableFilter } from 'app/features/templating/variable';
|
||||
import { AdHocVariableFilter } from 'app/features/templating/types';
|
||||
import { UrlQueryValue } from '@grafana/runtime';
|
||||
import { isString, isArray } from 'lodash';
|
||||
import { isArray, isString } from 'lodash';
|
||||
|
||||
export const toUrl = (filters: AdHocVariableFilter[]): string[] => {
|
||||
return filters.map(filter =>
|
||||
|
@ -1,7 +1,7 @@
|
||||
import React, { ChangeEvent, FocusEvent, PureComponent } from 'react';
|
||||
import { e2e } from '@grafana/e2e';
|
||||
|
||||
import { ConstantVariableModel } from '../../templating/variable';
|
||||
import { ConstantVariableModel } from '../../templating/types';
|
||||
import { VariableEditorProps } from '../editor/types';
|
||||
|
||||
export interface Props extends VariableEditorProps<ConstantVariableModel> {}
|
||||
|
@ -4,7 +4,7 @@ import { reduxTester } from '../../../../test/core/redux/reduxTester';
|
||||
import { TemplatingState } from 'app/features/variables/state/reducers';
|
||||
import { updateConstantVariableOptions } from './actions';
|
||||
import { getTemplatingRootReducer } from '../state/helpers';
|
||||
import { ConstantVariableModel, VariableHide, VariableOption } from '../../templating/variable';
|
||||
import { ConstantVariableModel, VariableHide, VariableOption } from '../../templating/types';
|
||||
import { toVariablePayload } from '../state/types';
|
||||
import { createConstantOptionsFromQuery } from './reducer';
|
||||
import { setCurrentVariableValue } from '../state/sharedReducer';
|
||||
|
@ -1,5 +1,5 @@
|
||||
import cloneDeep from 'lodash/cloneDeep';
|
||||
import { ConstantVariableModel } from '../../templating/variable';
|
||||
import { ConstantVariableModel } from '../../templating/types';
|
||||
import { dispatch } from '../../../store/store';
|
||||
import { setOptionAsCurrent, setOptionFromUrl } from '../state/actions';
|
||||
import { VariableAdapter } from '../adapters';
|
||||
|
@ -4,7 +4,7 @@ import { getVariableTestContext } from '../state/helpers';
|
||||
import { toVariablePayload } from '../state/types';
|
||||
import { constantVariableReducer, createConstantOptionsFromQuery } from './reducer';
|
||||
import { VariablesState } from '../state/variablesReducer';
|
||||
import { ConstantVariableModel } from '../../templating/variable';
|
||||
import { ConstantVariableModel } from '../../templating/types';
|
||||
import { createConstantVariableAdapter } from './adapter';
|
||||
|
||||
describe('constantVariableReducer', () => {
|
||||
|
@ -1,5 +1,5 @@
|
||||
import { createSlice, PayloadAction } from '@reduxjs/toolkit';
|
||||
import { ConstantVariableModel, VariableHide, VariableOption } from '../../templating/variable';
|
||||
import { ConstantVariableModel, VariableHide, VariableOption } from '../../templating/types';
|
||||
import { getInstanceState, NEW_VARIABLE_ID, VariablePayload } from '../state/types';
|
||||
import { initialVariablesState, VariablesState } from '../state/variablesReducer';
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
import React, { ChangeEvent, FocusEvent, PureComponent } from 'react';
|
||||
import { CustomVariableModel, VariableWithMultiSupport } from '../../templating/variable';
|
||||
import { CustomVariableModel, VariableWithMultiSupport } from '../../templating/types';
|
||||
import { SelectionOptionsEditor } from '../editor/SelectionOptionsEditor';
|
||||
import { OnPropChangeArguments, VariableEditorProps } from '../editor/types';
|
||||
|
||||
|
@ -3,7 +3,7 @@ import { updateCustomVariableOptions } from './actions';
|
||||
import { createCustomVariableAdapter } from './adapter';
|
||||
import { reduxTester } from '../../../../test/core/redux/reduxTester';
|
||||
import { getTemplatingRootReducer } from '../state/helpers';
|
||||
import { CustomVariableModel, VariableHide, VariableOption } from '../../templating/variable';
|
||||
import { CustomVariableModel, VariableHide, VariableOption } from '../../templating/types';
|
||||
import { toVariablePayload } from '../state/types';
|
||||
import { setCurrentVariableValue } from '../state/sharedReducer';
|
||||
import { initDashboardTemplating } from '../state/actions';
|
||||
|
@ -1,5 +1,5 @@
|
||||
import cloneDeep from 'lodash/cloneDeep';
|
||||
import { CustomVariableModel } from '../../templating/variable';
|
||||
import { CustomVariableModel } from '../../templating/types';
|
||||
import { dispatch } from '../../../store/store';
|
||||
import { setOptionAsCurrent, setOptionFromUrl } from '../state/actions';
|
||||
import { VariableAdapter } from '../adapters';
|
||||
|
@ -5,7 +5,7 @@ import { ALL_VARIABLE_TEXT, ALL_VARIABLE_VALUE, toVariablePayload } from '../sta
|
||||
import { createCustomOptionsFromQuery, customVariableReducer } from './reducer';
|
||||
import { createCustomVariableAdapter } from './adapter';
|
||||
import { VariablesState } from '../state/variablesReducer';
|
||||
import { CustomVariableModel } from '../../templating/variable';
|
||||
import { CustomVariableModel } from '../../templating/types';
|
||||
|
||||
describe('customVariableReducer', () => {
|
||||
const adapter = createCustomVariableAdapter();
|
||||
|
@ -1,6 +1,6 @@
|
||||
import { createSlice, PayloadAction } from '@reduxjs/toolkit';
|
||||
|
||||
import { CustomVariableModel, VariableHide, VariableOption } from '../../templating/variable';
|
||||
import { CustomVariableModel, VariableHide, VariableOption } from '../../templating/types';
|
||||
import {
|
||||
ALL_VARIABLE_TEXT,
|
||||
ALL_VARIABLE_VALUE,
|
||||
|
@ -1,6 +1,6 @@
|
||||
import React, { ChangeEvent, FocusEvent, PureComponent } from 'react';
|
||||
|
||||
import { DataSourceVariableModel, VariableWithMultiSupport } from '../../templating/variable';
|
||||
import { DataSourceVariableModel, VariableWithMultiSupport } from '../../templating/types';
|
||||
import { OnPropChangeArguments, VariableEditorProps } from '../editor/types';
|
||||
import { SelectionOptionsEditor } from '../editor/SelectionOptionsEditor';
|
||||
import { FormLabel } from '@grafana/ui';
|
||||
|
@ -5,7 +5,7 @@ import { validateVariableSelectionState } from '../state/actions';
|
||||
import { DataSourceSelectItem, stringToJsRegex } from '@grafana/data';
|
||||
import { getDatasourceSrv } from '../../plugins/datasource_srv';
|
||||
import { getVariable } from '../state/selectors';
|
||||
import { DataSourceVariableModel } from '../../templating/variable';
|
||||
import { DataSourceVariableModel } from '../../templating/types';
|
||||
import templateSrv from '../../templating/template_srv';
|
||||
import _ from 'lodash';
|
||||
import { changeVariableEditorExtended } from '../editor/reducer';
|
||||
|
@ -1,5 +1,5 @@
|
||||
import cloneDeep from 'lodash/cloneDeep';
|
||||
import { containsVariable, DataSourceVariableModel } from '../../templating/variable';
|
||||
import { DataSourceVariableModel } from '../../templating/types';
|
||||
import { dispatch } from '../../../store/store';
|
||||
import { setOptionAsCurrent, setOptionFromUrl } from '../state/actions';
|
||||
import { VariableAdapter } from '../adapters';
|
||||
@ -8,6 +8,7 @@ import { OptionsPicker } from '../pickers';
|
||||
import { ALL_VARIABLE_TEXT, toVariableIdentifier } from '../state/types';
|
||||
import { DataSourceVariableEditor } from './DataSourceVariableEditor';
|
||||
import { updateDataSourceVariableOptions } from './actions';
|
||||
import { containsVariable } from '../../templating/utils';
|
||||
|
||||
export const createDataSourceVariableAdapter = (): VariableAdapter<DataSourceVariableModel> => {
|
||||
return {
|
||||
|
@ -1,7 +1,7 @@
|
||||
import { reducerTester } from '../../../../test/core/redux/reducerTester';
|
||||
import { VariablesState } from '../state/variablesReducer';
|
||||
import { createDataSourceOptions, dataSourceVariableReducer } from './reducer';
|
||||
import { DataSourceVariableModel } from '../../templating/variable';
|
||||
import { DataSourceVariableModel } from '../../templating/types';
|
||||
import { getVariableTestContext } from '../state/helpers';
|
||||
import cloneDeep from 'lodash/cloneDeep';
|
||||
import { createDataSourceVariableAdapter } from './adapter';
|
||||
|
@ -1,5 +1,5 @@
|
||||
import { createSlice, PayloadAction } from '@reduxjs/toolkit';
|
||||
import { DataSourceVariableModel, VariableHide, VariableOption, VariableRefresh } from '../../templating/variable';
|
||||
import { DataSourceVariableModel, VariableHide, VariableOption, VariableRefresh } from '../../templating/types';
|
||||
import {
|
||||
ALL_VARIABLE_TEXT,
|
||||
ALL_VARIABLE_VALUE,
|
||||
|
@ -2,7 +2,7 @@ import React, { FunctionComponent, useCallback } from 'react';
|
||||
import { Switch } from '@grafana/ui';
|
||||
import { e2e } from '@grafana/e2e';
|
||||
|
||||
import { VariableWithMultiSupport } from '../../templating/variable';
|
||||
import { VariableWithMultiSupport } from '../../templating/types';
|
||||
import { VariableEditorProps } from './types';
|
||||
|
||||
export interface SelectionOptionsEditorProps<Model extends VariableWithMultiSupport = VariableWithMultiSupport>
|
||||
|
@ -7,7 +7,7 @@ import { VariableEditorEditor } from './VariableEditorEditor';
|
||||
import { MapDispatchToProps, MapStateToProps } from 'react-redux';
|
||||
import { connectWithStore } from '../../../core/utils/connectWithReduxStore';
|
||||
import { getVariableClones } from '../state/selectors';
|
||||
import { VariableModel } from '../../templating/variable';
|
||||
import { VariableModel } from '../../templating/types';
|
||||
import { switchToEditMode, switchToListMode, switchToNewMode } from './actions';
|
||||
import { changeVariableOrder, duplicateVariable, removeVariable } from '../state/sharedReducer';
|
||||
|
||||
|
@ -5,7 +5,7 @@ import { FormLabel } from '@grafana/ui';
|
||||
import { e2e } from '@grafana/e2e';
|
||||
import { variableAdapters } from '../adapters';
|
||||
import { NEW_VARIABLE_ID, toVariablePayload, VariableIdentifier } from '../state/types';
|
||||
import { VariableHide, VariableModel, VariableType } from '../../templating/variable';
|
||||
import { VariableHide, VariableModel, VariableType } from '../../templating/types';
|
||||
import { appEvents } from '../../../core/core';
|
||||
import { VariableValuesPreview } from './VariableValuesPreview';
|
||||
import { changeVariableName, onEditorAdd, onEditorUpdate, variableEditorMount, variableEditorUnMount } from './actions';
|
||||
|
@ -1,7 +1,7 @@
|
||||
import React, { MouseEvent, PureComponent } from 'react';
|
||||
import { e2e } from '@grafana/e2e';
|
||||
import EmptyListCTA from '../../../core/components/EmptyListCTA/EmptyListCTA';
|
||||
import { QueryVariableModel, VariableModel } from '../../templating/variable';
|
||||
import { QueryVariableModel, VariableModel } from '../../templating/types';
|
||||
import { toVariableIdentifier, VariableIdentifier } from '../state/types';
|
||||
|
||||
export interface Props {
|
||||
|
@ -1,5 +1,5 @@
|
||||
import React, { useCallback, useEffect, useState } from 'react';
|
||||
import { VariableModel, VariableOption, VariableWithOptions } from '../../templating/variable';
|
||||
import { VariableModel, VariableOption, VariableWithOptions } from '../../templating/types';
|
||||
import { e2e } from '@grafana/e2e';
|
||||
|
||||
export interface VariableValuesPreviewProps {
|
||||
|
@ -17,7 +17,7 @@ import {
|
||||
VariableIdentifier,
|
||||
} from '../state/types';
|
||||
import cloneDeep from 'lodash/cloneDeep';
|
||||
import { VariableType } from '../../templating/variable';
|
||||
import { VariableType } from '../../templating/types';
|
||||
import { addVariable, removeVariable, storeNewVariable } from '../state/sharedReducer';
|
||||
|
||||
export const variableEditorMount = (identifier: VariableIdentifier): ThunkResult<void> => {
|
||||
|
@ -1,4 +1,4 @@
|
||||
import { VariableModel } from '../../templating/variable';
|
||||
import { VariableModel } from '../../templating/types';
|
||||
|
||||
export interface OnPropChangeArguments<Model extends VariableModel = VariableModel> {
|
||||
propName: keyof Model;
|
||||
|
@ -1,4 +1,4 @@
|
||||
import { QueryVariableModel, VariableModel, AdHocVariableModel } from '../templating/variable';
|
||||
import { QueryVariableModel, VariableModel, AdHocVariableModel } from '../templating/types';
|
||||
|
||||
export const isQuery = (model: VariableModel): model is QueryVariableModel => {
|
||||
return model.type === 'query';
|
||||
|
@ -1,6 +1,6 @@
|
||||
import React, { ChangeEvent, FocusEvent, PureComponent } from 'react';
|
||||
|
||||
import { IntervalVariableModel } from '../../templating/variable';
|
||||
import { IntervalVariableModel } from '../../templating/types';
|
||||
import { VariableEditorProps } from '../editor/types';
|
||||
import { FormLabel, Switch } from '@grafana/ui';
|
||||
|
||||
|
@ -5,7 +5,7 @@ import { ThunkResult } from '../../../types';
|
||||
import { createIntervalOptions } from './reducer';
|
||||
import { validateVariableSelectionState } from '../state/actions';
|
||||
import { getVariable } from '../state/selectors';
|
||||
import { IntervalVariableModel } from '../../templating/variable';
|
||||
import { IntervalVariableModel } from '../../templating/types';
|
||||
import kbn from '../../../core/utils/kbn';
|
||||
import { getTimeSrv } from '../../dashboard/services/TimeSrv';
|
||||
import templateSrv from '../../templating/template_srv';
|
||||
|
@ -1,5 +1,5 @@
|
||||
import cloneDeep from 'lodash/cloneDeep';
|
||||
import { IntervalVariableModel } from '../../templating/variable';
|
||||
import { IntervalVariableModel } from '../../templating/types';
|
||||
import { dispatch } from '../../../store/store';
|
||||
import { setOptionAsCurrent, setOptionFromUrl } from '../state/actions';
|
||||
import { VariableAdapter } from '../adapters';
|
||||
|
@ -3,7 +3,7 @@ import cloneDeep from 'lodash/cloneDeep';
|
||||
import { getVariableTestContext } from '../state/helpers';
|
||||
import { toVariablePayload } from '../state/types';
|
||||
import { createIntervalVariableAdapter } from './adapter';
|
||||
import { IntervalVariableModel } from '../../templating/variable';
|
||||
import { IntervalVariableModel } from '../../templating/types';
|
||||
import { reducerTester } from '../../../../test/core/redux/reducerTester';
|
||||
import { VariablesState } from '../state/variablesReducer';
|
||||
import { createIntervalOptions, intervalVariableReducer } from './reducer';
|
||||
|
@ -1,5 +1,5 @@
|
||||
import { createSlice, PayloadAction } from '@reduxjs/toolkit';
|
||||
import { IntervalVariableModel, VariableHide, VariableOption, VariableRefresh } from '../../templating/variable';
|
||||
import { IntervalVariableModel, VariableHide, VariableOption, VariableRefresh } from '../../templating/types';
|
||||
import { getInstanceState, NEW_VARIABLE_ID, VariablePayload } from '../state/types';
|
||||
import { initialVariablesState, VariablesState } from '../state/variablesReducer';
|
||||
import _ from 'lodash';
|
||||
|
@ -6,12 +6,7 @@ import { VariableLink } from '../shared/VariableLink';
|
||||
import { VariableInput } from '../shared/VariableInput';
|
||||
import { commitChangesToVariable, filterOrSearchOptions, navigateOptions, toggleAndFetchTag } from './actions';
|
||||
import { OptionsPickerState, showOptions, toggleAllOptions, toggleOption } from './reducer';
|
||||
import {
|
||||
VariableOption,
|
||||
VariableTag,
|
||||
VariableWithMultiSupport,
|
||||
VariableWithOptions,
|
||||
} from '../../../templating/variable';
|
||||
import { VariableOption, VariableTag, VariableWithMultiSupport, VariableWithOptions } from '../../../templating/types';
|
||||
import { VariableOptions } from '../shared/VariableOptions';
|
||||
import { isQuery } from '../../guard';
|
||||
import { VariablePickerProps } from '../types';
|
||||
|
@ -2,7 +2,7 @@ import { reduxTester } from '../../../../../test/core/redux/reduxTester';
|
||||
import { getTemplatingRootReducer } from '../../state/helpers';
|
||||
import { initDashboardTemplating } from '../../state/actions';
|
||||
import { TemplatingState } from '../../state/reducers';
|
||||
import { QueryVariableModel, VariableHide, VariableRefresh, VariableSort } from '../../../templating/variable';
|
||||
import { QueryVariableModel, VariableHide, VariableRefresh, VariableSort } from '../../../templating/types';
|
||||
import {
|
||||
hideOptions,
|
||||
showOptions,
|
||||
|
@ -1,14 +1,13 @@
|
||||
import debounce from 'lodash/debounce';
|
||||
import { StoreState, ThunkDispatch, ThunkResult } from 'app/types';
|
||||
import {
|
||||
containsSearchFilter,
|
||||
QueryVariableModel,
|
||||
VariableOption,
|
||||
VariableRefresh,
|
||||
VariableTag,
|
||||
VariableWithMultiSupport,
|
||||
VariableWithOptions,
|
||||
} from '../../../templating/variable';
|
||||
} from '../../../templating/types';
|
||||
import { variableAdapters } from '../../adapters';
|
||||
import { getVariable } from '../../state/selectors';
|
||||
import { NavigationKey } from '../types';
|
||||
@ -26,6 +25,7 @@ import { getDataSourceSrv } from '@grafana/runtime';
|
||||
import { getTimeSrv } from 'app/features/dashboard/services/TimeSrv';
|
||||
import { changeVariableProp, setCurrentVariableValue } from '../../state/sharedReducer';
|
||||
import { toVariablePayload } from '../../state/types';
|
||||
import { containsSearchFilter } from '../../../templating/utils';
|
||||
|
||||
export const navigateOptions = (key: NavigationKey, clearOthers: boolean): ThunkResult<void> => {
|
||||
return async (dispatch, getState) => {
|
||||
|
@ -14,7 +14,7 @@ import {
|
||||
updateSearchQuery,
|
||||
} from './reducer';
|
||||
import { reducerTester } from '../../../../../test/core/redux/reducerTester';
|
||||
import { QueryVariableModel, VariableTag } from '../../../templating/variable';
|
||||
import { QueryVariableModel, VariableTag } from '../../../templating/types';
|
||||
import { ALL_VARIABLE_TEXT, ALL_VARIABLE_VALUE } from '../../state/types';
|
||||
|
||||
const getVariableTestContext = (extend: Partial<OptionsPickerState>) => {
|
||||
|
@ -1,14 +1,10 @@
|
||||
import { createSlice, PayloadAction } from '@reduxjs/toolkit';
|
||||
import { cloneDeep } from 'lodash';
|
||||
import {
|
||||
containsSearchFilter,
|
||||
VariableOption,
|
||||
VariableTag,
|
||||
VariableWithMultiSupport,
|
||||
} from '../../../templating/variable';
|
||||
import { VariableOption, VariableTag, VariableWithMultiSupport } from '../../../templating/types';
|
||||
import { ALL_VARIABLE_TEXT, ALL_VARIABLE_VALUE } from '../../state/types';
|
||||
import { isQuery } from '../../guard';
|
||||
import { applyStateChanges } from '../../../../core/utils/applyStateChanges';
|
||||
import { containsSearchFilter } from '../../../templating/utils';
|
||||
|
||||
export interface ToggleOption {
|
||||
option: VariableOption;
|
||||
|
@ -1,5 +1,5 @@
|
||||
import React, { FunctionComponent, useMemo } from 'react';
|
||||
import { VariableHide, VariableModel } from '../../templating/variable';
|
||||
import { VariableHide, VariableModel } from '../../templating/types';
|
||||
import { e2e } from '@grafana/e2e';
|
||||
import { variableAdapters } from '../adapters';
|
||||
|
||||
|
@ -1,7 +1,7 @@
|
||||
import React, { PureComponent } from 'react';
|
||||
import { getTagColorsFromName } from '@grafana/ui';
|
||||
import { e2e } from '@grafana/e2e';
|
||||
import { VariableTag } from '../../../templating/variable';
|
||||
import { VariableTag } from '../../../templating/types';
|
||||
|
||||
interface Props {
|
||||
onClick: () => void;
|
||||
|
@ -1,7 +1,7 @@
|
||||
import React, { PureComponent } from 'react';
|
||||
import { getTagColorsFromName, Tooltip } from '@grafana/ui';
|
||||
import { e2e } from '@grafana/e2e';
|
||||
import { VariableOption, VariableTag } from '../../../templating/variable';
|
||||
import { VariableOption, VariableTag } from '../../../templating/types';
|
||||
|
||||
export interface Props {
|
||||
multi: boolean;
|
||||
|
@ -1,4 +1,4 @@
|
||||
import { VariableModel } from '../../templating/variable';
|
||||
import { VariableModel } from '../../templating/types';
|
||||
|
||||
export interface VariablePickerProps<Model extends VariableModel = VariableModel> {
|
||||
variable: Model;
|
||||
|
@ -4,7 +4,7 @@ import { FormLabel, Switch } from '@grafana/ui';
|
||||
|
||||
import templateSrv from '../../templating/template_srv';
|
||||
import { SelectionOptionsEditor } from '../editor/SelectionOptionsEditor';
|
||||
import { QueryVariableModel, VariableRefresh, VariableSort, VariableWithMultiSupport } from '../../templating/variable';
|
||||
import { QueryVariableModel, VariableRefresh, VariableSort, VariableWithMultiSupport } from '../../templating/types';
|
||||
import { QueryVariableEditorState } from './reducer';
|
||||
import { changeQueryVariableDataSource, changeQueryVariableQuery, initQueryVariableEditor } from './actions';
|
||||
import { VariableEditorState } from '../editor/reducer';
|
||||
|
@ -2,7 +2,7 @@ import { variableAdapters } from '../adapters';
|
||||
import { createQueryVariableAdapter } from './adapter';
|
||||
import { reduxTester } from '../../../../test/core/redux/reduxTester';
|
||||
import { getTemplatingRootReducer } from '../state/helpers';
|
||||
import { QueryVariableModel, VariableHide, VariableRefresh, VariableSort } from '../../templating/variable';
|
||||
import { QueryVariableModel, VariableHide, VariableRefresh, VariableSort } from '../../templating/types';
|
||||
import { ALL_VARIABLE_TEXT, ALL_VARIABLE_VALUE, toVariablePayload } from '../state/types';
|
||||
import { changeVariableProp, setCurrentVariableValue } from '../state/sharedReducer';
|
||||
import { initDashboardTemplating } from '../state/actions';
|
||||
|
@ -1,7 +1,7 @@
|
||||
import { AppEvents, DataSourcePluginMeta, DataSourceSelectItem } from '@grafana/data';
|
||||
|
||||
import { validateVariableSelectionState } from '../state/actions';
|
||||
import { QueryVariableModel, VariableRefresh } from '../../templating/variable';
|
||||
import { QueryVariableModel, VariableRefresh } from '../../templating/types';
|
||||
import { ThunkResult } from '../../../types';
|
||||
import { getDatasourceSrv } from '../../plugins/datasource_srv';
|
||||
import { getTimeSrv } from '../../dashboard/services/TimeSrv';
|
||||
|
@ -1,6 +1,6 @@
|
||||
import cloneDeep from 'lodash/cloneDeep';
|
||||
|
||||
import { containsVariable, QueryVariableModel, VariableRefresh } from '../../templating/variable';
|
||||
import { QueryVariableModel, VariableRefresh } from '../../templating/types';
|
||||
import { initialQueryVariableModelState, queryVariableReducer } from './reducer';
|
||||
import { dispatch } from '../../../store/store';
|
||||
import { setOptionAsCurrent, setOptionFromUrl } from '../state/actions';
|
||||
@ -9,6 +9,7 @@ import { OptionsPicker } from '../pickers';
|
||||
import { QueryVariableEditor } from './QueryVariableEditor';
|
||||
import { updateQueryVariableOptions } from './actions';
|
||||
import { ALL_VARIABLE_TEXT, toVariableIdentifier } from '../state/types';
|
||||
import { containsVariable } from '../../templating/utils';
|
||||
|
||||
export const createQueryVariableAdapter = (): VariableAdapter<QueryVariableModel> => {
|
||||
return {
|
||||
|
@ -1,6 +1,6 @@
|
||||
import { reducerTester } from '../../../../test/core/redux/reducerTester';
|
||||
import { queryVariableReducer, updateVariableOptions, updateVariableTags } from './reducer';
|
||||
import { QueryVariableModel, VariableOption } from '../../templating/variable';
|
||||
import { QueryVariableModel, VariableOption } from '../../templating/types';
|
||||
import cloneDeep from 'lodash/cloneDeep';
|
||||
import { VariablesState } from '../state/variablesReducer';
|
||||
import { getVariableTestContext } from '../state/helpers';
|
||||
|
@ -9,7 +9,7 @@ import {
|
||||
VariableRefresh,
|
||||
VariableSort,
|
||||
VariableTag,
|
||||
} from '../../templating/variable';
|
||||
} from '../../templating/types';
|
||||
import templateSrv from '../../templating/template_srv';
|
||||
import {
|
||||
ALL_VARIABLE_TEXT,
|
||||
|
@ -1,4 +1,4 @@
|
||||
import { AdHocVariableModel, AdHocVariableFilter } from 'app/features/templating/variable';
|
||||
import { AdHocVariableFilter, AdHocVariableModel } from 'app/features/templating/types';
|
||||
import { VariableBuilder } from './variableBuilder';
|
||||
|
||||
export class AdHocVariableBuilder extends VariableBuilder<AdHocVariableModel> {
|
||||
|
@ -1,5 +1,5 @@
|
||||
import { MultiVariableBuilder } from './multiVariableBuilder';
|
||||
import { DataSourceVariableModel, VariableRefresh } from 'app/features/templating/variable';
|
||||
import { DataSourceVariableModel, VariableRefresh } from 'app/features/templating/types';
|
||||
|
||||
export class DatasourceVariableBuilder<T extends DataSourceVariableModel> extends MultiVariableBuilder<T> {
|
||||
withRefresh(refresh: VariableRefresh) {
|
||||
|
@ -1,5 +1,5 @@
|
||||
import { OptionsVariableBuilder } from './optionsVariableBuilder';
|
||||
import { IntervalVariableModel, VariableRefresh } from 'app/features/templating/variable';
|
||||
import { IntervalVariableModel, VariableRefresh } from 'app/features/templating/types';
|
||||
|
||||
export class IntervalVariableBuilder extends OptionsVariableBuilder<IntervalVariableModel> {
|
||||
withRefresh(refresh: VariableRefresh) {
|
||||
|
@ -1,4 +1,4 @@
|
||||
import { VariableWithMultiSupport } from 'app/features/templating/variable';
|
||||
import { VariableWithMultiSupport } from 'app/features/templating/types';
|
||||
import { OptionsVariableBuilder } from './optionsVariableBuilder';
|
||||
|
||||
export class MultiVariableBuilder<T extends VariableWithMultiSupport> extends OptionsVariableBuilder<T> {
|
||||
|
@ -1,4 +1,4 @@
|
||||
import { VariableWithOptions, VariableOption } from 'app/features/templating/variable';
|
||||
import { VariableOption, VariableWithOptions } from 'app/features/templating/types';
|
||||
import { VariableBuilder } from './variableBuilder';
|
||||
|
||||
export class OptionsVariableBuilder<T extends VariableWithOptions> extends VariableBuilder<T> {
|
||||
|
@ -1,5 +1,5 @@
|
||||
import cloneDeep from 'lodash/cloneDeep';
|
||||
import { VariableModel } from 'app/features/templating/variable';
|
||||
import { VariableModel } from 'app/features/templating/types';
|
||||
|
||||
export class VariableBuilder<T extends VariableModel> {
|
||||
protected variable: T;
|
||||
|
@ -10,8 +10,15 @@ import { createConstantVariableAdapter } from '../constant/adapter';
|
||||
import { reduxTester } from '../../../../test/core/redux/reduxTester';
|
||||
import { TemplatingState } from 'app/features/variables/state/reducers';
|
||||
import { initDashboardTemplating, processVariables, setOptionFromUrl, validateVariableSelectionState } from './actions';
|
||||
import { addInitLock, addVariable, removeInitLock, resolveInitLock, setCurrentVariableValue } from './sharedReducer';
|
||||
import { toVariableIdentifier, toVariablePayload } from './types';
|
||||
import {
|
||||
addInitLock,
|
||||
addVariable,
|
||||
removeInitLock,
|
||||
removeVariable,
|
||||
resolveInitLock,
|
||||
setCurrentVariableValue,
|
||||
} from './sharedReducer';
|
||||
import { NEW_VARIABLE_ID, toVariableIdentifier, toVariablePayload } from './types';
|
||||
import {
|
||||
constantBuilder,
|
||||
customBuilder,
|
||||
@ -19,6 +26,8 @@ import {
|
||||
queryBuilder,
|
||||
textboxBuilder,
|
||||
} from '../shared/testing/builders';
|
||||
import { changeVariableName } from '../editor/actions';
|
||||
import { changeVariableNameFailed, changeVariableNameSucceeded, setIdInEditor } from '../editor/reducer';
|
||||
|
||||
variableAdapters.setInit(() => [
|
||||
createQueryVariableAdapter(),
|
||||
@ -266,4 +275,168 @@ describe('shared actions', () => {
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
describe('changeVariableName', () => {
|
||||
describe('when changeVariableName is dispatched with the same name', () => {
|
||||
it('then no actions are dispatched', () => {
|
||||
const textbox = textboxBuilder()
|
||||
.withId('textbox')
|
||||
.withName('textbox')
|
||||
.build();
|
||||
const constant = constantBuilder()
|
||||
.withId('constant')
|
||||
.withName('constant')
|
||||
.build();
|
||||
|
||||
reduxTester<{ templating: TemplatingState }>()
|
||||
.givenRootReducer(getTemplatingRootReducer())
|
||||
.whenActionIsDispatched(addVariable(toVariablePayload(textbox, { global: false, index: 0, model: textbox })))
|
||||
.whenActionIsDispatched(
|
||||
addVariable(toVariablePayload(constant, { global: false, index: 1, model: constant }))
|
||||
)
|
||||
.whenActionIsDispatched(changeVariableName(toVariableIdentifier(constant), constant.name), true)
|
||||
.thenNoActionsWhereDispatched();
|
||||
});
|
||||
});
|
||||
|
||||
describe('when changeVariableName is dispatched with an unique name', () => {
|
||||
it('then the correct actions are dispatched', () => {
|
||||
const textbox = textboxBuilder()
|
||||
.withId('textbox')
|
||||
.withName('textbox')
|
||||
.build();
|
||||
const constant = constantBuilder()
|
||||
.withId('constant')
|
||||
.withName('constant')
|
||||
.build();
|
||||
|
||||
reduxTester<{ templating: TemplatingState }>()
|
||||
.givenRootReducer(getTemplatingRootReducer())
|
||||
.whenActionIsDispatched(addVariable(toVariablePayload(textbox, { global: false, index: 0, model: textbox })))
|
||||
.whenActionIsDispatched(
|
||||
addVariable(toVariablePayload(constant, { global: false, index: 1, model: constant }))
|
||||
)
|
||||
.whenActionIsDispatched(changeVariableName(toVariableIdentifier(constant), 'constant1'), true)
|
||||
.thenDispatchedActionsShouldEqual(
|
||||
addVariable({
|
||||
type: 'constant',
|
||||
id: 'constant1',
|
||||
data: {
|
||||
global: false,
|
||||
index: 1,
|
||||
model: { ...constant, name: 'constant1', id: 'constant1', global: false, index: 1 },
|
||||
},
|
||||
}),
|
||||
changeVariableNameSucceeded({ type: 'constant', id: 'constant1', data: { newName: 'constant1' } }),
|
||||
setIdInEditor({ id: 'constant1' }),
|
||||
removeVariable({ type: 'constant', id: 'constant', data: { reIndex: false } })
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
describe('when changeVariableName is dispatched with an unique name for a new variable', () => {
|
||||
it('then the correct actions are dispatched', () => {
|
||||
const textbox = textboxBuilder()
|
||||
.withId('textbox')
|
||||
.withName('textbox')
|
||||
.build();
|
||||
const constant = constantBuilder()
|
||||
.withId(NEW_VARIABLE_ID)
|
||||
.withName('constant')
|
||||
.build();
|
||||
|
||||
reduxTester<{ templating: TemplatingState }>()
|
||||
.givenRootReducer(getTemplatingRootReducer())
|
||||
.whenActionIsDispatched(addVariable(toVariablePayload(textbox, { global: false, index: 0, model: textbox })))
|
||||
.whenActionIsDispatched(
|
||||
addVariable(toVariablePayload(constant, { global: false, index: 1, model: constant }))
|
||||
)
|
||||
.whenActionIsDispatched(changeVariableName(toVariableIdentifier(constant), 'constant1'), true)
|
||||
.thenDispatchedActionsShouldEqual(
|
||||
changeVariableNameSucceeded({ type: 'constant', id: NEW_VARIABLE_ID, data: { newName: 'constant1' } })
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
describe('when changeVariableName is dispatched with __newName', () => {
|
||||
it('then the correct actions are dispatched', () => {
|
||||
const textbox = textboxBuilder()
|
||||
.withId('textbox')
|
||||
.withName('textbox')
|
||||
.build();
|
||||
const constant = constantBuilder()
|
||||
.withId('constant')
|
||||
.withName('constant')
|
||||
.build();
|
||||
|
||||
reduxTester<{ templating: TemplatingState }>()
|
||||
.givenRootReducer(getTemplatingRootReducer())
|
||||
.whenActionIsDispatched(addVariable(toVariablePayload(textbox, { global: false, index: 0, model: textbox })))
|
||||
.whenActionIsDispatched(
|
||||
addVariable(toVariablePayload(constant, { global: false, index: 1, model: constant }))
|
||||
)
|
||||
.whenActionIsDispatched(changeVariableName(toVariableIdentifier(constant), '__newName'), true)
|
||||
.thenDispatchedActionsShouldEqual(
|
||||
changeVariableNameFailed({
|
||||
newName: '__newName',
|
||||
errorText: "Template names cannot begin with '__', that's reserved for Grafana's global variables",
|
||||
})
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
describe('when changeVariableName is dispatched with illegal characters', () => {
|
||||
it('then the correct actions are dispatched', () => {
|
||||
const textbox = textboxBuilder()
|
||||
.withId('textbox')
|
||||
.withName('textbox')
|
||||
.build();
|
||||
const constant = constantBuilder()
|
||||
.withId('constant')
|
||||
.withName('constant')
|
||||
.build();
|
||||
|
||||
reduxTester<{ templating: TemplatingState }>()
|
||||
.givenRootReducer(getTemplatingRootReducer())
|
||||
.whenActionIsDispatched(addVariable(toVariablePayload(textbox, { global: false, index: 0, model: textbox })))
|
||||
.whenActionIsDispatched(
|
||||
addVariable(toVariablePayload(constant, { global: false, index: 1, model: constant }))
|
||||
)
|
||||
.whenActionIsDispatched(changeVariableName(toVariableIdentifier(constant), '#constant!'), true)
|
||||
.thenDispatchedActionsShouldEqual(
|
||||
changeVariableNameFailed({
|
||||
newName: '#constant!',
|
||||
errorText: 'Only word and digit characters are allowed in variable names',
|
||||
})
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
describe('when changeVariableName is dispatched with a name that is already used', () => {
|
||||
it('then the correct actions are dispatched', () => {
|
||||
const textbox = textboxBuilder()
|
||||
.withId('textbox')
|
||||
.withName('textbox')
|
||||
.build();
|
||||
const constant = constantBuilder()
|
||||
.withId('constant')
|
||||
.withName('constant')
|
||||
.build();
|
||||
|
||||
reduxTester<{ templating: TemplatingState }>()
|
||||
.givenRootReducer(getTemplatingRootReducer())
|
||||
.whenActionIsDispatched(addVariable(toVariablePayload(textbox, { global: false, index: 0, model: textbox })))
|
||||
.whenActionIsDispatched(
|
||||
addVariable(toVariablePayload(constant, { global: false, index: 1, model: constant }))
|
||||
)
|
||||
.whenActionIsDispatched(changeVariableName(toVariableIdentifier(constant), 'textbox'), true)
|
||||
.thenDispatchedActionsShouldEqual(
|
||||
changeVariableNameFailed({
|
||||
newName: 'textbox',
|
||||
errorText: 'Variable with the same name already exists',
|
||||
})
|
||||
);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
@ -9,7 +9,7 @@ import {
|
||||
VariableOption,
|
||||
VariableRefresh,
|
||||
VariableWithOptions,
|
||||
} from '../../templating/variable';
|
||||
} from '../../templating/types';
|
||||
import { StoreState, ThunkResult } from '../../../types';
|
||||
import { getVariable, getVariables } from './selectors';
|
||||
import { variableAdapters } from '../adapters';
|
||||
|
@ -1,7 +1,7 @@
|
||||
import { combineReducers } from '@reduxjs/toolkit';
|
||||
|
||||
import { NEW_VARIABLE_ID } from './types';
|
||||
import { VariableHide, VariableModel } from '../../templating/variable';
|
||||
import { VariableHide, VariableModel } from '../../templating/types';
|
||||
import { variablesReducer, VariablesState } from './variablesReducer';
|
||||
import { optionsPickerReducer } from '../pickers/OptionsPicker/reducer';
|
||||
import { variableEditorReducer } from '../editor/reducer';
|
||||
|
@ -1,4 +1,5 @@
|
||||
import { dateTime, TimeRange } from '@grafana/data';
|
||||
|
||||
import { TemplateSrv } from '../../templating/template_srv';
|
||||
import { Emitter } from '../../../core/utils/emitter';
|
||||
import { onTimeRangeUpdated, OnTimeRangeUpdatedDependencies } from './actions';
|
||||
@ -7,7 +8,7 @@ import { DashboardState } from '../../../types';
|
||||
import { createIntervalVariableAdapter } from '../interval/adapter';
|
||||
import { variableAdapters } from '../adapters';
|
||||
import { createConstantVariableAdapter } from '../constant/adapter';
|
||||
import { VariableRefresh } from '../../templating/variable';
|
||||
import { VariableRefresh } from '../../templating/types';
|
||||
import { constantBuilder, intervalBuilder } from '../shared/testing/builders';
|
||||
|
||||
variableAdapters.setInit(() => [createIntervalVariableAdapter(), createConstantVariableAdapter()]);
|
||||
|
@ -9,7 +9,7 @@ import { TemplatingState } from 'app/features/variables/state/reducers';
|
||||
import { initDashboardTemplating, processVariable } from './actions';
|
||||
import { resolveInitLock, setCurrentVariableValue } from './sharedReducer';
|
||||
import { toVariableIdentifier, toVariablePayload } from './types';
|
||||
import { VariableRefresh } from '../../templating/variable';
|
||||
import { VariableRefresh } from '../../templating/types';
|
||||
import { updateVariableOptions } from '../query/reducer';
|
||||
import { customBuilder, queryBuilder } from '../shared/testing/builders';
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
import { reducerTester } from '../../../../test/core/redux/reducerTester';
|
||||
import { cleanUpDashboard } from 'app/features/dashboard/state/reducers';
|
||||
import { QueryVariableModel, VariableHide, VariableType } from '../../templating/variable';
|
||||
import { QueryVariableModel, VariableHide, VariableType } from '../../templating/types';
|
||||
import { VariableAdapter, variableAdapters } from '../adapters';
|
||||
import { createAction } from '@reduxjs/toolkit';
|
||||
import { variablesReducer, VariablesState } from './variablesReducer';
|
||||
|
@ -2,7 +2,7 @@ import { combineReducers } from '@reduxjs/toolkit';
|
||||
import { optionsPickerReducer, OptionsPickerState } from '../pickers/OptionsPicker/reducer';
|
||||
import { variableEditorReducer, VariableEditorState } from '../editor/reducer';
|
||||
import { variablesReducer } from './variablesReducer';
|
||||
import { VariableModel } from '../../templating/variable';
|
||||
import { VariableModel } from '../../templating/types';
|
||||
|
||||
export interface TemplatingState {
|
||||
variables: Record<string, VariableModel>;
|
||||
|
@ -1,7 +1,7 @@
|
||||
import { cloneDeep } from 'lodash';
|
||||
|
||||
import { StoreState } from '../../../types';
|
||||
import { VariableModel } from '../../templating/variable';
|
||||
import { VariableModel } from '../../templating/types';
|
||||
import { getState } from '../../../store/store';
|
||||
import { NEW_VARIABLE_ID } from './types';
|
||||
|
||||
|
@ -14,7 +14,7 @@ import {
|
||||
sharedReducer,
|
||||
storeNewVariable,
|
||||
} from './sharedReducer';
|
||||
import { QueryVariableModel, VariableHide } from '../../templating/variable';
|
||||
import { QueryVariableModel, VariableHide } from '../../templating/types';
|
||||
import { ALL_VARIABLE_TEXT, ALL_VARIABLE_VALUE, NEW_VARIABLE_ID, toVariablePayload } from './types';
|
||||
import { variableAdapters } from '../adapters';
|
||||
import { createQueryVariableAdapter } from '../query/adapter';
|
||||
|
@ -1,7 +1,7 @@
|
||||
import { createSlice, PayloadAction } from '@reduxjs/toolkit';
|
||||
import cloneDeep from 'lodash/cloneDeep';
|
||||
|
||||
import { VariableModel, VariableOption, VariableType, VariableWithOptions } from '../../templating/variable';
|
||||
import { VariableModel, VariableOption, VariableType, VariableWithOptions } from '../../templating/types';
|
||||
import { AddVariable, ALL_VARIABLE_VALUE, getInstanceState, NEW_VARIABLE_ID, VariablePayload } from './types';
|
||||
import { variableAdapters } from '../adapters';
|
||||
import { changeVariableNameSucceeded } from '../editor/reducer';
|
||||
|
@ -1,4 +1,4 @@
|
||||
import { VariableModel, VariableType } from '../../templating/variable';
|
||||
import { VariableModel, VariableType } from '../../templating/types';
|
||||
import { VariablesState } from './variablesReducer';
|
||||
|
||||
export const NEW_VARIABLE_ID = '00000000-0000-0000-0000-000000000000';
|
||||
|
@ -2,7 +2,7 @@ import { PayloadAction } from '@reduxjs/toolkit';
|
||||
import { cleanUpDashboard } from '../../dashboard/state/reducers';
|
||||
import { variableAdapters } from '../adapters';
|
||||
import { sharedReducer } from './sharedReducer';
|
||||
import { VariableModel } from '../../templating/variable';
|
||||
import { VariableModel } from '../../templating/types';
|
||||
import { VariablePayload } from './types';
|
||||
|
||||
export interface VariablesState extends Record<string, VariableModel> {}
|
||||
|
@ -1,5 +1,5 @@
|
||||
import React, { ChangeEvent, PureComponent } from 'react';
|
||||
import { TextBoxVariableModel } from '../../templating/variable';
|
||||
import { TextBoxVariableModel } from '../../templating/types';
|
||||
import { VariableEditorProps } from '../editor/types';
|
||||
|
||||
export interface Props extends VariableEditorProps<TextBoxVariableModel> {}
|
||||
|
@ -1,6 +1,6 @@
|
||||
import React, { ChangeEvent, FocusEvent, KeyboardEvent, PureComponent } from 'react';
|
||||
|
||||
import { TextBoxVariableModel } from '../../templating/variable';
|
||||
import { TextBoxVariableModel } from '../../templating/types';
|
||||
import { toVariablePayload } from '../state/types';
|
||||
import { dispatch } from '../../../store/store';
|
||||
import { variableAdapters } from '../adapters';
|
||||
|
@ -4,7 +4,7 @@ import { reduxTester } from '../../../../test/core/redux/reduxTester';
|
||||
import { TemplatingState } from 'app/features/variables/state/reducers';
|
||||
import { updateTextBoxVariableOptions } from './actions';
|
||||
import { getTemplatingRootReducer } from '../state/helpers';
|
||||
import { TextBoxVariableModel, VariableHide, VariableOption } from '../../templating/variable';
|
||||
import { TextBoxVariableModel, VariableHide, VariableOption } from '../../templating/types';
|
||||
import { toVariablePayload } from '../state/types';
|
||||
import { createTextBoxOptions } from './reducer';
|
||||
import { setCurrentVariableValue } from '../state/sharedReducer';
|
||||
|
@ -1,4 +1,4 @@
|
||||
import { TextBoxVariableModel } from '../../templating/variable';
|
||||
import { TextBoxVariableModel } from '../../templating/types';
|
||||
import { ThunkResult } from '../../../types';
|
||||
import { getVariable } from '../state/selectors';
|
||||
import { variableAdapters } from '../adapters';
|
||||
|
@ -1,6 +1,6 @@
|
||||
import cloneDeep from 'lodash/cloneDeep';
|
||||
|
||||
import { TextBoxVariableModel } from '../../templating/variable';
|
||||
import { TextBoxVariableModel } from '../../templating/types';
|
||||
import { initialTextBoxVariableModelState, textBoxVariableReducer } from './reducer';
|
||||
import { dispatch } from '../../../store/store';
|
||||
import { setOptionAsCurrent, setOptionFromUrl } from '../state/actions';
|
||||
|
@ -4,7 +4,7 @@ import { getVariableTestContext } from '../state/helpers';
|
||||
import { toVariablePayload } from '../state/types';
|
||||
import { createTextBoxOptions, textBoxVariableReducer } from './reducer';
|
||||
import { VariablesState } from '../state/variablesReducer';
|
||||
import { TextBoxVariableModel } from '../../templating/variable';
|
||||
import { TextBoxVariableModel } from '../../templating/types';
|
||||
import { createTextBoxVariableAdapter } from './adapter';
|
||||
|
||||
describe('textBoxVariableReducer', () => {
|
||||
|
@ -1,6 +1,6 @@
|
||||
import { createSlice, PayloadAction } from '@reduxjs/toolkit';
|
||||
|
||||
import { TextBoxVariableModel, VariableHide, VariableOption } from '../../templating/variable';
|
||||
import { TextBoxVariableModel, VariableHide, VariableOption } from '../../templating/types';
|
||||
import { getInstanceState, NEW_VARIABLE_ID, VariablePayload } from '../state/types';
|
||||
import { initialVariablesState, VariablesState } from '../state/variablesReducer';
|
||||
|
||||
|
@ -1,13 +1,13 @@
|
||||
import _ from 'lodash';
|
||||
import {
|
||||
DataFrame,
|
||||
dateMath,
|
||||
ScopedVars,
|
||||
DataQueryResponse,
|
||||
DataQueryRequest,
|
||||
toDataFrame,
|
||||
DataQueryResponse,
|
||||
DataSourceApi,
|
||||
dateMath,
|
||||
QueryResultMetaStat,
|
||||
ScopedVars,
|
||||
toDataFrame,
|
||||
} from '@grafana/data';
|
||||
import { isVersionGtOrEq, SemVersion } from 'app/core/utils/version';
|
||||
import gfunc from './gfunc';
|
||||
@ -15,8 +15,8 @@ import { getBackendSrv } from '@grafana/runtime';
|
||||
import { TemplateSrv } from 'app/features/templating/template_srv';
|
||||
// Types
|
||||
import { GraphiteOptions, GraphiteQuery, GraphiteType, MetricTankRequestMeta } from './types';
|
||||
import { getSearchFilterScopedVar } from '../../../features/templating/variable';
|
||||
import { getRollupNotice, getRuntimeConsolidationNotice } from 'app/plugins/datasource/graphite/meta';
|
||||
import { getSearchFilterScopedVar } from '../../../features/templating/utils';
|
||||
|
||||
export class GraphiteDatasource extends DataSourceApi<GraphiteQuery, GraphiteOptions> {
|
||||
basicAuth: string;
|
||||
|
@ -7,7 +7,7 @@ import { TemplateSrv } from 'app/features/templating/template_srv';
|
||||
import { TimeSrv } from 'app/features/dashboard/services/TimeSrv';
|
||||
//Types
|
||||
import { MysqlQueryForInterpolation } from './types';
|
||||
import { getSearchFilterScopedVar } from '../../../features/templating/variable';
|
||||
import { getSearchFilterScopedVar } from '../../../features/templating/utils';
|
||||
|
||||
export class MysqlDatasource {
|
||||
id: any;
|
||||
|
@ -7,7 +7,7 @@ import { TemplateSrv } from 'app/features/templating/template_srv';
|
||||
import { TimeSrv } from 'app/features/dashboard/services/TimeSrv';
|
||||
//Types
|
||||
import { PostgresQueryForInterpolation } from './types';
|
||||
import { getSearchFilterScopedVar } from '../../../features/templating/variable';
|
||||
import { getSearchFilterScopedVar } from '../../../features/templating/utils';
|
||||
|
||||
export class PostgresDatasource {
|
||||
id: any;
|
||||
|
@ -1,4 +1,5 @@
|
||||
import {
|
||||
DataQueryError,
|
||||
DataQueryRequest,
|
||||
DataQueryResponse,
|
||||
DataSourceApi,
|
||||
@ -6,7 +7,6 @@ import {
|
||||
MetricFindValue,
|
||||
TableData,
|
||||
TimeSeries,
|
||||
DataQueryError,
|
||||
} from '@grafana/data';
|
||||
import { Scenario, TestDataQuery } from './types';
|
||||
import { getBackendSrv } from '@grafana/runtime';
|
||||
@ -14,7 +14,7 @@ import { queryMetricTree } from './metricTree';
|
||||
import { from, merge, Observable } from 'rxjs';
|
||||
import { runStream } from './runStreams';
|
||||
import templateSrv from 'app/features/templating/template_srv';
|
||||
import { getSearchFilterScopedVar } from '../../../features/templating/variable';
|
||||
import { getSearchFilterScopedVar } from '../../../features/templating/utils';
|
||||
|
||||
type TestData = TimeSeries | TableData;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user