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.

SeverityIcon.tsx 4.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. /*
  2. * SonarQube
  3. * Copyright (C) 2009-2019 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 * as React from 'react';
  21. import Icon, { IconProps } from './Icon';
  22. import * as theme from '../../app/theme';
  23. interface Props {
  24. className?: string;
  25. severity: string | null | undefined;
  26. }
  27. const severityIcons: T.Dict<(props: IconProps) => React.ReactElement<any>> = {
  28. blocker: BlockerSeverityIcon,
  29. critical: CriticalSeverityIcon,
  30. major: MajorSeverityIcon,
  31. minor: MinorSeverityIcon,
  32. info: InfoSeverityIcon
  33. };
  34. export default function SeverityIcon(props: Props) {
  35. if (!props.severity) {
  36. return null;
  37. }
  38. const severity = props.severity.toLowerCase();
  39. const Icon = severityIcons[severity];
  40. return Icon ? <Icon className={props.className} /> : null;
  41. }
  42. function BlockerSeverityIcon({ className, size }: IconProps) {
  43. return (
  44. <Icon className={className} size={size}>
  45. <path
  46. d="M8 14c-3.311 0-6-2.689-6-6s2.689-6 6-6 6 2.689 6 6-2.689 6-6 6zM7 9h2V4H7v5zm0 3h2v-2H7v2z"
  47. style={{ fill: theme.red, fillRule: 'nonzero' }}
  48. />
  49. </Icon>
  50. );
  51. }
  52. function CriticalSeverityIcon({ className, size }: IconProps) {
  53. return (
  54. <Icon className={className} size={size}>
  55. <path
  56. d="M8 2c3.311 0 6 2.689 6 6s-2.689 6-6 6-6-2.689-6-6 2.689-6 6-6zm1 10V7.414l1.893 1.893c.13.124.282.216.457.261a1.006 1.006 0 0 0 1.176-.591 1.01 1.01 0 0 0 .01-.729 1.052 1.052 0 0 0-.229-.355c-1.212-1.212-2.394-2.456-3.638-3.636a1.073 1.073 0 0 0-.169-.123 1.05 1.05 0 0 0-.448-.133h-.104a1.053 1.053 0 0 0-.493.16 1.212 1.212 0 0 0-.162.132C6.08 5.505 4.836 6.687 3.656 7.932a.994.994 0 0 0-.051 1.275c.208.271.548.42.888.389.198-.019.378-.098.535-.218.041-.035.04-.034.079-.071L7 7.414V12h2z"
  57. style={{ fill: theme.red, fillRule: 'nonzero' }}
  58. />
  59. </Icon>
  60. );
  61. }
  62. function MajorSeverityIcon({ className, size }: IconProps) {
  63. return (
  64. <Icon className={className} size={size}>
  65. <path
  66. d="M8 2c3.311 0 6 2.689 6 6s-2.689 6-6 6-6-2.689-6-6 2.689-6 6-6zm.08 2.903c.071.008.14.019.208.039.138.042.26.114.37.205 1.244 1.146 2.426 2.357 3.639 3.536.1.103.181.218.234.352a1.01 1.01 0 0 1 .001.728 1.002 1.002 0 0 1-1.169.609 1.042 1.042 0 0 1-.46-.255L8 7.295l-2.903 2.822c-.039.036-.039.036-.08.07a1.002 1.002 0 0 1-1.604-.947c.032-.196.122-.37.253-.519C4.847 7.51 6.09 6.362 7.303 5.183c.052-.048.106-.093.167-.131a1.041 1.041 0 0 1 .61-.149z"
  67. style={{ fill: theme.red }}
  68. />
  69. </Icon>
  70. );
  71. }
  72. function MinorSeverityIcon({ className, size }: IconProps) {
  73. return (
  74. <Icon className={className} size={size}>
  75. <path
  76. d="M8 2c3.311 0 6 2.689 6 6s-2.689 6-6 6-6-2.689-6-6 2.689-6 6-6zm1 6.586V4H7v4.586L5.107 6.693a1.178 1.178 0 0 0-.165-.134 1.041 1.041 0 0 0-.662-.152 1 1 0 0 0-.587 1.7c1.212 1.212 2.394 2.456 3.638 3.636.094.08.195.146.311.191a1.008 1.008 0 0 0 1.065-.227c1.213-1.212 2.457-2.394 3.637-3.639a.994.994 0 0 0 .051-1.275 1.012 1.012 0 0 0-.888-.389 1.041 1.041 0 0 0-.535.218c-.04.034-.04.034-.079.071L9 8.586z"
  77. style={{ fill: theme.lightGreen }}
  78. />
  79. </Icon>
  80. );
  81. }
  82. function InfoSeverityIcon({ className, size }: IconProps) {
  83. return (
  84. <Icon className={className} size={size}>
  85. <path
  86. d="M8 2c3.311 0 6 2.689 6 6s-2.689 6-6 6-6-2.689-6-6 2.689-6 6-6zm1 5H7v5h2V7zm0-3H7v2h2V4z"
  87. style={{ fill: theme.blue }}
  88. />
  89. </Icon>
  90. );
  91. }