]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-11700 Show QG badge instead of issue breakdown for PRs and SLBs
authorWouter Admiraal <wouter.admiraal@sonarsource.com>
Mon, 11 Feb 2019 07:50:45 +0000 (08:50 +0100)
committerSonarTech <sonartech@sonarsource.com>
Mon, 11 Mar 2019 19:21:02 +0000 (20:21 +0100)
19 files changed:
server/sonar-web/src/main/js/app/components/ComponentContainer.tsx
server/sonar-web/src/main/js/app/components/__tests__/ComponentContainer-test.tsx
server/sonar-web/src/main/js/app/components/nav/component/ComponentNav.tsx
server/sonar-web/src/main/js/app/components/nav/component/ComponentNavBranchesMenuItem.tsx
server/sonar-web/src/main/js/app/components/nav/component/ComponentNavMeta.tsx
server/sonar-web/src/main/js/app/components/nav/component/__tests__/ComponentNavMeta-test.tsx
server/sonar-web/src/main/js/app/components/nav/component/__tests__/__snapshots__/ComponentNavBranchesMenuItem-test.tsx.snap
server/sonar-web/src/main/js/app/components/nav/component/__tests__/__snapshots__/ComponentNavMeta-test.tsx.snap
server/sonar-web/src/main/js/app/types.d.ts
server/sonar-web/src/main/js/apps/background-tasks/components/__tests__/__snapshots__/TaskComponent-test.tsx.snap
server/sonar-web/src/main/js/components/SourceViewer/components/__tests__/__snapshots__/MeasuresOverlay-test.tsx.snap
server/sonar-web/src/main/js/components/common/BranchMeasures.tsx [deleted file]
server/sonar-web/src/main/js/components/common/BranchStatus.tsx
server/sonar-web/src/main/js/components/common/__tests__/BranchMeasures-test.tsx [deleted file]
server/sonar-web/src/main/js/components/common/__tests__/BranchStatus-test.tsx
server/sonar-web/src/main/js/components/common/__tests__/__snapshots__/BranchMeasures-test.tsx.snap [deleted file]
server/sonar-web/src/main/js/components/common/__tests__/__snapshots__/BranchStatus-test.tsx.snap
server/sonar-web/src/main/js/helpers/testMocks.ts
server/sonar-web/src/main/js/helpers/urls.ts

index 2defb5847f90b6bfe84bf7f7e742a4b729ce90c6..86b953bf60ea27426e42f0ecac06378aaa2e8d1b 100644 (file)
@@ -26,7 +26,6 @@ import ComponentNav from './nav/component/ComponentNav';
 import { getBranches, getPullRequests } from '../../api/branches';
 import { getTasksForComponent, getAnalysisStatus } from '../../api/ce';
 import { getComponentData } from '../../api/components';
-import { getMeasures } from '../../api/measures';
 import { getComponentNavigation } from '../../api/nav';
 import { fetchOrganization, requireAuthorization } from '../../store/rootActions';
 import { STATUSES } from '../../apps/background-tasks/constants';
@@ -52,7 +51,6 @@ interface Props {
 interface State {
   branchLike?: T.BranchLike;
   branchLikes: T.BranchLike[];
-  branchMeasures?: T.Measure[];
   component?: T.Component;
   currentTask?: T.Task;
   isPending: boolean;
@@ -120,13 +118,11 @@ export class ComponentContainer extends React.PureComponent<Props, State> {
         return component;
       })
       .then(this.fetchBranches)
-      .then(this.fetchBranchMeasures)
-      .then(({ branchLike, branchLikes, component, branchMeasures }) => {
+      .then(({ branchLike, branchLikes, component }) => {
         if (this.mounted) {
           this.setState({
             branchLike,
             branchLikes,
-            branchMeasures,
             component,
             loading: false
           });
@@ -168,33 +164,6 @@ export class ComponentContainer extends React.PureComponent<Props, State> {
     return Promise.resolve({ branchLikes: [], component });
   };
 
-  fetchBranchMeasures = ({
-    branchLike,
-    branchLikes,
-    component
-  }: {
-    branchLike: T.BranchLike;
-    branchLikes: T.BranchLike[];
-    component: T.Component;
-  }): Promise<{
-    branchLike?: T.BranchLike;
-    branchLikes: T.BranchLike[];
-    branchMeasures?: T.Measure[];
-    component: T.Component;
-  }> => {
-    const project = component.breadcrumbs.find(({ qualifier }) => qualifier === 'TRK');
-    if (project && (isShortLivingBranch(branchLike) || isPullRequest(branchLike))) {
-      return getMeasures({
-        component: project.key,
-        metricKeys: 'new_coverage,new_duplicated_lines_density',
-        ...getBranchLikeQuery(branchLike)
-      }).then(measures => {
-        return { branchLike, branchLikes, branchMeasures: measures, component };
-      });
-    }
-    return Promise.resolve({ branchLike, branchLikes, component });
-  };
-
   fetchStatus = (component: T.Component) => {
     getTasksForComponent(component.key).then(
       ({ current, queue }) => {
@@ -312,16 +281,14 @@ export class ComponentContainer extends React.PureComponent<Props, State> {
 
   handleBranchesChange = () => {
     if (this.mounted && this.state.component) {
-      this.fetchBranches(this.state.component)
-        .then(this.fetchBranchMeasures)
-        .then(
-          ({ branchLike, branchLikes, branchMeasures }) => {
-            if (this.mounted) {
-              this.setState({ branchLike, branchLikes, branchMeasures });
-            }
-          },
-          () => {}
-        );
+      this.fetchBranches(this.state.component).then(
+        ({ branchLike, branchLikes }) => {
+          if (this.mounted) {
+            this.setState({ branchLike, branchLikes });
+          }
+        },
+        () => {}
+      );
     }
   };
 
@@ -341,7 +308,6 @@ export class ComponentContainer extends React.PureComponent<Props, State> {
           !['FIL', 'UTS'].includes(component.qualifier) && (
             <ComponentNav
               branchLikes={branchLikes}
-              branchMeasures={this.state.branchMeasures}
               component={component}
               currentBranchLike={branchLike}
               currentTask={currentTask}
index 8a4f6a2afacf011340cdffeb190720b6c32c032e..c815f458025ee328a380e012d1c590a52ceb9093 100644 (file)
@@ -120,35 +120,6 @@ it('updates branches on change', () => {
   expect(getPullRequests).toBeCalledWith('projectKey');
 });
 
-it('updates the branch measures', async () => {
-  (getComponentNavigation as jest.Mock<any>).mockResolvedValueOnce({
-    breadcrumbs: [{ key: 'foo', name: 'Foo', qualifier: 'TRK' }],
-    key: 'foo'
-  });
-  (getBranches as jest.Mock<any>).mockResolvedValueOnce([
-    { isMain: false, mergeBranch: 'master', name: 'feature', type: 'SHORT' }
-  ]);
-  (getPullRequests as jest.Mock<any>).mockResolvedValueOnce([]);
-  const wrapper = shallowRender({
-    location: { query: { id: 'foo', branch: 'feature' } } as Location
-  });
-  wrapper.setState({
-    branchLikes: [mainBranch],
-    component: { breadcrumbs: [{ key: 'foo', name: 'Foo', qualifier: 'TRK' }] } as T.Component,
-    loading: false
-  });
-
-  await new Promise(setImmediate);
-  expect(getBranches).toBeCalledWith('foo');
-
-  await new Promise(setImmediate);
-  expect(getMeasures).toBeCalledWith({
-    component: 'foo',
-    metricKeys: 'new_coverage,new_duplicated_lines_density',
-    branch: 'feature'
-  });
-});
-
 it('loads organization', async () => {
   (isSonarCloud as jest.Mock).mockReturnValue(true);
   (getComponentData as jest.Mock<any>).mockResolvedValueOnce({ organization: 'org' });
index ccc74f892f7c807145f1fbf40252b8938efa3c75..02e9d6a01dec0cabdaa7504d4cead236c9e86d9f 100644 (file)
@@ -30,7 +30,6 @@ import './ComponentNav.css';
 
 interface Props {
   branchLikes: T.BranchLike[];
-  branchMeasures?: T.Measure[];
   currentBranchLike: T.BranchLike | undefined;
   component: T.Component;
   currentTask?: T.Task;
@@ -96,7 +95,6 @@ export default class ComponentNav extends React.PureComponent<Props> {
           />
           <ComponentNavMeta
             branchLike={currentBranchLike}
-            branchMeasures={this.props.branchMeasures}
             component={component}
             warnings={this.props.warnings}
           />
index 1c340a7d0712ab5f11591edc60161ce56666bd10..f05afbd4bfe075995d191bff79d0d33dd4b94d5e 100644 (file)
@@ -69,7 +69,7 @@ export default function ComponentNavBranchesMenuItem({ branchLike, ...props }: P
           )}
         </div>
         <div className="big-spacer-left note">
-          <BranchStatus branchLike={branchLike} concise={true} />
+          <BranchStatus branchLike={branchLike} />
         </div>
       </Link>
     </li>
index f2d056453d9a33857d3e51c832b0f81d21c0f395..9eb4704aa4335761910201691df68f898ea2eff6 100644 (file)
@@ -20,7 +20,6 @@
 import * as React from 'react';
 import { connect } from 'react-redux';
 import ComponentNavWarnings from './ComponentNavWarnings';
-import BranchMeasures from '../../../../components/common/BranchMeasures';
 import BranchStatus from '../../../../components/common/BranchStatus';
 import DateTimeFormatter from '../../../../components/intl/DateTimeFormatter';
 import Favorite from '../../../../components/controls/Favorite';
@@ -43,18 +42,11 @@ interface StateProps {
 
 interface Props extends StateProps {
   branchLike?: T.BranchLike;
-  branchMeasures?: T.Measure[];
   component: T.Component;
   warnings: string[];
 }
 
-export function ComponentNavMeta({
-  branchLike,
-  branchMeasures,
-  component,
-  currentUser,
-  warnings
-}: Props) {
+export function ComponentNavMeta({ branchLike, component, currentUser, warnings }: Props) {
   const mainBranch = !branchLike || isMainBranch(branchLike);
   const longBranch = isLongLivingBranch(branchLike);
   const currentPage = getCurrentPage(component, branchLike);
@@ -104,17 +96,6 @@ export function ComponentNavMeta({
               </a>
             )}
           <BranchStatus branchLike={branchLike} />
-          {branchMeasures &&
-            branchMeasures.length > 0 && (
-              <>
-                <span className="vertical-separator big-spacer-left big-spacer-right" />
-                <BranchMeasures
-                  branchLike={branchLike}
-                  componentKey={component.key}
-                  measures={branchMeasures}
-                />
-              </>
-            )}
         </div>
       )}
     </div>
index 374ffca8fd9ad91d7d32a79ad33869e23f296690..aa8efb0ba7a4f0d160e91dd794509b265336fd62 100644 (file)
 import * as React from 'react';
 import { shallow } from 'enzyme';
 import { ComponentNavMeta } from '../ComponentNavMeta';
-
-const COMPONENT = {
-  analysisDate: '2017-01-02T00:00:00.000Z',
-  breadcrumbs: [],
-  key: 'foo',
-  name: 'Foo',
-  organization: 'org',
-  qualifier: 'TRK',
-  version: '0.0.1'
-};
-
-const MEASURES = [
-  { metric: 'new_coverage', value: '0', periods: [{ index: 1, value: '95.9943' }] },
-  { metric: 'new_duplicated_lines_density', periods: [{ index: 1, value: '3.5' }] }
-];
+import {
+  mockShortLivingBranch,
+  mockComponent,
+  mockCurrentUser,
+  mockLongLivingBranch,
+  mockPullRequest
+} from '../../../../../helpers/testMocks';
 
 it('renders status of short-living branch', () => {
-  const branch: T.ShortLivingBranch = {
-    isMain: false,
-    mergeBranch: 'master',
-    name: 'feature',
-    status: { bugs: 0, codeSmells: 2, qualityGateStatus: 'ERROR', vulnerabilities: 3 },
-    type: 'SHORT'
-  };
-  expect(
-    shallow(
-      <ComponentNavMeta
-        branchLike={branch}
-        branchMeasures={MEASURES}
-        component={COMPONENT}
-        currentUser={{ isLoggedIn: false }}
-        warnings={[]}
-      />
-    )
-  ).toMatchSnapshot();
+  expect(shallowRender()).toMatchSnapshot();
 });
 
 it('renders meta for long-living branch', () => {
-  const branch: T.LongLivingBranch = {
-    isMain: false,
-    name: 'release',
-    status: { qualityGateStatus: 'OK' },
-    type: 'LONG'
-  };
-  expect(
-    shallow(
-      <ComponentNavMeta
-        branchLike={branch}
-        component={COMPONENT}
-        currentUser={{ isLoggedIn: false }}
-        warnings={[]}
-      />
-    )
-  ).toMatchSnapshot();
+  expect(shallowRender({ branchLike: mockLongLivingBranch() })).toMatchSnapshot();
 });
 
 it('renders meta for pull request', () => {
-  const pullRequest: T.PullRequest = {
-    base: 'master',
-    branch: 'feature',
-    key: '1234',
-    status: { bugs: 0, codeSmells: 2, qualityGateStatus: 'ERROR', vulnerabilities: 3 },
-    title: 'Feature PR',
-    url: 'https://example.com/pull/1234'
-  };
   expect(
-    shallow(
-      <ComponentNavMeta
-        branchLike={pullRequest}
-        component={COMPONENT}
-        currentUser={{ isLoggedIn: false }}
-        warnings={[]}
-      />
-    )
+    shallowRender({
+      branchLike: mockPullRequest({
+        status: { bugs: 0, codeSmells: 2, qualityGateStatus: 'ERROR', vulnerabilities: 3 },
+        url: 'https://example.com/pull/1234'
+      })
+    })
   ).toMatchSnapshot();
 });
+
+function shallowRender(props = {}) {
+  return shallow(
+    <ComponentNavMeta
+      branchLike={mockShortLivingBranch({
+        status: { bugs: 0, codeSmells: 2, qualityGateStatus: 'ERROR', vulnerabilities: 3 }
+      })}
+      component={mockComponent({ analysisDate: '2017-01-02T00:00:00.000Z', version: '0.0.1' })}
+      currentUser={mockCurrentUser({ isLoggedIn: false })}
+      warnings={[]}
+      {...props}
+    />
+  );
+}
index 25528a5523c017bae0e00a15f42d49a52e08b706..3df35d2137ea2612c89da1850a8e23b7d666b820 100644 (file)
@@ -49,7 +49,6 @@ exports[`renders main branch 1`] = `
             "name": "master",
           }
         }
-        concise={true}
       />
     </div>
   </Link>
@@ -67,7 +66,7 @@ exports[`renders short-living branch 1`] = `
     style={Object {}}
     to={
       Object {
-        "pathname": "/project/issues",
+        "pathname": "/dashboard",
         "query": Object {
           "branch": "foo",
           "id": "component",
@@ -117,7 +116,6 @@ exports[`renders short-living branch 1`] = `
             "type": "SHORT",
           }
         }
-        concise={true}
       />
     </div>
   </Link>
@@ -135,7 +133,7 @@ exports[`renders short-living orhpan branch 1`] = `
     style={Object {}}
     to={
       Object {
-        "pathname": "/project/issues",
+        "pathname": "/dashboard",
         "query": Object {
           "branch": "foo",
           "id": "component",
@@ -187,7 +185,6 @@ exports[`renders short-living orhpan branch 1`] = `
             "type": "SHORT",
           }
         }
-        concise={true}
       />
     </div>
   </Link>
index 35f80d6ab41871baee476128e124a055003ecb9b..c7637342d5c1caf978d4845db51ad0c0d84b35f6 100644 (file)
@@ -55,16 +55,17 @@ exports[`renders meta for pull request 1`] = `
     <BranchStatus
       branchLike={
         Object {
+          "analysisDate": "2018-01-01",
           "base": "master",
-          "branch": "feature",
-          "key": "1234",
+          "branch": "feature/foo/bar",
+          "key": "1001",
           "status": Object {
             "bugs": 0,
             "codeSmells": 2,
             "qualityGateStatus": "ERROR",
             "vulnerabilities": 3,
           },
-          "title": "Feature PR",
+          "title": "Foo Bar feature",
           "url": "https://example.com/pull/1234",
         }
       }
@@ -90,9 +91,10 @@ exports[`renders status of short-living branch 1`] = `
     <BranchStatus
       branchLike={
         Object {
+          "analysisDate": "2018-01-01",
           "isMain": false,
           "mergeBranch": "master",
-          "name": "feature",
+          "name": "release-1.0",
           "status": Object {
             "bugs": 0,
             "codeSmells": 2,
@@ -103,49 +105,6 @@ exports[`renders status of short-living branch 1`] = `
         }
       }
     />
-    <span
-      className="vertical-separator big-spacer-left big-spacer-right"
-    />
-    <BranchMeasures
-      branchLike={
-        Object {
-          "isMain": false,
-          "mergeBranch": "master",
-          "name": "feature",
-          "status": Object {
-            "bugs": 0,
-            "codeSmells": 2,
-            "qualityGateStatus": "ERROR",
-            "vulnerabilities": 3,
-          },
-          "type": "SHORT",
-        }
-      }
-      componentKey="foo"
-      measures={
-        Array [
-          Object {
-            "metric": "new_coverage",
-            "periods": Array [
-              Object {
-                "index": 1,
-                "value": "95.9943",
-              },
-            ],
-            "value": "0",
-          },
-          Object {
-            "metric": "new_duplicated_lines_density",
-            "periods": Array [
-              Object {
-                "index": 1,
-                "value": "3.5",
-              },
-            ],
-          },
-        ]
-      }
-    />
   </div>
 </div>
 `;
index f412c82962d5205d32cec8ca7553d4166e9aa896..816f12440e745059360b92246367c321cec5b469 100644 (file)
@@ -100,6 +100,7 @@ declare namespace T {
     analysisDate?: string;
     isMain: boolean;
     name: string;
+    status?: { qualityGateStatus: string };
   }
 
   export type BranchLike = Branch | PullRequest;
@@ -429,13 +430,11 @@ declare namespace T {
 
   export interface LongLivingBranch extends Branch {
     isMain: false;
-    status?: { qualityGateStatus: string };
     type: 'LONG';
   }
 
   export interface MainBranch extends Branch {
     isMain: true;
-    status?: { qualityGateStatus: string };
   }
 
   export interface Measure extends MeasureIntern {
index b054cb915e8ed1f3303694322f62cf36d0dc328d..4b510fa8d43daa72d113cc8702ccca47de82683b 100644 (file)
@@ -61,7 +61,7 @@ exports[`renders correctly for branches and pullrequest 1`] = `
     style={Object {}}
     to={
       Object {
-        "pathname": "/project/issues",
+        "pathname": "/dashboard",
         "query": Object {
           "branch": "feature",
           "id": "foo",
@@ -154,7 +154,7 @@ exports[`renders correctly for branches and pullrequest 3`] = `
     style={Object {}}
     to={
       Object {
-        "pathname": "/project/issues",
+        "pathname": "/dashboard",
         "query": Object {
           "id": "foo",
           "pullRequest": "pr-89",
index fb658fc95a27b66f0666bde0bc7ad66bbad03dd4..3fe6740c037f600f4b35e37d2f18a72d874a6f7a 100644 (file)
@@ -24,7 +24,7 @@ exports[`should render source file 1`] = `
           style={Object {}}
           to={
             Object {
-              "pathname": "/project/issues",
+              "pathname": "/dashboard",
               "query": Object {
                 "branch": "feature",
                 "id": "project-key",
@@ -383,7 +383,7 @@ exports[`should render source file 2`] = `
           style={Object {}}
           to={
             Object {
-              "pathname": "/project/issues",
+              "pathname": "/dashboard",
               "query": Object {
                 "branch": "feature",
                 "id": "project-key",
@@ -1348,7 +1348,7 @@ exports[`should render test file 1`] = `
           style={Object {}}
           to={
             Object {
-              "pathname": "/project/issues",
+              "pathname": "/dashboard",
               "query": Object {
                 "branch": "feature",
                 "id": "project-key",
diff --git a/server/sonar-web/src/main/js/components/common/BranchMeasures.tsx b/server/sonar-web/src/main/js/components/common/BranchMeasures.tsx
deleted file mode 100644 (file)
index 8d37f92..0000000
+++ /dev/null
@@ -1,139 +0,0 @@
-/*
- * SonarQube
- * Copyright (C) 2009-2019 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 * as classNames from 'classnames';
-import { FormattedMessage } from 'react-intl';
-import { Link } from 'react-router';
-import { getLeakValue } from '../measure/utils';
-import CoverageRating from '../ui/CoverageRating';
-import { formatMeasure } from '../../helpers/measures';
-import HelpTooltip from '../controls/HelpTooltip';
-import { translate } from '../../helpers/l10n';
-import DuplicationsRating from '../ui/DuplicationsRating';
-import { getComponentDrilldownUrl } from '../../helpers/urls';
-
-interface Props {
-  branchLike: T.BranchLike;
-  componentKey: string;
-  measures: T.Measure[];
-}
-
-export default function BranchMeasures({ branchLike, componentKey, measures }: Props) {
-  const newCoverage = measures.find(measure => measure.metric === 'new_coverage');
-  const newDuplications = measures.find(
-    measure => measure.metric === 'new_duplicated_lines_density'
-  );
-  if (!newCoverage && !newDuplications) {
-    return null;
-  }
-
-  return (
-    <div className="display-inline-flex-center">
-      <BranchCoverage branchLike={branchLike} componentKey={componentKey} measure={newCoverage} />
-      <BranchDuplications
-        branchLike={branchLike}
-        className="big-spacer-left"
-        componentKey={componentKey}
-        measure={newDuplications}
-      />
-    </div>
-  );
-}
-
-interface MeasureProps {
-  branchLike: T.BranchLike;
-  className?: string;
-  componentKey: string;
-  measure: T.Measure | undefined;
-}
-
-export function BranchCoverage({ branchLike, className, componentKey, measure }: MeasureProps) {
-  const value = getLeakValue(measure);
-  return (
-    <div className={classNames('display-inline-flex-center', className)}>
-      <CoverageRating size="small" value={value} />
-      <span className="little-spacer-left">
-        {value !== undefined ? formatMeasure(value, 'PERCENT') : '–'}
-      </span>
-      <HelpTooltip
-        className="little-spacer-left"
-        overlay={
-          measure ? (
-            <FormattedMessage
-              defaultMessage={translate('branches.measures.new_coverage.help')}
-              id="branches.measures.new_coverage.help"
-              values={{
-                link: (
-                  <Link
-                    to={getComponentDrilldownUrl({
-                      componentKey,
-                      branchLike,
-                      metric: 'new_coverage'
-                    })}>
-                    {translate('layout.measures')}
-                  </Link>
-                )
-              }}
-            />
-          ) : (
-            translate('branches.measures.new_coverage.missing')
-          )
-        }
-      />
-    </div>
-  );
-}
-
-export function BranchDuplications({ branchLike, className, componentKey, measure }: MeasureProps) {
-  const value = getLeakValue(measure);
-  return (
-    <div className={classNames('display-inline-flex-center', className)}>
-      <DuplicationsRating size="small" value={Number(value)} />
-      <span className="little-spacer-left">
-        {value !== undefined ? formatMeasure(value, 'PERCENT') : '–'}
-      </span>
-      <HelpTooltip
-        className="little-spacer-left"
-        overlay={
-          measure ? (
-            <FormattedMessage
-              defaultMessage={translate('branches.measures.new_duplicated_lines_density.help')}
-              id="branches.measures.new_duplicated_lines_density.help"
-              values={{
-                link: (
-                  <Link
-                    to={getComponentDrilldownUrl({
-                      componentKey,
-                      branchLike,
-                      metric: 'new_duplicated_lines_density'
-                    })}>
-                    {translate('layout.measures')}
-                  </Link>
-                )
-              }}
-            />
-          ) : (
-            translate('branches.measures.new_duplicated_lines_density.missing')
-          )
-        }
-      />
-    </div>
-  );
-}
index 439fef2822af76969cc1c4902e23bc42da113c20..6345b0de276d65b85c468a904fc218bd29ac4726 100644 (file)
  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
  */
 import * as React from 'react';
-import StatusIndicator from './StatusIndicator';
 import Level from '../ui/Level';
-import BugIcon from '../icons-components/BugIcon';
-import CodeSmellIcon from '../icons-components/CodeSmellIcon';
-import HelpTooltip from '../controls/HelpTooltip';
-import Tooltip from '../controls/Tooltip';
-import VulnerabilityIcon from '../icons-components/VulnerabilityIcon';
-import {
-  getBranchQualityGateColor,
-  isShortLivingBranch,
-  isPullRequest,
-  isLongLivingBranch,
-  isMainBranch
-} from '../../helpers/branches';
-import { translateWithParameters } from '../../helpers/l10n';
-import { formatMeasure } from '../../helpers/measures';
 import './BranchStatus.css';
 
 interface Props {
   branchLike: T.BranchLike;
-  concise?: boolean;
 }
 
-export default function BranchStatus({ branchLike, concise = false }: Props) {
-  if (isShortLivingBranch(branchLike) || isPullRequest(branchLike)) {
-    if (!branchLike.status) {
-      return null;
-    }
-
-    const totalIssues =
-      branchLike.status.bugs + branchLike.status.vulnerabilities + branchLike.status.codeSmells;
-    const status = branchLike.status.qualityGateStatus;
-    const indicatorColor = getBranchQualityGateColor(status);
-    const shouldDisplayHelper = status === 'OK' && totalIssues > 0;
-
-    const label =
-      translateWithParameters('overview.quality_gate_x', formatMeasure(status, 'LEVEL')) +
-      (status !== 'OK'
-        ? ' ' + translateWithParameters('overview.quality_gate_failed_with_x', totalIssues)
-        : '');
-
-    return concise ? (
-      <Tooltip overlay={label} placement="right">
-        <ul className="branch-status">
-          <li>{totalIssues}</li>
-          <li className="spacer-left">
-            <StatusIndicator color={indicatorColor} size="small" />
-          </li>
-        </ul>
-      </Tooltip>
-    ) : (
-      <ul className="branch-status">
-        <li className="little-spacer-right">
-          <StatusIndicator color={indicatorColor} size="small" />
-        </li>
-        <li className="spacer-left">
-          {branchLike.status.bugs}
-          <BugIcon className="little-spacer-left" />
-        </li>
-        <li className="spacer-left">
-          {branchLike.status.vulnerabilities}
-          <VulnerabilityIcon className="little-spacer-left" />
-        </li>
-        <li className="spacer-left">
-          {branchLike.status.codeSmells}
-          <CodeSmellIcon className="little-spacer-left" />
-        </li>
-        {shouldDisplayHelper && (
-          <HelpTooltip
-            className="spacer-left"
-            overlay={translateWithParameters(
-              'branches.short_lived.quality_gate.description',
-              totalIssues
-            )}
-            tagName="li"
-          />
-        )}
-      </ul>
-    );
-  } else if (isLongLivingBranch(branchLike) || isMainBranch(branchLike)) {
-    if (!branchLike.status) {
-      return null;
-    }
-
-    return <Level level={branchLike.status.qualityGateStatus} small={true} />;
+export default function BranchStatus({ branchLike }: Props) {
+  if (!branchLike.status) {
+    return null;
   }
-  return null;
+
+  return <Level level={branchLike.status.qualityGateStatus} small={true} />;
 }
diff --git a/server/sonar-web/src/main/js/components/common/__tests__/BranchMeasures-test.tsx b/server/sonar-web/src/main/js/components/common/__tests__/BranchMeasures-test.tsx
deleted file mode 100644 (file)
index 3ea160e..0000000
+++ /dev/null
@@ -1,65 +0,0 @@
-/*
- * SonarQube
- * Copyright (C) 2009-2019 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 { shallow } from 'enzyme';
-import BranchMeasures, { BranchCoverage, BranchDuplications } from '../BranchMeasures';
-
-const MEASURES = [
-  { metric: 'new_coverage', value: '0', periods: [{ index: 1, value: '95.9943' }] },
-  { metric: 'new_duplicated_lines_density', periods: [{ index: 1, value: '3.5' }] }
-];
-
-const pr: T.PullRequest = { base: 'master', branch: 'feature-x', key: '5', title: '' };
-
-describe('BranchMeasures', () => {
-  it('should render coverage and duplications', () => {
-    expect(
-      shallow(<BranchMeasures branchLike={pr} componentKey="foo" measures={MEASURES} />)
-    ).toMatchSnapshot();
-  });
-
-  it('should render correctly when coverage is missing', () => {
-    expect(
-      shallow(<BranchMeasures branchLike={pr} componentKey="foo" measures={[MEASURES[1]]} />)
-    ).toMatchSnapshot();
-  });
-
-  it('should not render anything', () => {
-    expect(
-      shallow(<BranchMeasures branchLike={pr} componentKey="foo" measures={[]} />).type()
-    ).toBeNull();
-  });
-});
-
-describe('BranchCoverage', () => {
-  it('should render correctly', () => {
-    expect(
-      shallow(<BranchCoverage branchLike={pr} componentKey="foo" measure={MEASURES[0]} />)
-    ).toMatchSnapshot();
-  });
-});
-
-describe('BranchDuplications', () => {
-  it('should render correctly', () => {
-    expect(
-      shallow(<BranchDuplications branchLike={pr} componentKey="foo" measure={MEASURES[1]} />)
-    ).toMatchSnapshot();
-  });
-});
index 54fa84deeb90d543515b6d9da3b5da3eb3e42f3a..c09200b988059af1d2bdc5f7beb7cbbb34da8a5b 100644 (file)
@@ -21,44 +21,14 @@ import * as React from 'react';
 import { shallow } from 'enzyme';
 import BranchStatus from '../BranchStatus';
 
-it('renders status of short-living branches', () => {
-  checkShort('OK', 0, 0, 0);
-  checkShort('WARN', 0, 1, 0);
-  checkShort('ERROR', 7, 3, 6);
-  checkShort('OK', 0, 0, 1);
-
-  function checkShort(
-    qualityGateStatus: string,
-    bugs: number,
-    codeSmells: number,
-    vulnerabilities: number
-  ) {
-    const shortBranch: T.ShortLivingBranch = {
-      isMain: false,
-      mergeBranch: 'master',
-      name: 'foo',
-      status: { bugs, codeSmells, qualityGateStatus, vulnerabilities },
-      type: 'SHORT'
-    };
-    expect(shallow(<BranchStatus branchLike={shortBranch} />)).toMatchSnapshot();
-  }
-});
-
-it('renders status of long-living branches', () => {
-  const branch: T.LongLivingBranch = { isMain: false, name: 'foo', type: 'LONG' };
-  expect(getWrapper(branch).type()).toBeNull();
-  expect(getWrapper(branch, 'OK')).toMatchSnapshot();
-  expect(getWrapper(branch, 'ERROR')).toMatchSnapshot();
-});
-
-it('renders status of main branch', () => {
+it('should render correctly', () => {
   const branch: T.MainBranch = { isMain: true, name: 'foo' };
   expect(getWrapper(branch).type()).toBeNull();
   expect(getWrapper(branch, 'OK')).toMatchSnapshot();
   expect(getWrapper(branch, 'ERROR')).toMatchSnapshot();
 });
 
-function getWrapper(branch: T.MainBranch | T.LongLivingBranch, qualityGateStatus?: string) {
+function getWrapper(branch: T.MainBranch, qualityGateStatus?: string) {
   if (qualityGateStatus) {
     branch.status = { qualityGateStatus };
   }
diff --git a/server/sonar-web/src/main/js/components/common/__tests__/__snapshots__/BranchMeasures-test.tsx.snap b/server/sonar-web/src/main/js/components/common/__tests__/__snapshots__/BranchMeasures-test.tsx.snap
deleted file mode 100644 (file)
index 6734123..0000000
+++ /dev/null
@@ -1,185 +0,0 @@
-// Jest Snapshot v1, https://goo.gl/fbAQLP
-
-exports[`BranchCoverage should render correctly 1`] = `
-<div
-  className="display-inline-flex-center"
->
-  <CoverageRating
-    size="small"
-    value="95.9943"
-  />
-  <span
-    className="little-spacer-left"
-  >
-    96.0%
-  </span>
-  <HelpTooltip
-    className="little-spacer-left"
-    overlay={
-      <FormattedMessage
-        defaultMessage="branches.measures.new_coverage.help"
-        id="branches.measures.new_coverage.help"
-        values={
-          Object {
-            "link": <Link
-              onlyActiveOnIndex={false}
-              style={Object {}}
-              to={
-                Object {
-                  "pathname": "/component_measures",
-                  "query": Object {
-                    "id": "foo",
-                    "metric": "new_coverage",
-                    "pullRequest": "5",
-                  },
-                }
-              }
-            >
-              layout.measures
-            </Link>,
-          }
-        }
-      />
-    }
-  />
-</div>
-`;
-
-exports[`BranchDuplications should render correctly 1`] = `
-<div
-  className="display-inline-flex-center"
->
-  <DuplicationsRating
-    size="small"
-    value={3.5}
-  />
-  <span
-    className="little-spacer-left"
-  >
-    3.5%
-  </span>
-  <HelpTooltip
-    className="little-spacer-left"
-    overlay={
-      <FormattedMessage
-        defaultMessage="branches.measures.new_duplicated_lines_density.help"
-        id="branches.measures.new_duplicated_lines_density.help"
-        values={
-          Object {
-            "link": <Link
-              onlyActiveOnIndex={false}
-              style={Object {}}
-              to={
-                Object {
-                  "pathname": "/component_measures",
-                  "query": Object {
-                    "id": "foo",
-                    "metric": "new_duplicated_lines_density",
-                    "pullRequest": "5",
-                  },
-                }
-              }
-            >
-              layout.measures
-            </Link>,
-          }
-        }
-      />
-    }
-  />
-</div>
-`;
-
-exports[`BranchMeasures should render correctly when coverage is missing 1`] = `
-<div
-  className="display-inline-flex-center"
->
-  <BranchCoverage
-    branchLike={
-      Object {
-        "base": "master",
-        "branch": "feature-x",
-        "key": "5",
-        "title": "",
-      }
-    }
-    componentKey="foo"
-  />
-  <BranchDuplications
-    branchLike={
-      Object {
-        "base": "master",
-        "branch": "feature-x",
-        "key": "5",
-        "title": "",
-      }
-    }
-    className="big-spacer-left"
-    componentKey="foo"
-    measure={
-      Object {
-        "metric": "new_duplicated_lines_density",
-        "periods": Array [
-          Object {
-            "index": 1,
-            "value": "3.5",
-          },
-        ],
-      }
-    }
-  />
-</div>
-`;
-
-exports[`BranchMeasures should render coverage and duplications 1`] = `
-<div
-  className="display-inline-flex-center"
->
-  <BranchCoverage
-    branchLike={
-      Object {
-        "base": "master",
-        "branch": "feature-x",
-        "key": "5",
-        "title": "",
-      }
-    }
-    componentKey="foo"
-    measure={
-      Object {
-        "metric": "new_coverage",
-        "periods": Array [
-          Object {
-            "index": 1,
-            "value": "95.9943",
-          },
-        ],
-        "value": "0",
-      }
-    }
-  />
-  <BranchDuplications
-    branchLike={
-      Object {
-        "base": "master",
-        "branch": "feature-x",
-        "key": "5",
-        "title": "",
-      }
-    }
-    className="big-spacer-left"
-    componentKey="foo"
-    measure={
-      Object {
-        "metric": "new_duplicated_lines_density",
-        "periods": Array [
-          Object {
-            "index": 1,
-            "value": "3.5",
-          },
-        ],
-      }
-    }
-  />
-</div>
-`;
index 8a731ff9f0b213c3e129257cf4fd4de1f335f20a..df907fd0bfb198c8ef9d861e10edfd57d4479d29 100644 (file)
 // Jest Snapshot v1, https://goo.gl/fbAQLP
 
-exports[`renders status of long-living branches 1`] = `
+exports[`should render correctly 1`] = `
 <Level
   level="OK"
   small={true}
 />
 `;
 
-exports[`renders status of long-living branches 2`] = `
+exports[`should render correctly 2`] = `
 <Level
   level="ERROR"
   small={true}
 />
 `;
-
-exports[`renders status of main branch 1`] = `
-<Level
-  level="OK"
-  small={true}
-/>
-`;
-
-exports[`renders status of main branch 2`] = `
-<Level
-  level="ERROR"
-  small={true}
-/>
-`;
-
-exports[`renders status of short-living branches 1`] = `
-<ul
-  className="branch-status"
->
-  <li
-    className="little-spacer-right"
-  >
-    <StatusIndicator
-      color="green"
-      size="small"
-    />
-  </li>
-  <li
-    className="spacer-left"
-  >
-    0
-    <BugIcon
-      className="little-spacer-left"
-    />
-  </li>
-  <li
-    className="spacer-left"
-  >
-    0
-    <VulnerabilityIcon
-      className="little-spacer-left"
-    />
-  </li>
-  <li
-    className="spacer-left"
-  >
-    0
-    <CodeSmellIcon
-      className="little-spacer-left"
-    />
-  </li>
-</ul>
-`;
-
-exports[`renders status of short-living branches 2`] = `
-<ul
-  className="branch-status"
->
-  <li
-    className="little-spacer-right"
-  >
-    <StatusIndicator
-      color="orange"
-      size="small"
-    />
-  </li>
-  <li
-    className="spacer-left"
-  >
-    0
-    <BugIcon
-      className="little-spacer-left"
-    />
-  </li>
-  <li
-    className="spacer-left"
-  >
-    0
-    <VulnerabilityIcon
-      className="little-spacer-left"
-    />
-  </li>
-  <li
-    className="spacer-left"
-  >
-    1
-    <CodeSmellIcon
-      className="little-spacer-left"
-    />
-  </li>
-</ul>
-`;
-
-exports[`renders status of short-living branches 3`] = `
-<ul
-  className="branch-status"
->
-  <li
-    className="little-spacer-right"
-  >
-    <StatusIndicator
-      color="red"
-      size="small"
-    />
-  </li>
-  <li
-    className="spacer-left"
-  >
-    7
-    <BugIcon
-      className="little-spacer-left"
-    />
-  </li>
-  <li
-    className="spacer-left"
-  >
-    6
-    <VulnerabilityIcon
-      className="little-spacer-left"
-    />
-  </li>
-  <li
-    className="spacer-left"
-  >
-    3
-    <CodeSmellIcon
-      className="little-spacer-left"
-    />
-  </li>
-</ul>
-`;
-
-exports[`renders status of short-living branches 4`] = `
-<ul
-  className="branch-status"
->
-  <li
-    className="little-spacer-right"
-  >
-    <StatusIndicator
-      color="green"
-      size="small"
-    />
-  </li>
-  <li
-    className="spacer-left"
-  >
-    0
-    <BugIcon
-      className="little-spacer-left"
-    />
-  </li>
-  <li
-    className="spacer-left"
-  >
-    1
-    <VulnerabilityIcon
-      className="little-spacer-left"
-    />
-  </li>
-  <li
-    className="spacer-left"
-  >
-    0
-    <CodeSmellIcon
-      className="little-spacer-left"
-    />
-  </li>
-  <HelpTooltip
-    className="spacer-left"
-    overlay="branches.short_lived.quality_gate.description.1"
-    tagName="li"
-  />
-</ul>
-`;
index dc0927642f87bce0c8f740eb66005327c8f3dd14..30cc2c1f81bf281acb7f17cbe700c43ceb27ded0 100644 (file)
@@ -188,6 +188,23 @@ export function mockQualityGate(overrides: Partial<T.QualityGate> = {}): T.Quali
   };
 }
 
+export function mockPullRequest(overrides: Partial<T.PullRequest> = {}): T.PullRequest {
+  return {
+    analysisDate: '2018-01-01',
+    base: 'master',
+    branch: 'feature/foo/bar',
+    status: {
+      bugs: 0,
+      codeSmells: 0,
+      qualityGateStatus: 'OK',
+      vulnerabilities: 0
+    },
+    key: '1001',
+    title: 'Foo Bar feature',
+    ...overrides
+  };
+}
+
 export function mockQualityProfile(overrides: Partial<Profile> = {}): Profile {
   return {
     activeDeprecatedRuleCount: 2,
@@ -236,3 +253,37 @@ export function mockRule(overrides: Partial<T.Rule> = {}): T.Rule {
     ...overrides
   } as T.Rule;
 }
+
+export function mockShortLivingBranch(
+  overrides: Partial<T.ShortLivingBranch> = {}
+): T.ShortLivingBranch {
+  return {
+    analysisDate: '2018-01-01',
+    isMain: false,
+    name: 'release-1.0',
+    mergeBranch: 'master',
+    status: {
+      bugs: 0,
+      codeSmells: 0,
+      qualityGateStatus: 'OK',
+      vulnerabilities: 0
+    },
+    type: 'SHORT',
+    ...overrides
+  };
+}
+
+export function mockLongLivingBranch(
+  overrides: Partial<T.LongLivingBranch> = {}
+): T.LongLivingBranch {
+  return {
+    analysisDate: '2018-01-01',
+    isMain: false,
+    name: 'master',
+    status: {
+      qualityGateStatus: 'OK'
+    },
+    type: 'LONG',
+    ...overrides
+  };
+}
index c7090bc67705d8c2879b426a1e43c4cd39076f3a..cf255e6919b24eb43d5ba8d010194ddbbc274b94 100644 (file)
@@ -83,11 +83,11 @@ export function getLongLivingBranchUrl(project: string, branch: string): Locatio
 }
 
 export function getShortLivingBranchUrl(project: string, branch: string): Location {
-  return { pathname: '/project/issues', query: { branch, id: project, resolved: 'false' } };
+  return { pathname: '/dashboard', query: { branch, id: project, resolved: 'false' } };
 }
 
 export function getPullRequestUrl(project: string, pullRequest: string): Location {
-  return { pathname: '/project/issues', query: { id: project, pullRequest, resolved: 'false' } };
+  return { pathname: '/dashboard', query: { id: project, pullRequest, resolved: 'false' } };
 }
 
 /**