export interface FlowLocation {
component: string;
componentName?: string;
- msg: string;
+ msg?: string;
textRange: TextRange;
}
* 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;
}
interface Props {
index: number;
- message: string;
+ message: string | undefined;
onClick: (index: number) => void;
scroll: (element: Element) => void;
selected: boolean;
return groups;
};
- renderLocation = (index: number, message: string) => {
+ renderLocation = (index: number, message: string | undefined) => {
return (
<ConciseIssueLocationsNavigatorLocation
index={index}
return undefined;
}
}
+
+export function allLocationsEmpty(
+ issue: Pick<Issue, 'flows' | 'secondaryLocations'>,
+ selectedFlowIndex: number | undefined
+) {
+ return getLocations(issue, selectedFlowIndex).every(location => !location.msg);
+}
// `undefined` elements mean they are located in a different file,
// but kept to maintaint the location indexes
highlightedLocations?: (FlowLocation | undefined)[];
- highlightedLocationMessage?: { index: number; text: string };
+ highlightedLocationMessage?: { index: number; text: string | undefined };
loadComponent?: (
component: string,
branchLike: BranchLike | undefined
hasSourcesAfter: boolean;
hasSourcesBefore: boolean;
highlightedLine: number | undefined;
- highlightedLocationMessage: { index: number; text: string } | undefined;
+ highlightedLocationMessage: { index: number; text: string | undefined } | undefined;
// `undefined` elements mean they are located in a different file,
// but kept to maintain the location indexes
highlightedLocations: (FlowLocation | undefined)[] | undefined;
duplicationsCount: number;
filtered: boolean | undefined;
highlighted: boolean;
- highlightedLocationMessage: { index: number; text: string } | undefined;
+ highlightedLocationMessage: { index: number; text: string | undefined } | undefined;
highlightedSymbols: string[] | undefined;
issueLocations: LinearIssueLocation[];
issuePopup: { issue: string; name: string } | undefined;
displayIssueLocationsCount?: boolean;
displayIssueLocationsLink?: boolean;
displayLocationMarkers?: boolean;
- highlightedLocationMessage: { index: number; text: string } | undefined;
+ highlightedLocationMessage: { index: number; text: string | undefined } | undefined;
highlightedSymbols: string[] | undefined;
issueLocations: LinearIssueLocation[];
issuePopup: { issue: string; name: string } | undefined;
}
};
- renderMarker(index: number, message: string | undefined, leading = false) {
+ renderMarker(index: number, message: string | undefined, selected: boolean, leading: boolean) {
const { onLocationSelect } = this.props;
const onClick = onLocationSelect ? () => onLocationSelect(index) : undefined;
- const ref =
- message != null ? (node: HTMLElement | null) => (this.activeMarkerNode = node) : undefined;
+ const ref = selected ? (node: HTMLElement | null) => (this.activeMarkerNode = node) : undefined;
return (
<LocationIndex
key={`marker-${index}`}
leading={leading}
onClick={onClick}
- selected={message != null}>
+ selected={selected}>
<span ref={ref}>{index + 1}</span>
- {message != null && <LocationMessage selected={true}>{message}</LocationMessage>}
+ {message && <LocationMessage selected={true}>{message}</LocationMessage>}
</LocationIndex>
);
}
tokens.forEach((token, index) => {
if (this.props.displayLocationMarkers && token.markers.length > 0) {
token.markers.forEach(marker => {
- const message =
- highlightedLocationMessage != null && highlightedLocationMessage.index === marker
- ? highlightedLocationMessage.text
- : undefined;
- renderedTokens.push(this.renderMarker(marker, message, leadingMarker));
+ const selected =
+ highlightedLocationMessage !== undefined && highlightedLocationMessage.index === marker;
+ const message = selected ? highlightedLocationMessage!.text : undefined;
+ renderedTokens.push(this.renderMarker(marker, message, selected, leadingMarker));
});
}
renderedTokens.push(