update panels on back button pressed (#6300)

Signed-off-by: Boyko Lalov <boyskila@gmail.com>
pull/6308/head
Boyko 5 years ago committed by Julius Volz
parent ce7bab04dd
commit fc309a35bb

@ -96,11 +96,11 @@ describe('ExpressionInput', () => {
}); });
}); });
describe('handleDropdownSelection', () => { describe('onSelect', () => {
it('should call setState with selected value', () => { it('should call setState with selected value', () => {
const instance: any = expressionInput.instance(); const instance: any = expressionInput.instance();
const stateSpy = jest.spyOn(instance, 'setState'); const stateSpy = jest.spyOn(instance, 'setState');
instance.handleDropdownSelection('foo'); instance.setValue('foo');
expect(stateSpy).toHaveBeenCalledWith({ value: 'foo', height: 'auto' }, expect.anything()); expect(stateSpy).toHaveBeenCalledWith({ value: 'foo', height: 'auto' }, expect.anything());
}); });
}); });

@ -42,19 +42,20 @@ class ExpressionInput extends Component<ExpressionInputProps, ExpressionInputSta
}; };
handleInput = () => { handleInput = () => {
this.setState( this.setValue(this.exprInputRef.current!.value);
{
height: 'auto',
value: this.exprInputRef.current!.value,
},
this.setHeight
);
}; };
handleDropdownSelection = (value: string) => { setValue = (value: string) => {
this.setState({ value, height: 'auto' }, this.setHeight); this.setState({ value, height: 'auto' }, this.setHeight);
}; };
componentDidUpdate(prevProps: ExpressionInputProps) {
const { value } = this.props;
if (value !== prevProps.value) {
this.setValue(value);
}
}
handleKeyPress = (event: React.KeyboardEvent<HTMLInputElement>) => { handleKeyPress = (event: React.KeyboardEvent<HTMLInputElement>) => {
if (event.key === 'Enter' && !event.shiftKey) { if (event.key === 'Enter' && !event.shiftKey) {
this.executeQuery(); this.executeQuery();
@ -126,7 +127,7 @@ class ExpressionInput extends Component<ExpressionInputProps, ExpressionInputSta
render() { render() {
const { value, height } = this.state; const { value, height } = this.state;
return ( return (
<Downshift onSelect={this.handleDropdownSelection}> <Downshift onSelect={this.setValue}>
{downshift => ( {downshift => (
<div> <div>
<InputGroup className="expression-input"> <InputGroup className="expression-input">

@ -79,7 +79,8 @@ class Panel extends Component<PanelProps & PathPrefixProps, PanelState> {
prevOpts.type !== opts.type || prevOpts.type !== opts.type ||
prevOpts.range !== opts.range || prevOpts.range !== opts.range ||
prevOpts.endTime !== opts.endTime || prevOpts.endTime !== opts.endTime ||
prevOpts.resolution !== opts.resolution prevOpts.resolution !== opts.resolution ||
prevOpts.expr !== opts.expr
) { ) {
if (prevOpts.type !== opts.type) { if (prevOpts.type !== opts.type) {
// If the other options change, we still want to show the old data until the new // If the other options change, we still want to show the old data until the new

Loading…
Cancel
Save