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.

IssueMeasuresCardInner.tsx 3.2KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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 { LinkHighlight, LinkStandalone } from '@sonarsource/echoes-react';
  22. import classNames from 'classnames';
  23. import { Badge, NoDataIcon, themeColor } from 'design-system';
  24. import * as React from 'react';
  25. import { Path } from 'react-router-dom';
  26. import { translate, translateWithParameters } from '../../../helpers/l10n';
  27. import { localizeMetric } from '../../../helpers/measures';
  28. import { MetricKey } from '../../../types/metrics';
  29. interface IssueMeasuresCardInnerProps extends React.HTMLAttributes<HTMLDivElement> {
  30. metric: MetricKey;
  31. value?: string;
  32. header: React.ReactNode;
  33. url: Path;
  34. failed?: boolean;
  35. icon?: React.ReactNode;
  36. disabled?: boolean;
  37. footer?: React.ReactNode;
  38. }
  39. export function IssueMeasuresCardInner(props: Readonly<IssueMeasuresCardInnerProps>) {
  40. const { header, metric, icon, value, url, failed, footer, className, disabled, ...rest } = props;
  41. return (
  42. <div className={classNames('sw-flex sw-flex-col sw-gap-3', className)} {...rest}>
  43. <div
  44. className={classNames('sw-flex sw-flex-col sw-gap-2 sw-font-semibold', {
  45. 'sw-opacity-60': disabled,
  46. })}
  47. >
  48. <ColorBold className="sw-flex sw-items-center sw-gap-2 sw-body-sm-highlight">
  49. {header}
  50. {failed && (
  51. <Badge className="sw-h-fit" variant="deleted">
  52. {translate('overview.measures.failed_badge')}
  53. </Badge>
  54. )}
  55. </ColorBold>
  56. <div className="sw-flex sw-justify-between sw-items-center sw-h-9">
  57. <div className="sw-h-fit">
  58. <LinkStandalone
  59. highlight={LinkHighlight.Default}
  60. aria-label={
  61. value
  62. ? translateWithParameters(
  63. 'overview.see_more_details_on_x_of_y',
  64. value,
  65. localizeMetric(metric),
  66. )
  67. : translateWithParameters('no_measure_value_x', localizeMetric(metric))
  68. }
  69. className="it__overview-measures-value sw-w-fit sw-text-lg"
  70. to={url}
  71. >
  72. {value ?? '-'}
  73. </LinkStandalone>
  74. </div>
  75. {value ? icon : <NoDataIcon size="md" />}
  76. </div>
  77. </div>
  78. {footer}
  79. </div>
  80. );
  81. }
  82. const ColorBold = styled.div`
  83. color: ${themeColor('pageTitle')};
  84. `;