diff --git a/public/app/core/directives/value_select_dropdown.ts b/public/app/core/directives/value_select_dropdown.ts index 6dd7b9cc57f..3f1169cc317 100644 --- a/public/app/core/directives/value_select_dropdown.ts +++ b/public/app/core/directives/value_select_dropdown.ts @@ -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; diff --git a/public/app/features/dashboard/components/SubMenu/SubMenu.tsx b/public/app/features/dashboard/components/SubMenu/SubMenu.tsx index e46c257fefa..afcceeba22e 100644 --- a/public/app/features/dashboard/components/SubMenu/SubMenu.tsx +++ b/public/app/features/dashboard/components/SubMenu/SubMenu.tsx @@ -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'; diff --git a/public/app/features/dashboard/components/SubMenu/SubMenuItems.tsx b/public/app/features/dashboard/components/SubMenu/SubMenuItems.tsx index 3dd44509aaa..093645d06b0 100644 --- a/public/app/features/dashboard/components/SubMenu/SubMenuItems.tsx +++ b/public/app/features/dashboard/components/SubMenu/SubMenuItems.tsx @@ -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'; diff --git a/public/app/features/dashboard/state/DashboardModel.ts b/public/app/features/dashboard/state/DashboardModel.ts index 4f09d20a96d..814457972d9 100644 --- a/public/app/features/dashboard/state/DashboardModel.ts +++ b/public/app/features/dashboard/state/DashboardModel.ts @@ -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'; diff --git a/public/app/features/templating/TextBoxVariable.ts b/public/app/features/templating/TextBoxVariable.ts index fcf5bd79b58..62c2c1b2f51 100644 --- a/public/app/features/templating/TextBoxVariable.ts +++ b/public/app/features/templating/TextBoxVariable.ts @@ -6,7 +6,7 @@ import { VariableOption, VariableType, variableTypes, -} from './variable'; +} from './types'; import { VariableSrv } from './variable_srv'; export class TextBoxVariable implements TextBoxVariableModel, VariableActions { diff --git a/public/app/features/templating/adhoc_variable.ts b/public/app/features/templating/adhoc_variable.ts index f1016369656..36fa527c1a3 100644 --- a/public/app/features/templating/adhoc_variable.ts +++ b/public/app/features/templating/adhoc_variable.ts @@ -7,7 +7,7 @@ import { VariableHide, VariableType, variableTypes, -} from './variable'; +} from './types'; export class AdhocVariable implements AdHocVariableModel, VariableActions { type: VariableType; diff --git a/public/app/features/templating/constant_variable.ts b/public/app/features/templating/constant_variable.ts index 8097671e614..15eb3c3538a 100644 --- a/public/app/features/templating/constant_variable.ts +++ b/public/app/features/templating/constant_variable.ts @@ -6,7 +6,7 @@ import { VariableOption, VariableType, variableTypes, -} from './variable'; +} from './types'; import { VariableSrv } from './all'; export class ConstantVariable implements ConstantVariableModel, VariableActions { diff --git a/public/app/features/templating/custom_variable.ts b/public/app/features/templating/custom_variable.ts index d083824687b..032dfc6ef4a 100644 --- a/public/app/features/templating/custom_variable.ts +++ b/public/app/features/templating/custom_variable.ts @@ -7,7 +7,7 @@ import { VariableOption, VariableType, variableTypes, -} from './variable'; +} from './types'; import { VariableSrv } from './variable_srv'; export class CustomVariable implements CustomVariableModel, VariableActions { diff --git a/public/app/features/templating/datasource_variable.ts b/public/app/features/templating/datasource_variable.ts index 835a9bfe22e..924be3da150 100644 --- a/public/app/features/templating/datasource_variable.ts +++ b/public/app/features/templating/datasource_variable.ts @@ -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; diff --git a/public/app/features/templating/editor_ctrl.ts b/public/app/features/templating/editor_ctrl.ts index 2752db32606..4c41ca976cb 100644 --- a/public/app/features/templating/editor_ctrl.ts +++ b/public/app/features/templating/editor_ctrl.ts @@ -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'; diff --git a/public/app/features/templating/interval_variable.ts b/public/app/features/templating/interval_variable.ts index a367b0f46e0..1152e1f24ed 100644 --- a/public/app/features/templating/interval_variable.ts +++ b/public/app/features/templating/interval_variable.ts @@ -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'; diff --git a/public/app/features/templating/query_variable.ts b/public/app/features/templating/query_variable.ts index ae0527e18c4..ccab522ffc2 100644 --- a/public/app/features/templating/query_variable.ts +++ b/public/app/features/templating/query_variable.ts @@ -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 }; diff --git a/public/app/features/templating/specs/variable.test.ts b/public/app/features/templating/specs/utils.test.ts similarity index 97% rename from public/app/features/templating/specs/variable.test.ts rename to public/app/features/templating/specs/utils.test.ts index 35b374f712e..cf129672ea7 100644 --- a/public/app/features/templating/specs/variable.test.ts +++ b/public/app/features/templating/specs/utils.test.ts @@ -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', () => { diff --git a/public/app/features/templating/template_srv.ts b/public/app/features/templating/template_srv.ts index 2a8e6f9d0df..c91b2f8fe6d 100644 --- a/public/app/features/templating/template_srv.ts +++ b/public/app/features/templating/template_srv.ts @@ -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) { diff --git a/public/app/features/templating/variable.ts b/public/app/features/templating/types.ts similarity index 60% rename from public/app/features/templating/variable.ts rename to public/app/features/templating/types.ts index d2ec672b483..d31f7037508 100644 --- a/public/app/features/templating/variable.ts +++ b/public/app/features/templating/types.ts @@ -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; -} diff --git a/public/app/features/templating/utils.ts b/public/app/features/templating/utils.ts new file mode 100644 index 00000000000..67194dd09d7 --- /dev/null +++ b/public/app/features/templating/utils.ts @@ -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; +} diff --git a/public/app/features/templating/variable_srv.ts b/public/app/features/templating/variable_srv.ts index d4170d61a60..b3036c79004 100644 --- a/public/app/features/templating/variable_srv.ts +++ b/public/app/features/templating/variable_srv.ts @@ -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'; diff --git a/public/app/features/variables/adapters.ts b/public/app/features/variables/adapters.ts index a9bfc21e40a..4c5244d5b10 100644 --- a/public/app/features/variables/adapters.ts +++ b/public/app/features/variables/adapters.ts @@ -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'; diff --git a/public/app/features/variables/adhoc/AdHocVariableEditor.tsx b/public/app/features/variables/adhoc/AdHocVariableEditor.tsx index 7617dfac8c3..4eb6258bd99 100644 --- a/public/app/features/variables/adhoc/AdHocVariableEditor.tsx +++ b/public/app/features/variables/adhoc/AdHocVariableEditor.tsx @@ -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 {} diff --git a/public/app/features/variables/adhoc/actions.test.ts b/public/app/features/variables/adhoc/actions.test.ts index c28cfea774a..93cf3e8c68a 100644 --- a/public/app/features/variables/adhoc/actions.test.ts +++ b/public/app/features/variables/adhoc/actions.test.ts @@ -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'; diff --git a/public/app/features/variables/adhoc/actions.ts b/public/app/features/variables/adhoc/actions.ts index 40be5f10ecd..0c522c549a4 100644 --- a/public/app/features/variables/adhoc/actions.ts +++ b/public/app/features/variables/adhoc/actions.ts @@ -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'; diff --git a/public/app/features/variables/adhoc/adapter.ts b/public/app/features/variables/adhoc/adapter.ts index b5a3cd5d12e..a6bc3c81f8b 100644 --- a/public/app/features/variables/adhoc/adapter.ts +++ b/public/app/features/variables/adhoc/adapter.ts @@ -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'; diff --git a/public/app/features/variables/adhoc/picker/AdHocFilterBuilder.tsx b/public/app/features/variables/adhoc/picker/AdHocFilterBuilder.tsx index be429df98ca..f84c6b8e953 100644 --- a/public/app/features/variables/adhoc/picker/AdHocFilterBuilder.tsx +++ b/public/app/features/variables/adhoc/picker/AdHocFilterBuilder.tsx @@ -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 { diff --git a/public/app/features/variables/adhoc/picker/AdHocPicker.tsx b/public/app/features/variables/adhoc/picker/AdHocPicker.tsx index 6c68b915e3a..2a4378bb28d 100644 --- a/public/app/features/variables/adhoc/picker/AdHocPicker.tsx +++ b/public/app/features/variables/adhoc/picker/AdHocPicker.tsx @@ -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'; diff --git a/public/app/features/variables/adhoc/reducer.test.ts b/public/app/features/variables/adhoc/reducer.test.ts index 0198b1fd47b..c4fbae380e1 100644 --- a/public/app/features/variables/adhoc/reducer.test.ts +++ b/public/app/features/variables/adhoc/reducer.test.ts @@ -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', () => { diff --git a/public/app/features/variables/adhoc/reducer.ts b/public/app/features/variables/adhoc/reducer.ts index 2657fb3ea86..0e1c7bd2687 100644 --- a/public/app/features/variables/adhoc/reducer.ts +++ b/public/app/features/variables/adhoc/reducer.ts @@ -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'; diff --git a/public/app/features/variables/adhoc/urlParser.test.ts b/public/app/features/variables/adhoc/urlParser.test.ts index 664910bf649..97010e44039 100644 --- a/public/app/features/variables/adhoc/urlParser.test.ts +++ b/public/app/features/variables/adhoc/urlParser.test.ts @@ -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', () => { diff --git a/public/app/features/variables/adhoc/urlParser.ts b/public/app/features/variables/adhoc/urlParser.ts index 201d6e1d5cc..8430a4b71bf 100644 --- a/public/app/features/variables/adhoc/urlParser.ts +++ b/public/app/features/variables/adhoc/urlParser.ts @@ -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 => diff --git a/public/app/features/variables/constant/ConstantVariableEditor.tsx b/public/app/features/variables/constant/ConstantVariableEditor.tsx index d946f467fab..794fd072293 100644 --- a/public/app/features/variables/constant/ConstantVariableEditor.tsx +++ b/public/app/features/variables/constant/ConstantVariableEditor.tsx @@ -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 {} diff --git a/public/app/features/variables/constant/actions.test.ts b/public/app/features/variables/constant/actions.test.ts index ad4551ce4e8..9df353157ce 100644 --- a/public/app/features/variables/constant/actions.test.ts +++ b/public/app/features/variables/constant/actions.test.ts @@ -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'; diff --git a/public/app/features/variables/constant/adapter.ts b/public/app/features/variables/constant/adapter.ts index 3dd2e13f1f4..608499bdbc0 100644 --- a/public/app/features/variables/constant/adapter.ts +++ b/public/app/features/variables/constant/adapter.ts @@ -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'; diff --git a/public/app/features/variables/constant/reducer.test.ts b/public/app/features/variables/constant/reducer.test.ts index 0e63cb8c1d8..0b2482259fb 100644 --- a/public/app/features/variables/constant/reducer.test.ts +++ b/public/app/features/variables/constant/reducer.test.ts @@ -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', () => { diff --git a/public/app/features/variables/constant/reducer.ts b/public/app/features/variables/constant/reducer.ts index 5fe2c3772f9..bf18b2d3951 100644 --- a/public/app/features/variables/constant/reducer.ts +++ b/public/app/features/variables/constant/reducer.ts @@ -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'; diff --git a/public/app/features/variables/custom/CustomVariableEditor.tsx b/public/app/features/variables/custom/CustomVariableEditor.tsx index d895752e809..d08f0589e92 100644 --- a/public/app/features/variables/custom/CustomVariableEditor.tsx +++ b/public/app/features/variables/custom/CustomVariableEditor.tsx @@ -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'; diff --git a/public/app/features/variables/custom/actions.test.ts b/public/app/features/variables/custom/actions.test.ts index 305b631df30..78ce61214e4 100644 --- a/public/app/features/variables/custom/actions.test.ts +++ b/public/app/features/variables/custom/actions.test.ts @@ -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'; diff --git a/public/app/features/variables/custom/adapter.ts b/public/app/features/variables/custom/adapter.ts index 0f40bc3f60f..71335442b01 100644 --- a/public/app/features/variables/custom/adapter.ts +++ b/public/app/features/variables/custom/adapter.ts @@ -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'; diff --git a/public/app/features/variables/custom/reducer.test.ts b/public/app/features/variables/custom/reducer.test.ts index 93e420a7be1..87f8f8aafb3 100644 --- a/public/app/features/variables/custom/reducer.test.ts +++ b/public/app/features/variables/custom/reducer.test.ts @@ -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(); diff --git a/public/app/features/variables/custom/reducer.ts b/public/app/features/variables/custom/reducer.ts index d1c6185a724..7a8d5ce00a0 100644 --- a/public/app/features/variables/custom/reducer.ts +++ b/public/app/features/variables/custom/reducer.ts @@ -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, diff --git a/public/app/features/variables/datasource/DataSourceVariableEditor.tsx b/public/app/features/variables/datasource/DataSourceVariableEditor.tsx index fd021e9cd44..f24968f85ee 100644 --- a/public/app/features/variables/datasource/DataSourceVariableEditor.tsx +++ b/public/app/features/variables/datasource/DataSourceVariableEditor.tsx @@ -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'; diff --git a/public/app/features/variables/datasource/actions.ts b/public/app/features/variables/datasource/actions.ts index a8a31a03188..032647a7ff4 100644 --- a/public/app/features/variables/datasource/actions.ts +++ b/public/app/features/variables/datasource/actions.ts @@ -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'; diff --git a/public/app/features/variables/datasource/adapter.ts b/public/app/features/variables/datasource/adapter.ts index a03ca9a8704..de09172771f 100644 --- a/public/app/features/variables/datasource/adapter.ts +++ b/public/app/features/variables/datasource/adapter.ts @@ -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 => { return { diff --git a/public/app/features/variables/datasource/reducer.test.ts b/public/app/features/variables/datasource/reducer.test.ts index ad300405e97..eadf9da84fa 100644 --- a/public/app/features/variables/datasource/reducer.test.ts +++ b/public/app/features/variables/datasource/reducer.test.ts @@ -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'; diff --git a/public/app/features/variables/datasource/reducer.ts b/public/app/features/variables/datasource/reducer.ts index 91130caeece..4b6a25d6afc 100644 --- a/public/app/features/variables/datasource/reducer.ts +++ b/public/app/features/variables/datasource/reducer.ts @@ -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, diff --git a/public/app/features/variables/editor/SelectionOptionsEditor.tsx b/public/app/features/variables/editor/SelectionOptionsEditor.tsx index 95d4d074fc1..563fb452eac 100644 --- a/public/app/features/variables/editor/SelectionOptionsEditor.tsx +++ b/public/app/features/variables/editor/SelectionOptionsEditor.tsx @@ -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 diff --git a/public/app/features/variables/editor/VariableEditorContainer.tsx b/public/app/features/variables/editor/VariableEditorContainer.tsx index 92555f1f0fe..9fd7a2d63c5 100644 --- a/public/app/features/variables/editor/VariableEditorContainer.tsx +++ b/public/app/features/variables/editor/VariableEditorContainer.tsx @@ -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'; diff --git a/public/app/features/variables/editor/VariableEditorEditor.tsx b/public/app/features/variables/editor/VariableEditorEditor.tsx index e5868dc8f8e..bcd8a9d0df8 100644 --- a/public/app/features/variables/editor/VariableEditorEditor.tsx +++ b/public/app/features/variables/editor/VariableEditorEditor.tsx @@ -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'; diff --git a/public/app/features/variables/editor/VariableEditorList.tsx b/public/app/features/variables/editor/VariableEditorList.tsx index b6472773956..e91701ca154 100644 --- a/public/app/features/variables/editor/VariableEditorList.tsx +++ b/public/app/features/variables/editor/VariableEditorList.tsx @@ -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 { diff --git a/public/app/features/variables/editor/VariableValuesPreview.tsx b/public/app/features/variables/editor/VariableValuesPreview.tsx index 37fea9ea96d..de63079ac70 100644 --- a/public/app/features/variables/editor/VariableValuesPreview.tsx +++ b/public/app/features/variables/editor/VariableValuesPreview.tsx @@ -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 { diff --git a/public/app/features/variables/editor/actions.ts b/public/app/features/variables/editor/actions.ts index 4851fb17b71..a3d8a07f666 100644 --- a/public/app/features/variables/editor/actions.ts +++ b/public/app/features/variables/editor/actions.ts @@ -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 => { diff --git a/public/app/features/variables/editor/types.ts b/public/app/features/variables/editor/types.ts index 674926c22f1..c43df1e9510 100644 --- a/public/app/features/variables/editor/types.ts +++ b/public/app/features/variables/editor/types.ts @@ -1,4 +1,4 @@ -import { VariableModel } from '../../templating/variable'; +import { VariableModel } from '../../templating/types'; export interface OnPropChangeArguments { propName: keyof Model; diff --git a/public/app/features/variables/guard.ts b/public/app/features/variables/guard.ts index 99210dad4a0..767b84e125a 100644 --- a/public/app/features/variables/guard.ts +++ b/public/app/features/variables/guard.ts @@ -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'; diff --git a/public/app/features/variables/interval/IntervalVariableEditor.tsx b/public/app/features/variables/interval/IntervalVariableEditor.tsx index ad216d61419..05504e27af5 100644 --- a/public/app/features/variables/interval/IntervalVariableEditor.tsx +++ b/public/app/features/variables/interval/IntervalVariableEditor.tsx @@ -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'; diff --git a/public/app/features/variables/interval/actions.ts b/public/app/features/variables/interval/actions.ts index 3888410e756..b42d6c18023 100644 --- a/public/app/features/variables/interval/actions.ts +++ b/public/app/features/variables/interval/actions.ts @@ -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'; diff --git a/public/app/features/variables/interval/adapter.ts b/public/app/features/variables/interval/adapter.ts index a38f28126d1..34c4b344156 100644 --- a/public/app/features/variables/interval/adapter.ts +++ b/public/app/features/variables/interval/adapter.ts @@ -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'; diff --git a/public/app/features/variables/interval/reducer.test.ts b/public/app/features/variables/interval/reducer.test.ts index 64a669e6849..849994f583e 100644 --- a/public/app/features/variables/interval/reducer.test.ts +++ b/public/app/features/variables/interval/reducer.test.ts @@ -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'; diff --git a/public/app/features/variables/interval/reducer.ts b/public/app/features/variables/interval/reducer.ts index 9162a9af4b4..2d79d6f35d9 100644 --- a/public/app/features/variables/interval/reducer.ts +++ b/public/app/features/variables/interval/reducer.ts @@ -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'; diff --git a/public/app/features/variables/pickers/OptionsPicker/OptionsPicker.tsx b/public/app/features/variables/pickers/OptionsPicker/OptionsPicker.tsx index f755ca7ced2..34d6618dd2e 100644 --- a/public/app/features/variables/pickers/OptionsPicker/OptionsPicker.tsx +++ b/public/app/features/variables/pickers/OptionsPicker/OptionsPicker.tsx @@ -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'; diff --git a/public/app/features/variables/pickers/OptionsPicker/actions.test.ts b/public/app/features/variables/pickers/OptionsPicker/actions.test.ts index f044ec1ce9c..4d15d8cda8f 100644 --- a/public/app/features/variables/pickers/OptionsPicker/actions.test.ts +++ b/public/app/features/variables/pickers/OptionsPicker/actions.test.ts @@ -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, diff --git a/public/app/features/variables/pickers/OptionsPicker/actions.ts b/public/app/features/variables/pickers/OptionsPicker/actions.ts index aed60b87abc..44271edece1 100644 --- a/public/app/features/variables/pickers/OptionsPicker/actions.ts +++ b/public/app/features/variables/pickers/OptionsPicker/actions.ts @@ -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 => { return async (dispatch, getState) => { diff --git a/public/app/features/variables/pickers/OptionsPicker/reducer.test.ts b/public/app/features/variables/pickers/OptionsPicker/reducer.test.ts index 19f94489400..a520c35057e 100644 --- a/public/app/features/variables/pickers/OptionsPicker/reducer.test.ts +++ b/public/app/features/variables/pickers/OptionsPicker/reducer.test.ts @@ -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) => { diff --git a/public/app/features/variables/pickers/OptionsPicker/reducer.ts b/public/app/features/variables/pickers/OptionsPicker/reducer.ts index 5f1fcdefab6..e60d595d897 100644 --- a/public/app/features/variables/pickers/OptionsPicker/reducer.ts +++ b/public/app/features/variables/pickers/OptionsPicker/reducer.ts @@ -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; diff --git a/public/app/features/variables/pickers/PickerRenderer.tsx b/public/app/features/variables/pickers/PickerRenderer.tsx index 523046a14a5..aa5d78316bf 100644 --- a/public/app/features/variables/pickers/PickerRenderer.tsx +++ b/public/app/features/variables/pickers/PickerRenderer.tsx @@ -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'; diff --git a/public/app/features/variables/pickers/shared/VariableLink.tsx b/public/app/features/variables/pickers/shared/VariableLink.tsx index 313f460754d..9428ee84220 100644 --- a/public/app/features/variables/pickers/shared/VariableLink.tsx +++ b/public/app/features/variables/pickers/shared/VariableLink.tsx @@ -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; diff --git a/public/app/features/variables/pickers/shared/VariableOptions.tsx b/public/app/features/variables/pickers/shared/VariableOptions.tsx index 3c71d546881..18430ef6c83 100644 --- a/public/app/features/variables/pickers/shared/VariableOptions.tsx +++ b/public/app/features/variables/pickers/shared/VariableOptions.tsx @@ -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; diff --git a/public/app/features/variables/pickers/types.ts b/public/app/features/variables/pickers/types.ts index f3e2e8c7aa7..4d86cd92d37 100644 --- a/public/app/features/variables/pickers/types.ts +++ b/public/app/features/variables/pickers/types.ts @@ -1,4 +1,4 @@ -import { VariableModel } from '../../templating/variable'; +import { VariableModel } from '../../templating/types'; export interface VariablePickerProps { variable: Model; diff --git a/public/app/features/variables/query/QueryVariableEditor.tsx b/public/app/features/variables/query/QueryVariableEditor.tsx index f6ad57d664b..500abe86d0a 100644 --- a/public/app/features/variables/query/QueryVariableEditor.tsx +++ b/public/app/features/variables/query/QueryVariableEditor.tsx @@ -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'; diff --git a/public/app/features/variables/query/actions.test.ts b/public/app/features/variables/query/actions.test.ts index 927258576ac..31c1c476c97 100644 --- a/public/app/features/variables/query/actions.test.ts +++ b/public/app/features/variables/query/actions.test.ts @@ -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'; diff --git a/public/app/features/variables/query/actions.ts b/public/app/features/variables/query/actions.ts index b9e4efa2254..9fcb3eeebc4 100644 --- a/public/app/features/variables/query/actions.ts +++ b/public/app/features/variables/query/actions.ts @@ -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'; diff --git a/public/app/features/variables/query/adapter.ts b/public/app/features/variables/query/adapter.ts index 6949c01fcdf..58159c8c3d9 100644 --- a/public/app/features/variables/query/adapter.ts +++ b/public/app/features/variables/query/adapter.ts @@ -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 => { return { diff --git a/public/app/features/variables/query/reducer.test.ts b/public/app/features/variables/query/reducer.test.ts index d8b0cad7801..b3ff0224b2e 100644 --- a/public/app/features/variables/query/reducer.test.ts +++ b/public/app/features/variables/query/reducer.test.ts @@ -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'; diff --git a/public/app/features/variables/query/reducer.ts b/public/app/features/variables/query/reducer.ts index 7025c39eeb7..6643ae5e9e2 100644 --- a/public/app/features/variables/query/reducer.ts +++ b/public/app/features/variables/query/reducer.ts @@ -9,7 +9,7 @@ import { VariableRefresh, VariableSort, VariableTag, -} from '../../templating/variable'; +} from '../../templating/types'; import templateSrv from '../../templating/template_srv'; import { ALL_VARIABLE_TEXT, diff --git a/public/app/features/variables/shared/testing/adHocVariableBuilder.ts b/public/app/features/variables/shared/testing/adHocVariableBuilder.ts index 5c8b042989b..6e36ed25439 100644 --- a/public/app/features/variables/shared/testing/adHocVariableBuilder.ts +++ b/public/app/features/variables/shared/testing/adHocVariableBuilder.ts @@ -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 { diff --git a/public/app/features/variables/shared/testing/datasourceVariableBuilder.ts b/public/app/features/variables/shared/testing/datasourceVariableBuilder.ts index 8922450835f..73bea4871ae 100644 --- a/public/app/features/variables/shared/testing/datasourceVariableBuilder.ts +++ b/public/app/features/variables/shared/testing/datasourceVariableBuilder.ts @@ -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 extends MultiVariableBuilder { withRefresh(refresh: VariableRefresh) { diff --git a/public/app/features/variables/shared/testing/intervalVariableBuilder.ts b/public/app/features/variables/shared/testing/intervalVariableBuilder.ts index 92a4a448f95..6d4b13ca327 100644 --- a/public/app/features/variables/shared/testing/intervalVariableBuilder.ts +++ b/public/app/features/variables/shared/testing/intervalVariableBuilder.ts @@ -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 { withRefresh(refresh: VariableRefresh) { diff --git a/public/app/features/variables/shared/testing/multiVariableBuilder.ts b/public/app/features/variables/shared/testing/multiVariableBuilder.ts index a93e0e6e848..2599bfa90f9 100644 --- a/public/app/features/variables/shared/testing/multiVariableBuilder.ts +++ b/public/app/features/variables/shared/testing/multiVariableBuilder.ts @@ -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 extends OptionsVariableBuilder { diff --git a/public/app/features/variables/shared/testing/optionsVariableBuilder.ts b/public/app/features/variables/shared/testing/optionsVariableBuilder.ts index 3d7d163caa2..859906004bd 100644 --- a/public/app/features/variables/shared/testing/optionsVariableBuilder.ts +++ b/public/app/features/variables/shared/testing/optionsVariableBuilder.ts @@ -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 extends VariableBuilder { diff --git a/public/app/features/variables/shared/testing/variableBuilder.ts b/public/app/features/variables/shared/testing/variableBuilder.ts index 105d1b8aa58..21f03c0b493 100644 --- a/public/app/features/variables/shared/testing/variableBuilder.ts +++ b/public/app/features/variables/shared/testing/variableBuilder.ts @@ -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 { protected variable: T; diff --git a/public/app/features/variables/state/actions.test.ts b/public/app/features/variables/state/actions.test.ts index f5122537cd4..6c4ba6e095e 100644 --- a/public/app/features/variables/state/actions.test.ts +++ b/public/app/features/variables/state/actions.test.ts @@ -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', + }) + ); + }); + }); + }); }); diff --git a/public/app/features/variables/state/actions.ts b/public/app/features/variables/state/actions.ts index 21e3b2033cd..abad3d4fe8d 100644 --- a/public/app/features/variables/state/actions.ts +++ b/public/app/features/variables/state/actions.ts @@ -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'; diff --git a/public/app/features/variables/state/helpers.ts b/public/app/features/variables/state/helpers.ts index bbe00e57283..8d705c04fce 100644 --- a/public/app/features/variables/state/helpers.ts +++ b/public/app/features/variables/state/helpers.ts @@ -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'; diff --git a/public/app/features/variables/state/onTimeRangeUpdated.test.ts b/public/app/features/variables/state/onTimeRangeUpdated.test.ts index 3cd5c16e41e..8622e1bd7c1 100644 --- a/public/app/features/variables/state/onTimeRangeUpdated.test.ts +++ b/public/app/features/variables/state/onTimeRangeUpdated.test.ts @@ -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()]); diff --git a/public/app/features/variables/state/processVariable.test.ts b/public/app/features/variables/state/processVariable.test.ts index 1c9df4c7c63..a61c41b1bed 100644 --- a/public/app/features/variables/state/processVariable.test.ts +++ b/public/app/features/variables/state/processVariable.test.ts @@ -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'; diff --git a/public/app/features/variables/state/reducers.test.ts b/public/app/features/variables/state/reducers.test.ts index 37a185704f3..cdec57ec326 100644 --- a/public/app/features/variables/state/reducers.test.ts +++ b/public/app/features/variables/state/reducers.test.ts @@ -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'; diff --git a/public/app/features/variables/state/reducers.ts b/public/app/features/variables/state/reducers.ts index 3246e203746..86107d0c8b0 100644 --- a/public/app/features/variables/state/reducers.ts +++ b/public/app/features/variables/state/reducers.ts @@ -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; diff --git a/public/app/features/variables/state/selectors.ts b/public/app/features/variables/state/selectors.ts index 3f879345da7..de88b60c701 100644 --- a/public/app/features/variables/state/selectors.ts +++ b/public/app/features/variables/state/selectors.ts @@ -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'; diff --git a/public/app/features/variables/state/sharedReducer.test.ts b/public/app/features/variables/state/sharedReducer.test.ts index f23b03bba78..f05b26a0638 100644 --- a/public/app/features/variables/state/sharedReducer.test.ts +++ b/public/app/features/variables/state/sharedReducer.test.ts @@ -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'; diff --git a/public/app/features/variables/state/sharedReducer.ts b/public/app/features/variables/state/sharedReducer.ts index 5ba332d17f7..ba42e965432 100644 --- a/public/app/features/variables/state/sharedReducer.ts +++ b/public/app/features/variables/state/sharedReducer.ts @@ -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'; diff --git a/public/app/features/variables/state/types.ts b/public/app/features/variables/state/types.ts index 0841c2c4d37..76a4e53cdd0 100644 --- a/public/app/features/variables/state/types.ts +++ b/public/app/features/variables/state/types.ts @@ -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'; diff --git a/public/app/features/variables/state/variablesReducer.ts b/public/app/features/variables/state/variablesReducer.ts index 10fcaf23cad..317da662458 100644 --- a/public/app/features/variables/state/variablesReducer.ts +++ b/public/app/features/variables/state/variablesReducer.ts @@ -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 {} diff --git a/public/app/features/variables/textbox/TextBoxVariableEditor.tsx b/public/app/features/variables/textbox/TextBoxVariableEditor.tsx index 7390e1537de..d4de06a3951 100644 --- a/public/app/features/variables/textbox/TextBoxVariableEditor.tsx +++ b/public/app/features/variables/textbox/TextBoxVariableEditor.tsx @@ -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 {} diff --git a/public/app/features/variables/textbox/TextBoxVariablePicker.tsx b/public/app/features/variables/textbox/TextBoxVariablePicker.tsx index 878a9158d25..2797782d2aa 100644 --- a/public/app/features/variables/textbox/TextBoxVariablePicker.tsx +++ b/public/app/features/variables/textbox/TextBoxVariablePicker.tsx @@ -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'; diff --git a/public/app/features/variables/textbox/actions.test.ts b/public/app/features/variables/textbox/actions.test.ts index a0995860cf5..1c3555c7a1f 100644 --- a/public/app/features/variables/textbox/actions.test.ts +++ b/public/app/features/variables/textbox/actions.test.ts @@ -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'; diff --git a/public/app/features/variables/textbox/actions.ts b/public/app/features/variables/textbox/actions.ts index a1639a5759a..928f54f5ed3 100644 --- a/public/app/features/variables/textbox/actions.ts +++ b/public/app/features/variables/textbox/actions.ts @@ -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'; diff --git a/public/app/features/variables/textbox/adapter.ts b/public/app/features/variables/textbox/adapter.ts index c7ffc6ffcf3..2a16fdd8ada 100644 --- a/public/app/features/variables/textbox/adapter.ts +++ b/public/app/features/variables/textbox/adapter.ts @@ -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'; diff --git a/public/app/features/variables/textbox/reducer.test.ts b/public/app/features/variables/textbox/reducer.test.ts index e64a35c22a2..f5c28f88c67 100644 --- a/public/app/features/variables/textbox/reducer.test.ts +++ b/public/app/features/variables/textbox/reducer.test.ts @@ -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', () => { diff --git a/public/app/features/variables/textbox/reducer.ts b/public/app/features/variables/textbox/reducer.ts index f6702c7a769..d3c19ab775e 100644 --- a/public/app/features/variables/textbox/reducer.ts +++ b/public/app/features/variables/textbox/reducer.ts @@ -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'; diff --git a/public/app/plugins/datasource/graphite/datasource.ts b/public/app/plugins/datasource/graphite/datasource.ts index cb5f77edbbb..bbee54bcac3 100644 --- a/public/app/plugins/datasource/graphite/datasource.ts +++ b/public/app/plugins/datasource/graphite/datasource.ts @@ -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 { basicAuth: string; diff --git a/public/app/plugins/datasource/mysql/datasource.ts b/public/app/plugins/datasource/mysql/datasource.ts index 75943207a03..2bb39ebf0e1 100644 --- a/public/app/plugins/datasource/mysql/datasource.ts +++ b/public/app/plugins/datasource/mysql/datasource.ts @@ -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; diff --git a/public/app/plugins/datasource/postgres/datasource.ts b/public/app/plugins/datasource/postgres/datasource.ts index dbb7b0d93a9..c4a3723722b 100644 --- a/public/app/plugins/datasource/postgres/datasource.ts +++ b/public/app/plugins/datasource/postgres/datasource.ts @@ -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; diff --git a/public/app/plugins/datasource/testdata/datasource.ts b/public/app/plugins/datasource/testdata/datasource.ts index 7b7ab65f9ce..2a60728eece 100644 --- a/public/app/plugins/datasource/testdata/datasource.ts +++ b/public/app/plugins/datasource/testdata/datasource.ts @@ -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;