Commit d6449ee6 by Johannes Schill

fix: Logo goes Home instead of toggling side menu #15482

parent bc2a7981
...@@ -2,7 +2,6 @@ import React from 'react'; ...@@ -2,7 +2,6 @@ import React from 'react';
import { shallow } from 'enzyme'; import { shallow } from 'enzyme';
import { SideMenu } from './SideMenu'; import { SideMenu } from './SideMenu';
import appEvents from '../../app_events'; import appEvents from '../../app_events';
import { contextSrv } from 'app/core/services/context_srv';
jest.mock('../../app_events', () => ({ jest.mock('../../app_events', () => ({
emit: jest.fn(), emit: jest.fn(),
...@@ -26,7 +25,6 @@ jest.mock('app/core/services/context_srv', () => ({ ...@@ -26,7 +25,6 @@ jest.mock('app/core/services/context_srv', () => ({
isGrafanaAdmin: false, isGrafanaAdmin: false,
isEditor: false, isEditor: false,
hasEditPermissionFolders: false, hasEditPermissionFolders: false,
toggleSideMenu: jest.fn(),
}, },
})); }));
...@@ -54,20 +52,6 @@ describe('Render', () => { ...@@ -54,20 +52,6 @@ describe('Render', () => {
}); });
describe('Functions', () => { describe('Functions', () => {
describe('toggle side menu', () => {
const wrapper = setup();
const instance = wrapper.instance() as SideMenu;
instance.toggleSideMenu();
it('should call contextSrv.toggleSideMenu', () => {
expect(contextSrv.toggleSideMenu).toHaveBeenCalled();
});
it('should emit toggle sidemenu event', () => {
expect(appEvents.emit).toHaveBeenCalledWith('toggle-sidemenu');
});
});
describe('toggle side menu on mobile', () => { describe('toggle side menu on mobile', () => {
const wrapper = setup(); const wrapper = setup();
const instance = wrapper.instance() as SideMenu; const instance = wrapper.instance() as SideMenu;
......
import React, { PureComponent } from 'react'; import React, { PureComponent } from 'react';
import appEvents from '../../app_events'; import appEvents from '../../app_events';
import { contextSrv } from 'app/core/services/context_srv';
import TopSection from './TopSection'; import TopSection from './TopSection';
import BottomSection from './BottomSection'; import BottomSection from './BottomSection';
import { store } from 'app/store/store'; import config from 'app/core/config';
export class SideMenu extends PureComponent { const homeUrl = config.appSubUrl || '/';
toggleSideMenu = () => {
// ignore if we just made a location change, stops hiding sidemenu on double clicks of back button
const timeSinceLocationChanged = new Date().getTime() - store.getState().location.lastUpdated;
if (timeSinceLocationChanged < 1000) {
return;
}
contextSrv.toggleSideMenu();
appEvents.emit('toggle-sidemenu');
};
export class SideMenu extends PureComponent {
toggleSideMenuSmallBreakpoint = () => { toggleSideMenuSmallBreakpoint = () => {
appEvents.emit('toggle-sidemenu-mobile'); appEvents.emit('toggle-sidemenu-mobile');
}; };
render() { render() {
return [ return [
<div className="sidemenu__logo" onClick={this.toggleSideMenu} key="logo"> <a href={homeUrl} className="sidemenu__logo" key="logo">
<img src="public/img/grafana_icon.svg" alt="Grafana" /> <img src="public/img/grafana_icon.svg" alt="Grafana" />
</div>, </a>,
<div className="sidemenu__logo_small_breakpoint" onClick={this.toggleSideMenuSmallBreakpoint} key="hamburger"> <div className="sidemenu__logo_small_breakpoint" onClick={this.toggleSideMenuSmallBreakpoint} key="hamburger">
<i className="fa fa-bars" /> <i className="fa fa-bars" />
<span className="sidemenu__close"> <span className="sidemenu__close">
......
import config from 'app/core/config'; import config from 'app/core/config';
import _ from 'lodash'; import _ from 'lodash';
import coreModule from 'app/core/core_module'; import coreModule from 'app/core/core_module';
import store from 'app/core/store';
export class User { export class User {
isGrafanaAdmin: any; isGrafanaAdmin: any;
...@@ -29,13 +28,11 @@ export class ContextSrv { ...@@ -29,13 +28,11 @@ export class ContextSrv {
isSignedIn: any; isSignedIn: any;
isGrafanaAdmin: any; isGrafanaAdmin: any;
isEditor: any; isEditor: any;
sidemenu: any; sidemenu = true;
sidemenuSmallBreakpoint = false; sidemenuSmallBreakpoint = false;
hasEditPermissionInFolders: boolean; hasEditPermissionInFolders: boolean;
constructor() { constructor() {
this.sidemenu = store.getBool('grafana.sidemenu', true);
if (!config.bootData) { if (!config.bootData) {
config.bootData = { user: {}, settings: {} }; config.bootData = { user: {}, settings: {} };
} }
...@@ -55,11 +52,6 @@ export class ContextSrv { ...@@ -55,11 +52,6 @@ export class ContextSrv {
return !!(document.visibilityState === undefined || document.visibilityState === 'visible'); return !!(document.visibilityState === undefined || document.visibilityState === 'visible');
} }
toggleSideMenu() {
this.sidemenu = !this.sidemenu;
store.set('grafana.sidemenu', this.sidemenu);
}
hasAccessToExplore() { hasAccessToExplore() {
return (this.isEditor || config.viewersCanEdit) && config.exploreEnabled; return (this.isEditor || config.viewersCanEdit) && config.exploreEnabled;
} }
......
...@@ -116,11 +116,6 @@ export function grafanaAppDirective(playlistSrv, contextSrv, $timeout, $rootScop ...@@ -116,11 +116,6 @@ export function grafanaAppDirective(playlistSrv, contextSrv, $timeout, $rootScop
sidemenuOpen = scope.contextSrv.sidemenu; sidemenuOpen = scope.contextSrv.sidemenu;
body.toggleClass('sidemenu-open', sidemenuOpen); body.toggleClass('sidemenu-open', sidemenuOpen);
appEvents.on('toggle-sidemenu', () => {
sidemenuOpen = scope.contextSrv.sidemenu;
body.toggleClass('sidemenu-open');
});
appEvents.on('toggle-sidemenu-mobile', () => { appEvents.on('toggle-sidemenu-mobile', () => {
body.toggleClass('sidemenu-open--xs'); body.toggleClass('sidemenu-open--xs');
}); });
......
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