From 1cd0fe3fd30a7a2bdb801e8636330313da79fa46 Mon Sep 17 00:00:00 2001 From: Jeremy Davis Date: Thu, 1 Jul 2021 11:48:58 +0200 Subject: SONAR-15115 SONAR-15121 Fix missing hotspot code in App branches and remove permalink --- .../crossComponentSourceViewer/SnippetViewer.tsx | 4 +- .../components/HotspotSnippetContainerRenderer.tsx | 3 +- .../components/HotspotViewerRenderer.tsx | 4 +- .../__tests__/HotspotSnippetContainer-test.tsx | 5 +- .../HotspotReviewHistoryAndComments-test.tsx.snap | 84 +- .../HotspotSnippetContainer-test.tsx.snap | 50 +- .../HotspotSnippetContainerRenderer-test.tsx.snap | 51 +- .../HotspotViewerRenderer-test.tsx.snap | 1100 ++++---------------- .../__tests__/__snapshots__/Status-test.tsx.snap | 84 +- .../js/components/SourceViewer/components/Line.tsx | 7 +- .../SourceViewer/components/LineNumber.tsx | 37 +- .../components/__tests__/LineNumber-test.tsx | 7 +- .../__tests__/__snapshots__/Line-test.tsx.snap | 6 + .../__snapshots__/LineNumber-test.tsx.snap | 9 + .../src/main/js/helpers/mocks/security-hotspots.ts | 18 +- .../src/main/js/types/security-hotspots.ts | 16 +- 16 files changed, 346 insertions(+), 1139 deletions(-) (limited to 'server/sonar-web/src') diff --git a/server/sonar-web/src/main/js/apps/issues/crossComponentSourceViewer/SnippetViewer.tsx b/server/sonar-web/src/main/js/apps/issues/crossComponentSourceViewer/SnippetViewer.tsx index 4e0cbe6cb89..fb4a5147c62 100644 --- a/server/sonar-web/src/main/js/apps/issues/crossComponentSourceViewer/SnippetViewer.tsx +++ b/server/sonar-web/src/main/js/apps/issues/crossComponentSourceViewer/SnippetViewer.tsx @@ -37,6 +37,7 @@ import { inSnippet, LINES_BELOW_ISSUE } from './utils'; interface Props { branchLike: BranchLike | undefined; component: T.SourceViewerFile; + displayLineNumberOptions?: boolean; displaySCM?: boolean; duplications?: T.Duplication[]; duplicationsByLine?: { [line: number]: number[] }; @@ -130,7 +131,7 @@ export default class SnippetViewer extends React.PureComponent { }) { const secondaryIssueLocations = getSecondaryIssueLocationsForLine(line, this.props.locations); - const { duplications, duplicationsByLine } = this.props; + const { displayLineNumberOptions, duplications, duplicationsByLine } = this.props; const duplicationsCount = duplications ? duplications.length : 0; const lineDuplications = (duplicationsCount && duplicationsByLine && duplicationsByLine[line.line]) || []; @@ -146,6 +147,7 @@ export default class SnippetViewer extends React.PureComponent { displayCoverage={true} displayDuplications={displayDuplications} displayIssues={!isSinkLine || issuesForLine.length > 1} + displayLineNumberOptions={displayLineNumberOptions} displayLocationMarkers={true} displaySCM={displaySCM} duplications={lineDuplications} diff --git a/server/sonar-web/src/main/js/apps/security-hotspots/components/HotspotSnippetContainerRenderer.tsx b/server/sonar-web/src/main/js/apps/security-hotspots/components/HotspotSnippetContainerRenderer.tsx index ab47a648f7d..6934ac0d5a2 100644 --- a/server/sonar-web/src/main/js/apps/security-hotspots/components/HotspotSnippetContainerRenderer.tsx +++ b/server/sonar-web/src/main/js/apps/security-hotspots/components/HotspotSnippetContainerRenderer.tsx @@ -75,8 +75,9 @@ export default function HotspotSnippetContainerRenderer( props.onExpandBlock(direction)} handleCloseIssues={noop} diff --git a/server/sonar-web/src/main/js/apps/security-hotspots/components/HotspotViewerRenderer.tsx b/server/sonar-web/src/main/js/apps/security-hotspots/components/HotspotViewerRenderer.tsx index 20d6f086e62..0ab8dd44b48 100644 --- a/server/sonar-web/src/main/js/apps/security-hotspots/components/HotspotViewerRenderer.tsx +++ b/server/sonar-web/src/main/js/apps/security-hotspots/components/HotspotViewerRenderer.tsx @@ -27,7 +27,7 @@ import DeferredSpinner from 'sonar-ui-common/components/ui/DeferredSpinner'; import { translate } from 'sonar-ui-common/helpers/l10n'; import { getPathUrlAsString } from 'sonar-ui-common/helpers/urls'; import { withCurrentUser } from '../../../components/hoc/withCurrentUser'; -import { getBranchLikeQuery } from '../../../helpers/branch-like'; +import { fillBranchLike, getBranchLikeQuery } from '../../../helpers/branch-like'; import { getComponentSecurityHotspotsUrl, getRuleUrl } from '../../../helpers/urls'; import { isLoggedIn } from '../../../helpers/users'; import { BranchLike } from '../../../types/branch-like'; @@ -144,7 +144,7 @@ export function HotspotViewerRenderer(props: HotspotViewerRendererProps) { diff --git a/server/sonar-web/src/main/js/apps/security-hotspots/components/__tests__/HotspotSnippetContainer-test.tsx b/server/sonar-web/src/main/js/apps/security-hotspots/components/__tests__/HotspotSnippetContainer-test.tsx index 8b1e007b084..4e7698db772 100644 --- a/server/sonar-web/src/main/js/apps/security-hotspots/components/__tests__/HotspotSnippetContainer-test.tsx +++ b/server/sonar-web/src/main/js/apps/security-hotspots/components/__tests__/HotspotSnippetContainer-test.tsx @@ -23,8 +23,9 @@ import * as React from 'react'; import { waitAndUpdate } from 'sonar-ui-common/helpers/testUtils'; import { getSources } from '../../../../api/components'; import { mockBranch } from '../../../../helpers/mocks/branch-like'; -import { mockHotspot } from '../../../../helpers/mocks/security-hotspots'; +import { mockHotspot, mockHotspotComponent } from '../../../../helpers/mocks/security-hotspots'; import { mockComponent, mockSourceLine } from '../../../../helpers/testMocks'; +import { ComponentQualifier } from '../../../../types/component'; import HotspotSnippetContainer from '../HotspotSnippetContainer'; import HotspotSnippetContainerRenderer from '../HotspotSnippetContainerRenderer'; @@ -46,6 +47,7 @@ it('should load sources on mount', async () => { ); const hotspot = mockHotspot({ + project: mockHotspotComponent({ branch: branch.name, qualifier: ComponentQualifier.Project }), textRange: { startLine: 10, endLine: 11, startOffset: 0, endOffset: 12 } }); @@ -116,6 +118,7 @@ describe('Expansion', () => { }); const hotspot = mockHotspot({ + project: mockHotspotComponent({ branch: branch.name, qualifier: ComponentQualifier.Project }), textRange: { startLine: 10, endLine: 11, startOffset: 0, endOffset: 12 } }); diff --git a/server/sonar-web/src/main/js/apps/security-hotspots/components/__tests__/__snapshots__/HotspotReviewHistoryAndComments-test.tsx.snap b/server/sonar-web/src/main/js/apps/security-hotspots/components/__tests__/__snapshots__/HotspotReviewHistoryAndComments-test.tsx.snap index 8758b8bff1c..e576a075c66 100644 --- a/server/sonar-web/src/main/js/apps/security-hotspots/components/__tests__/__snapshots__/HotspotReviewHistoryAndComments-test.tsx.snap +++ b/server/sonar-web/src/main/js/apps/security-hotspots/components/__tests__/__snapshots__/HotspotReviewHistoryAndComments-test.tsx.snap @@ -29,48 +29,22 @@ exports[`should render correctly 1`] = ` "changelog": Array [], "comment": Array [], "component": Object { - "breadcrumbs": Array [], - "key": "my-project", - "name": "MyProject", + "key": "hotspot-component", + "longName": "Hotspot component long name", + "name": "Hotspot Component", + "path": "path/to/component", "qualifier": "FIL", - "qualityGate": Object { - "isDefault": true, - "key": "30", - "name": "Sonar way", - }, - "qualityProfiles": Array [ - Object { - "deleted": false, - "key": "my-qp", - "language": "ts", - "name": "Sonar way", - }, - ], - "tags": Array [], }, "creationDate": "2013-05-13T17:55:41+0200", "key": "01fc972e-2a3c-433e-bcae-0bd7f88f5123", "line": 142, "message": "'3' is a magic number.", "project": Object { - "breadcrumbs": Array [], - "key": "my-project", - "name": "MyProject", + "key": "hotspot-component", + "longName": "Hotspot component long name", + "name": "Hotspot Component", + "path": "path/to/component", "qualifier": "TRK", - "qualityGate": Object { - "isDefault": true, - "key": "30", - "name": "Sonar way", - }, - "qualityProfiles": Array [ - Object { - "deleted": false, - "key": "my-qp", - "language": "ts", - "name": "Sonar way", - }, - ], - "tags": Array [], }, "resolution": "FIXED", "rule": Object { @@ -192,48 +166,22 @@ exports[`should render correctly without user 1`] = ` "changelog": Array [], "comment": Array [], "component": Object { - "breadcrumbs": Array [], - "key": "my-project", - "name": "MyProject", + "key": "hotspot-component", + "longName": "Hotspot component long name", + "name": "Hotspot Component", + "path": "path/to/component", "qualifier": "FIL", - "qualityGate": Object { - "isDefault": true, - "key": "30", - "name": "Sonar way", - }, - "qualityProfiles": Array [ - Object { - "deleted": false, - "key": "my-qp", - "language": "ts", - "name": "Sonar way", - }, - ], - "tags": Array [], }, "creationDate": "2013-05-13T17:55:41+0200", "key": "01fc972e-2a3c-433e-bcae-0bd7f88f5123", "line": 142, "message": "'3' is a magic number.", "project": Object { - "breadcrumbs": Array [], - "key": "my-project", - "name": "MyProject", + "key": "hotspot-component", + "longName": "Hotspot component long name", + "name": "Hotspot Component", + "path": "path/to/component", "qualifier": "TRK", - "qualityGate": Object { - "isDefault": true, - "key": "30", - "name": "Sonar way", - }, - "qualityProfiles": Array [ - Object { - "deleted": false, - "key": "my-qp", - "language": "ts", - "name": "Sonar way", - }, - ], - "tags": Array [], }, "resolution": "FIXED", "rule": Object { diff --git a/server/sonar-web/src/main/js/apps/security-hotspots/components/__tests__/__snapshots__/HotspotSnippetContainer-test.tsx.snap b/server/sonar-web/src/main/js/apps/security-hotspots/components/__tests__/__snapshots__/HotspotSnippetContainer-test.tsx.snap index c049d85dad7..2dcb778d83e 100644 --- a/server/sonar-web/src/main/js/apps/security-hotspots/components/__tests__/__snapshots__/HotspotSnippetContainer-test.tsx.snap +++ b/server/sonar-web/src/main/js/apps/security-hotspots/components/__tests__/__snapshots__/HotspotSnippetContainer-test.tsx.snap @@ -32,48 +32,22 @@ exports[`should render correctly 1`] = ` "changelog": Array [], "comment": Array [], "component": Object { - "breadcrumbs": Array [], - "key": "my-project", - "name": "MyProject", + "key": "hotspot-component", + "longName": "Hotspot component long name", + "name": "Hotspot Component", + "path": "path/to/component", "qualifier": "FIL", - "qualityGate": Object { - "isDefault": true, - "key": "30", - "name": "Sonar way", - }, - "qualityProfiles": Array [ - Object { - "deleted": false, - "key": "my-qp", - "language": "ts", - "name": "Sonar way", - }, - ], - "tags": Array [], }, "creationDate": "2013-05-13T17:55:41+0200", "key": "01fc972e-2a3c-433e-bcae-0bd7f88f5123", "line": 142, "message": "'3' is a magic number.", "project": Object { - "breadcrumbs": Array [], - "key": "my-project", - "name": "MyProject", + "key": "hotspot-component", + "longName": "Hotspot component long name", + "name": "Hotspot Component", + "path": "path/to/component", "qualifier": "TRK", - "qualityGate": Object { - "isDefault": true, - "key": "30", - "name": "Sonar way", - }, - "qualityProfiles": Array [ - Object { - "deleted": false, - "key": "my-qp", - "language": "ts", - "name": "Sonar way", - }, - ], - "tags": Array [], }, "resolution": "FIXED", "rule": Object { @@ -126,13 +100,13 @@ exports[`should render correctly 1`] = ` sourceLines={Array []} sourceViewerFile={ Object { - "key": "my-project", + "key": "hotspot-component", "measures": Object { "lines": undefined, }, - "path": "", - "project": "my-project", - "projectName": "MyProject", + "path": "path/to/component", + "project": "hotspot-component", + "projectName": "Hotspot Component", "q": "FIL", "uuid": "", } diff --git a/server/sonar-web/src/main/js/apps/security-hotspots/components/__tests__/__snapshots__/HotspotSnippetContainerRenderer-test.tsx.snap b/server/sonar-web/src/main/js/apps/security-hotspots/components/__tests__/__snapshots__/HotspotSnippetContainerRenderer-test.tsx.snap index 6ddb9d1ee5f..2807a804133 100644 --- a/server/sonar-web/src/main/js/apps/security-hotspots/components/__tests__/__snapshots__/HotspotSnippetContainerRenderer-test.tsx.snap +++ b/server/sonar-web/src/main/js/apps/security-hotspots/components/__tests__/__snapshots__/HotspotSnippetContainerRenderer-test.tsx.snap @@ -116,14 +116,6 @@ exports[`should render correctly: with sourcelines 1`] = ` } > { displayDuplications, displayIssueLocationsCount, displayIssueLocationsLink, + displayLineNumberOptions, displayLocationMarkers, highlightedLocationMessage, displayIssues, @@ -127,9 +129,12 @@ export default class Line extends React.PureComponent { const bottomPadding = verticalBuffer ? verticalBuffer * LINE_HEIGHT : undefined; + // default is true + const displayOptions = displayLineNumberOptions !== false; + return ( - + {displaySCM && } {displayIssues && !displayAllIssues ? ( diff --git a/server/sonar-web/src/main/js/components/SourceViewer/components/LineNumber.tsx b/server/sonar-web/src/main/js/components/SourceViewer/components/LineNumber.tsx index 21df17a4fa2..48e63fe419d 100644 --- a/server/sonar-web/src/main/js/components/SourceViewer/components/LineNumber.tsx +++ b/server/sonar-web/src/main/js/components/SourceViewer/components/LineNumber.tsx @@ -23,32 +23,37 @@ import { translateWithParameters } from 'sonar-ui-common/helpers/l10n'; import LineOptionsPopup from './LineOptionsPopup'; export interface LineNumberProps { + displayOptions: boolean; firstLineNumber: number; line: T.SourceLine; } -export function LineNumber({ firstLineNumber, line }: LineNumberProps) { +export function LineNumber({ displayOptions, firstLineNumber, line }: LineNumberProps) { const [isOpen, setOpen] = React.useState(false); const { line: lineNumber } = line; const hasLineNumber = !!lineNumber; return hasLineNumber ? ( - setOpen(false)} - open={isOpen} - overlay={}> - setOpen(true)} - role="button" - tabIndex={0}> - {lineNumber} - - + {displayOptions ? ( + setOpen(false)} + open={isOpen} + overlay={}> + setOpen(true)} + role="button" + tabIndex={0}> + {lineNumber} + + + ) : ( + lineNumber + )} ) : ( diff --git a/server/sonar-web/src/main/js/components/SourceViewer/components/__tests__/LineNumber-test.tsx b/server/sonar-web/src/main/js/components/SourceViewer/components/__tests__/LineNumber-test.tsx index f536dd12bcb..849f09a059a 100644 --- a/server/sonar-web/src/main/js/components/SourceViewer/components/__tests__/LineNumber-test.tsx +++ b/server/sonar-web/src/main/js/components/SourceViewer/components/__tests__/LineNumber-test.tsx @@ -25,8 +25,13 @@ it('should render correctly', () => { expect(shallowRender()).toMatchSnapshot('default'); expect(shallowRender({ line: { line: 0 } })).toMatchSnapshot('no line number'); expect(shallowRender({ line: { line: 12 } })).toMatchSnapshot('first line'); + expect(shallowRender({ displayOptions: false, line: { line: 12 } })).toMatchSnapshot( + 'no options' + ); }); function shallowRender(props: Partial = {}) { - return shallow(); + return shallow( + + ); } 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 853ff92974d..784b30a9192 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 @@ -6,6 +6,7 @@ exports[`should render correctly 1`] = ` data-line-number={16} > `; + +exports[`should render correctly: no options 1`] = ` + + 12 + +`; diff --git a/server/sonar-web/src/main/js/helpers/mocks/security-hotspots.ts b/server/sonar-web/src/main/js/helpers/mocks/security-hotspots.ts index 90ce5c0c031..74a2b80a647 100644 --- a/server/sonar-web/src/main/js/helpers/mocks/security-hotspots.ts +++ b/server/sonar-web/src/main/js/helpers/mocks/security-hotspots.ts @@ -21,6 +21,7 @@ import { ComponentQualifier } from '../../types/component'; import { Standards } from '../../types/security'; import { Hotspot, + HotspotComponent, HotspotResolution, HotspotRule, HotspotStatus, @@ -29,7 +30,7 @@ import { ReviewHistoryType, RiskExposure } from '../../types/security-hotspots'; -import { mockComponent, mockUser } from '../testMocks'; +import { mockUser } from '../testMocks'; export function mockRawHotspot(overrides: Partial = {}): RawHotspot { return { @@ -61,12 +62,12 @@ export function mockHotspot(overrides?: Partial): Hotspot { canChangeStatus: true, changelog: [], comment: [], - component: mockComponent({ qualifier: ComponentQualifier.File }), + component: mockHotspotComponent({ qualifier: ComponentQualifier.File }), creationDate: '2013-05-13T17:55:41+0200', key: '01fc972e-2a3c-433e-bcae-0bd7f88f5123', line: 142, message: "'3' is a magic number.", - project: mockComponent({ qualifier: ComponentQualifier.Project }), + project: mockHotspotComponent({ qualifier: ComponentQualifier.Project }), resolution: HotspotResolution.FIXED, rule: mockHotspotRule(), status: HotspotStatus.REVIEWED, @@ -82,6 +83,17 @@ export function mockHotspot(overrides?: Partial): Hotspot { }; } +export function mockHotspotComponent(overrides?: Partial): HotspotComponent { + return { + key: 'hotspot-component', + name: 'Hotspot Component', + longName: 'Hotspot component long name', + qualifier: ComponentQualifier.File, + path: 'path/to/component', + ...overrides + }; +} + export function mockHotspotRule(overrides?: Partial): HotspotRule { return { key: 'squid:S2077', diff --git a/server/sonar-web/src/main/js/types/security-hotspots.ts b/server/sonar-web/src/main/js/types/security-hotspots.ts index ba043f8f344..557f92ac3ec 100644 --- a/server/sonar-web/src/main/js/types/security-hotspots.ts +++ b/server/sonar-web/src/main/js/types/security-hotspots.ts @@ -17,6 +17,8 @@ * along with this program; if not, write to the Free Software Foundation, * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ +import { ComponentQualifier } from './component'; + export enum RiskExposure { LOW = 'LOW', MEDIUM = 'MEDIUM', @@ -77,12 +79,12 @@ export interface Hotspot { canChangeStatus: boolean; changelog: T.IssueChangelog[]; comment: HotspotComment[]; - component: T.Component; + component: HotspotComponent; creationDate: string; key: string; line?: number; message: string; - project: T.Component; + project: HotspotComponent; resolution?: HotspotResolution; rule: HotspotRule; status: HotspotStatus; @@ -91,6 +93,16 @@ export interface Hotspot { users: T.UserBase[]; } +export interface HotspotComponent { + key: string; + qualifier: ComponentQualifier; + name: string; + longName: string; + path: string; + branch?: string; + pullRequest?: string; +} + export interface HotspotUpdateFields { status: HotspotStatus; resolution?: HotspotResolution; -- cgit v1.2.3