From 11a18d8b58714a907ccda96d0d982729b7b1ce6c Mon Sep 17 00:00:00 2001 From: Wouter Admiraal Date: Tue, 22 Feb 2022 16:03:32 +0100 Subject: SONAR-11672 Improve display of project-level issues --- .../components/SourceViewer/SourceViewerCode.tsx | 1 + .../SourceViewer/SourceViewerHeaderSlim.tsx | 22 +++++--- .../__tests__/SourceViewerCode-test.tsx | 3 + .../__tests__/SourceViewerHeaderSlim-test.tsx | 4 ++ .../__snapshots__/SourceViewerCode-test.tsx.snap | 66 ++++++++++++++++++++++ .../SourceViewerHeaderSlim-test.tsx.snap | 41 ++++++++++++++ 6 files changed, 129 insertions(+), 8 deletions(-) (limited to 'server/sonar-web/src/main/js/components/SourceViewer') diff --git a/server/sonar-web/src/main/js/components/SourceViewer/SourceViewerCode.tsx b/server/sonar-web/src/main/js/components/SourceViewer/SourceViewerCode.tsx index d1b2d7588df..ebeb526fff6 100644 --- a/server/sonar-web/src/main/js/components/SourceViewer/SourceViewerCode.tsx +++ b/server/sonar-web/src/main/js/components/SourceViewer/SourceViewerCode.tsx @@ -161,6 +161,7 @@ export default class SourceViewerCode extends React.PureComponent { displayIssueLocationsLink={this.props.displayIssueLocationsLink} displayIssues={displayIssues} displayLocationMarkers={this.props.displayLocationMarkers} + displaySCM={sources.length > 0} duplications={this.getDuplicationsForLine(line)} duplicationsCount={duplicationsCount} firstLineNumber={firstLineNumber} diff --git a/server/sonar-web/src/main/js/components/SourceViewer/SourceViewerHeaderSlim.tsx b/server/sonar-web/src/main/js/components/SourceViewer/SourceViewerHeaderSlim.tsx index 8b2caf68bc0..6ae845568eb 100644 --- a/server/sonar-web/src/main/js/components/SourceViewer/SourceViewerHeaderSlim.tsx +++ b/server/sonar-web/src/main/js/components/SourceViewer/SourceViewerHeaderSlim.tsx @@ -62,6 +62,8 @@ export default function SourceViewerHeaderSlim(props: Props) { ); + const isProjectRoot = q === ComponentQualifier.Project; + return (
@@ -86,17 +88,21 @@ export default function SourceViewerHeaderSlim(props: Props) { )} -
- {collapsedDirFromPath(path)} - {fileFromPath(path)} -
+ {!isProjectRoot && ( + <> +
+ {collapsedDirFromPath(path)} + {fileFromPath(path)} +
-
- -
+
+ +
+ + )}
- {measures.issues !== undefined && ( + {!isProjectRoot && measures.issues !== undefined && (
{ expect(shallowRender({ hasSourcesAfter: true, hasSourcesBefore: true })).toMatchSnapshot( 'has more sources' ); + expect( + shallowRender({ sources: [], issues: [mockIssue(false, { textRange: undefined })] }) + ).toMatchSnapshot('only file issues'); }); it('should correctly flag a line for scrolling', () => { diff --git a/server/sonar-web/src/main/js/components/SourceViewer/__tests__/SourceViewerHeaderSlim-test.tsx b/server/sonar-web/src/main/js/components/SourceViewer/__tests__/SourceViewerHeaderSlim-test.tsx index 85286a05bb9..82232a309b3 100644 --- a/server/sonar-web/src/main/js/components/SourceViewer/__tests__/SourceViewerHeaderSlim-test.tsx +++ b/server/sonar-web/src/main/js/components/SourceViewer/__tests__/SourceViewerHeaderSlim-test.tsx @@ -21,12 +21,16 @@ import { shallow } from 'enzyme'; import * as React from 'react'; import { mockMainBranch } from '../../../helpers/mocks/branch-like'; import { mockSourceViewerFile } from '../../../helpers/testMocks'; +import { ComponentQualifier } from '../../../types/component'; import SourceViewerHeaderSlim, { Props } from '../SourceViewerHeaderSlim'; it('should render correctly', () => { expect(shallowRender()).toMatchSnapshot(); expect(shallowRender({ linkToProject: false })).toMatchSnapshot('no link to project'); expect(shallowRender({ displayProjectName: false })).toMatchSnapshot('no project name'); + expect( + shallowRender({ sourceViewerFile: mockSourceViewerFile({ q: ComponentQualifier.Project }) }) + ).toMatchSnapshot('project root'); }); it('should render correctly for subproject', () => { diff --git a/server/sonar-web/src/main/js/components/SourceViewer/__tests__/__snapshots__/SourceViewerCode-test.tsx.snap b/server/sonar-web/src/main/js/components/SourceViewer/__tests__/__snapshots__/SourceViewerCode-test.tsx.snap index 1784b9b6fa0..cc589e87fa0 100644 --- a/server/sonar-web/src/main/js/components/SourceViewer/__tests__/__snapshots__/SourceViewerCode-test.tsx.snap +++ b/server/sonar-web/src/main/js/components/SourceViewer/__tests__/__snapshots__/SourceViewerCode-test.tsx.snap @@ -20,6 +20,7 @@ exports[`should render correctly: default 1`] = ` displayCoverage={true} displayDuplications={false} displayIssues={true} + displaySCM={true} duplications={Array []} duplicationsCount={0} firstLineNumber={16} @@ -67,6 +68,7 @@ exports[`should render correctly: default 1`] = ` displayCoverage={true} displayDuplications={false} displayIssues={true} + displaySCM={true} duplications={Array []} duplicationsCount={0} firstLineNumber={16} @@ -127,6 +129,7 @@ exports[`should render correctly: default 1`] = ` displayCoverage={true} displayDuplications={false} displayIssues={true} + displaySCM={true} duplications={Array []} duplicationsCount={0} firstLineNumber={16} @@ -200,6 +203,7 @@ exports[`should render correctly: has file level issues 1`] = ` displayCoverage={true} displayDuplications={false} displayIssues={true} + displaySCM={true} duplications={Array []} duplicationsCount={0} firstLineNumber={16} @@ -242,6 +246,7 @@ exports[`should render correctly: has file level issues 1`] = ` displayCoverage={true} displayDuplications={false} displayIssues={true} + displaySCM={true} duplications={Array []} duplicationsCount={0} firstLineNumber={16} @@ -289,6 +294,7 @@ exports[`should render correctly: has file level issues 1`] = ` displayCoverage={true} displayDuplications={false} displayIssues={true} + displaySCM={true} duplications={Array []} duplicationsCount={0} firstLineNumber={16} @@ -349,6 +355,7 @@ exports[`should render correctly: has file level issues 1`] = ` displayCoverage={true} displayDuplications={false} displayIssues={true} + displaySCM={true} duplications={Array []} duplicationsCount={0} firstLineNumber={16} @@ -432,6 +439,7 @@ exports[`should render correctly: has more sources 1`] = ` displayCoverage={true} displayDuplications={false} displayIssues={true} + displaySCM={true} duplications={Array []} duplicationsCount={0} firstLineNumber={16} @@ -479,6 +487,7 @@ exports[`should render correctly: has more sources 1`] = ` displayCoverage={true} displayDuplications={false} displayIssues={true} + displaySCM={true} duplications={Array []} duplicationsCount={0} firstLineNumber={16} @@ -539,6 +548,7 @@ exports[`should render correctly: has more sources 1`] = ` displayCoverage={true} displayDuplications={false} displayIssues={true} + displaySCM={true} duplications={Array []} duplicationsCount={0} firstLineNumber={16} @@ -601,3 +611,59 @@ exports[`should render correctly: has more sources 1`] = `
`; + +exports[`should render correctly: only file issues 1`] = ` +
+ + + + +
+
+`; diff --git a/server/sonar-web/src/main/js/components/SourceViewer/__tests__/__snapshots__/SourceViewerHeaderSlim-test.tsx.snap b/server/sonar-web/src/main/js/components/SourceViewer/__tests__/__snapshots__/SourceViewerHeaderSlim-test.tsx.snap index dc4035a4fae..d25353697d6 100644 --- a/server/sonar-web/src/main/js/components/SourceViewer/__tests__/__snapshots__/SourceViewerHeaderSlim-test.tsx.snap +++ b/server/sonar-web/src/main/js/components/SourceViewer/__tests__/__snapshots__/SourceViewerHeaderSlim-test.tsx.snap @@ -327,3 +327,44 @@ exports[`should render correctly: no project name 1`] = ` `; + +exports[`should render correctly: project root 1`] = ` +
+
+
+ + + + + MyProject + + +
+
+ +
+ + + +
+
+
+`; -- cgit v1.2.3