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.

SubnavigationIssue.tsx 3.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. /*
  2. * SonarQube
  3. * Copyright (C) 2009-2024 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 styled from '@emotion/styled';
  21. import {
  22. BareButton,
  23. IssueMessageHighlighting,
  24. SubnavigationItem,
  25. themeColor,
  26. themeContrast,
  27. } from 'design-system';
  28. import { noop } from 'lodash';
  29. import * as React from 'react';
  30. import { Issue } from '../../../types/types';
  31. import IssueItemLocationsQuantity from './IssueItemLocationsQuantity';
  32. import IssueLocationsNavigator from './IssueLocationsNavigator';
  33. export interface ConciseIssueProps {
  34. issue: Issue;
  35. onFlowSelect: (index?: number) => void;
  36. onLocationSelect: (index: number) => void;
  37. onClick: (issueKey: string) => void;
  38. selected: boolean;
  39. selectedFlowIndex: number | undefined;
  40. selectedLocationIndex: number | undefined;
  41. }
  42. export default function SubnavigationIssue(props: ConciseIssueProps) {
  43. const { issue, selected, selectedFlowIndex, selectedLocationIndex } = props;
  44. const element = React.useRef<HTMLLIElement>(null);
  45. React.useEffect(() => {
  46. if (selected) {
  47. element.current?.scrollIntoView({ block: 'nearest' });
  48. }
  49. }, [selected]);
  50. return (
  51. <li ref={element}>
  52. <SubnavigationItem
  53. active={selected}
  54. onClick={selected ? noop : props.onClick}
  55. value={issue.key}
  56. >
  57. <div className="sw-w-full">
  58. <StyledIssueTitle aria-current={selected} className="sw-mb-2">
  59. <IssueMessageHighlighting
  60. message={issue.message}
  61. messageFormattings={issue.messageFormattings}
  62. />
  63. </StyledIssueTitle>
  64. <IssueInfo className="sw-flex sw-justify-between sw-gap-2">
  65. <IssueItemLocationsQuantity issue={issue} />
  66. </IssueInfo>
  67. {selected && (
  68. <IssueLocationsNavigator
  69. issue={issue}
  70. onFlowSelect={props.onFlowSelect}
  71. onLocationSelect={props.onLocationSelect}
  72. selectedFlowIndex={selectedFlowIndex}
  73. selectedLocationIndex={selectedLocationIndex}
  74. />
  75. )}
  76. </div>
  77. </SubnavigationItem>
  78. </li>
  79. );
  80. }
  81. const IssueInfo = styled.div`
  82. color: ${themeContrast('pageContentLight')};
  83. .active &,
  84. :hover & {
  85. color: ${themeContrast('subnavigation')};
  86. }
  87. `;
  88. const StyledIssueTitle = styled(BareButton)`
  89. word-break: break-word;
  90. &:focus {
  91. background-color: ${themeColor('subnavigationSelected')};
  92. }
  93. `;