/*:: 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
};
}
};
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 };
}
};
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) {
/*:: 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();
}
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 = {