From: Stas Vilchik Date: Mon, 18 Sep 2017 11:25:28 +0000 (+0200) Subject: SONAR-9833 'A' ratings when a portfolio without project is analyzed X-Git-Tag: 6.6-RC1~274 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=c9c9262a4ca404ed4860085d17aaf8ac6b64ca1f;p=sonarqube.git SONAR-9833 'A' ratings when a portfolio without project is analyzed --- diff --git a/server/sonar-web/src/main/js/apps/portfolio/components/Activity.tsx b/server/sonar-web/src/main/js/apps/portfolio/components/Activity.tsx index 26a66872a01..63ccdd7217c 100644 --- a/server/sonar-web/src/main/js/apps/portfolio/components/Activity.tsx +++ b/server/sonar-web/src/main/js/apps/portfolio/components/Activity.tsx @@ -97,7 +97,7 @@ export default class Activity extends React.PureComponent { render() { return ( -
+

{translate('project_activity.page')}

diff --git a/server/sonar-web/src/main/js/apps/portfolio/components/App.tsx b/server/sonar-web/src/main/js/apps/portfolio/components/App.tsx index e0910baa420..ec7f35fc0b2 100644 --- a/server/sonar-web/src/main/js/apps/portfolio/components/App.tsx +++ b/server/sonar-web/src/main/js/apps/portfolio/components/App.tsx @@ -31,6 +31,7 @@ import { getChildren } from '../../../api/components'; import { PORTFOLIO_METRICS, SUB_COMPONENTS_METRICS, convertMeasures } from '../utils'; import { SubComponent } from '../types'; import '../styles.css'; +import { translate } from '../../../helpers/l10n'; interface Props { component: { key: string; name: string }; @@ -97,6 +98,11 @@ export default class App extends React.PureComponent { ); } + isEmpty = () => this.state.measures == undefined || this.state.measures['ncloc'] == undefined; + + isNotComputed = () => + this.state.measures && this.state.measures['reliability_rating'] == undefined; + renderSpinner() { return (
@@ -107,9 +113,59 @@ export default class App extends React.PureComponent { ); } + renderEmpty() { + return ( +
+

{translate('portfolio.empty')}

+

{translate('portfolio.empty.hint')}

+
+ ); + } + + renderWhenNotComputed() { + return ( +
+

{translate('portfolio.not_computed')}

+
+ ); + } + + renderMain() { + const { component } = this.props; + const { measures, subComponents, totalSubComponents } = this.state; + + if (this.isEmpty()) { + return this.renderEmpty(); + } + + if (this.isNotComputed()) { + return this.renderWhenNotComputed(); + } + + return ( +
+
+ + + + +
+ + {subComponents != undefined && + totalSubComponents != undefined && ( + + )} +
+ ); + } + render() { const { component } = this.props; - const { loading, measures, subComponents, totalSubComponents } = this.state; + const { loading, measures } = this.state; if (loading) { return this.renderSpinner(); @@ -118,28 +174,11 @@ export default class App extends React.PureComponent { return (
-
- {measures != undefined && ( -
- - - - -
- )} - - {subComponents != undefined && - totalSubComponents != undefined && ( - - )} -
+
{this.renderMain()}
diff --git a/server/sonar-web/src/main/js/apps/portfolio/components/Report.tsx b/server/sonar-web/src/main/js/apps/portfolio/components/Report.tsx index 596afcba973..86bf16d5050 100644 --- a/server/sonar-web/src/main/js/apps/portfolio/components/Report.tsx +++ b/server/sonar-web/src/main/js/apps/portfolio/components/Report.tsx @@ -71,7 +71,7 @@ export default class Report extends React.PureComponent { if (loading) { return ( -
+
{this.renderHeader()}
@@ -83,7 +83,7 @@ export default class Report extends React.PureComponent { } return ( -
+
{this.renderHeader()} {!status.canDownload && ( diff --git a/server/sonar-web/src/main/js/apps/portfolio/components/Summary.tsx b/server/sonar-web/src/main/js/apps/portfolio/components/Summary.tsx index ef13cf58cb8..aa229597a1e 100644 --- a/server/sonar-web/src/main/js/apps/portfolio/components/Summary.tsx +++ b/server/sonar-web/src/main/js/apps/portfolio/components/Summary.tsx @@ -35,7 +35,7 @@ export default function Summary({ component, measures }: Props) { const nclocDistribution = measures['ncloc_language_distribution']; return ( -
+
{component.description &&
{component.description}
}
    diff --git a/server/sonar-web/src/main/js/apps/portfolio/components/__tests__/App-test.tsx b/server/sonar-web/src/main/js/apps/portfolio/components/__tests__/App-test.tsx index fafff182895..e9c93fb7279 100644 --- a/server/sonar-web/src/main/js/apps/portfolio/components/__tests__/App-test.tsx +++ b/server/sonar-web/src/main/js/apps/portfolio/components/__tests__/App-test.tsx @@ -49,7 +49,24 @@ const component = { key: 'foo', name: 'Foo' }; it('renders', () => { const wrapper = shallow(); - wrapper.setState({ loading: false, measures: {}, subComponents: [], totalSubComponents: 0 }); + wrapper.setState({ + loading: false, + measures: { ncloc: '173', reliability_rating: '1' }, + subComponents: [], + totalSubComponents: 0 + }); + expect(wrapper).toMatchSnapshot(); +}); + +it('renders when portfolio is empty', () => { + const wrapper = shallow(); + wrapper.setState({ loading: false, measures: { reliability_rating: '1' } }); + expect(wrapper).toMatchSnapshot(); +}); + +it('renders when portfolio is not computed', () => { + const wrapper = shallow(); + wrapper.setState({ loading: false, measures: { ncloc: '173' } }); expect(wrapper).toMatchSnapshot(); }); diff --git a/server/sonar-web/src/main/js/apps/portfolio/components/__tests__/__snapshots__/Activity-test.tsx.snap b/server/sonar-web/src/main/js/apps/portfolio/components/__tests__/__snapshots__/Activity-test.tsx.snap index 1df37032691..fa3361a98b5 100644 --- a/server/sonar-web/src/main/js/apps/portfolio/components/__tests__/__snapshots__/Activity-test.tsx.snap +++ b/server/sonar-web/src/main/js/apps/portfolio/components/__tests__/__snapshots__/Activity-test.tsx.snap @@ -2,7 +2,7 @@ exports[`renders 1`] = `
    -
    - - - - +
    + + + + +
    +
    - + +
    +
+`; + +exports[`renders when portfolio is empty 1`] = ` +
+
+
+
+

+ portfolio.empty +

+

+ portfolio.empty.hint +

+
+
+
+`; + +exports[`renders when portfolio is not computed 1`] = ` +
+
+
+
+

+ portfolio.not_computed +

+
+
+