]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-19197 Show code variants on issues
authorWouter Admiraal <wouter.admiraal@sonarsource.com>
Thu, 11 May 2023 09:52:17 +0000 (11:52 +0200)
committersonartech <sonartech@sonarsource.com>
Tue, 16 May 2023 20:02:50 +0000 (20:02 +0000)
server/sonar-web/src/main/js/components/issue/__tests__/Issue-it.tsx
server/sonar-web/src/main/js/components/issue/components/IssueActionsBar.tsx
server/sonar-web/src/main/js/helpers/testReactTestingUtils.tsx
sonar-core/src/main/resources/org/sonar/l10n/core.properties

index 0f6d97998983f075f918cbdb61af3d46ef4f0bb3..d613bc0718a2706003b1db6ba4941b4da635b0a2 100644 (file)
@@ -122,6 +122,13 @@ describe('rendering', () => {
     ).toBeInTheDocument();
     expect(ui.changelogRow('assign', 'luke.skywalker', 'darth.vader').get()).toBeInTheDocument();
   });
+
+  it('should correctly render any code variants', () => {
+    const { ui } = getPageObject();
+    renderIssue({ issue: mockIssue(false, { codeVariants: ['variant 1', 'variant 2'] }) });
+    expect(ui.variants(2).get()).toBeInTheDocument();
+    expect(findTooltipWithContent('variant 1, variant 2', undefined, 'div')).toBeInTheDocument();
+  });
 });
 
 describe('updating', () => {
@@ -337,6 +344,7 @@ function getPageObject() {
     whyLink: byRole('link', { name: 'issue.why_this_issue.long' }),
     checkbox: byRole('checkbox'),
     issueMessageBtn: byRole('button', { name: 'This is an issue' }),
+    variants: (n: number) => byText(`issue.x_code_variants.${n}`),
 
     // Changelog
     toggleChangelogBtn: byRole('button', {
index 1153e95b6c891b78e37769be4b5c8f0518fe6dda..3a8980252a64544e43a0d1f4b94fa4157955c143 100644 (file)
@@ -27,6 +27,7 @@ import {
   IssueType as IssueTypeEnum,
 } from '../../../types/issues';
 import { Issue, RawQuery } from '../../../types/types';
+import Tooltip from '../../controls/Tooltip';
 import { updateIssue } from '../actions';
 import IssueAssign from './IssueAssign';
 import IssueCommentAction from './IssueCommentAction';
@@ -162,7 +163,18 @@ export default class IssueActionsBar extends React.PureComponent<Props, State> {
             />
           )}
         </div>
-        <div className="list-inline">
+        <div className="display-flex-end list-inline">
+          {issue.codeVariants && issue.codeVariants.length > 0 && (
+            <div className="issue-meta">
+              <Tooltip overlay={issue.codeVariants.join(', ')}>
+                <span className="issue-meta-label">
+                  {issue.codeVariants.length > 1
+                    ? translateWithParameters('issue.x_code_variants', issue.codeVariants.length)
+                    : translate('issue.1_code_variant')}
+                </span>
+              </Tooltip>
+            </div>
+          )}
           <div className="issue-meta js-issue-tags">
             <IssueTags
               canSetTags={canSetTags}
index 53c99fe652ad8878d07c0d55b57e3e04e8462813..1d0ffcf5f5cc4dd2a0de030169d0df955b730747 100644 (file)
@@ -254,8 +254,12 @@ export function dateInputEvent(user: UserEvent) {
 }
 /* eslint-enable testing-library/no-node-access */
 
-export function findTooltipWithContent(text: Matcher, target?: HTMLElement) {
+export function findTooltipWithContent(
+  text: Matcher,
+  target?: HTMLElement,
+  selector = 'svg > desc'
+) {
   return target
-    ? within(target).getByText(text, { selector: 'svg > desc' })
-    : screen.getByText(text, { selector: 'svg > desc' });
+    ? within(target).getByText(text, { selector })
+    : screen.getByText(text, { selector });
 }
index ac422445838b2eda45338b8b8231ff4013c4cf13..26561038619a81122ea389d9f3c93041a068e5ab 100644 (file)
@@ -948,6 +948,8 @@ issue.unresolved.description=Unresolved issues have not been addressed in any wa
 issue.action.permalink=Get permalink
 issue.effort=Effort:
 issue.x_effort={0} effort
+issue.1_code_variant=1 variant
+issue.x_code_variants={0} variants
 issue.filter_similar_issues=Filter Similar Issues
 issue.this_issue_involves_x_code_locations=This issue involves {0} code location(s)
 issue.this_flow_involves_x_code_locations=This flow involves {0} code location(s)
@@ -996,6 +998,7 @@ issue.changelog.field.resolution=Resolution
 issue.changelog.field.effort=Effort
 issue.changelog.field.status=Status
 issue.changelog.field.tags=Tags
+issue.changelog.field.code_variants=Code Variants
 issue.changelog.field.type=Type
 issue.changelog.field.file=File