/* * SonarQube * Copyright (C) 2009-2020 SonarSource SA * mailto:info AT sonarsource DOT com * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 3 of the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public License * along with this program; if not, write to the Free Software Foundation, * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ import * as React from 'react'; import { Link } from 'react-router'; import Tooltip from 'sonar-ui-common/components/controls/Tooltip'; import ClockIcon from 'sonar-ui-common/components/icons/ClockIcon'; import FavoriteIcon from 'sonar-ui-common/components/icons/FavoriteIcon'; import QualifierIcon from 'sonar-ui-common/components/icons/QualifierIcon'; import { getCodeUrl, getProjectUrl } from '../../../helpers/urls'; import { ComponentResult } from './utils'; interface Props { appState: Pick; component: ComponentResult; innerRef: (componentKey: string, node: HTMLElement | null) => void; onClose: () => void; onSelect: (componentKey: string) => void; organizations: T.Dict<{ name: string }>; projects: T.Dict<{ name: string }>; selected: boolean; } interface State { tooltipVisible: boolean; } const TOOLTIP_DELAY = 1000; export default class SearchResult extends React.PureComponent { interval?: number; state: State = { tooltipVisible: false }; componentDidMount() { if (this.props.selected) { this.scheduleTooltip(); } } componentWillReceiveProps(nextProps: Props) { if (!this.props.selected && nextProps.selected) { this.scheduleTooltip(); } else if (this.props.selected && !nextProps.selected) { this.unscheduleTooltip(); this.setState({ tooltipVisible: false }); } } componentWillUnmount() { this.unscheduleTooltip(); } scheduleTooltip = () => { this.interval = window.setTimeout(() => { this.setState({ tooltipVisible: true }); }, TOOLTIP_DELAY); }; unscheduleTooltip = () => { if (this.interval) { window.clearInterval(this.interval); } }; handleMouseEnter = () => { this.props.onSelect(this.props.component.key); }; renderOrganization = (component: ComponentResult) => { if (!this.props.appState.organizationsEnabled) { return null; } if (!['VW', 'SVW', 'APP', 'TRK'].includes(component.qualifier) || !component.organization) { return null; } const organization = this.props.organizations[component.organization]; return organization ? (
{organization.name}
) : null; }; renderProject = (component: ComponentResult) => { if (!['BRC', 'FIL', 'UTS'].includes(component.qualifier) || component.project == null) { return null; } const project = this.props.projects[component.project]; return project ? (
{project.name}
) : null; }; render() { const { component } = this.props; const isFile = component.qualifier === 'FIL' || component.qualifier === 'UTS'; const to = isFile ? getCodeUrl(component.project!, undefined, component.key) : getProjectUrl(component.key); return (
  • this.props.innerRef(component.key, node)}> {component.isFavorite && } {!component.isFavorite && component.isRecentlyBrowsed && } {component.match ? ( ) : ( {component.name} )} {this.renderOrganization(component)} {this.renderProject(component)}
  • ); } }