]> source.dussan.org Git - sonarqube.git/commitdiff
Use new ComponentQualifier enum
authorWouter Admiraal <wouter.admiraal@sonarsource.com>
Thu, 19 Dec 2019 13:30:50 +0000 (14:30 +0100)
committerSonarTech <sonartech@sonarsource.com>
Mon, 10 Feb 2020 19:46:15 +0000 (20:46 +0100)
12 files changed:
server/sonar-web/src/main/js/apps/overview/branches/Analysis.tsx
server/sonar-web/src/main/js/apps/overview/branches/BranchOverview.tsx
server/sonar-web/src/main/js/apps/overview/branches/NoCodeWarning.tsx
server/sonar-web/src/main/js/apps/overview/branches/QualityGatePanelSection.tsx
server/sonar-web/src/main/js/apps/overview/branches/__tests__/Analysis-test.tsx
server/sonar-web/src/main/js/apps/overview/branches/__tests__/BranchOverview-test.tsx
server/sonar-web/src/main/js/apps/overview/branches/__tests__/MeasuresPanel-test.tsx
server/sonar-web/src/main/js/apps/overview/branches/__tests__/NoCodeWarning-test.tsx
server/sonar-web/src/main/js/apps/overview/branches/__tests__/QualityGatePanel-test.tsx
server/sonar-web/src/main/js/apps/overview/branches/__tests__/QualityGatePanelSection-test.tsx
server/sonar-web/src/main/js/apps/overview/components/App.tsx
server/sonar-web/src/main/js/apps/overview/components/__tests__/EmptyOverview-test.tsx

index 0860bfa80c4b2209a3506b8dcadccb7e6e1b6020..af6a7889954cf91f86e989ee57fa0919e4e9f61f 100644 (file)
@@ -21,6 +21,7 @@ import { sortBy } from 'lodash';
 import * as React from 'react';
 import { translate } from 'sonar-ui-common/helpers/l10n';
 import DateTooltipFormatter from '../../../components/intl/DateTooltipFormatter';
+import { ComponentQualifier } from '../../../types/component';
 import Event from './Event';
 
 export interface AnalysisProps {
@@ -38,7 +39,10 @@ export function Analysis({ analysis, ...props }: AnalysisProps) {
   );
 
   // use `TRK` for all components but applications
-  const qualifier = props.qualifier === 'APP' ? 'APP' : 'TRK';
+  const qualifier =
+    props.qualifier === ComponentQualifier.Application
+      ? ComponentQualifier.Application
+      : ComponentQualifier.Project;
 
   return (
     <li className="overview-analysis">
index 6ad66b9295d64dccd27bb25e567756a9b9ecafb4..0baa63ff4206947922b1919368f7f7dd640721ea 100644 (file)
@@ -44,6 +44,7 @@ import {
 } from '../../../helpers/qualityGates';
 import { ApplicationPeriod } from '../../../types/application';
 import { BranchLike } from '../../../types/branch-like';
+import { ComponentQualifier } from '../../../types/component';
 import { MetricKey } from '../../../types/metrics';
 import { GraphType, MeasureHistory } from '../../../types/project-activity';
 import { QualityGateStatus, QualityGateStatusCondition } from '../../../types/quality-gates';
@@ -106,7 +107,7 @@ export default class BranchOverview extends React.PureComponent<Props, State> {
   }
 
   loadStatus = () => {
-    if (this.props.component.qualifier === 'APP') {
+    if (this.props.component.qualifier === ComponentQualifier.Application) {
       this.loadApplicationStatus();
     } else {
       this.loadProjectStatus();
@@ -342,7 +343,11 @@ export default class BranchOverview extends React.PureComponent<Props, State> {
     let current = component.breadcrumbs.length - 1;
     while (
       current > 0 &&
-      !['TRK', 'VW', 'APP'].includes(component.breadcrumbs[current].qualifier)
+      !([
+        ComponentQualifier.Project,
+        ComponentQualifier.Portfolio,
+        ComponentQualifier.Application
+      ] as string[]).includes(component.breadcrumbs[current].qualifier)
     ) {
       current--;
     }
@@ -380,7 +385,8 @@ export default class BranchOverview extends React.PureComponent<Props, State> {
       qgStatuses
     } = this.state;
 
-    const leakPeriod = component.qualifier === 'APP' ? appLeak : getLeakPeriod(periods);
+    const leakPeriod =
+      component.qualifier === ComponentQualifier.Application ? appLeak : getLeakPeriod(periods);
 
     const projectIsEmpty =
       loadingStatus === false &&
index 1a81132e2a17a3920672db9923c0b260222c0556..3442ba440ea9346d175431a5e4514c83eddfecec 100644 (file)
@@ -22,6 +22,8 @@ import { Alert } from 'sonar-ui-common/components/ui/Alert';
 import { translate, translateWithParameters } from 'sonar-ui-common/helpers/l10n';
 import { getBranchLikeDisplayName, isMainBranch } from '../../../helpers/branch-like';
 import { BranchLike } from '../../../types/branch-like';
+import { ComponentQualifier } from '../../../types/component';
+import { MetricKey } from '../../../types/metrics';
 
 interface Props {
   branchLike?: BranchLike;
@@ -30,7 +32,7 @@ interface Props {
 }
 
 export function NoCodeWarning({ branchLike, component, measures }: Props) {
-  const isApp = component.qualifier === 'APP';
+  const isApp = component.qualifier === ComponentQualifier.Application;
 
   /* eslint-disable no-lonely-if */
   // - Is App
@@ -49,7 +51,7 @@ export function NoCodeWarning({ branchLike, component, measures }: Props) {
   if (isApp) {
     if (
       measures === undefined ||
-      measures.find(measure => measure.metric.key === 'projects') === undefined
+      measures.find(measure => measure.metric.key === MetricKey.projects) === undefined
     ) {
       title = translate('portfolio.app.empty');
     } else {
index a304c5dccd931c9af25849110adcfd5b4f156f6e..888467d9779b300f42c8c064e3d9dcfcd86c4ddb 100644 (file)
@@ -21,6 +21,7 @@ import * as React from 'react';
 import { translate } from 'sonar-ui-common/helpers/l10n';
 import { isDiffMetric } from '../../../helpers/measures';
 import { BranchLike } from '../../../types/branch-like';
+import { ComponentQualifier } from '../../../types/component';
 import { QualityGateStatus } from '../../../types/quality-gates';
 import { QualityGateConditions } from '../components/QualityGateConditions';
 
@@ -39,7 +40,7 @@ export function QualityGatePanelSection(props: QualityGatePanelSectionProps) {
     return null;
   }
 
-  const showName = component.qualifier === 'APP';
+  const showName = component.qualifier === ComponentQualifier.Application;
 
   return (
     <div className="overview-quality-gate-conditions">
index d530f2fff8d1d23caa4138b87add38657eeafaf8..07617049e4c086808c9514d1db54d44efd3fdf8d 100644 (file)
 import { shallow } from 'enzyme';
 import * as React from 'react';
 import { mockAnalysis } from '../../../../helpers/testMocks';
+import { ComponentQualifier } from '../../../../types/component';
 import { Analysis, AnalysisProps } from '../Analysis';
 
 it('should render correctly', () => {
   expect(shallowRender()).toMatchSnapshot();
-  expect(shallowRender({ qualifier: 'APP' })).toMatchSnapshot();
+  expect(shallowRender({ qualifier: ComponentQualifier.Application })).toMatchSnapshot();
 });
 
 function shallowRender(props: Partial<AnalysisProps> = {}) {
@@ -36,7 +37,7 @@ function shallowRender(props: Partial<AnalysisProps> = {}) {
           { key: '2', category: 'VERSION', name: '6.5-SNAPSHOT' }
         ]
       })}
-      qualifier="TRK"
+      qualifier={ComponentQualifier.Project}
       {...props}
     />
   );
index 99244d2f41cfb5547c47af543c70039c7ebacc74..56e0a1bce43bbee14c71a9d91752e298814aa884 100644 (file)
@@ -33,6 +33,7 @@ import { getTimeMachineData } from '../../../../api/time-machine';
 import { getActivityGraph, saveActivityGraph } from '../../../../components/activity-graph/utils';
 import { mockMainBranch } from '../../../../helpers/mocks/branch-like';
 import { mockComponent } from '../../../../helpers/testMocks';
+import { ComponentQualifier } from '../../../../types/component';
 import { MetricKey } from '../../../../types/metrics';
 import { GraphType } from '../../../../types/project-activity';
 import BranchOverview, { BRANCH_OVERVIEW_ACTIVITY_GRAPH } from '../BranchOverview';
@@ -229,8 +230,8 @@ describe('project overview', () => {
 
 describe('application overview', () => {
   const component = mockComponent({
-    breadcrumbs: [mockComponent({ key: 'foo', qualifier: 'APP' })],
-    qualifier: 'APP'
+    breadcrumbs: [mockComponent({ key: 'foo', qualifier: ComponentQualifier.Application })],
+    qualifier: ComponentQualifier.Application
   });
 
   it('should render correctly', async () => {
index 4f0094bc1b4124f946020946d868675829971bf1..c6bd613049b91d357e5e0c825291cb37226e281f 100644 (file)
@@ -22,6 +22,7 @@ import * as React from 'react';
 import BoxedTabs from 'sonar-ui-common/components/controls/BoxedTabs';
 import { mockMainBranch } from '../../../../helpers/mocks/branch-like';
 import { mockComponent, mockMeasureEnhanced, mockMetric } from '../../../../helpers/testMocks';
+import { ComponentQualifier } from '../../../../types/component';
 import { MetricKey } from '../../../../types/metrics';
 import { MeasuresPanel, MeasuresPanelProps, MeasuresPanelTabs } from '../MeasuresPanel';
 
@@ -33,7 +34,9 @@ it('should render correctly for projects', () => {
 });
 
 it('should render correctly for applications', () => {
-  const wrapper = shallowRender({ component: mockComponent({ qualifier: 'APP' }) });
+  const wrapper = shallowRender({
+    component: mockComponent({ qualifier: ComponentQualifier.Application })
+  });
   expect(wrapper).toMatchSnapshot();
   wrapper.find(BoxedTabs).prop<Function>('onSelect')(MeasuresPanelTabs.Overall);
   expect(wrapper).toMatchSnapshot();
index cfec0025b070b7deb0b6627c6019b1352b6cb7d8..4639e817808894bff83bc8073c5153c5931997ed 100644 (file)
@@ -21,9 +21,11 @@ import { shallow } from 'enzyme';
 import * as React from 'react';
 import { mockBranch, mockMainBranch } from '../../../../helpers/mocks/branch-like';
 import { mockComponent, mockMeasureEnhanced, mockMetric } from '../../../../helpers/testMocks';
+import { ComponentQualifier } from '../../../../types/component';
+import { MetricKey } from '../../../../types/metrics';
 import { NoCodeWarning } from '../NoCodeWarning';
 
-it.only('should render correctly if the project has no lines of code', () => {
+it('should render correctly if the project has no lines of code', () => {
   const wrapper = shallowRender();
   expect(wrapper.children().text()).toBe('overview.project.main_branch_no_lines_of_code');
 
@@ -47,8 +49,8 @@ it('should correctly if the project is empty', () => {
 
 it('should render correctly if the application is empty or has no lines of code', () => {
   const wrapper = shallowRender({
-    component: mockComponent({ qualifier: 'APP' }),
-    measures: [mockMeasureEnhanced({ metric: mockMetric({ key: 'projects' }) })]
+    component: mockComponent({ qualifier: ComponentQualifier.Application }),
+    measures: [mockMeasureEnhanced({ metric: mockMetric({ key: MetricKey.projects }) })]
   });
   expect(wrapper.children().text()).toBe('portfolio.app.no_lines_of_code');
 
@@ -61,7 +63,7 @@ function shallowRender(props = {}) {
     <NoCodeWarning
       branchLike={mockMainBranch()}
       component={mockComponent()}
-      measures={[mockMeasureEnhanced({ metric: mockMetric({ key: 'bugs' }) })]}
+      measures={[mockMeasureEnhanced({ metric: mockMetric({ key: MetricKey.bugs }) })]}
       {...props}
     />
   );
index 8769973e216dc5f4e1587ed4ac21f798054dc19b..2f5a83793781388ba7f540030097df503c399428 100644 (file)
@@ -25,6 +25,8 @@ import {
   mockQualityGateStatusConditionEnhanced
 } from '../../../../helpers/mocks/quality-gates';
 import { mockComponent, mockMeasureEnhanced, mockMetric } from '../../../../helpers/testMocks';
+import { ComponentQualifier } from '../../../../types/component';
+import { MetricKey } from '../../../../types/metrics';
 import { QualityGatePanel, QualityGatePanelProps } from '../QualityGatePanel';
 
 it('should render correctly for projects', () => {
@@ -42,15 +44,17 @@ it('should render correctly for projects', () => {
 it('should render correctly for applications', () => {
   expect(
     shallowRender({
-      component: mockComponent({ qualifier: 'APP' }),
+      component: mockComponent({ qualifier: ComponentQualifier.Application }),
       qgStatuses: [
         mockQualityGateStatus(),
         mockQualityGateStatus({
           failedConditions: [
             mockQualityGateStatusConditionEnhanced(),
             mockQualityGateStatusConditionEnhanced({
-              measure: mockMeasureEnhanced({ metric: mockMetric({ key: 'new_code_smells' }) }),
-              metric: 'new_code_smells'
+              measure: mockMeasureEnhanced({
+                metric: mockMetric({ key: MetricKey.new_code_smells })
+              }),
+              metric: MetricKey.new_code_smells
             })
           ]
         })
@@ -59,7 +63,7 @@ it('should render correctly for applications', () => {
   ).toMatchSnapshot();
 
   const wrapper = shallowRender({
-    component: mockComponent({ qualifier: 'APP' }),
+    component: mockComponent({ qualifier: ComponentQualifier.Application }),
     qgStatuses: [
       mockQualityGateStatus(),
       mockQualityGateStatus({
index 50169bf82238c01500618e9b021bd918382ef8d9..2fb27f0aa7fdec4b542bb9449aa1fcc040a5e725 100644 (file)
@@ -25,6 +25,8 @@ import {
   mockQualityGateStatusConditionEnhanced
 } from '../../../../helpers/mocks/quality-gates';
 import { mockComponent } from '../../../../helpers/testMocks';
+import { ComponentQualifier } from '../../../../types/component';
+import { MetricKey } from '../../../../types/metrics';
 import { QualityGatePanelSection, QualityGatePanelSectionProps } from '../QualityGatePanelSection';
 
 it('should render correctly', () => {
@@ -37,7 +39,9 @@ it('should render correctly', () => {
       })
     }).type()
   ).toBeNull();
-  expect(shallowRender({ component: mockComponent({ qualifier: 'APP' }) })).toMatchSnapshot();
+  expect(
+    shallowRender({ component: mockComponent({ qualifier: ComponentQualifier.Application }) })
+  ).toMatchSnapshot();
 });
 
 function shallowRender(props: Partial<QualityGatePanelSectionProps> = {}) {
@@ -47,8 +51,8 @@ function shallowRender(props: Partial<QualityGatePanelSectionProps> = {}) {
       component={mockComponent()}
       qgStatus={mockQualityGateStatus({
         failedConditions: [
-          mockQualityGateStatusConditionEnhanced({ metric: 'bugs' }),
-          mockQualityGateStatusConditionEnhanced({ metric: 'new_bugs' })
+          mockQualityGateStatusConditionEnhanced({ metric: MetricKey.bugs }),
+          mockQualityGateStatusConditionEnhanced({ metric: MetricKey.new_bugs })
         ],
         status: 'ERROR'
       })}
index 7790272f2e4a1b7c3a3d13e5ba95ed1098602811..e10115c97808f7ca64a24a1f86fb65209441142e 100644 (file)
@@ -23,6 +23,7 @@ import Suggestions from '../../../app/components/embed-docs-modal/Suggestions';
 import { Router, withRouter } from '../../../components/hoc/withRouter';
 import { isPullRequest } from '../../../helpers/branch-like';
 import { BranchLike } from '../../../types/branch-like';
+import { ComponentQualifier } from '../../../types/component';
 import BranchOverview from '../branches/BranchOverview';
 
 const EmptyOverview = lazyLoad(() => import('./EmptyOverview'));
@@ -50,7 +51,9 @@ export class App extends React.PureComponent<Props> {
   }
 
   isPortfolio = () => {
-    return ['VW', 'SVW'].includes(this.props.component.qualifier);
+    return ([ComponentQualifier.Portfolio, ComponentQualifier.SubPortfolio] as string[]).includes(
+      this.props.component.qualifier
+    );
   };
 
   render() {
index 655ff347aee496e7cd1db11e9ae9dbf7bc8df57c..f87c9a235c7784a2f8dc6c6c749eb9c07b1f2aa4 100644 (file)
@@ -21,6 +21,7 @@ import { shallow } from 'enzyme';
 import * as React from 'react';
 import { mockBranch, mockMainBranch, mockPullRequest } from '../../../../helpers/mocks/branch-like';
 import { mockComponent, mockCurrentUser, mockLoggedInUser } from '../../../../helpers/testMocks';
+import { ComponentQualifier } from '../../../../types/component';
 import { EmptyOverview } from '../EmptyOverview';
 
 it('renders correctly', () => {
@@ -43,7 +44,9 @@ it('should not render warning message for pull requests', () => {
 });
 
 it('should not render the tutorial for applications', () => {
-  expect(shallowRender({ component: mockComponent({ qualifier: 'APP' }) })).toMatchSnapshot();
+  expect(
+    shallowRender({ component: mockComponent({ qualifier: ComponentQualifier.Application }) })
+  ).toMatchSnapshot();
 });
 
 function shallowRender(props = {}) {