]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-16158 Fix duplication block displaying wrong block
authorMathieu Suen <mathieu.suen@sonarsource.com>
Tue, 29 Mar 2022 14:26:12 +0000 (16:26 +0200)
committersonartech <sonartech@sonarsource.com>
Wed, 30 Mar 2022 20:03:10 +0000 (20:03 +0000)
server/sonar-web/src/main/js/api/rules.ts
server/sonar-web/src/main/js/components/SourceViewer/components/Line.tsx
server/sonar-web/src/main/js/components/SourceViewer/components/__tests__/Line-test.tsx
server/sonar-web/src/main/js/components/SourceViewer/components/__tests__/__snapshots__/Line-test.tsx.snap

index 6a39950ed35051df406f50c0423154b617a03a35..0ab2ad21c44436cbc9ce090951b6163c8814beb6 100644 (file)
@@ -39,7 +39,7 @@ export function takeFacet(response: SearchRulesResponse, property: string) {
 export function getRuleRepositories(parameters: {
   q: string;
 }): Promise<Array<{ key: string; language: string; name: string }>> {
-  return getJSON('api/rules/repositories', parameters).then(
+  return getJSON('/api/rules/repositories', parameters).then(
     ({ repositories }) => repositories,
     throwGlobalError
   );
index 6a8cbac14eb433c8ae1e47d7ec3934232a064956..590160f141b1eb5bf485967fdd8cfb3c674d2004 100644 (file)
@@ -131,6 +131,7 @@ export default class Line extends React.PureComponent<Props> {
     });
 
     const bottomPadding = verticalBuffer ? verticalBuffer * LINE_HEIGHT : undefined;
+    const blocksLoaded = duplicationsCount > 0;
 
     // default is true
     const displayOptions = displayLineNumberOptions !== false;
@@ -153,8 +154,8 @@ export default class Line extends React.PureComponent<Props> {
 
         {displayDuplications && (
           <LineDuplicationBlock
-            blocksLoaded={duplicationsCount > 0}
-            duplicated={Boolean(line.duplicated)}
+            blocksLoaded={blocksLoaded}
+            duplicated={!blocksLoaded ? Boolean(line.duplicated) : duplications.includes(0)}
             index={0}
             key={0}
             line={this.props.line}
@@ -163,17 +164,19 @@ export default class Line extends React.PureComponent<Props> {
           />
         )}
 
-        {duplicationsCount > 1 &&
-          times(duplicationsCount - 1, index => (
-            <LineDuplicationBlock
-              blocksLoaded={true}
-              duplicated={duplications.includes(index + 1)}
-              index={index + 1}
-              key={index + 1}
-              line={this.props.line}
-              renderDuplicationPopup={this.props.renderDuplicationPopup}
-            />
-          ))}
+        {blocksLoaded &&
+          times(duplicationsCount - 1, index => {
+            return (
+              <LineDuplicationBlock
+                blocksLoaded={blocksLoaded}
+                duplicated={duplications.includes(index + 1)}
+                index={index + 1}
+                key={index + 1}
+                line={this.props.line}
+                renderDuplicationPopup={this.props.renderDuplicationPopup}
+              />
+            );
+          })}
 
         {displayCoverage && (
           <LineCoverage
index ab8dff7f3e8da373cbfb7bf5c33d54410be832b1..3576622165773fa1386abc35823717a6dded94f4 100644 (file)
@@ -96,7 +96,7 @@ function shallowRender(props: Partial<Line['props']> = {}) {
       displayDuplications={false}
       displayIssues={false}
       displayLocationMarkers={false}
-      duplications={[]}
+      duplications={[0]}
       duplicationsCount={0}
       firstLineNumber={1}
       highlighted={false}
index 784b30a9192026e09c77bd55c2953dc7b29794c3..13ea52d94d85c5c15252e84ffe4e462537f30edd 100644 (file)
@@ -478,7 +478,7 @@ exports[`should render correctly with duplication information 1`] = `
   />
   <Memo(LineDuplicationBlock)
     blocksLoaded={true}
-    duplicated={false}
+    duplicated={true}
     index={0}
     key="0"
     line={