]> source.dussan.org Git - sonarqube.git/commitdiff
Move favorite button side by side with the breadcrumb
authorPhilippe Perrin <philippe.perrin@sonarsource.com>
Thu, 21 Nov 2019 16:39:49 +0000 (17:39 +0100)
committerSonarTech <sonartech@sonarsource.com>
Mon, 10 Feb 2020 19:46:13 +0000 (20:46 +0100)
server/sonar-web/src/main/js/app/components/nav/component/ComponentNav.tsx
server/sonar-web/src/main/js/app/components/nav/component/ComponentNavHeader.tsx [deleted file]
server/sonar-web/src/main/js/app/components/nav/component/ComponentNavMeta.tsx
server/sonar-web/src/main/js/app/components/nav/component/Header.tsx [new file with mode: 0644]
server/sonar-web/src/main/js/app/components/nav/component/__tests__/ComponentNavHeader-test.tsx [deleted file]
server/sonar-web/src/main/js/app/components/nav/component/__tests__/Header-test.tsx [new file with mode: 0644]
server/sonar-web/src/main/js/app/components/nav/component/__tests__/__snapshots__/ComponentNav-test.tsx.snap
server/sonar-web/src/main/js/app/components/nav/component/__tests__/__snapshots__/ComponentNavHeader-test.tsx.snap [deleted file]
server/sonar-web/src/main/js/app/components/nav/component/__tests__/__snapshots__/Header-test.tsx.snap [new file with mode: 0644]

index 19b3f24aaf96243efe8e28f9c93d3f448562c5d0..775ac1fc23ce9330e3247ba10c922e44c738f917 100644 (file)
@@ -25,9 +25,9 @@ import { rawSizes } from '../../../theme';
 import RecentHistory from '../../RecentHistory';
 import './ComponentNav.css';
 import ComponentNavBgTaskNotif from './ComponentNavBgTaskNotif';
-import ComponentNavHeader from './ComponentNavHeader';
 import ComponentNavMenu from './ComponentNavMenu';
 import ComponentNavMeta from './ComponentNavMeta';
+import Header from './Header';
 
 interface Props {
   branchLikes: BranchLike[];
@@ -88,7 +88,7 @@ export default class ComponentNav extends React.PureComponent<Props> {
         id="context-navigation"
         notif={notifComponent}>
         <div className="navbar-context-justified">
-          <ComponentNavHeader
+          <Header
             branchLikes={this.props.branchLikes}
             component={component}
             currentBranchLike={currentBranchLike}
diff --git a/server/sonar-web/src/main/js/app/components/nav/component/ComponentNavHeader.tsx b/server/sonar-web/src/main/js/app/components/nav/component/ComponentNavHeader.tsx
deleted file mode 100644 (file)
index dec1d32..0000000
+++ /dev/null
@@ -1,56 +0,0 @@
-/*
- * SonarQube
- * Copyright (C) 2009-2020 SonarSource SA
- * mailto:info 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 * as React from 'react';
-import { Helmet } from 'react-helmet-async';
-import { BranchLike } from '../../../../types/branch-like';
-import BranchLikeNavigation from './branch-like/BranchLikeNavigation';
-import CurrentBranchLikeMergeInformation from './branch-like/CurrentBranchLikeMergeInformation';
-import { ComponentBreadcrumb } from './ComponentBreadcrumb';
-
-export interface ComponentNavHeaderProps {
-  branchLikes: BranchLike[];
-  component: T.Component;
-  currentBranchLike: BranchLike | undefined;
-}
-
-export function ComponentNavHeader(props: ComponentNavHeaderProps) {
-  const { branchLikes, component, currentBranchLike } = props;
-
-  return (
-    <>
-      <Helmet title={component.name} />
-      <header className="display-flex-center flex-shrink">
-        <ComponentBreadcrumb component={component} currentBranchLike={currentBranchLike} />
-        {currentBranchLike && (
-          <>
-            <BranchLikeNavigation
-              branchLikes={branchLikes}
-              component={component}
-              currentBranchLike={currentBranchLike}
-            />
-            <CurrentBranchLikeMergeInformation currentBranchLike={currentBranchLike} />
-          </>
-        )}
-      </header>
-    </>
-  );
-}
-
-export default React.memo(ComponentNavHeader);
index 6ab02fd532b07cd4448477de717e392353d04449..a4a6c278561dfa711657279fd03945c9ebe8ee4e 100644 (file)
@@ -23,7 +23,6 @@ import Tooltip from 'sonar-ui-common/components/controls/Tooltip';
 import DetachIcon from 'sonar-ui-common/components/icons/DetachIcon';
 import { translate } from 'sonar-ui-common/helpers/l10n';
 import BranchStatus from '../../../../components/common/BranchStatus';
-import Favorite from '../../../../components/controls/Favorite';
 import HomePageSelect from '../../../../components/controls/HomePageSelect';
 import DateTimeFormatter from '../../../../components/intl/DateTimeFormatter';
 import { isBranch, isMainBranch, isPullRequest } from '../../../../helpers/branch-like';
@@ -62,14 +61,7 @@ export function ComponentNavMeta({ branchLike, component, currentUser, warnings
       )}
       {isLoggedIn(currentUser) && (
         <div className="navbar-context-meta-secondary">
-          {mainBranch && (
-            <Favorite
-              component={component.key}
-              favorite={Boolean(component.isFavorite)}
-              qualifier={component.qualifier}
-            />
-          )}
-          {isABranch && currentPage !== undefined && (
+          {mainBranch && currentPage !== undefined && (
             <HomePageSelect className="spacer-left" currentPage={currentPage} />
           )}
         </div>
diff --git a/server/sonar-web/src/main/js/app/components/nav/component/Header.tsx b/server/sonar-web/src/main/js/app/components/nav/component/Header.tsx
new file mode 100644 (file)
index 0000000..0ed44b0
--- /dev/null
@@ -0,0 +1,73 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2020 SonarSource SA
+ * mailto:info 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 * as React from 'react';
+import { Helmet } from 'react-helmet-async';
+import { connect } from 'react-redux';
+import Favorite from '../../../../components/controls/Favorite';
+import { isLoggedIn } from '../../../../helpers/users';
+import { getCurrentUser, Store } from '../../../../store/rootReducer';
+import { BranchLike } from '../../../../types/branch-like';
+import BranchLikeNavigation from './branch-like/BranchLikeNavigation';
+import CurrentBranchLikeMergeInformation from './branch-like/CurrentBranchLikeMergeInformation';
+import { ComponentBreadcrumb } from './ComponentBreadcrumb';
+
+export interface HeaderProps {
+  branchLikes: BranchLike[];
+  component: T.Component;
+  currentBranchLike: BranchLike | undefined;
+  currentUser: T.CurrentUser;
+}
+
+export function Header(props: HeaderProps) {
+  const { branchLikes, component, currentBranchLike, currentUser } = props;
+
+  return (
+    <>
+      <Helmet title={component.name} />
+      <header className="display-flex-center flex-shrink">
+        <ComponentBreadcrumb component={component} currentBranchLike={currentBranchLike} />
+        {isLoggedIn(currentUser) && (
+          <Favorite
+            className="spacer-left"
+            component={component.key}
+            favorite={Boolean(component.isFavorite)}
+            qualifier={component.qualifier}
+          />
+        )}
+        {currentBranchLike && (
+          <>
+            <BranchLikeNavigation
+              branchLikes={branchLikes}
+              component={component}
+              currentBranchLike={currentBranchLike}
+            />
+            <CurrentBranchLikeMergeInformation currentBranchLike={currentBranchLike} />
+          </>
+        )}
+      </header>
+    </>
+  );
+}
+
+const mapStateToProps = (state: Store) => ({
+  currentUser: getCurrentUser(state)
+});
+
+export default connect(mapStateToProps)(React.memo(Header));
diff --git a/server/sonar-web/src/main/js/app/components/nav/component/__tests__/ComponentNavHeader-test.tsx b/server/sonar-web/src/main/js/app/components/nav/component/__tests__/ComponentNavHeader-test.tsx
deleted file mode 100644 (file)
index 31fbec9..0000000
+++ /dev/null
@@ -1,42 +0,0 @@
-/*
- * SonarQube
- * Copyright (C) 2009-2020 SonarSource SA
- * mailto:info 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 { shallow } from 'enzyme';
-import * as React from 'react';
-import { mockSetOfBranchAndPullRequest } from '../../../../../helpers/mocks/branch-like';
-import { mockComponent } from '../../../../../helpers/testMocks';
-import { ComponentNavHeader, ComponentNavHeaderProps } from '../ComponentNavHeader';
-
-it('should render correctly', () => {
-  const wrapper = shallowRender();
-  expect(wrapper).toMatchSnapshot();
-});
-
-function shallowRender(props?: Partial<ComponentNavHeaderProps>) {
-  const branchLikes = mockSetOfBranchAndPullRequest();
-
-  return shallow(
-    <ComponentNavHeader
-      branchLikes={branchLikes}
-      component={mockComponent()}
-      currentBranchLike={branchLikes[0]}
-      {...props}
-    />
-  );
-}
diff --git a/server/sonar-web/src/main/js/app/components/nav/component/__tests__/Header-test.tsx b/server/sonar-web/src/main/js/app/components/nav/component/__tests__/Header-test.tsx
new file mode 100644 (file)
index 0000000..aff2c93
--- /dev/null
@@ -0,0 +1,49 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2020 SonarSource SA
+ * mailto:info 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 { shallow } from 'enzyme';
+import * as React from 'react';
+import Favorite from '../../../../../components/controls/Favorite';
+import { mockSetOfBranchAndPullRequest } from '../../../../../helpers/mocks/branch-like';
+import { mockComponent, mockCurrentUser } from '../../../../../helpers/testMocks';
+import { Header, HeaderProps } from '../Header';
+
+it('should render correctly', () => {
+  const wrapper = shallowRender({ currentUser: mockCurrentUser({ isLoggedIn: true }) });
+  expect(wrapper).toMatchSnapshot();
+});
+
+it('should not render favorite button if the user is not logged in', () => {
+  const wrapper = shallowRender();
+  expect(wrapper.find(Favorite).exists()).toBeFalsy();
+});
+
+function shallowRender(props?: Partial<HeaderProps>) {
+  const branchLikes = mockSetOfBranchAndPullRequest();
+
+  return shallow(
+    <Header
+      branchLikes={branchLikes}
+      component={mockComponent()}
+      currentBranchLike={branchLikes[0]}
+      currentUser={mockCurrentUser()}
+      {...props}
+    />
+  );
+}
index 8052b0bf3bda7bbdbf89a3ce253bf01c23f87680..42b3f9dc55f37900c7ca2503920d48423795f8b2 100644 (file)
@@ -8,7 +8,7 @@ exports[`renders 1`] = `
   <div
     className="navbar-context-justified"
   >
-    <Memo(ComponentNavHeader)
+    <Connect(Component)
       branchLikes={Array []}
       component={
         Object {
diff --git a/server/sonar-web/src/main/js/app/components/nav/component/__tests__/__snapshots__/ComponentNavHeader-test.tsx.snap b/server/sonar-web/src/main/js/app/components/nav/component/__tests__/__snapshots__/ComponentNavHeader-test.tsx.snap
deleted file mode 100644 (file)
index e230965..0000000
+++ /dev/null
@@ -1,156 +0,0 @@
-// Jest Snapshot v1, https://goo.gl/fbAQLP
-
-exports[`should render correctly 1`] = `
-<Fragment>
-  <Helmet
-    defer={true}
-    encodeSpecialCharacters={true}
-    title="MyProject"
-  />
-  <header
-    className="display-flex-center flex-shrink"
-  >
-    <ComponentBreadcrumb
-      component={
-        Object {
-          "breadcrumbs": Array [],
-          "key": "my-project",
-          "name": "MyProject",
-          "organization": "foo",
-          "qualifier": "TRK",
-          "qualityGate": Object {
-            "isDefault": true,
-            "key": "30",
-            "name": "Sonar way",
-          },
-          "qualityProfiles": Array [
-            Object {
-              "deleted": false,
-              "key": "my-qp",
-              "language": "ts",
-              "name": "Sonar way",
-            },
-          ],
-          "tags": Array [],
-        }
-      }
-      currentBranchLike={
-        Object {
-          "analysisDate": "2018-01-01",
-          "excludedFromPurge": true,
-          "isMain": false,
-          "name": "branch-11",
-        }
-      }
-    />
-    <Connect(withAppState(Component))
-      branchLikes={
-        Array [
-          Object {
-            "analysisDate": "2018-01-01",
-            "excludedFromPurge": true,
-            "isMain": false,
-            "name": "branch-11",
-          },
-          Object {
-            "analysisDate": "2018-01-01",
-            "excludedFromPurge": true,
-            "isMain": false,
-            "name": "branch-1",
-          },
-          Object {
-            "analysisDate": "2018-01-01",
-            "excludedFromPurge": true,
-            "isMain": true,
-            "name": "master",
-          },
-          Object {
-            "analysisDate": "2018-01-01",
-            "base": "master",
-            "branch": "feature/foo/bar",
-            "key": "1",
-            "target": "master",
-            "title": "PR-1",
-          },
-          Object {
-            "analysisDate": "2018-01-01",
-            "excludedFromPurge": true,
-            "isMain": false,
-            "name": "branch-12",
-          },
-          Object {
-            "analysisDate": "2018-01-01",
-            "base": "master",
-            "branch": "feature/foo/bar",
-            "key": "2",
-            "target": "master",
-            "title": "PR-2",
-          },
-          Object {
-            "analysisDate": "2018-01-01",
-            "excludedFromPurge": true,
-            "isMain": false,
-            "name": "branch-3",
-          },
-          Object {
-            "analysisDate": "2018-01-01",
-            "excludedFromPurge": true,
-            "isMain": false,
-            "name": "branch-2",
-          },
-          Object {
-            "analysisDate": "2018-01-01",
-            "base": "master",
-            "branch": "feature/foo/bar",
-            "isOrphan": true,
-            "key": "2",
-            "target": "llb-100",
-            "title": "PR-2",
-          },
-        ]
-      }
-      component={
-        Object {
-          "breadcrumbs": Array [],
-          "key": "my-project",
-          "name": "MyProject",
-          "organization": "foo",
-          "qualifier": "TRK",
-          "qualityGate": Object {
-            "isDefault": true,
-            "key": "30",
-            "name": "Sonar way",
-          },
-          "qualityProfiles": Array [
-            Object {
-              "deleted": false,
-              "key": "my-qp",
-              "language": "ts",
-              "name": "Sonar way",
-            },
-          ],
-          "tags": Array [],
-        }
-      }
-      currentBranchLike={
-        Object {
-          "analysisDate": "2018-01-01",
-          "excludedFromPurge": true,
-          "isMain": false,
-          "name": "branch-11",
-        }
-      }
-    />
-    <Memo(CurrentBranchLikeMergeInformation)
-      currentBranchLike={
-        Object {
-          "analysisDate": "2018-01-01",
-          "excludedFromPurge": true,
-          "isMain": false,
-          "name": "branch-11",
-        }
-      }
-    />
-  </header>
-</Fragment>
-`;
diff --git a/server/sonar-web/src/main/js/app/components/nav/component/__tests__/__snapshots__/Header-test.tsx.snap b/server/sonar-web/src/main/js/app/components/nav/component/__tests__/__snapshots__/Header-test.tsx.snap
new file mode 100644 (file)
index 0000000..bf77fa8
--- /dev/null
@@ -0,0 +1,162 @@
+// Jest Snapshot v1, https://goo.gl/fbAQLP
+
+exports[`should render correctly 1`] = `
+<Fragment>
+  <Helmet
+    defer={true}
+    encodeSpecialCharacters={true}
+    title="MyProject"
+  />
+  <header
+    className="display-flex-center flex-shrink"
+  >
+    <ComponentBreadcrumb
+      component={
+        Object {
+          "breadcrumbs": Array [],
+          "key": "my-project",
+          "name": "MyProject",
+          "organization": "foo",
+          "qualifier": "TRK",
+          "qualityGate": Object {
+            "isDefault": true,
+            "key": "30",
+            "name": "Sonar way",
+          },
+          "qualityProfiles": Array [
+            Object {
+              "deleted": false,
+              "key": "my-qp",
+              "language": "ts",
+              "name": "Sonar way",
+            },
+          ],
+          "tags": Array [],
+        }
+      }
+      currentBranchLike={
+        Object {
+          "analysisDate": "2018-01-01",
+          "excludedFromPurge": true,
+          "isMain": false,
+          "name": "branch-11",
+        }
+      }
+    />
+    <Favorite
+      className="spacer-left"
+      component="my-project"
+      favorite={false}
+      qualifier="TRK"
+    />
+    <Connect(withAppState(Component))
+      branchLikes={
+        Array [
+          Object {
+            "analysisDate": "2018-01-01",
+            "excludedFromPurge": true,
+            "isMain": false,
+            "name": "branch-11",
+          },
+          Object {
+            "analysisDate": "2018-01-01",
+            "excludedFromPurge": true,
+            "isMain": false,
+            "name": "branch-1",
+          },
+          Object {
+            "analysisDate": "2018-01-01",
+            "excludedFromPurge": true,
+            "isMain": true,
+            "name": "master",
+          },
+          Object {
+            "analysisDate": "2018-01-01",
+            "base": "master",
+            "branch": "feature/foo/bar",
+            "key": "1",
+            "target": "master",
+            "title": "PR-1",
+          },
+          Object {
+            "analysisDate": "2018-01-01",
+            "excludedFromPurge": true,
+            "isMain": false,
+            "name": "branch-12",
+          },
+          Object {
+            "analysisDate": "2018-01-01",
+            "base": "master",
+            "branch": "feature/foo/bar",
+            "key": "2",
+            "target": "master",
+            "title": "PR-2",
+          },
+          Object {
+            "analysisDate": "2018-01-01",
+            "excludedFromPurge": true,
+            "isMain": false,
+            "name": "branch-3",
+          },
+          Object {
+            "analysisDate": "2018-01-01",
+            "excludedFromPurge": true,
+            "isMain": false,
+            "name": "branch-2",
+          },
+          Object {
+            "analysisDate": "2018-01-01",
+            "base": "master",
+            "branch": "feature/foo/bar",
+            "isOrphan": true,
+            "key": "2",
+            "target": "llb-100",
+            "title": "PR-2",
+          },
+        ]
+      }
+      component={
+        Object {
+          "breadcrumbs": Array [],
+          "key": "my-project",
+          "name": "MyProject",
+          "organization": "foo",
+          "qualifier": "TRK",
+          "qualityGate": Object {
+            "isDefault": true,
+            "key": "30",
+            "name": "Sonar way",
+          },
+          "qualityProfiles": Array [
+            Object {
+              "deleted": false,
+              "key": "my-qp",
+              "language": "ts",
+              "name": "Sonar way",
+            },
+          ],
+          "tags": Array [],
+        }
+      }
+      currentBranchLike={
+        Object {
+          "analysisDate": "2018-01-01",
+          "excludedFromPurge": true,
+          "isMain": false,
+          "name": "branch-11",
+        }
+      }
+    />
+    <Memo(CurrentBranchLikeMergeInformation)
+      currentBranchLike={
+        Object {
+          "analysisDate": "2018-01-01",
+          "excludedFromPurge": true,
+          "isMain": false,
+          "name": "branch-11",
+        }
+      }
+    />
+  </header>
+</Fragment>
+`;