Files
Hugo Häggmark 00a9af00fc Templating: removes old Angular variable system and featureToggle (#24779)
* Chore: initial commit

* Tests: fixes MetricsQueryEditor.test.tsx

* Tests: fixes cloudwatch/specs/datasource.test.ts

* Tests: fixes stackdriver/specs/datasource.test.ts

* Tests: remove refrences to CustomVariable

* Refactor: moves DefaultVariableQueryEditor

* Refactor: moves utils

* Refactor: moves types

* Refactor: removes variableSrv

* Refactor: removes feature toggle newVariables

* Refactor: removes valueSelectDropDown

* Chore: removes GeneralTabCtrl

* Chore: migrates RowOptions

* Refactor: adds RowOptionsButton

* Refactor: makes the interface more explicit

* Refactor: small changes

* Refactor: changed type as it can be any variable type

* Tests: fixes broken test

* Refactor: changes after PR comments

* Refactor: adds loading state and call to onChange in componentDidMount
2020-06-04 13:44:48 +02:00

82 lines
2.0 KiB
TypeScript

import { combineReducers } from '@reduxjs/toolkit';
import { NEW_VARIABLE_ID } from './types';
import { VariableHide, VariableModel } from '../types';
import { VariablesState } from './variablesReducer';
import { locationReducer } from '../../../core/reducers/location';
import { VariableAdapter } from '../adapters';
import { dashboardReducer } from 'app/features/dashboard/state/reducers';
import { templatingReducers } from './reducers';
export const getVariableState = (
noOfVariables: number,
inEditorIndex = -1,
includeEmpty = false
): Record<string, VariableModel> => {
const variables: Record<string, VariableModel> = {};
for (let index = 0; index < noOfVariables; index++) {
variables[index] = {
id: index.toString(),
type: 'query',
name: `Name-${index}`,
hide: VariableHide.dontHide,
index,
label: `Label-${index}`,
skipUrlSync: false,
global: false,
};
}
if (includeEmpty) {
variables[NEW_VARIABLE_ID] = {
id: NEW_VARIABLE_ID,
type: 'query',
name: `Name-${NEW_VARIABLE_ID}`,
hide: VariableHide.dontHide,
index: noOfVariables,
label: `Label-${NEW_VARIABLE_ID}`,
skipUrlSync: false,
global: false,
};
}
return variables;
};
export const getVariableTestContext = <Model extends VariableModel>(
adapter: VariableAdapter<Model>,
variableOverrides: Partial<Model> = {}
) => {
const defaultVariable = {
...adapter.initialState,
id: '0',
index: 0,
name: '0',
};
const initialState: VariablesState = {
'0': { ...defaultVariable, ...variableOverrides },
};
return { initialState };
};
export const getRootReducer = () =>
combineReducers({
location: locationReducer,
dashboard: dashboardReducer,
templating: templatingReducers,
});
export const getTemplatingRootReducer = () =>
combineReducers({
templating: templatingReducers,
});
export const getTemplatingAndLocationRootReducer = () =>
combineReducers({
templating: templatingReducers,
location: locationReducer,
});