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
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
|
/*
* 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 { Badge, HelperHintIcon, Link, Note, SeparatorCircleIcon } from 'design-system';
import React from 'react';
import HelpTooltip from '../../../components/controls/HelpTooltip';
import Tooltip from '../../../components/controls/Tooltip';
import { translate, translateWithParameters } from '../../../helpers/l10n';
import { getRuleUrl } from '../../../helpers/urls';
import { Dict, RuleDetails } from '../../../types/types';
const EXTERNAL_RULE_REPO_PREFIX = 'external_';
interface Props {
ruleDetails: RuleDetails;
referencedRepositories: Dict<{ key: string; language: string; name: string }>;
}
export default function RuleDetailsHeaderMeta(props: Readonly<Props>) {
const { referencedRepositories, ruleDetails } = props;
const repository = referencedRepositories[ruleDetails.repo];
const externalEngine = ruleDetails.repo.replace(new RegExp(`^${EXTERNAL_RULE_REPO_PREFIX}`), '');
return (
<Note className="sw-flex sw-flex-wrap sw-items-center sw-gap-2 sw-body-xs" as="ul">
{/* Template */}
{!ruleDetails.isExternal && ruleDetails.isTemplate && (
<>
<li>
<Tooltip overlay={translate('coding_rules.rule_template.title')}>
<span className="it__coding-rules-detail-property">
{translate('coding_rules.rule_template')}
</span>
</Tooltip>
</li>
<SeparatorCircleIcon aria-hidden as="li" />
</>
)}
{/* Parent template */}
{!ruleDetails.isExternal && ruleDetails.templateKey && (
<>
<li
className="it__coding-rules-detail-property sw-flex sw-items-center sw-gap-1"
data-meta="parent"
>
<span>
{translate('coding_rules.custom_rule')}
{' ('}
<Link to={getRuleUrl(ruleDetails.templateKey)}>
{translate('coding_rules.show_template')}
</Link>
{') '}
</span>
<HelpTooltip overlay={translate('coding_rules.custom_rule.help')}>
<HelperHintIcon />
</HelpTooltip>
</li>
<SeparatorCircleIcon aria-hidden as="li" />
</>
)}
{/* Key */}
<li className="sw-flex sw-gap-1">
<span>{translate('coding_rules.rule_id')}</span>
<span className="sw-font-semibold">{ruleDetails.key}</span>
</li>
{/* Scope */}
{ruleDetails.scope && (
<>
<SeparatorCircleIcon aria-hidden as="li" />
<li className="sw-flex sw-gap-1">
<span>{translate('coding_rules.analysis_scope')}</span>
<span className="sw-font-semibold">
{translate('coding_rules.scope', ruleDetails.scope)}
</span>
</li>
</>
)}
{/* Repository */}
{repository && (
<>
<SeparatorCircleIcon aria-hidden as="li" />
<li className="sw-flex sw-gap-1">
<span>{translate('coding_rules.repository')}</span>
<span
className="it__coding-rules-detail-property sw-font-semibold"
data-meta="repository"
>
{repository.name} ({ruleDetails.langName})
</span>
</li>
</>
)}
{/* Engine */}
{ruleDetails.isExternal && ruleDetails.repo && externalEngine && (
<>
<SeparatorCircleIcon aria-hidden as="li" />
<li>
<Tooltip
overlay={translateWithParameters(
'coding_rules.external_rule.engine_tooltip',
externalEngine,
)}
>
<div className="sw-flex sw-gap-1">
<span>{translate('coding_rules.external_rule.engine')}</span>
<span
className="it__coding-rules-detail-property sw-font-semibold"
data-meta="engine"
>
<Badge>{externalEngine}</Badge>
</span>
</div>
</Tooltip>
</li>
</>
)}
{/* Status */}
{!ruleDetails.isExternal && ruleDetails.status !== 'READY' && (
<>
<SeparatorCircleIcon aria-hidden as="li" />
<li>
<Tooltip overlay={translate('status')}>
<Note data-meta="status">
<Badge variant="deleted">{translate('rules.status', ruleDetails.status)}</Badge>
</Note>
</Tooltip>
</li>
</>
)}
{/* Effort */}
{ruleDetails.remFnType && ruleDetails.remFnBaseEffort && (
<>
<SeparatorCircleIcon aria-hidden as="li" />
<li className="sw-flex sw-gap-1">
<span>{translate('coding_rules.remediation_effort')}</span>
<span
className="it__coding-rules-detail-property sw-font-semibold"
data-meta="remediation-function"
>
{ruleDetails.remFnBaseEffort !== undefined && ` ${ruleDetails.remFnBaseEffort}`}
</span>
</li>
</>
)}
</Note>
);
}
|