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.

IssueMessage.tsx 4.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. /*
  2. * SonarQube
  3. * Copyright (C) 2009-2021 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 { FormattedMessage } from 'react-intl';
  22. import { ButtonLink } from '../../../components/controls/buttons';
  23. import Tooltip from '../../../components/controls/Tooltip';
  24. import { translate, translateWithParameters } from '../../../helpers/l10n';
  25. import { RuleStatus } from '../../../types/rules';
  26. import DocumentationTooltip from '../../common/DocumentationTooltip';
  27. import SonarLintIcon from '../../icons/SonarLintIcon';
  28. import { WorkspaceContextShape } from '../../workspace/context';
  29. export interface IssueMessageProps {
  30. engine?: string;
  31. engineName?: string;
  32. quickFixAvailable?: boolean;
  33. manualVulnerability: boolean;
  34. message: string;
  35. onOpenRule: WorkspaceContextShape['openRule'];
  36. ruleKey: string;
  37. ruleStatus?: RuleStatus;
  38. }
  39. export default function IssueMessage(props: IssueMessageProps) {
  40. const {
  41. engine,
  42. engineName,
  43. quickFixAvailable,
  44. manualVulnerability,
  45. message,
  46. ruleKey,
  47. ruleStatus
  48. } = props;
  49. const ruleEngine = engineName ? engineName : engine;
  50. return (
  51. <div className="display-inline-flex-center issue-message break-word">
  52. <span className="spacer-right">{message}</span>
  53. {quickFixAvailable && (
  54. <Tooltip
  55. overlay={
  56. <FormattedMessage
  57. id="issue.quick_fix_available_with_sonarlint"
  58. defaultMessage={translate('issue.quick_fix_available_with_sonarlint')}
  59. values={{
  60. link: (
  61. <a
  62. href="https://www.sonarqube.org/sonarlint/?referrer=sonarqube-quick-fix"
  63. rel="noopener noreferrer"
  64. target="_blank">
  65. SonarLint
  66. </a>
  67. )
  68. }}
  69. />
  70. }
  71. mouseLeaveDelay={0.5}>
  72. <SonarLintIcon className="it__issues-sonarlint-quick-fix spacer-right" size={15} />
  73. </Tooltip>
  74. )}
  75. <ButtonLink
  76. aria-label={translate('issue.why_this_issue.long')}
  77. className="issue-see-rule spacer-right text-baseline"
  78. onClick={() =>
  79. props.onOpenRule({
  80. key: ruleKey
  81. })
  82. }>
  83. {translate('issue.why_this_issue')}
  84. </ButtonLink>
  85. {ruleStatus && (ruleStatus === RuleStatus.Deprecated || ruleStatus === RuleStatus.Removed) && (
  86. <DocumentationTooltip
  87. className="spacer-left"
  88. content={translate('rules.status', ruleStatus, 'help')}
  89. links={[
  90. {
  91. href: '/documentation/user-guide/rules/',
  92. label: translateWithParameters('see_x', translate('rules'))
  93. }
  94. ]}>
  95. <span className="spacer-right badge badge-error">
  96. {translate('rules.status', ruleStatus)}
  97. </span>
  98. </DocumentationTooltip>
  99. )}
  100. {ruleEngine && (
  101. <Tooltip overlay={translateWithParameters('issue.from_external_rule_engine', ruleEngine)}>
  102. <div className="badge spacer-right text-baseline">{ruleEngine}</div>
  103. </Tooltip>
  104. )}
  105. {manualVulnerability && (
  106. <Tooltip overlay={translate('issue.manual_vulnerability.description')}>
  107. <div className="badge spacer-right text-baseline">
  108. {translate('issue.manual_vulnerability')}
  109. </div>
  110. </Tooltip>
  111. )}
  112. </div>
  113. );
  114. }