From: Philippe Perrin Date: Thu, 21 Nov 2019 16:39:49 +0000 (+0100) Subject: Move favorite button side by side with the breadcrumb X-Git-Tag: 8.2.0.32929~117 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=14929ba18f1443ba93538aebee9181d31584764c;p=sonarqube.git Move favorite button side by side with the breadcrumb --- diff --git a/server/sonar-web/src/main/js/app/components/nav/component/ComponentNav.tsx b/server/sonar-web/src/main/js/app/components/nav/component/ComponentNav.tsx index 19b3f24aaf9..775ac1fc23c 100644 --- a/server/sonar-web/src/main/js/app/components/nav/component/ComponentNav.tsx +++ b/server/sonar-web/src/main/js/app/components/nav/component/ComponentNav.tsx @@ -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 { id="context-navigation" notif={notifComponent}>
- - -
- - {currentBranchLike && ( - <> - - - - )} -
- - ); -} - -export default React.memo(ComponentNavHeader); diff --git a/server/sonar-web/src/main/js/app/components/nav/component/ComponentNavMeta.tsx b/server/sonar-web/src/main/js/app/components/nav/component/ComponentNavMeta.tsx index 6ab02fd532b..a4a6c278561 100644 --- a/server/sonar-web/src/main/js/app/components/nav/component/ComponentNavMeta.tsx +++ b/server/sonar-web/src/main/js/app/components/nav/component/ComponentNavMeta.tsx @@ -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) && (
- {mainBranch && ( - - )} - {isABranch && currentPage !== undefined && ( + {mainBranch && currentPage !== undefined && ( )}
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 index 00000000000..0ed44b073ce --- /dev/null +++ b/server/sonar-web/src/main/js/app/components/nav/component/Header.tsx @@ -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 ( + <> + +
+ + {isLoggedIn(currentUser) && ( + + )} + {currentBranchLike && ( + <> + + + + )} +
+ + ); +} + +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 index 31fbec9001d..00000000000 --- a/server/sonar-web/src/main/js/app/components/nav/component/__tests__/ComponentNavHeader-test.tsx +++ /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) { - const branchLikes = mockSetOfBranchAndPullRequest(); - - return shallow( - - ); -} 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 index 00000000000..aff2c9336f0 --- /dev/null +++ b/server/sonar-web/src/main/js/app/components/nav/component/__tests__/Header-test.tsx @@ -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) { + const branchLikes = mockSetOfBranchAndPullRequest(); + + return shallow( +
+ ); +} diff --git a/server/sonar-web/src/main/js/app/components/nav/component/__tests__/__snapshots__/ComponentNav-test.tsx.snap b/server/sonar-web/src/main/js/app/components/nav/component/__tests__/__snapshots__/ComponentNav-test.tsx.snap index 8052b0bf3bd..42b3f9dc55f 100644 --- a/server/sonar-web/src/main/js/app/components/nav/component/__tests__/__snapshots__/ComponentNav-test.tsx.snap +++ b/server/sonar-web/src/main/js/app/components/nav/component/__tests__/__snapshots__/ComponentNav-test.tsx.snap @@ -8,7 +8,7 @@ exports[`renders 1`] = `
- - -
- - - -
- -`; 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 index 00000000000..bf77fa89ed0 --- /dev/null +++ b/server/sonar-web/src/main/js/app/components/nav/component/__tests__/__snapshots__/Header-test.tsx.snap @@ -0,0 +1,162 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`should render correctly 1`] = ` + + +
+ + + + +
+
+`;