From bf1a177bdd101ee445a502c969e125a1fe066e8d Mon Sep 17 00:00:00 2001 From: Jeremy Davis Date: Tue, 18 Jun 2019 16:21:01 +0200 Subject: [PATCH] SONAR-12209 Prevent flashing page in PR QG overview --- .../apps/overview/pullRequests/ReviewApp.tsx | 174 +++---- .../pullRequests/__tests__/ReviewApp-test.tsx | 5 +- .../__snapshots__/ReviewApp-test.tsx.snap | 469 +----------------- 3 files changed, 96 insertions(+), 552 deletions(-) diff --git a/server/sonar-web/src/main/js/apps/overview/pullRequests/ReviewApp.tsx b/server/sonar-web/src/main/js/apps/overview/pullRequests/ReviewApp.tsx index ceee7deba0b..11905e375a1 100644 --- a/server/sonar-web/src/main/js/apps/overview/pullRequests/ReviewApp.tsx +++ b/server/sonar-web/src/main/js/apps/overview/pullRequests/ReviewApp.tsx @@ -26,7 +26,6 @@ import IssueLabel from './IssueLabel'; import IssueRating from './IssueRating'; import MeasurementLabel from './MeasurementLabel'; import { Alert } from '../../../components/ui/Alert'; -import DeferredSpinner from '../../../components/common/DeferredSpinner'; import DocTooltip from '../../../components/docs/DocTooltip'; import HelpTooltip from '../../../components/controls/HelpTooltip'; import QualityGateConditions from '../qualityGate/QualityGateConditions'; @@ -119,114 +118,119 @@ export class ReviewApp extends React.PureComponent { }; render() { - const { branchLike, component, conditions = [], ignoredConditions, status } = this.props; + const { branchLike, component, conditions, ignoredConditions, status } = this.props; const { loading, measures } = this.state; + + if (loading || !conditions) { + return ( +
+ +
+ ); + } + const erroredConditions = conditions.filter(condition => condition.level === 'ERROR'); return (
- {loading ? ( - - ) : ( -
0 - })}> - {ignoredConditions && ( - - - {translate('overview.quality_gate.ignored_conditions')} - - 0 + })}> + {ignoredConditions && ( + + + {translate('overview.quality_gate.ignored_conditions')} + + + + )} +
+
+

+ {translate('overview.quality_gate')} + - - )} -
-
-

- {translate('overview.quality_gate')} - -

- -
+

+ +
- {erroredConditions.length > 0 && ( -
-

{translate('overview.failed_conditions')}

- -
- )} + {erroredConditions.length > 0 && ( +
+

{translate('overview.failed_conditions')}

+ +
+ )} -
-

{translate('overview.metrics')}

+
+

{translate('overview.metrics')}

- {['BUG', 'VULNERABILITY', 'CODE_SMELL'].map((type: IssueType) => ( -
+ {['BUG', 'VULNERABILITY', 'CODE_SMELL'].map((type: IssueType) => ( +
+
+ +
+ {type === 'VULNERABILITY' && (
-
- {type === 'VULNERABILITY' && ( -
- -
- )} -
-
+ )} +
+
- ))} - - {['COVERAGE', 'DUPLICATION'].map((type: MeasurementType) => ( -
-
- -
- - + ))} + + {['COVERAGE', 'DUPLICATION'].map((type: MeasurementType) => ( +
+
+
- ))} -
+ + +
+ ))}
- )} +
); } diff --git a/server/sonar-web/src/main/js/apps/overview/pullRequests/__tests__/ReviewApp-test.tsx b/server/sonar-web/src/main/js/apps/overview/pullRequests/__tests__/ReviewApp-test.tsx index 565982b1825..cdbfe0d8ce5 100644 --- a/server/sonar-web/src/main/js/apps/overview/pullRequests/__tests__/ReviewApp-test.tsx +++ b/server/sonar-web/src/main/js/apps/overview/pullRequests/__tests__/ReviewApp-test.tsx @@ -48,8 +48,11 @@ beforeEach(() => { it('should render correctly for a passed QG', async () => { const fetchBranchStatus = jest.fn(); + const wrapper = shallowRender({ fetchBranchStatus, status: 'OK' }); + wrapper.setProps({ conditions: [] }); + await waitAndUpdate(wrapper); expect(wrapper).toMatchSnapshot(); @@ -60,7 +63,7 @@ it('should render correctly for a passed QG', async () => { }); it('should render correctly if conditions are ignored', async () => { - const wrapper = shallowRender({ ignoredConditions: true }); + const wrapper = shallowRender({ conditions: [], ignoredConditions: true }); await waitAndUpdate(wrapper); expect(wrapper.find('Alert').exists()).toBe(true); }); diff --git a/server/sonar-web/src/main/js/apps/overview/pullRequests/__tests__/__snapshots__/ReviewApp-test.tsx.snap b/server/sonar-web/src/main/js/apps/overview/pullRequests/__tests__/__snapshots__/ReviewApp-test.tsx.snap index 530b37dda8b..f23c3a895ff 100644 --- a/server/sonar-web/src/main/js/apps/overview/pullRequests/__tests__/__snapshots__/ReviewApp-test.tsx.snap +++ b/server/sonar-web/src/main/js/apps/overview/pullRequests/__tests__/__snapshots__/ReviewApp-test.tsx.snap @@ -4,472 +4,9 @@ exports[`should correctly handle a WS failure 1`] = `
-
-
-
-

- overview.quality_gate - -

- -
-
-

- overview.metrics -

-
-
- -
-
- -
-
-
-
- -
-
- -
-
- -
-
-
-
- -
-
- -
-
-
-
- -
- -
-
-
- -
- -
-
-
-
+
`; -- 2.39.5