diff options
author | Wouter Admiraal <wouter.admiraal@sonarsource.com> | 2022-02-22 16:03:32 +0100 |
---|---|---|
committer | sonartech <sonartech@sonarsource.com> | 2022-02-24 20:02:52 +0000 |
commit | 11a18d8b58714a907ccda96d0d982729b7b1ce6c (patch) | |
tree | f7888bb2537be5dffee0de85c82ae4d78ae3c35f /server/sonar-web/src/main/js/components/SourceViewer | |
parent | 5fb0f5edafa247fafe76f50f24226528d6774638 (diff) | |
download | sonarqube-11a18d8b58714a907ccda96d0d982729b7b1ce6c.tar.gz sonarqube-11a18d8b58714a907ccda96d0d982729b7b1ce6c.zip |
SONAR-11672 Improve display of project-level issues
Diffstat (limited to 'server/sonar-web/src/main/js/components/SourceViewer')
6 files changed, 129 insertions, 8 deletions
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<Props> { 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 ( <div className="source-viewer-header-slim display-flex-row display-flex-space-between"> <div className="display-flex-center flex-1"> @@ -86,17 +88,21 @@ export default function SourceViewerHeaderSlim(props: Props) { </> )} - <div className="spacer-right"> - <QualifierIcon qualifier={q} /> <span>{collapsedDirFromPath(path)}</span> - <span className="component-name-file">{fileFromPath(path)}</span> - </div> + {!isProjectRoot && ( + <> + <div className="spacer-right"> + <QualifierIcon qualifier={q} /> <span>{collapsedDirFromPath(path)}</span> + <span className="component-name-file">{fileFromPath(path)}</span> + </div> - <div className="spacer-right"> - <ClipboardIconButton className="button-link link-no-underline" copyValue={path} /> - </div> + <div className="spacer-right"> + <ClipboardIconButton className="button-link link-no-underline" copyValue={path} /> + </div> + </> + )} </div> - {measures.issues !== undefined && ( + {!isProjectRoot && measures.issues !== undefined && ( <div className={classNames('flex-0 big-spacer-left', { 'little-spacer-right': !expandable || loading diff --git a/server/sonar-web/src/main/js/components/SourceViewer/__tests__/SourceViewerCode-test.tsx b/server/sonar-web/src/main/js/components/SourceViewer/__tests__/SourceViewerCode-test.tsx index a07d5f276e0..605f29a1930 100644 --- a/server/sonar-web/src/main/js/components/SourceViewer/__tests__/SourceViewerCode-test.tsx +++ b/server/sonar-web/src/main/js/components/SourceViewer/__tests__/SourceViewerCode-test.tsx @@ -33,6 +33,9 @@ it('should render correctly', () => { 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`] = ` </div> </div> `; + +exports[`should render correctly: only file issues 1`] = ` +<div + className="source-viewer-code" +> + <table + className="source-table" + > + <tbody> + <Line + branchLike={ + Object { + "analysisDate": "2018-01-01", + "excludedFromPurge": true, + "isMain": false, + "name": "branch-6.7", + } + } + displayCoverage={false} + displayDuplications={false} + displayIssues={true} + displaySCM={false} + duplications={Array []} + duplicationsCount={0} + firstLineNumber={0} + highlighted={false} + issueLocations={Array []} + issues={Array []} + key="0" + last={true} + line={ + Object { + "code": "", + "duplicated": false, + "isNew": false, + "line": 0, + } + } + loadDuplications={[MockFunction]} + onIssueChange={[MockFunction]} + onIssuePopupToggle={[MockFunction]} + onIssueSelect={[MockFunction]} + onIssueUnselect={[MockFunction]} + onIssuesClose={[MockFunction]} + onIssuesOpen={[MockFunction]} + onLocationSelect={[MockFunction]} + onSymbolClick={[MockFunction]} + openIssues={false} + renderDuplicationPopup={[MockFunction]} + scrollToUncoveredLine={false} + secondaryIssueLocations={Array []} + /> + </tbody> + </table> +</div> +`; 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`] = ` </DeferredSpinner> </div> `; + +exports[`should render correctly: project root 1`] = ` +<div + className="source-viewer-header-slim display-flex-row display-flex-space-between" +> + <div + className="display-flex-center flex-1" + > + <div + className="spacer-right" + > + <a + className="link-with-icon" + href="/dashboard?id=my-project" + > + <QualifierIcon + qualifier="TRK" + /> + + <span> + MyProject + </span> + </a> + </div> + </div> + <DeferredSpinner + className="little-spacer-right" + > + <div + className="flex-0 big-spacer-left" + > + <ButtonIcon + className="js-actions" + onClick={[MockFunction]} + > + <ExpandSnippetIcon /> + </ButtonIcon> + </div> + </DeferredSpinner> +</div> +`; |