3 * Copyright (C) 2009-2020 SonarSource SA
4 * mailto:info AT sonarsource DOT com
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 3 of the License, or (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public License
17 * along with this program; if not, write to the Free Software Foundation,
18 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20 import * as React from 'react';
21 import LocationIndex from '../../../components/common/LocationIndex';
22 import LocationMessage from '../../../components/common/LocationMessage';
26 isTaintAnalysis: boolean;
27 message: string | undefined;
28 onClick: (index: number) => void;
29 scroll: (element: Element) => void;
34 export default class ConciseIssueLocationsNavigatorLocation extends React.PureComponent<Props> {
35 node?: HTMLElement | null;
38 if (this.props.selected && this.node) {
39 this.props.scroll(this.node);
43 componentDidUpdate(prevProps: Props) {
44 if (this.props.selected && prevProps.selected !== this.props.selected && this.node) {
45 this.props.scroll(this.node);
49 handleClick = (event: React.MouseEvent<HTMLAnchorElement>) => {
50 event.preventDefault();
51 this.props.onClick(this.props.index);
54 prefixMessage(index: number, message = '', totalCount: number) {
57 return 'source: ' + message;
59 return 'sink: ' + message;
66 const { index, isTaintAnalysis, message, selected, totalCount } = this.props;
69 <div className="little-spacer-top" ref={node => (this.node = node)}>
71 className="concise-issue-locations-navigator-location"
73 onClick={this.handleClick}>
74 <LocationIndex selected={selected}>{index + 1}</LocationIndex>
75 <LocationMessage selected={selected}>
76 {isTaintAnalysis ? this.prefixMessage(index, message, totalCount) : message}