From b9849bbf55bc69d25ca35ebf343bfa2f20b99319 Mon Sep 17 00:00:00 2001 From: Revanshu Paliwal Date: Thu, 11 Aug 2022 10:55:31 +0200 Subject: [PATCH] SONAR-16538 Common component for issue message tags --- .../main/js/api/mocks/IssuesServiceMock.ts | 29 ++++++ .../js/apps/issues/__tests__/IssueApp-it.tsx | 15 +++ .../js/apps/issues/components/IssueHeader.tsx | 57 ++---------- .../issue/components/IssueMessage.tsx | 57 ++---------- .../issue/components/IssueMessageTags.tsx | 91 +++++++++++++++++++ .../__snapshots__/IssueMessage-test.tsx.snap | 84 +++-------------- server/sonar-web/src/main/js/types/issues.ts | 2 + 7 files changed, 167 insertions(+), 168 deletions(-) create mode 100644 server/sonar-web/src/main/js/components/issue/components/IssueMessageTags.tsx diff --git a/server/sonar-web/src/main/js/api/mocks/IssuesServiceMock.ts b/server/sonar-web/src/main/js/api/mocks/IssuesServiceMock.ts index d0e9abd2661..ac260fff216 100644 --- a/server/sonar-web/src/main/js/api/mocks/IssuesServiceMock.ts +++ b/server/sonar-web/src/main/js/api/mocks/IssuesServiceMock.ts @@ -214,6 +214,35 @@ export default class IssuesServiceMock { ], 'component.key' ) + }, + { + issue: mockRawIssue(false, { + actions: ['set_type', 'set_tags', 'comment', 'set_severity', 'assign'], + transitions: ['confirm', 'resolve', 'falsepositive', 'wontfix'], + key: 'issue4', + component: 'project:file.bar', + message: 'Issue with tags', + rule: 'external_eslint_repo:no-div-regex', + textRange: { + startLine: 25, + endLine: 25, + startOffset: 0, + endOffset: 1 + }, + ruleDescriptionContextKey: 'spring', + ruleStatus: 'DEPRECATED', + quickFixAvailable: true + }), + snippets: keyBy( + [ + mockSnippetsByComponent( + 'file.bar', + 'project', + times(40, i => i + 20) + ) + ], + 'component.key' + ) } ]; (searchIssues as jest.Mock).mockImplementation(this.handleSearchIssues); diff --git a/server/sonar-web/src/main/js/apps/issues/__tests__/IssueApp-it.tsx b/server/sonar-web/src/main/js/apps/issues/__tests__/IssueApp-it.tsx index 2746ea8e931..0d3a43a18b8 100644 --- a/server/sonar-web/src/main/js/apps/issues/__tests__/IssueApp-it.tsx +++ b/server/sonar-web/src/main/js/apps/issues/__tests__/IssueApp-it.tsx @@ -446,6 +446,21 @@ it('should show code tabs when any secondary location is selected', async () => ).toBeInTheDocument(); }); +it('should show issue tags if applicable', async () => { + const user = userEvent.setup(); + handler.setIsAdmin(true); + renderIssueApp(); + + // Select an issue with an advanced rule + await user.click(await screen.findByRole('region', { name: 'Issue with tags' })); + + expect( + screen.getByRole('heading', { + name: 'Issue with tags sonar-lint-icon issue.resolution.badge.DEPRECATED' + }) + ).toBeInTheDocument(); +}); + describe('redirects', () => { it('should work for hotspots', () => { renderProjectIssuesApp(`project/issues?types=${IssueType.SecurityHotspot}`); diff --git a/server/sonar-web/src/main/js/apps/issues/components/IssueHeader.tsx b/server/sonar-web/src/main/js/apps/issues/components/IssueHeader.tsx index 61eda47277e..630c044e89f 100644 --- a/server/sonar-web/src/main/js/apps/issues/components/IssueHeader.tsx +++ b/server/sonar-web/src/main/js/apps/issues/components/IssueHeader.tsx @@ -18,20 +18,17 @@ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ import * as React from 'react'; -import { FormattedMessage } from 'react-intl'; import { Link } from 'react-router-dom'; import { setIssueAssignee } from '../../../api/issues'; -import DocumentationTooltip from '../../../components/common/DocumentationTooltip'; -import Tooltip from '../../../components/controls/Tooltip'; import LinkIcon from '../../../components/icons/LinkIcon'; -import SonarLintIcon from '../../../components/icons/SonarLintIcon'; import { updateIssue } from '../../../components/issue/actions'; import IssueActionsBar from '../../../components/issue/components/IssueActionsBar'; import IssueChangelog from '../../../components/issue/components/IssueChangelog'; +import IssueMessageTags from '../../../components/issue/components/IssueMessageTags'; import { getBranchLikeQuery } from '../../../helpers/branch-like'; import { isInput, isShortcut } from '../../../helpers/keyboardEventHelpers'; import { KeyboardKeys } from '../../../helpers/keycodes'; -import { translate, translateWithParameters } from '../../../helpers/l10n'; +import { translate } from '../../../helpers/l10n'; import { getComponentIssuesUrl, getRuleUrl } from '../../../helpers/urls'; import { BranchLike } from '../../../types/branch-like'; import { RuleStatus } from '../../../types/rules'; @@ -132,56 +129,18 @@ export default class IssueHeader extends React.PureComponent { types: issue.type === 'SECURITY_HOTSPOT' ? issue.type : undefined }); const ruleStatus = issue.ruleStatus as RuleStatus | undefined; - const ruleEngine = issue.externalRuleEngine; const { quickFixAvailable } = issue; return ( <>

- {issue.message} - {quickFixAvailable && ( - - SonarLint - - ) - }} - /> - } - mouseLeaveDelay={0.5}> - - - )} - {(ruleStatus === RuleStatus.Deprecated || ruleStatus === RuleStatus.Removed) && ( - - - {translate('issue.resolution.badge', ruleStatus)} - - - )} - {ruleEngine && ( - -
{ruleEngine}
-
- )} + {issue.message} +

{message} - {quickFixAvailable && ( - - SonarLint - - ) - }} - /> - } - mouseLeaveDelay={0.5}> - - - )} - {ruleStatus && (ruleStatus === RuleStatus.Deprecated || ruleStatus === RuleStatus.Removed) && ( - - - {translate('issue.resolution.badge', ruleStatus)} - - - )} - {ruleEngine && ( - -
{ruleEngine}
-
- )} +
{displayWhyIsThisAnIssue && ( + {quickFixAvailable && ( + + SonarLint + + ) + }} + /> + } + mouseLeaveDelay={0.5}> + + + )} + {ruleStatus && (ruleStatus === RuleStatus.Deprecated || ruleStatus === RuleStatus.Removed) && ( + + + {translate('issue.resolution.badge', ruleStatus)} + + + )} + {ruleEngine && ( + +
{ruleEngine}
+
+ )} + + ); +} 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 eb1c297404f..3a8e73822e2 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 @@ -10,6 +10,7 @@ exports[`should render correctly: default 1`] = ` > Reduce the number of conditional operators (4) used in the expression +
Reduce the number of conditional operators (4) used in the expression +
`; @@ -45,24 +47,9 @@ exports[`should render correctly: is deprecated rule 1`] = ` > Reduce the number of conditional operators (4) used in the expression - - - issue.resolution.badge.DEPRECATED - - + Reduce the number of conditional operators (4) used in the expression - - - issue.resolution.badge.REMOVED - - + Reduce the number of conditional operators (4) used in the expression - -
- js -
-
+ Reduce the number of conditional operators (4) used in the expression - - SonarLint - , - } - } - /> - } - > - - +