Skip to content

Commit

Permalink
React UI: broken graph page browser history (#6659)
Browse files Browse the repository at this point in the history
* add panel state for the expression input

Signed-off-by: blalov <boiskila@gmail.com>

* remove redundant test

Signed-off-by: blalov <boiskila@gmail.com>
  • Loading branch information
boyskila authored and juliusv committed Jan 18, 2020
1 parent 669592a commit 0f84d5b
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 13 deletions.
11 changes: 8 additions & 3 deletions web/ui/react-app/src/pages/graph/Panel.tsx
Expand Up @@ -28,6 +28,7 @@ interface PanelState {
loading: boolean;
error: string | null;
stats: QueryStats | null;
exprInputValue: string;
}

export interface PanelOptions {
Expand Down Expand Up @@ -65,6 +66,7 @@ class Panel extends Component<PanelProps & PathPrefixProps, PanelState> {
loading: false,
error: null,
stats: null,
exprInputValue: props.options.expr,
};
}

Expand All @@ -85,9 +87,12 @@ class Panel extends Component<PanelProps & PathPrefixProps, PanelState> {
}

executeQuery = (): void => {
const { expr } = this.props.options;
const { exprInputValue: expr } = this.state;
const queryStart = Date.now();
this.props.onExecuteQuery(expr);
if (this.props.options.expr !== expr) {
this.setOptions({ expr });
}
if (expr === '') {
return;
}
Expand Down Expand Up @@ -177,7 +182,7 @@ class Panel extends Component<PanelProps & PathPrefixProps, PanelState> {
}

handleExpressionChange = (expr: string): void => {
this.setOptions({ expr: expr });
this.setState({ exprInputValue: expr });
};

handleChangeRange = (range: number): void => {
Expand Down Expand Up @@ -215,7 +220,7 @@ class Panel extends Component<PanelProps & PathPrefixProps, PanelState> {
<Row>
<Col>
<ExpressionInput
value={options.expr}
value={this.state.exprInputValue}
onExpressionChange={this.handleExpressionChange}
executeQuery={this.executeQuery}
loading={this.state.loading}
Expand Down
8 changes: 0 additions & 8 deletions web/ui/react-app/src/pages/graph/PanelList.test.tsx
Expand Up @@ -37,12 +37,4 @@ describe('PanelList', () => {
expect(btn.prop('color')).toEqual('primary');
expect(btn.children().text()).toEqual('Add Panel');
});

it('updates URL when a query is executed', () => {
const panelList = mount(<PanelList />);
const instance: any = panelList.instance();
const updateURLSpy = jest.spyOn(instance, 'updateURL');
instance.handleExecuteQuery('new');
expect(updateURLSpy).toHaveBeenCalledTimes(1);
});
});
3 changes: 1 addition & 2 deletions web/ui/react-app/src/pages/graph/PanelList.tsx
Expand Up @@ -109,7 +109,6 @@ class PanelList extends Component<RouteComponentProps & PathPrefixProps, PanelLi
);
localStorage.setItem('history', JSON.stringify(extendedItems.slice(0, 50)));
this.updatePastQueries();
this.updateURL();
};

updateURL() {
Expand All @@ -119,7 +118,7 @@ class PanelList extends Component<RouteComponentProps & PathPrefixProps, PanelLi

handleOptionsChanged = (id: string, options: PanelOptions) => {
const updatedPanels = this.state.panels.map(p => (id === p.id ? { ...p, options } : p));
this.setState({ panels: updatedPanels });
this.setState({ panels: updatedPanels }, this.updateURL);
};

addPanel = () => {
Expand Down

0 comments on commit 0f84d5b

Please sign in to comment.