Commit a40f08c8 authored by Sudheer's avatar Sudheer Committed by sudheer
Browse files

MM-27346 Fix for excessive analytic events on scroll of LHS (#6007)

* MM-27346 Fix for excessive analytic events on scroll of LHS

  * Prevent onToggle when menu state hasnt changed

* Fix lint

* Remove rudder keys
parent 625adf07
......@@ -54,6 +54,19 @@ describe('components/sidebar/sidebar_menu', () => {
expect(baseProps.onToggle).toHaveBeenCalledWith(false);
});
test('should not call external onToggle when menu state hasnt changed', () => {
const wrapper = shallow<SidebarMenu>(
<SidebarMenu {...baseProps}/>,
);
wrapper.instance().handleMenuToggle(true);
expect(baseProps.onToggle).toHaveBeenCalledWith(true);
expect(baseProps.onToggle).toHaveBeenCalledTimes(1);
wrapper.instance().handleMenuToggle(true);
expect(baseProps.onToggle).toHaveBeenCalledTimes(1);
});
test('should set the openUp and width properties correctly based on window and ref information', () => {
const windowSpy = jest.spyOn(global, 'window' as any, 'get');
windowSpy.mockImplementation(() => ({
......
......@@ -119,13 +119,15 @@ export default class SidebarMenu extends React.PureComponent<Props, State> {
}
handleMenuToggle = (isMenuOpen: boolean) => {
this.setState({isMenuOpen}, () => {
if (this.props.onToggle) {
this.props.onToggle(isMenuOpen);
}
this.setMenuPosition();
this.disableScrollbar();
});
if (this.state.isMenuOpen !== isMenuOpen) {
this.setState({isMenuOpen}, () => {
if (this.props.onToggle) {
this.props.onToggle(isMenuOpen);
}
this.setMenuPosition();
this.disableScrollbar();
});
}
}
render() {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment