mirror of
https://github.com/grafana/grafana.git
synced 2025-08-02 18:32:23 +08:00
Variables: removes cloneDeep from getVariables selector (#23196)
* Refactor: removes getVariables * Refactor: renames getVariableClones to getVariables
This commit is contained in:
@ -1,7 +1,7 @@
|
||||
import React, { useMemo, FC } from 'react';
|
||||
import React, { FC, useMemo } from 'react';
|
||||
import { PanelModel } from '../../state';
|
||||
import { SelectableValue } from '@grafana/data';
|
||||
import { Forms, DataLinksInlineEditor } from '@grafana/ui';
|
||||
import { DataLinksInlineEditor, Forms } from '@grafana/ui';
|
||||
import { OptionsGroup } from './OptionsGroup';
|
||||
import { getPanelLinksVariableSuggestions } from '../../../panel/panellinks/link_srv';
|
||||
import { getVariables } from '../../../variables/state/selectors';
|
||||
|
@ -1,7 +1,7 @@
|
||||
import React, { PureComponent } from 'react';
|
||||
import { connect, MapStateToProps } from 'react-redux';
|
||||
import { StoreState } from '../../../../types';
|
||||
import { getVariableClones } from '../../../variables/state/selectors';
|
||||
import { getVariables } from '../../../variables/state/selectors';
|
||||
import { VariableHide, VariableModel } from '../../../templating/types';
|
||||
import { DashboardModel } from '../../state';
|
||||
import { AngularDashboardLinks } from './AngularDashboardLinks';
|
||||
@ -69,7 +69,7 @@ class SubMenuUnConnected extends PureComponent<Props> {
|
||||
}
|
||||
|
||||
const mapStateToProps: MapStateToProps<ConnectedProps, OwnProps, StoreState> = state => ({
|
||||
variables: getVariableClones(state, false),
|
||||
variables: getVariables(state, false),
|
||||
});
|
||||
|
||||
export const SubMenu = connect(mapStateToProps)(SubMenuUnConnected);
|
||||
|
@ -14,7 +14,7 @@ import { AppEvent, dateTime, DateTimeInput, isDateTime, PanelEvents, TimeRange,
|
||||
import { UrlQueryValue } from '@grafana/runtime';
|
||||
import { CoreEvents, DashboardMeta, KIOSK_MODE_TV } from 'app/types';
|
||||
import { getConfig } from '../../../core/config';
|
||||
import { getVariableClones, getVariables } from 'app/features/variables/state/selectors';
|
||||
import { getVariables } from 'app/features/variables/state/selectors';
|
||||
import { variableAdapters } from 'app/features/variables/adapters';
|
||||
import { onTimeRangeUpdated } from 'app/features/variables/state/actions';
|
||||
import { dispatch } from '../../../store/store';
|
||||
@ -238,7 +238,7 @@ export class DashboardModel {
|
||||
defaults: { saveTimerange: boolean; saveVariables: boolean } & CloneOptions
|
||||
) {
|
||||
const originalVariables = this.originalTemplating;
|
||||
const currentVariables = getVariableClones();
|
||||
const currentVariables = getVariables();
|
||||
|
||||
copy.templating = {
|
||||
list: currentVariables.map(variable => variableAdapters.get(variable.type).getSaveModel(variable)),
|
||||
@ -940,12 +940,12 @@ export class DashboardModel {
|
||||
return;
|
||||
}
|
||||
|
||||
this.originalTemplating = this.cloneVariablesFrom(getVariableClones());
|
||||
this.originalTemplating = this.cloneVariablesFrom(getVariables());
|
||||
}
|
||||
|
||||
hasVariableValuesChanged() {
|
||||
if (getConfig().featureToggles.newVariables) {
|
||||
return this.hasVariablesChanged(this.originalTemplating, getVariableClones());
|
||||
return this.hasVariablesChanged(this.originalTemplating, getVariables());
|
||||
}
|
||||
|
||||
return this.hasVariablesChanged(this.originalTemplating, this.templating.list);
|
||||
@ -1019,7 +1019,7 @@ export class DashboardModel {
|
||||
|
||||
getVariables = () => {
|
||||
if (getConfig().featureToggles.newVariables) {
|
||||
return getVariableClones();
|
||||
return getVariables();
|
||||
}
|
||||
return this.templating.list;
|
||||
};
|
||||
|
@ -2,7 +2,7 @@ import kbn from 'app/core/utils/kbn';
|
||||
import _ from 'lodash';
|
||||
import { escapeHtml } from 'app/core/utils/text';
|
||||
import { deprecationWarning, ScopedVars, TimeRange } from '@grafana/data';
|
||||
import { getFilteredVariables, getVariableClones, getVariableWithName } from '../variables/state/selectors';
|
||||
import { getFilteredVariables, getVariables, getVariableWithName } from '../variables/state/selectors';
|
||||
import { getConfig } from 'app/core/config';
|
||||
import { variableRegex } from './utils';
|
||||
import { isAdHoc } from '../variables/guard';
|
||||
@ -53,7 +53,7 @@ export class TemplateSrv {
|
||||
|
||||
getVariables(): VariableModel[] {
|
||||
if (getConfig().featureToggles.newVariables) {
|
||||
return getVariableClones();
|
||||
return getVariables();
|
||||
}
|
||||
|
||||
return this._variables;
|
||||
|
@ -6,7 +6,7 @@ import { VariableEditorList } from './VariableEditorList';
|
||||
import { VariableEditorEditor } from './VariableEditorEditor';
|
||||
import { MapDispatchToProps, MapStateToProps } from 'react-redux';
|
||||
import { connectWithStore } from '../../../core/utils/connectWithReduxStore';
|
||||
import { getVariableClones } from '../state/selectors';
|
||||
import { getVariables } from '../state/selectors';
|
||||
import { VariableModel } from '../../templating/types';
|
||||
import { switchToEditMode, switchToListMode, switchToNewMode } from './actions';
|
||||
import { changeVariableOrder, duplicateVariable, removeVariable } from '../state/sharedReducer';
|
||||
@ -122,7 +122,7 @@ class VariableEditorContainerUnconnected extends PureComponent<Props> {
|
||||
}
|
||||
|
||||
const mapStateToProps: MapStateToProps<ConnectedProps, OwnProps, StoreState> = state => ({
|
||||
variables: getVariableClones(state, true),
|
||||
variables: getVariables(state, true),
|
||||
idInEditor: state.templating.editor.id,
|
||||
});
|
||||
|
||||
|
@ -1,5 +1,5 @@
|
||||
import { ThunkResult } from '../../../types';
|
||||
import { getVariable, getVariables, getNewVariabelIndex } from '../state/selectors';
|
||||
import { getNewVariabelIndex, getVariable, getVariables } from '../state/selectors';
|
||||
import {
|
||||
changeVariableNameFailed,
|
||||
changeVariableNameSucceeded,
|
||||
|
@ -1,5 +1,3 @@
|
||||
import { cloneDeep } from 'lodash';
|
||||
|
||||
import { StoreState } from '../../../types';
|
||||
import { VariableModel } from '../../templating/types';
|
||||
import { getState } from '../../../store/store';
|
||||
@ -28,15 +26,11 @@ export const getVariableWithName = (name: string) => {
|
||||
return getVariable(name, getState(), false);
|
||||
};
|
||||
|
||||
export const getVariables = (state: StoreState = getState()): VariableModel[] => {
|
||||
return getFilteredVariables(variable => variable.id! !== NEW_VARIABLE_ID, state);
|
||||
};
|
||||
|
||||
export const getVariableClones = (state: StoreState = getState(), includeEmptyUuid = false): VariableModel[] => {
|
||||
export const getVariables = (state: StoreState = getState(), includeNewVariable = false): VariableModel[] => {
|
||||
const variables = getFilteredVariables(
|
||||
variable => (includeEmptyUuid ? true : variable.id! !== NEW_VARIABLE_ID),
|
||||
variable => (includeNewVariable ? true : variable.id! !== NEW_VARIABLE_ID),
|
||||
state
|
||||
).map(variable => cloneDeep(variable));
|
||||
);
|
||||
return variables.sort((s1, s2) => s1.index! - s2.index!);
|
||||
};
|
||||
|
||||
|
Reference in New Issue
Block a user