From cc891bbeb8c26a4f2e75c96919d26f90419e60bf Mon Sep 17 00:00:00 2001 From: Mathieu Suen Date: Tue, 29 Mar 2022 16:26:12 +0200 Subject: [PATCH] SONAR-16158 Fix duplication block displaying wrong block --- server/sonar-web/src/main/js/api/rules.ts | 2 +- .../SourceViewer/components/Line.tsx | 29 ++++++++++--------- .../components/__tests__/Line-test.tsx | 2 +- .../__snapshots__/Line-test.tsx.snap | 2 +- 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> { - 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 { }); 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 { {displayDuplications && ( 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 { /> )} - {duplicationsCount > 1 && - times(duplicationsCount - 1, index => ( - - ))} + {blocksLoaded && + times(duplicationsCount - 1, index => { + return ( + + ); + })} {displayCoverage && ( = {}) { 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`] = ` />