aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMathieu Suen <mathieu.suen@sonarsource.com>2022-03-29 16:26:12 +0200
committersonartech <sonartech@sonarsource.com>2022-03-30 20:03:10 +0000
commitcc891bbeb8c26a4f2e75c96919d26f90419e60bf (patch)
treea3de0f8df355a5c1cb1855896825bfcc922171fb
parent7b234b4d750332c7e14feded399482264827fd81 (diff)
downloadsonarqube-cc891bbeb8c26a4f2e75c96919d26f90419e60bf.tar.gz
sonarqube-cc891bbeb8c26a4f2e75c96919d26f90419e60bf.zip
SONAR-16158 Fix duplication block displaying wrong block
-rw-r--r--server/sonar-web/src/main/js/api/rules.ts2
-rw-r--r--server/sonar-web/src/main/js/components/SourceViewer/components/Line.tsx29
-rw-r--r--server/sonar-web/src/main/js/components/SourceViewer/components/__tests__/Line-test.tsx2
-rw-r--r--server/sonar-web/src/main/js/components/SourceViewer/components/__tests__/__snapshots__/Line-test.tsx.snap2
4 files changed, 19 insertions, 16 deletions
diff --git a/server/sonar-web/src/main/js/api/rules.ts b/server/sonar-web/src/main/js/api/rules.ts
index 6a39950ed35..0ab2ad21c44 100644
--- a/server/sonar-web/src/main/js/api/rules.ts
+++ b/server/sonar-web/src/main/js/api/rules.ts
@@ -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
);
diff --git a/server/sonar-web/src/main/js/components/SourceViewer/components/Line.tsx b/server/sonar-web/src/main/js/components/SourceViewer/components/Line.tsx
index 6a8cbac14eb..590160f141b 100644
--- a/server/sonar-web/src/main/js/components/SourceViewer/components/Line.tsx
+++ b/server/sonar-web/src/main/js/components/SourceViewer/components/Line.tsx
@@ -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
diff --git a/server/sonar-web/src/main/js/components/SourceViewer/components/__tests__/Line-test.tsx b/server/sonar-web/src/main/js/components/SourceViewer/components/__tests__/Line-test.tsx
index ab8dff7f3e8..35766221657 100644
--- a/server/sonar-web/src/main/js/components/SourceViewer/components/__tests__/Line-test.tsx
+++ b/server/sonar-web/src/main/js/components/SourceViewer/components/__tests__/Line-test.tsx
@@ -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}
diff --git a/server/sonar-web/src/main/js/components/SourceViewer/components/__tests__/__snapshots__/Line-test.tsx.snap b/server/sonar-web/src/main/js/components/SourceViewer/components/__tests__/__snapshots__/Line-test.tsx.snap
index 784b30a9192..13ea52d94d8 100644
--- a/server/sonar-web/src/main/js/components/SourceViewer/components/__tests__/__snapshots__/Line-test.tsx.snap
+++ b/server/sonar-web/src/main/js/components/SourceViewer/components/__tests__/__snapshots__/Line-test.tsx.snap
@@ -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={