From 5368594546991fbea6c4b4dcdf2386493b78189d Mon Sep 17 00:00:00 2001 From: Wouter Admiraal Date: Mon, 7 Dec 2020 12:00:02 +0100 Subject: [PATCH] SONAR-10070 Show badge on issues raised by deprecated/removed rules Co-authored-by: Siegfried Ehret Co-authored-by: Wouter Admiraal --- server/sonar-web/src/main/js/app/theme.js | 1 + .../src/main/js/components/issue/Issue.css | 4 + .../issue/components/IssueMessage.tsx | 29 +++++++- .../issue/components/IssueTitleBar.tsx | 2 + .../__tests__/IssueMessage-test.tsx | 5 ++ .../__snapshots__/IssueMessage-test.tsx.snap | 74 +++++++++++++++++++ server/sonar-web/src/main/js/types/rules.ts | 26 +++++++ server/sonar-web/src/main/js/types/types.d.ts | 1 + .../resources/org/sonar/l10n/core.properties | 3 + 9 files changed, 144 insertions(+), 1 deletion(-) create mode 100644 server/sonar-web/src/main/js/types/rules.ts diff --git a/server/sonar-web/src/main/js/app/theme.js b/server/sonar-web/src/main/js/app/theme.js index f888c8c5709..12fdd4422bc 100644 --- a/server/sonar-web/src/main/js/app/theme.js +++ b/server/sonar-web/src/main/js/app/theme.js @@ -107,6 +107,7 @@ module.exports = { // badge badgeBlueBackground: '#2E7CB5', badgeBlueColor: '#FFFFFF', + badgeRedBackgroundOnIssue: '#EEC8C8', // alm azure: '#0078d7', diff --git a/server/sonar-web/src/main/js/components/issue/Issue.css b/server/sonar-web/src/main/js/components/issue/Issue.css index 899ee3a0e42..c659effd5d6 100644 --- a/server/sonar-web/src/main/js/components/issue/Issue.css +++ b/server/sonar-web/src/main/js/components/issue/Issue.css @@ -240,3 +240,7 @@ max-height: 120px; overflow: auto; } + +.issue .badge-error { + background-color: var(--badgeRedBackgroundOnIssue); +} diff --git a/server/sonar-web/src/main/js/components/issue/components/IssueMessage.tsx b/server/sonar-web/src/main/js/components/issue/components/IssueMessage.tsx index 970748031e9..e0ccc98b4f8 100644 --- a/server/sonar-web/src/main/js/components/issue/components/IssueMessage.tsx +++ b/server/sonar-web/src/main/js/components/issue/components/IssueMessage.tsx @@ -21,6 +21,8 @@ import * as React from 'react'; import { ButtonLink } from 'sonar-ui-common/components/controls/buttons'; import Tooltip from 'sonar-ui-common/components/controls/Tooltip'; import { translate, translateWithParameters } from 'sonar-ui-common/helpers/l10n'; +import { RuleStatus } from '../../../types/rules'; +import DocumentationTooltip from '../../common/DocumentationTooltip'; import { WorkspaceContextShape } from '../../workspace/context'; export interface IssueMessageProps { @@ -31,10 +33,19 @@ export interface IssueMessageProps { onOpenRule: WorkspaceContextShape['openRule']; organization: string; ruleKey: string; + ruleStatus?: RuleStatus; } export default function IssueMessage(props: IssueMessageProps) { - const { engine, engineName, manualVulnerability, message, organization, ruleKey } = props; + const { + engine, + engineName, + manualVulnerability, + message, + organization, + ruleKey, + ruleStatus + } = props; const ruleEngine = engineName ? engineName : engine; return ( @@ -47,6 +58,22 @@ export default function IssueMessage(props: IssueMessageProps) { {translate('issue.why_this_issue')} + {ruleStatus && (ruleStatus === RuleStatus.Deprecated || ruleStatus === RuleStatus.Removed) && ( + + + {translate('rules.status', ruleStatus)} + + + )} + {ruleEngine && (
{ruleEngine}
diff --git a/server/sonar-web/src/main/js/components/issue/components/IssueTitleBar.tsx b/server/sonar-web/src/main/js/components/issue/components/IssueTitleBar.tsx index 1b9ec10f0a9..c19554396a6 100644 --- a/server/sonar-web/src/main/js/components/issue/components/IssueTitleBar.tsx +++ b/server/sonar-web/src/main/js/components/issue/components/IssueTitleBar.tsx @@ -26,6 +26,7 @@ import { formatMeasure } from 'sonar-ui-common/helpers/measures'; import { getBranchLikeQuery } from '../../../helpers/branch-like'; import { getComponentIssuesUrl } from '../../../helpers/urls'; import { BranchLike } from '../../../types/branch-like'; +import { RuleStatus } from '../../../types/rules'; import LocationIndex from '../../common/LocationIndex'; import { WorkspaceContext } from '../../workspace/context'; import IssueChangelog from './IssueChangelog'; @@ -85,6 +86,7 @@ export default function IssueTitleBar(props: IssueTitleBarProps) { onOpenRule={openRule} organization={issue.organization} ruleKey={issue.rule} + ruleStatus={issue.ruleStatus as RuleStatus | undefined} /> )} diff --git a/server/sonar-web/src/main/js/components/issue/components/__tests__/IssueMessage-test.tsx b/server/sonar-web/src/main/js/components/issue/components/__tests__/IssueMessage-test.tsx index 61793579040..a53ad25f7c0 100644 --- a/server/sonar-web/src/main/js/components/issue/components/__tests__/IssueMessage-test.tsx +++ b/server/sonar-web/src/main/js/components/issue/components/__tests__/IssueMessage-test.tsx @@ -22,6 +22,7 @@ import { shallow } from 'enzyme'; import * as React from 'react'; import { ButtonLink } from 'sonar-ui-common/components/controls/buttons'; import { click } from 'sonar-ui-common/helpers/testUtils'; +import { RuleStatus } from '../../../../types/rules'; import IssueMessage, { IssueMessageProps } from '../IssueMessage'; it('should render correctly', () => { @@ -29,6 +30,10 @@ it('should render correctly', () => { expect(shallowRender({ engine: 'js' })).toMatchSnapshot('with engine info'); expect(shallowRender({ engineName: 'JS' })).toMatchSnapshot('with engine name'); expect(shallowRender({ manualVulnerability: true })).toMatchSnapshot('is manual vulnerability'); + expect(shallowRender({ ruleStatus: RuleStatus.Deprecated })).toMatchSnapshot( + 'is deprecated rule' + ); + expect(shallowRender({ ruleStatus: RuleStatus.Removed })).toMatchSnapshot('is removed rule'); }); it('should handle click correctly', () => { diff --git a/server/sonar-web/src/main/js/components/issue/components/__tests__/__snapshots__/IssueMessage-test.tsx.snap b/server/sonar-web/src/main/js/components/issue/components/__tests__/__snapshots__/IssueMessage-test.tsx.snap index 1142d0b5bb8..05ac47ff7ea 100644 --- a/server/sonar-web/src/main/js/components/issue/components/__tests__/__snapshots__/IssueMessage-test.tsx.snap +++ b/server/sonar-web/src/main/js/components/issue/components/__tests__/__snapshots__/IssueMessage-test.tsx.snap @@ -19,6 +19,43 @@ exports[`should render correctly: default 1`] = ` `; +exports[`should render correctly: is deprecated rule 1`] = ` +
+ + Reduce the number of conditional operators (4) used in the expression + + + issue.why_this_issue + + + + rules.status.DEPRECATED + + +
+`; + exports[`should render correctly: is manual vulnerability 1`] = `
`; +exports[`should render correctly: is removed rule 1`] = ` +
+ + Reduce the number of conditional operators (4) used in the expression + + + issue.why_this_issue + + + + rules.status.REMOVED + + +
+`; + exports[`should render correctly: with engine info 1`] = `