aboutsummaryrefslogtreecommitdiffstats
path: root/server/sonar-web/src/main/js/app
diff options
context:
space:
mode:
authorStas Vilchik <vilchiks@gmail.com>2016-12-20 16:16:16 +0100
committerStas Vilchik <vilchiks@gmail.com>2016-12-20 16:35:14 +0100
commit8c9d3d5bb674a0ea9a8dcff2fef5a1eeb70537a8 (patch)
tree76a79e8438a2b5c024cb23c596c6962149a6ab1e /server/sonar-web/src/main/js/app
parentad9cf3363e466ad8e62c1b7c91363b18c80940ef (diff)
downloadsonarqube-8c9d3d5bb674a0ea9a8dcff2fef5a1eeb70537a8.tar.gz
sonarqube-8c9d3d5bb674a0ea9a8dcff2fef5a1eeb70537a8.zip
SONAR-8552 fix global navigation
Diffstat (limited to 'server/sonar-web/src/main/js/app')
-rw-r--r--server/sonar-web/src/main/js/app/components/nav/global/GlobalNav.js5
-rw-r--r--server/sonar-web/src/main/js/app/components/nav/global/GlobalNavMenu.js16
-rw-r--r--server/sonar-web/src/main/js/app/components/nav/global/__tests__/GlobalNavMenu-test.js35
-rw-r--r--server/sonar-web/src/main/js/app/components/nav/global/__tests__/__snapshots__/GlobalNavMenu-test.js.snap77
4 files changed, 123 insertions, 10 deletions
diff --git a/server/sonar-web/src/main/js/app/components/nav/global/GlobalNav.js b/server/sonar-web/src/main/js/app/components/nav/global/GlobalNav.js
index 7543197a7ae..e2a6bd52631 100644
--- a/server/sonar-web/src/main/js/app/components/nav/global/GlobalNav.js
+++ b/server/sonar-web/src/main/js/app/components/nav/global/GlobalNav.js
@@ -24,7 +24,7 @@ import GlobalNavMenu from './GlobalNavMenu';
import GlobalNavUser from './GlobalNavUser';
import GlobalNavSearch from './GlobalNavSearch';
import ShortcutsHelpView from './ShortcutsHelpView';
-import { getCurrentUser } from '../../../../store/rootReducer';
+import { getCurrentUser, getAppState } from '../../../../store/rootReducer';
class GlobalNav extends React.Component {
componentDidMount () {
@@ -77,7 +77,8 @@ class GlobalNav extends React.Component {
}
const mapStateToProps = state => ({
- currentUser: getCurrentUser(state)
+ currentUser: getCurrentUser(state),
+ appState: getAppState(state)
});
export default connect(mapStateToProps)(GlobalNav);
diff --git a/server/sonar-web/src/main/js/app/components/nav/global/GlobalNavMenu.js b/server/sonar-web/src/main/js/app/components/nav/global/GlobalNavMenu.js
index d5c2f6402a8..4f5ca4ef2cf 100644
--- a/server/sonar-web/src/main/js/app/components/nav/global/GlobalNavMenu.js
+++ b/server/sonar-web/src/main/js/app/components/nav/global/GlobalNavMenu.js
@@ -24,6 +24,7 @@ import { isUserAdmin } from '../../../../helpers/users';
export default class GlobalNavMenu extends React.Component {
static propTypes = {
+ appState: React.PropTypes.object.isRequired,
currentUser: React.PropTypes.object.isRequired
};
@@ -102,20 +103,19 @@ export default class GlobalNavMenu extends React.Component {
);
}
- renderGlobalPageLink (globalPage, index) {
- const url = window.baseUrl + globalPage.url;
+ renderGlobalPageLink = ({ id, name }) => {
return (
- <li key={index}>
- <a href={url}>{globalPage.name}</a>
+ <li key={id}>
+ <Link to={`/extension/${id}`}>{name}</Link>
</li>
);
- }
+ };
renderMore () {
- if (this.props.globalPages.length === 0) {
+ const { globalPages } = this.props.appState;
+ if (globalPages.length === 0) {
return null;
}
- const globalPages = this.props.globalPages.map((p, i) => this.renderGlobalPageLink(p, i));
return (
<li className="dropdown">
<a className="dropdown-toggle" data-toggle="dropdown" href="#">
@@ -123,7 +123,7 @@ export default class GlobalNavMenu extends React.Component {
<span className="icon-dropdown"/>
</a>
<ul className="dropdown-menu">
- {globalPages}
+ {globalPages.map(this.renderGlobalPageLink)}
</ul>
</li>
);
diff --git a/server/sonar-web/src/main/js/app/components/nav/global/__tests__/GlobalNavMenu-test.js b/server/sonar-web/src/main/js/app/components/nav/global/__tests__/GlobalNavMenu-test.js
new file mode 100644
index 00000000000..94fe7d69878
--- /dev/null
+++ b/server/sonar-web/src/main/js/app/components/nav/global/__tests__/GlobalNavMenu-test.js
@@ -0,0 +1,35 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2016 SonarSource SA
+ * mailto:contact AT sonarsource DOT com
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+import React from 'react';
+import { shallow } from 'enzyme';
+import toJSON from 'enzyme-to-json';
+import GlobalNavMenu from '../GlobalNavMenu';
+
+it('should work with extensions', () => {
+ const appState = {
+ globalPages: [{ id: 'foo', name: 'Foo' }]
+ };
+ const currentUser = {
+ isLoggedIn: false,
+ permissions: { global: [] }
+ };
+ const wrapper = shallow(<GlobalNavMenu appState={appState} currentUser={currentUser}/>);
+ expect(toJSON(wrapper)).toMatchSnapshot();
+});
diff --git a/server/sonar-web/src/main/js/app/components/nav/global/__tests__/__snapshots__/GlobalNavMenu-test.js.snap b/server/sonar-web/src/main/js/app/components/nav/global/__tests__/__snapshots__/GlobalNavMenu-test.js.snap
new file mode 100644
index 00000000000..9e8810eb407
--- /dev/null
+++ b/server/sonar-web/src/main/js/app/components/nav/global/__tests__/__snapshots__/GlobalNavMenu-test.js.snap
@@ -0,0 +1,77 @@
+exports[`test should work with extensions 1`] = `
+<ul
+ className="nav navbar-nav">
+ <li>
+ <Link
+ activeClassName="active"
+ onlyActiveOnIndex={false}
+ style={Object {}}
+ to={
+ Object {
+ "pathname": "/projects",
+ }
+ }>
+ projects.page
+ </Link>
+ </li>
+ <li>
+ <Link
+ className={null}
+ onlyActiveOnIndex={false}
+ style={Object {}}
+ to="/issues#resolved=false">
+ issues.page
+ </Link>
+ </li>
+ <li>
+ <Link
+ className={null}
+ onlyActiveOnIndex={false}
+ style={Object {}}
+ to="/coding_rules">
+ coding_rules.page
+ </Link>
+ </li>
+ <li>
+ <Link
+ activeClassName="active"
+ onlyActiveOnIndex={false}
+ style={Object {}}
+ to="/profiles">
+ quality_profiles.page
+ </Link>
+ </li>
+ <li>
+ <Link
+ activeClassName="active"
+ onlyActiveOnIndex={false}
+ style={Object {}}
+ to="/quality_gates">
+ quality_gates.page
+ </Link>
+ </li>
+ <li
+ className="dropdown">
+ <a
+ className="dropdown-toggle"
+ data-toggle="dropdown"
+ href="#">
+ more
+  
+ <span
+ className="icon-dropdown" />
+ </a>
+ <ul
+ className="dropdown-menu">
+ <li>
+ <Link
+ onlyActiveOnIndex={false}
+ style={Object {}}
+ to="/extension/foo">
+ Foo
+ </Link>
+ </li>
+ </ul>
+ </li>
+</ul>
+`;