From 7c8113fcecf6e123c9cff834ecf50df20a30825d Mon Sep 17 00:00:00 2001 From: Stas Vilchik Date: Mon, 22 Oct 2018 09:24:10 +0200 Subject: [PATCH] SONAR-11368 Disable links in duplications popup for branches and prs (#856) --- .../SourceViewer/components/CoveragePopup.tsx | 34 ++++++++--- .../components/DuplicationPopup.tsx | 61 ++++++++++++------- .../SourceViewer/components/LineCoverage.tsx | 18 +++--- .../components/LineDuplicationBlock.tsx | 24 ++++---- .../__snapshots__/LineCoverage-test.tsx.snap | 6 +- .../LineDuplicationBlock-test.tsx.snap | 6 +- .../js/components/SourceViewer/styles.css | 9 +++ 7 files changed, 99 insertions(+), 59 deletions(-) diff --git a/server/sonar-web/src/main/js/components/SourceViewer/components/CoveragePopup.tsx b/server/sonar-web/src/main/js/components/SourceViewer/components/CoveragePopup.tsx index 9c35f78e269..cff05965304 100644 --- a/server/sonar-web/src/main/js/components/SourceViewer/components/CoveragePopup.tsx +++ b/server/sonar-web/src/main/js/components/SourceViewer/components/CoveragePopup.tsx @@ -26,7 +26,12 @@ import { DropdownOverlay } from '../../controls/Dropdown'; import TestStatusIcon from '../../icons-components/TestStatusIcon'; import { PopupPlacement } from '../../ui/popups'; import { WorkspaceContext } from '../../workspace/context'; -import { isSameBranchLike, getBranchLikeQuery } from '../../../helpers/branches'; +import { + isSameBranchLike, + getBranchLikeQuery, + isShortLivingBranch, + isPullRequest +} from '../../../helpers/branches'; import { translate } from '../../../helpers/l10n'; import { collapsePath } from '../../../helpers/path'; @@ -71,6 +76,11 @@ export default class CoveragePopup extends React.PureComponent { this.mounted = false; } + shouldLink() { + const { branchLike } = this.props; + return !isShortLivingBranch(branchLike) && !isPullRequest(branchLike); + } + fetchTests = () => { this.setState({ loading: true }); getTests({ @@ -95,12 +105,22 @@ export default class CoveragePopup extends React.PureComponent { event.preventDefault(); event.currentTarget.blur(); const { key } = event.currentTarget.dataset; - if (key) { + if (this.shouldLink() && key) { this.context.workspace.openComponent({ branchLike: this.props.branchLike, key }); } this.props.onClose(); }; + renderFile(file: { key: string; longName: string }) { + return this.shouldLink() ? ( + + {collapsePath(file.longName)} + + ) : ( + {collapsePath(file.longName)} + ); + } + render() { const { line } = this.props; const testCasesByFile = groupBy(this.state.testCases || [], 'fileKey'); @@ -115,7 +135,7 @@ export default class CoveragePopup extends React.PureComponent { return ( -
+
{translate('source_viewer.covered')} {!!line.conditions && ( @@ -136,13 +156,7 @@ export default class CoveragePopup extends React.PureComponent { translate('source_viewer.tooltip.no_information_about_tests')} {testFiles.map(testFile => (
- - {collapsePath(testFile.file.longName)} - + {this.renderFile(testFile.file)}
    {testFile.tests.map(testCase => (
  • { workspace: PropTypes.object.isRequired }; + shouldLink() { + const { branchLike } = this.props; + return !isShortLivingBranch(branchLike) && !isPullRequest(branchLike); + } + isDifferentComponent = ( a: { project: string; subProject?: string }, b: { project: string; subProject?: string } @@ -59,7 +65,7 @@ export default class DuplicationPopup extends React.PureComponent { event.preventDefault(); event.currentTarget.blur(); const { key, line } = event.currentTarget.dataset; - if (key) { + if (this.shouldLink() && key) { this.context.workspace.openComponent({ branchLike: this.props.branchLike, key, @@ -69,6 +75,21 @@ export default class DuplicationPopup extends React.PureComponent { this.props.onClose(); }; + renderDuplication(file: DuplicatedFile, children: React.ReactNode, line?: number) { + return this.shouldLink() ? ( + + {children} + + ) : ( + children + ); + } + render() { const { duplicatedFiles = {}, sourceViewerFile } = this.props; @@ -129,17 +150,15 @@ export default class DuplicationPopup extends React.PureComponent { {duplication.file.key !== this.props.sourceViewerFile.key && (
    - - {collapsedDirFromPath(duplication.file.name)} - - {fileFromPath(duplication.file.name)} - - + {this.renderDuplication( + duplication.file, + <> + {collapsedDirFromPath(duplication.file.name)} + + {fileFromPath(duplication.file.name)} + + + )}
    )} @@ -147,15 +166,15 @@ export default class DuplicationPopup extends React.PureComponent { {'Lines: '} {duplication.blocks.map((block, index) => ( - - {block.from} - {' – '} - {block.from + block.size - 1} - + {this.renderDuplication( + duplication.file, + <> + {block.from} + {' – '} + {block.from + block.size - 1} + , + block.from + )} {index < duplication.blocks.length - 1 && ', '} ))} diff --git a/server/sonar-web/src/main/js/components/SourceViewer/components/LineCoverage.tsx b/server/sonar-web/src/main/js/components/SourceViewer/components/LineCoverage.tsx index be4c2d1a842..2be765bb904 100644 --- a/server/sonar-web/src/main/js/components/SourceViewer/components/LineCoverage.tsx +++ b/server/sonar-web/src/main/js/components/SourceViewer/components/LineCoverage.tsx @@ -58,25 +58,25 @@ export default class LineCoverage extends React.PureComponent { const hasPopup = line.coverageStatus === 'covered' || line.coverageStatus === 'partially-covered'; + const bar = hasPopup ? ( +
    + ) : ( +
    + ); + const cell = line.coverageStatus ? ( -
    + {bar} ) : ( -
    + bar ); if (hasPopup) { return ( - + { 'source-line-duplicated': duplicated }); - const cell =
    ; - return duplicated ? ( - + - - {cell} + +
    ) : ( - {cell} +
    ); } diff --git a/server/sonar-web/src/main/js/components/SourceViewer/components/__tests__/__snapshots__/LineCoverage-test.tsx.snap b/server/sonar-web/src/main/js/components/SourceViewer/components/__tests__/__snapshots__/LineCoverage-test.tsx.snap index fc47e783cac..fe461767489 100644 --- a/server/sonar-web/src/main/js/components/SourceViewer/components/__tests__/__snapshots__/LineCoverage-test.tsx.snap +++ b/server/sonar-web/src/main/js/components/SourceViewer/components/__tests__/__snapshots__/LineCoverage-test.tsx.snap @@ -4,9 +4,6 @@ exports[`render covered line 1`] = `
    diff --git a/server/sonar-web/src/main/js/components/SourceViewer/components/__tests__/__snapshots__/LineDuplicationBlock-test.tsx.snap b/server/sonar-web/src/main/js/components/SourceViewer/components/__tests__/__snapshots__/LineDuplicationBlock-test.tsx.snap index 7147eca868e..86a35b7a083 100644 --- a/server/sonar-web/src/main/js/components/SourceViewer/components/__tests__/__snapshots__/LineDuplicationBlock-test.tsx.snap +++ b/server/sonar-web/src/main/js/components/SourceViewer/components/__tests__/__snapshots__/LineDuplicationBlock-test.tsx.snap @@ -5,9 +5,6 @@ exports[`render duplicated line 1`] = ` className="source-meta source-line-duplications-extra source-line-duplicated" data-index={1} data-line-number={3} - onClick={[Function]} - role="button" - tabIndex={0} >
    diff --git a/server/sonar-web/src/main/js/components/SourceViewer/styles.css b/server/sonar-web/src/main/js/components/SourceViewer/styles.css index c95c5a71925..2d1a80c67b1 100644 --- a/server/sonar-web/src/main/js/components/SourceViewer/styles.css +++ b/server/sonar-web/src/main/js/components/SourceViewer/styles.css @@ -227,6 +227,14 @@ height: 18px; } +.source-line-bar[role='button'] { + cursor: pointer; +} + +.source-line-bar:focus { + outline: none; +} + .source-line-covered { background-color: var(--green) !important; } @@ -512,6 +520,7 @@ font-family: var(--baseFontFamily); font-size: var(--baseFontSize); text-align: left; + user-select: text; } .issue-location { -- 2.39.5