From caa927052caed31756f8865efb6804f3249f8f0a Mon Sep 17 00:00:00 2001 From: Pascal Mugnier Date: Thu, 12 Jul 2018 11:39:46 +0200 Subject: Apply feedback for security reports (#503) --- .../components/nav/component/ComponentNavMenu.tsx | 3 + .../__snapshots__/ComponentNavMenu-test.tsx.snap | 43 --- .../src/main/js/app/styles/init/links.css | 9 + .../js/apps/securityReports/components/App.tsx | 9 +- .../components/VulnerabilityList.tsx | 90 +++-- .../__snapshots__/VulnerabilityList-test.tsx.snap | 406 ++++++++++++--------- .../src/main/js/apps/securityReports/style.css | 4 + .../sonar-web/src/main/js/helpers/standards.json | 2 +- 8 files changed, 315 insertions(+), 251 deletions(-) (limited to 'server/sonar-web/src') diff --git a/server/sonar-web/src/main/js/app/components/nav/component/ComponentNavMenu.tsx b/server/sonar-web/src/main/js/app/components/nav/component/ComponentNavMenu.tsx index ca3a9ce6f5f..45c15f90b35 100644 --- a/server/sonar-web/src/main/js/app/components/nav/component/ComponentNavMenu.tsx +++ b/server/sonar-web/src/main/js/app/components/nav/component/ComponentNavMenu.tsx @@ -191,6 +191,9 @@ export default class ComponentNavMenu extends React.PureComponent { } renderSecurityReports() { + if (this.props.component.qualifier === 'BRC' || this.props.component.qualifier === 'DIR') { + return null; + } const isActive = location.pathname.startsWith('/project/security_reports'); return ( diff --git a/server/sonar-web/src/main/js/app/components/nav/component/__tests__/__snapshots__/ComponentNavMenu-test.tsx.snap b/server/sonar-web/src/main/js/app/components/nav/component/__tests__/__snapshots__/ComponentNavMenu-test.tsx.snap index 40cbe0f76bb..d35a9a9e59e 100644 --- a/server/sonar-web/src/main/js/app/components/nav/component/__tests__/__snapshots__/ComponentNavMenu-test.tsx.snap +++ b/server/sonar-web/src/main/js/app/components/nav/component/__tests__/__snapshots__/ComponentNavMenu-test.tsx.snap @@ -251,49 +251,6 @@ exports[`should work for all qualifiers 2`] = ` issues.page - -
  • - - security_reports.owaspTop10.page - -
  • -
  • - - security_reports.sansTop25.page - -
  • - - } - tagName="li" - />
  • { }) .then(results => { if (this.mounted) { - const hasVulnerabilities = results.categories.some(item => item.vulnerabilities > 0); + const hasVulnerabilities = results.categories.some( + item => + item.vulnerabilities + + item.openSecurityHotspots + + item.toReviewSecurityHotspots + + item.wontFixSecurityHotspots > + 0 + ); this.setState({ hasVulnerabilities, findings: results.categories, loading: false }); } }) diff --git a/server/sonar-web/src/main/js/apps/securityReports/components/VulnerabilityList.tsx b/server/sonar-web/src/main/js/apps/securityReports/components/VulnerabilityList.tsx index c2bc6b51304..a1af8a0f808 100755 --- a/server/sonar-web/src/main/js/apps/securityReports/components/VulnerabilityList.tsx +++ b/server/sonar-web/src/main/js/apps/securityReports/components/VulnerabilityList.tsx @@ -18,6 +18,7 @@ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ import * as React from 'react'; +import * as classNames from 'classnames'; import { Link } from 'react-router'; import { translate } from '../../../helpers/l10n'; import { SecurityHotspot, Component, BranchLike } from '../../../app/types'; @@ -33,6 +34,9 @@ import { renderCWECategory, Standards } from '../utils'; +import DetachIcon from '../../../components/icons-components/DetachIcon'; +import Tooltip from '../../../components/controls/Tooltip'; +import { getRatingTooltip } from '../../../helpers/measures'; interface Props { branchLike?: BranchLike; @@ -86,78 +90,108 @@ export default class VulnerabilityList extends React.PureComponent this.state.standards[type][category].description && ( )} ); } + renderOverlay = (description: string | undefined) => { + return ( + <> +

    {description}

    +
    + {translate('learn_more')}: + + Security Reports + + + + ); + }; + renderFinding(finding: SecurityHotspot, isCWE?: boolean): React.ReactFragment { const { branchLike, component, type } = this.props; const params: { [name: string]: string | undefined } = { ...getBranchLikeQuery(branchLike), types: 'SECURITY_HOTSPOT' }; - params[type] = finding.category || finding.cwe; + params[isCWE ? 'cwe' : type] = finding.cwe || finding.category; const subFindings = this.props.showCWE && finding.distribution ? finding.distribution.map(f => this.renderFinding(f, true)) : null; + const title = getRatingTooltip('security_rating', finding.vulnerabilityRating || 1); return ( - {isCWE && } - -
    - {this.getName(finding, isCWE ? 'cwe' : type)} -
    + + {this.getName(finding, isCWE ? 'cwe' : type)} - +
    + to={getComponentIssuesUrl(component.key, { + ...params, + types: 'VULNERABILITY', + resolved: 'false' + })}> {finding.vulnerabilities} - - - + + + + +
    - + {finding.openSecurityHotspots} - + {finding.toReviewSecurityHotspots} - + {finding.wontFixSecurityHotspots} @@ -174,29 +208,31 @@ export default class VulnerabilityList extends React.PureComponent - - - + - diff --git a/server/sonar-web/src/main/js/apps/securityReports/components/__tests__/__snapshots__/VulnerabilityList-test.tsx.snap b/server/sonar-web/src/main/js/apps/securityReports/components/__tests__/__snapshots__/VulnerabilityList-test.tsx.snap index 437b86a78db..cde2b7944a4 100644 --- a/server/sonar-web/src/main/js/apps/securityReports/components/__tests__/__snapshots__/VulnerabilityList-test.tsx.snap +++ b/server/sonar-web/src/main/js/apps/securityReports/components/__tests__/__snapshots__/VulnerabilityList-test.tsx.snap @@ -11,7 +11,6 @@ exports[`renders 1`] = ` @@ -24,7 +23,6 @@ exports[`renders 1`] = ` - security_reports.list.vulnerabilities @@ -37,7 +35,6 @@ exports[`renders 1`] = ` - security_reports.list.hotspots @@ -46,20 +43,20 @@ exports[`renders 1`] = ` className="subheader" > @@ -71,18 +68,15 @@ exports[`renders 1`] = ` > - - - - - - - - @@ -335,7 +353,6 @@ exports[`renders with cwe 1`] = ` - security_reports.list.vulnerabilities @@ -348,7 +365,6 @@ exports[`renders with cwe 1`] = ` - security_reports.list.hotspots @@ -357,20 +373,20 @@ exports[`renders with cwe 1`] = ` className="subheader" > @@ -382,18 +398,15 @@ exports[`renders with cwe 1`] = ` > - - - - - - - - - - - - -
    + {translate('security_reports.list.categories')}
    - {' '} + {translate('security_reports.list.vulnerabilities')}
    - {' '} + {translate('security_reports.list.hotspots')}
    - {translate('security_reports.line.open')} + + + {translate('security_reports.line.open')} + {translate('security_reports.line.in_review')} + {translate('security_reports.line.wont_fix')}
    security_reports.list.categories security_reports.line.open security_reports.line.in_review security_reports.line.wont_fix
    -
    - - A1 - -
    + + A1 +
    +
    @@ -95,6 +89,7 @@ exports[`renders 1`] = ` "query": Object { "id": "foo", "owaspTop10": "a1", + "resolved": "false", "types": "VULNERABILITY", }, } @@ -102,28 +97,35 @@ exports[`renders 1`] = ` > 2 - - - + + + +
    + + +
    -
    - - UNKNOWN - -
    + + UNKNOWN +
    +
    @@ -215,6 +220,7 @@ exports[`renders 1`] = ` "query": Object { "id": "foo", "owaspTop10": "unknown", + "resolved": "false", "types": "VULNERABILITY", }, } @@ -222,28 +228,35 @@ exports[`renders 1`] = ` > 3 - - - + + + +
    + + + security_reports.list.categories security_reports.line.open security_reports.line.in_review security_reports.line.wont_fix
    -
    - - A1 - -
    + + A1 +
    +
    @@ -406,6 +419,7 @@ exports[`renders with cwe 1`] = ` "query": Object { "id": "foo", "owaspTop10": "a1", + "resolved": "false", "types": "VULNERABILITY", }, } @@ -413,28 +427,35 @@ exports[`renders with cwe 1`] = ` > 2 - - - + + + +
    + + +
    -
    - - CWE-42 - -
    + + CWE-42 +
    +
    @@ -524,8 +547,9 @@ exports[`renders with cwe 1`] = ` Object { "pathname": "/project/issues", "query": Object { + "cwe": "42", "id": "foo", - "owaspTop10": "42", + "resolved": "false", "types": "VULNERABILITY", }, } @@ -533,28 +557,35 @@ exports[`renders with cwe 1`] = ` > 1 - - - + + + +
    + + +
    -
    - - UNKNOWN - -
    + + UNKNOWN +
    +
    @@ -647,6 +681,7 @@ exports[`renders with cwe 1`] = ` "query": Object { "id": "foo", "owaspTop10": "unknown", + "resolved": "false", "types": "VULNERABILITY", }, } @@ -654,28 +689,35 @@ exports[`renders with cwe 1`] = ` > 3 - - - + + + +
    + + +