Browse Source

SONAR-9787 Allow to navigate back to the issue from the last issue locations

tags/6.6-RC1
Grégoire Aubert 6 years ago
parent
commit
1863f1cddf

+ 19
- 4
server/sonar-web/src/main/js/apps/issues/actions.js View File

@@ -21,12 +21,14 @@
/*:: import type { State } from './components/App'; */

export const enableLocationsNavigator = (state /*: State */) => {
const { openIssue } = state;
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 : null),
selectedLocationIndex: state.selectedLocationIndex || 0
// 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
};
}
};
@@ -57,15 +59,28 @@ export const selectNextLocation = (state /*: State */) => {
if (openIssue) {
const locations =
selectedFlowIndex != null ? openIssue.flows[selectedFlowIndex] : openIssue.secondaryLocations;
const lastLocationIdx = locations.length - 1;
if (index === lastLocationIdx) {
// -1 to jump back to the issue itself
return { selectedLocationIndex: -1 };
}
return {
selectedLocationIndex: index != null && locations.length > index + 1 ? index + 1 : index
selectedLocationIndex: index != null && index < lastLocationIdx ? index + 1 : index
};
}
};

export const selectPreviousLocation = (state /*: State */) => {
const { selectedLocationIndex: index, openIssue } = state;
const { selectedFlowIndex, selectedLocationIndex: index, openIssue } = state;
if (openIssue) {
if (index === -1) {
const locations =
selectedFlowIndex != null
? openIssue.flows[selectedFlowIndex]
: openIssue.secondaryLocations;
const lastLocationIdx = locations.length - 1;
return { selectedLocationIndex: lastLocationIdx };
}
return { selectedLocationIndex: index != null && index > 0 ? index - 1 : index };
}
};

+ 2
- 2
server/sonar-web/src/main/js/apps/issues/components/App.js View File

@@ -236,11 +236,11 @@ export default class App extends React.PureComponent {
event.preventDefault();
this.setState(actions.enableLocationsNavigator);
} else if (event.keyCode === 40 && event.altKey) {
// alt + up
// alt + down
event.preventDefault();
this.selectNextLocation();
} else if (event.keyCode === 38 && event.altKey) {
// alt + down
// alt + up
event.preventDefault();
this.selectPreviousLocation();
} else if (event.keyCode === 37 && event.altKey) {

+ 10
- 2
server/sonar-web/src/main/js/apps/issues/components/IssuesSourceViewer.js View File

@@ -43,9 +43,14 @@ export default class IssuesSourceViewer extends React.PureComponent {
/*:: props: Props; */

componentDidUpdate(prevProps /*: Props */) {
const { openIssue, selectedLocationIndex } = this.props;

// Scroll back to the issue when the selected location is set to -1
const shouldScrollBackToIssue =
selectedLocationIndex === -1 && selectedLocationIndex !== prevProps.selectedLocationIndex;
if (
prevProps.openIssue !== this.props.openIssue &&
prevProps.openIssue.component === this.props.openIssue.component
prevProps.openIssue.component === openIssue.component &&
(prevProps.openIssue !== openIssue || shouldScrollBackToIssue)
) {
this.scrollToIssue();
}
@@ -77,9 +82,12 @@ export default class IssuesSourceViewer extends React.PureComponent {

let locationMessage = undefined;
let locationLine = undefined;

// We don't want to display a location message when selected location is -1
if (
locations != null &&
selectedLocationIndex != null &&
selectedLocationIndex >= 0 &&
locations.length >= selectedLocationIndex
) {
locationMessage = {

Loading…
Cancel
Save