diff options
author | Stas Vilchik <stas.vilchik@sonarsource.com> | 2018-03-26 16:04:10 +0200 |
---|---|---|
committer | SonarTech <sonartech@sonarsource.com> | 2018-03-27 20:22:34 +0200 |
commit | 1f102401231189e014ba99e453e0daf0e440faea (patch) | |
tree | ed6c77221765fc18248ab23c4f44a454edda13e9 /server/sonar-web/src/main/js/apps | |
parent | 139b2c9b94d519b1787d5ac9c7ad71cf7397cf9d (diff) | |
download | sonarqube-1f102401231189e014ba99e453e0daf0e440faea.tar.gz sonarqube-1f102401231189e014ba99e453e0daf0e440faea.zip |
SONAR-10489 improve navigation between locations (#57)
Diffstat (limited to 'server/sonar-web/src/main/js/apps')
4 files changed, 22 insertions, 9 deletions
diff --git a/server/sonar-web/src/main/js/apps/issues/actions.ts b/server/sonar-web/src/main/js/apps/issues/actions.ts index f814bbf5b00..90a6897177f 100644 --- a/server/sonar-web/src/main/js/apps/issues/actions.ts +++ b/server/sonar-web/src/main/js/apps/issues/actions.ts @@ -18,17 +18,23 @@ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ import { State } from './components/App'; +import { allLocationsEmpty } from './utils'; export function enableLocationsNavigator(state: State): Partial<State> | undefined { const { openIssue, selectedLocationIndex } = state; if (openIssue && (openIssue.secondaryLocations.length > 0 || openIssue.flows.length > 0)) { - return { - locationsNavigator: true, - selectedFlowIndex: state.selectedFlowIndex || (openIssue.flows.length > 0 ? 0 : undefined), - // Also reset index = -1 to 0, we don't want to start on the issue when enabling the location navigator - selectedLocationIndex: - !selectedLocationIndex || selectedLocationIndex < 0 ? 0 : selectedLocationIndex - }; + const selectedFlowIndex = + state.selectedFlowIndex || (openIssue.flows.length > 0 ? 0 : undefined); + + if (!allLocationsEmpty(openIssue, selectedFlowIndex)) { + return { + locationsNavigator: true, + selectedFlowIndex, + // Also reset index = -1 to 0, we don't want to start on the issue when enabling the location navigator + selectedLocationIndex: + !selectedLocationIndex || selectedLocationIndex < 0 ? 0 : selectedLocationIndex + }; + } } return undefined; } diff --git a/server/sonar-web/src/main/js/apps/issues/conciseIssuesList/ConciseIssueLocationsNavigatorLocation.tsx b/server/sonar-web/src/main/js/apps/issues/conciseIssuesList/ConciseIssueLocationsNavigatorLocation.tsx index 1fe90aa029e..a9f0d9e0bc1 100644 --- a/server/sonar-web/src/main/js/apps/issues/conciseIssuesList/ConciseIssueLocationsNavigatorLocation.tsx +++ b/server/sonar-web/src/main/js/apps/issues/conciseIssuesList/ConciseIssueLocationsNavigatorLocation.tsx @@ -23,7 +23,7 @@ import LocationMessage from '../../../components/common/LocationMessage'; interface Props { index: number; - message: string; + message: string | undefined; onClick: (index: number) => void; scroll: (element: Element) => void; selected: boolean; diff --git a/server/sonar-web/src/main/js/apps/issues/conciseIssuesList/CrossFileLocationsNavigator.tsx b/server/sonar-web/src/main/js/apps/issues/conciseIssuesList/CrossFileLocationsNavigator.tsx index a2826a6b47b..295ffe694fa 100644 --- a/server/sonar-web/src/main/js/apps/issues/conciseIssuesList/CrossFileLocationsNavigator.tsx +++ b/server/sonar-web/src/main/js/apps/issues/conciseIssuesList/CrossFileLocationsNavigator.tsx @@ -108,7 +108,7 @@ export default class CrossFileLocationsNavigator extends React.PureComponent<Pro return groups; }; - renderLocation = (index: number, message: string) => { + renderLocation = (index: number, message: string | undefined) => { return ( <ConciseIssueLocationsNavigatorLocation index={index} 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 f148547d9e1..0423bc1ee64 100644 --- a/server/sonar-web/src/main/js/apps/issues/utils.ts +++ b/server/sonar-web/src/main/js/apps/issues/utils.ts @@ -256,3 +256,10 @@ export function getSelectedLocation( return undefined; } } + +export function allLocationsEmpty( + issue: Pick<Issue, 'flows' | 'secondaryLocations'>, + selectedFlowIndex: number | undefined +) { + return getLocations(issue, selectedFlowIndex).every(location => !location.msg); +} |