aboutsummaryrefslogtreecommitdiffstats
path: root/server/sonar-web/src/main/js/apps/coding-rules/components/RuleDetailsHeaderActions.tsx
blob: 46d82b187b40a8e9af6fe871cb3ab23162627497 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
/*
 * SonarQube
 * Copyright (C) 2009-2024 SonarSource SA
 * mailto:info AT sonarsource DOT com
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 3 of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with this program; if not, write to the Free Software Foundation,
 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 */
import { Note, SeparatorCircleIcon, TextSubdued } from 'design-system';
import * as React from 'react';
import DocHelpTooltip from '~sonar-aligned/components/controls/DocHelpTooltip';
import IssueSeverityIcon from '../../../components/icon-mappers/IssueSeverityIcon';
import IssueTypeIcon from '../../../components/icon-mappers/IssueTypeIcon';
import TagsList from '../../../components/tags/TagsList';
import { translate } from '../../../helpers/l10n';
import { IssueSeverity } from '../../../types/issues';
import { Dict, RuleDetails } from '../../../types/types';
import RuleDetailsTagsPopup from './RuleDetailsTagsPopup';

interface Props {
  canWrite: boolean | undefined;
  onTagsChange: (tags: string[]) => void;
  referencedRepositories: Dict<{ key: string; language: string; name: string }>;
  ruleDetails: RuleDetails;
}

export default function RuleDetailsHeaderActions(props: Readonly<Props>) {
  const { canWrite, ruleDetails, onTagsChange } = props;
  const { sysTags = [], tags = [] } = ruleDetails;
  const allTags = [...sysTags, ...tags];
  const TAGS_TO_DISPLAY = 1;

  return (
    <Note className="sw-flex sw-flex-wrap sw-items-center sw-gap-2 sw-body-xs">
      {/* Type */}
      <DocHelpTooltip
        content={
          <>
            <p className="sw-mb-4">{translate('coding_rules.type.deprecation.title')}</p>
            <p>{translate('coding_rules.type.deprecation.filter_by')}</p>
          </>
        }
        links={[
          {
            href: '/user-guide/rules/overview',
            label: translate('learn_more'),
          },
        ]}
      >
        <TextSubdued
          className="it__coding-rules-detail-property sw-flex sw-items-center sw-gap-1"
          data-meta="type"
        >
          <IssueTypeIcon
            fill="iconTypeDisabled"
            type={ruleDetails.type}
            aria-hidden
            width={12}
            height={12}
          />
          {translate('issue.type', ruleDetails.type)}
        </TextSubdued>
      </DocHelpTooltip>
      <SeparatorCircleIcon />

      {/* Severity */}
      <DocHelpTooltip
        content={
          <>
            <p className="sw-mb-4">{translate('coding_rules.severity.deprecation.title')}</p>
            <p>{translate('coding_rules.severity.deprecation.filter_by')}</p>
          </>
        }
        links={[
          {
            href: '/user-guide/rules/overview',
            label: translate('learn_more'),
          },
        ]}
      >
        <TextSubdued
          className="it__coding-rules-detail-property sw-flex sw-items-center sw-gap-1"
          data-meta="severity"
        >
          <IssueSeverityIcon
            fill="iconSeverityDisabled"
            severity={ruleDetails.severity as IssueSeverity}
            aria-hidden
            width={12}
            height={12}
          />
          {translate('severity', ruleDetails.severity)}
        </TextSubdued>
      </DocHelpTooltip>
      <SeparatorCircleIcon />

      {/* Tags */}
      <div className="it__coding-rules-detail-property" data-meta="tags">
        <TagsList
          className="sw-body-xs"
          tagsClassName="sw-body-xs"
          allowUpdate={canWrite}
          tagsToDisplay={TAGS_TO_DISPLAY}
          tags={allTags.length > 0 ? allTags : [translate('coding_rules.no_tags')]}
          overlay={
            canWrite ? (
              <RuleDetailsTagsPopup setTags={onTagsChange} sysTags={sysTags} tags={tags} />
            ) : undefined
          }
        />
      </div>
    </Note>
  );
}