Variables: move state tree into a keyed state (#44642)

* Variables: move state tree into a keyed state

* Update public/app/features/variables/state/transactionReducer.ts

Co-authored-by: kay delaney <45561153+kaydelaney@users.noreply.github.com>

* Chore: fix prettier error

* Chore: renamed slices and lastUid

* Chore: rename toUidAction

* Chore: rename dashboardVariableReducer

* Chore: rename state prop back to templating

* Chore renames variable.dashboardUid

* Chore: rename toDashboardVariableIdentifier

* Chore: rename getDashboardVariable

* Chore: rename getDashboardVariablesState

* Chore: rename getDashboardVariables

* Chore: some more renames

* Chore: small clean up

* Chore: small rename

* Chore: removes unused function

* Chore: rename VariableModel.stateKey

* Chore: rename KeyedVariableIdentifier.stateKey

* user essentials mob! 🔱

* user essentials mob! 🔱

* user essentials mob! 🔱

* user essentials mob! 🔱

Co-authored-by: kay delaney <45561153+kaydelaney@users.noreply.github.com>
Co-authored-by: kay delaney <kay@grafana.com>
Co-authored-by: Alexandra Vargas <alexa1866@gmail.com>
Co-authored-by: Ashley Harrison <ashley.harrison@grafana.com>
This commit is contained in:
Hugo Häggmark
2022-02-18 06:06:04 +01:00
committed by GitHub
parent a9de33601c
commit dbec2b02fd
105 changed files with 2894 additions and 1644 deletions

View File

@@ -5,15 +5,31 @@ import { DataSourceRef, SelectableValue } from '@grafana/data';
import { AdHocVariableModel } from '../types';
import { VariableEditorProps } from '../editor/types';
import { initialVariableEditorState } from '../editor/reducer';
import { changeVariableDatasource, initAdHocVariableEditor } from './actions';
import { StoreState } from 'app/types';
import { VariableSectionHeader } from '../editor/VariableSectionHeader';
import { VariableSelectField } from '../editor/VariableSelectField';
import { getAdhocVariableEditorState } from '../editor/selectors';
import { getVariablesState } from '../state/selectors';
import { toKeyedVariableIdentifier } from '../utils';
const mapStateToProps = (state: StoreState) => ({
extended: getAdhocVariableEditorState(state.templating.editor),
});
const mapStateToProps = (state: StoreState, ownProps: OwnProps) => {
const { rootStateKey } = ownProps.variable;
if (!rootStateKey) {
console.error('AdHocVariableEditor: variable has no rootStateKey');
return {
extended: getAdhocVariableEditorState(initialVariableEditorState),
};
}
const { editor } = getVariablesState(rootStateKey, state);
return {
extended: getAdhocVariableEditorState(editor),
};
};
const mapDispatchToProps = {
initAdHocVariableEditor,
@@ -28,11 +44,17 @@ type Props = OwnProps & ConnectedProps<typeof connector>;
export class AdHocVariableEditorUnConnected extends PureComponent<Props> {
componentDidMount() {
this.props.initAdHocVariableEditor();
const { rootStateKey } = this.props.variable;
if (!rootStateKey) {
console.error('AdHocVariableEditor: variable has no rootStateKey');
return;
}
this.props.initAdHocVariableEditor(rootStateKey);
}
onDatasourceChanged = (option: SelectableValue<DataSourceRef>) => {
this.props.changeVariableDatasource(option.value);
this.props.changeVariableDatasource(toKeyedVariableIdentifier(this.props.variable), option.value);
};
render() {