From 5628e76b89bdf9cab65863db0109dfee7f8b7f8b Mon Sep 17 00:00:00 2001 From: Ambroise C Date: Thu, 7 Dec 2023 17:24:14 +0100 Subject: [PATCH] SONAR-20141 Reverse execution flow locations when there are data flows --- .../js/apps/issues/__tests__/IssueApp-it.tsx | 2 +- .../IssueLocationsNavigator.tsx | 4 +-- .../src/main/js/apps/issues/utils.ts | 25 ++++++++++++++++--- 3 files changed, 25 insertions(+), 6 deletions(-) diff --git a/server/sonar-web/src/main/js/apps/issues/__tests__/IssueApp-it.tsx b/server/sonar-web/src/main/js/apps/issues/__tests__/IssueApp-it.tsx index fdc438e8319..f6fb678e153 100644 --- a/server/sonar-web/src/main/js/apps/issues/__tests__/IssueApp-it.tsx +++ b/server/sonar-web/src/main/js/apps/issues/__tests__/IssueApp-it.tsx @@ -136,7 +136,7 @@ describe('issue app', () => { // Flow navigation await user.keyboard('{Alt>}{ArrowRight}{/Alt}'); - expect(screen.getByLabelText('Execution location 1')).toHaveAttribute('aria-current', 'true'); + expect(screen.getByLabelText('Execution location 3')).toHaveAttribute('aria-current', 'true'); await user.keyboard('{Alt>}{ArrowLeft}{/Alt}'); expect(screen.getByLabelText('Data location 1')).toHaveAttribute('aria-current', 'true'); }); diff --git a/server/sonar-web/src/main/js/apps/issues/issues-subnavigation/IssueLocationsNavigator.tsx b/server/sonar-web/src/main/js/apps/issues/issues-subnavigation/IssueLocationsNavigator.tsx index 4e9906ffcf7..1d1d78721d0 100644 --- a/server/sonar-web/src/main/js/apps/issues/issues-subnavigation/IssueLocationsNavigator.tsx +++ b/server/sonar-web/src/main/js/apps/issues/issues-subnavigation/IssueLocationsNavigator.tsx @@ -21,7 +21,7 @@ import { DiscreetLink, ExecutionFlowAccordion, SubnavigationFlowSeparator } from import React, { Fragment, useCallback, useRef } from 'react'; import { translate, translateWithParameters } from '../../../helpers/l10n'; import { Flow, FlowType, Issue } from '../../../types/types'; -import { getLocations } from '../utils'; +import { getLocations, getTypedFlows } from '../utils'; import IssueLocations from './IssueLocations'; import IssueLocationsNavigatorKeyboardHint from './IssueLocationsNavigatorKeyboardHint'; @@ -90,7 +90,7 @@ export default function IssueLocationsNavigator(props: Props) { const hasFlowsWithType = issue.flowsWithType.length > 0; const flows = hasFlowsWithType - ? issue.flowsWithType + ? getTypedFlows(issue.flowsWithType) : issue.flows.map((locations) => ({ type: FlowType.EXECUTION, locations })); if (flows.length > 0) { diff --git a/server/sonar-web/src/main/js/apps/issues/utils.ts b/server/sonar-web/src/main/js/apps/issues/utils.ts index 664a01d2515..7524ec16825 100644 --- a/server/sonar-web/src/main/js/apps/issues/utils.ts +++ b/server/sonar-web/src/main/js/apps/issues/utils.ts @@ -48,7 +48,7 @@ import { } from '../../types/issues'; import { MetricType } from '../../types/metrics'; import { SecurityStandard } from '../../types/security'; -import { Dict, Issue, Paging, RawQuery } from '../../types/types'; +import { Dict, Flow, FlowType, Issue, Paging, RawQuery } from '../../types/types'; import { RestUser } from '../../types/users'; const OWASP_ASVS_4_0 = 'owaspAsvs-4.0'; @@ -291,6 +291,14 @@ export const isMySet = () => { export const saveMyIssues = (myIssues: boolean) => save(ISSUES_DEFAULT, myIssues ? LOCALSTORAGE_MY : LOCALSTORAGE_ALL); +export function getTypedFlows(flows: Flow[]) { + return flows.map((flow) => ({ + ...flow, + locations: + flow.type === FlowType.EXECUTION ? [...(flow.locations ?? [])].reverse() : flow.locations, + })); +} + export function getLocations( { flows, @@ -301,9 +309,20 @@ export function getLocations( ) { if (secondaryLocations.length > 0) { return secondaryLocations; - } else if (selectedFlowIndex !== undefined) { - return flows[selectedFlowIndex] || flowsWithType[selectedFlowIndex]?.locations || []; } + + if (selectedFlowIndex !== undefined) { + if (flows[selectedFlowIndex] !== undefined) { + return flows[selectedFlowIndex]; + } + + if (flowsWithType[selectedFlowIndex] !== undefined) { + return getTypedFlows(flowsWithType)[selectedFlowIndex].locations || []; + } + + return []; + } + return []; } -- 2.39.5