mirror of
https://github.com/grafana/grafana.git
synced 2025-08-02 07:32:13 +08:00
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:
@ -1,12 +1,13 @@
|
||||
import React, { ChangeEvent, FocusEvent, KeyboardEvent, ReactElement, useCallback, useEffect, useState } from 'react';
|
||||
|
||||
import { TextBoxVariableModel } from '../types';
|
||||
import { toVariablePayload } from '../state/types';
|
||||
import { changeVariableProp } from '../state/sharedReducer';
|
||||
import { VariablePickerProps } from '../pickers/types';
|
||||
import { Input } from '@grafana/ui';
|
||||
import { variableAdapters } from '../adapters';
|
||||
import { useDispatch } from 'react-redux';
|
||||
import { toKeyedAction } from '../state/keyedVariablesReducer';
|
||||
import { toVariablePayload } from '../utils';
|
||||
|
||||
export interface Props extends VariablePickerProps<TextBoxVariableModel> {}
|
||||
|
||||
@ -18,13 +19,21 @@ export function TextBoxVariablePicker({ variable, onVariableChange }: Props): Re
|
||||
}, [variable]);
|
||||
|
||||
const updateVariable = useCallback(() => {
|
||||
if (!variable.rootStateKey) {
|
||||
console.error('Cannot update variable without rootStateKey');
|
||||
return;
|
||||
}
|
||||
|
||||
if (variable.current.value === updatedValue) {
|
||||
return;
|
||||
}
|
||||
|
||||
dispatch(
|
||||
changeVariableProp(
|
||||
toVariablePayload({ id: variable.id, type: variable.type }, { propName: 'query', propValue: updatedValue })
|
||||
toKeyedAction(
|
||||
variable.rootStateKey,
|
||||
changeVariableProp(
|
||||
toVariablePayload({ id: variable.id, type: variable.type }, { propName: 'query', propValue: updatedValue })
|
||||
)
|
||||
)
|
||||
);
|
||||
|
||||
|
Reference in New Issue
Block a user