From: Wouter Admiraal Date: Thu, 19 Dec 2019 13:30:50 +0000 (+0100) Subject: Use new ComponentQualifier enum X-Git-Tag: 8.2.0.32929~104 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=04237dba5156dca631d687c4ce6b88de60eef14b;p=sonarqube.git Use new ComponentQualifier enum --- diff --git a/server/sonar-web/src/main/js/apps/overview/branches/Analysis.tsx b/server/sonar-web/src/main/js/apps/overview/branches/Analysis.tsx index 0860bfa80c4..af6a7889954 100644 --- a/server/sonar-web/src/main/js/apps/overview/branches/Analysis.tsx +++ b/server/sonar-web/src/main/js/apps/overview/branches/Analysis.tsx @@ -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 (
  • diff --git a/server/sonar-web/src/main/js/apps/overview/branches/BranchOverview.tsx b/server/sonar-web/src/main/js/apps/overview/branches/BranchOverview.tsx index 6ad66b9295d..0baa63ff420 100644 --- a/server/sonar-web/src/main/js/apps/overview/branches/BranchOverview.tsx +++ b/server/sonar-web/src/main/js/apps/overview/branches/BranchOverview.tsx @@ -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 { } 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 { 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 { qgStatuses } = this.state; - const leakPeriod = component.qualifier === 'APP' ? appLeak : getLeakPeriod(periods); + const leakPeriod = + component.qualifier === ComponentQualifier.Application ? appLeak : getLeakPeriod(periods); const projectIsEmpty = loadingStatus === false && diff --git a/server/sonar-web/src/main/js/apps/overview/branches/NoCodeWarning.tsx b/server/sonar-web/src/main/js/apps/overview/branches/NoCodeWarning.tsx index 1a81132e2a1..3442ba440ea 100644 --- a/server/sonar-web/src/main/js/apps/overview/branches/NoCodeWarning.tsx +++ b/server/sonar-web/src/main/js/apps/overview/branches/NoCodeWarning.tsx @@ -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 { diff --git a/server/sonar-web/src/main/js/apps/overview/branches/QualityGatePanelSection.tsx b/server/sonar-web/src/main/js/apps/overview/branches/QualityGatePanelSection.tsx index a304c5dccd9..888467d9779 100644 --- a/server/sonar-web/src/main/js/apps/overview/branches/QualityGatePanelSection.tsx +++ b/server/sonar-web/src/main/js/apps/overview/branches/QualityGatePanelSection.tsx @@ -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 (
    diff --git a/server/sonar-web/src/main/js/apps/overview/branches/__tests__/Analysis-test.tsx b/server/sonar-web/src/main/js/apps/overview/branches/__tests__/Analysis-test.tsx index d530f2fff8d..07617049e4c 100644 --- a/server/sonar-web/src/main/js/apps/overview/branches/__tests__/Analysis-test.tsx +++ b/server/sonar-web/src/main/js/apps/overview/branches/__tests__/Analysis-test.tsx @@ -20,11 +20,12 @@ 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 = {}) { @@ -36,7 +37,7 @@ function shallowRender(props: Partial = {}) { { key: '2', category: 'VERSION', name: '6.5-SNAPSHOT' } ] })} - qualifier="TRK" + qualifier={ComponentQualifier.Project} {...props} /> ); diff --git a/server/sonar-web/src/main/js/apps/overview/branches/__tests__/BranchOverview-test.tsx b/server/sonar-web/src/main/js/apps/overview/branches/__tests__/BranchOverview-test.tsx index 99244d2f41c..56e0a1bce43 100644 --- a/server/sonar-web/src/main/js/apps/overview/branches/__tests__/BranchOverview-test.tsx +++ b/server/sonar-web/src/main/js/apps/overview/branches/__tests__/BranchOverview-test.tsx @@ -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 () => { diff --git a/server/sonar-web/src/main/js/apps/overview/branches/__tests__/MeasuresPanel-test.tsx b/server/sonar-web/src/main/js/apps/overview/branches/__tests__/MeasuresPanel-test.tsx index 4f0094bc1b4..c6bd613049b 100644 --- a/server/sonar-web/src/main/js/apps/overview/branches/__tests__/MeasuresPanel-test.tsx +++ b/server/sonar-web/src/main/js/apps/overview/branches/__tests__/MeasuresPanel-test.tsx @@ -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('onSelect')(MeasuresPanelTabs.Overall); expect(wrapper).toMatchSnapshot(); diff --git a/server/sonar-web/src/main/js/apps/overview/branches/__tests__/NoCodeWarning-test.tsx b/server/sonar-web/src/main/js/apps/overview/branches/__tests__/NoCodeWarning-test.tsx index cfec0025b07..4639e817808 100644 --- a/server/sonar-web/src/main/js/apps/overview/branches/__tests__/NoCodeWarning-test.tsx +++ b/server/sonar-web/src/main/js/apps/overview/branches/__tests__/NoCodeWarning-test.tsx @@ -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 = {}) { ); diff --git a/server/sonar-web/src/main/js/apps/overview/branches/__tests__/QualityGatePanel-test.tsx b/server/sonar-web/src/main/js/apps/overview/branches/__tests__/QualityGatePanel-test.tsx index 8769973e216..2f5a8379378 100644 --- a/server/sonar-web/src/main/js/apps/overview/branches/__tests__/QualityGatePanel-test.tsx +++ b/server/sonar-web/src/main/js/apps/overview/branches/__tests__/QualityGatePanel-test.tsx @@ -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({ diff --git a/server/sonar-web/src/main/js/apps/overview/branches/__tests__/QualityGatePanelSection-test.tsx b/server/sonar-web/src/main/js/apps/overview/branches/__tests__/QualityGatePanelSection-test.tsx index 50169bf8223..2fb27f0aa7f 100644 --- a/server/sonar-web/src/main/js/apps/overview/branches/__tests__/QualityGatePanelSection-test.tsx +++ b/server/sonar-web/src/main/js/apps/overview/branches/__tests__/QualityGatePanelSection-test.tsx @@ -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 = {}) { @@ -47,8 +51,8 @@ function shallowRender(props: Partial = {}) { component={mockComponent()} qgStatus={mockQualityGateStatus({ failedConditions: [ - mockQualityGateStatusConditionEnhanced({ metric: 'bugs' }), - mockQualityGateStatusConditionEnhanced({ metric: 'new_bugs' }) + mockQualityGateStatusConditionEnhanced({ metric: MetricKey.bugs }), + mockQualityGateStatusConditionEnhanced({ metric: MetricKey.new_bugs }) ], status: 'ERROR' })} diff --git a/server/sonar-web/src/main/js/apps/overview/components/App.tsx b/server/sonar-web/src/main/js/apps/overview/components/App.tsx index 7790272f2e4..e10115c9780 100644 --- a/server/sonar-web/src/main/js/apps/overview/components/App.tsx +++ b/server/sonar-web/src/main/js/apps/overview/components/App.tsx @@ -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 { } isPortfolio = () => { - return ['VW', 'SVW'].includes(this.props.component.qualifier); + return ([ComponentQualifier.Portfolio, ComponentQualifier.SubPortfolio] as string[]).includes( + this.props.component.qualifier + ); }; render() { diff --git a/server/sonar-web/src/main/js/apps/overview/components/__tests__/EmptyOverview-test.tsx b/server/sonar-web/src/main/js/apps/overview/components/__tests__/EmptyOverview-test.tsx index 655ff347aee..f87c9a235c7 100644 --- a/server/sonar-web/src/main/js/apps/overview/components/__tests__/EmptyOverview-test.tsx +++ b/server/sonar-web/src/main/js/apps/overview/components/__tests__/EmptyOverview-test.tsx @@ -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 = {}) {