You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

GlobalSearchResult.tsx 2.5KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. /*
  2. * SonarQube
  3. * Copyright (C) 2009-2023 SonarSource SA
  4. * mailto:info AT sonarsource DOT com
  5. *
  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.
  10. *
  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.
  15. *
  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.
  19. */
  20. import classNames from 'classnames';
  21. import { ClockIcon, ItemLink, SearchText, TextMuted } from 'design-system';
  22. import * as React from 'react';
  23. import FavoriteIcon from '../../../components/icons/FavoriteIcon';
  24. import { translate } from '../../../helpers/l10n';
  25. import { getComponentOverviewUrl } from '../../../helpers/urls';
  26. import { ComponentResult } from './utils';
  27. interface Props {
  28. component: ComponentResult;
  29. innerRef: (componentKey: string, node: HTMLElement | null) => void;
  30. onClose: () => void;
  31. onSelect: (componentKey: string) => void;
  32. selected: boolean;
  33. }
  34. export default class GlobalSearchResult extends React.PureComponent<Props> {
  35. doSelect = () => {
  36. this.props.onSelect(this.props.component.key);
  37. };
  38. render() {
  39. const { component, selected } = this.props;
  40. const to = getComponentOverviewUrl(component.key, component.qualifier);
  41. return (
  42. <ItemLink
  43. className={classNames('sw-flex sw-flex-col sw-items-start sw-space-y-1', {
  44. active: selected,
  45. })}
  46. innerRef={(node: HTMLAnchorElement | null) => this.props.innerRef(component.key, node)}
  47. key={component.key}
  48. onClick={this.props.onClose}
  49. onPointerEnter={this.doSelect}
  50. to={to}
  51. >
  52. <div className="sw-flex sw-justify-between sw-items-center sw-w-full">
  53. <SearchText match={component.match} name={component.name} />
  54. {component.isFavorite && <FavoriteIcon favorite={true} size={16} />}
  55. {!component.isFavorite && component.isRecentlyBrowsed && (
  56. <ClockIcon aria-label={translate('recently_browsed')} />
  57. )}
  58. </div>
  59. <TextMuted text={component.key} />
  60. </ItemLink>
  61. );
  62. }
  63. }