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
171
172
173
174
175
|
/*
* SonarQube
* Copyright (C) 2009-2021 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 * as React from 'react';
import { Button } from 'sonar-ui-common/components/controls/buttons';
import HelpTooltip from 'sonar-ui-common/components/controls/HelpTooltip';
import Tooltip from 'sonar-ui-common/components/controls/Tooltip';
import AlertErrorIcon from 'sonar-ui-common/components/icons/AlertErrorIcon';
import AlertSuccessIcon from 'sonar-ui-common/components/icons/AlertSuccessIcon';
import DeleteIcon from 'sonar-ui-common/components/icons/DeleteIcon';
import EditIcon from 'sonar-ui-common/components/icons/EditIcon';
import { Alert } from 'sonar-ui-common/components/ui/Alert';
import { translate } from 'sonar-ui-common/helpers/l10n';
import {
AlmBindingDefinition,
AlmKeys,
AlmSettingsBindingStatus,
AlmSettingsBindingStatusType
} from '../../../../types/alm-settings';
export interface AlmBindingDefinitionBoxProps {
alm: AlmKeys;
definition: AlmBindingDefinition;
multipleDefinitions: boolean;
onCheck: (definitionKey: string) => void;
onDelete: (definitionKey: string) => void;
onEdit: (definitionKey: string) => void;
status?: AlmSettingsBindingStatus;
}
const DEFAULT_STATUS: AlmSettingsBindingStatus = {
alertSuccess: false,
failureMessage: '',
type: AlmSettingsBindingStatusType.Validating
};
const STATUS_ICON = {
[AlmSettingsBindingStatusType.Failure]: <AlertErrorIcon className="spacer-left" />,
[AlmSettingsBindingStatusType.Success]: <AlertSuccessIcon className="spacer-left" />
};
function getImportFeatureStatus(
definition: AlmBindingDefinition,
multipleDefinitions: boolean,
type: AlmSettingsBindingStatusType.Success | AlmSettingsBindingStatusType.Failure
) {
if (multipleDefinitions) {
return (
<div className="display-inline-flex-center">
<strong className="spacer-left">
{translate('settings.almintegration.feature.alm_repo_import.disabled')}
</strong>
<HelpTooltip
className="little-spacer-left"
overlay={translate('settings.almintegration.feature.alm_repo_import.disabled.multiple')}
/>
</div>
);
} else if (!definition.url) {
return (
<div className="display-inline-flex-center">
<strong className="spacer-left">
{translate('settings.almintegration.feature.alm_repo_import.disabled')}
</strong>
<HelpTooltip
className="little-spacer-left"
overlay={translate('settings.almintegration.feature.alm_repo_import.disabled.no_url')}
/>
</div>
);
} else {
return STATUS_ICON[type];
}
}
export default function AlmBindingDefinitionBox(props: AlmBindingDefinitionBoxProps) {
const { alm, definition, multipleDefinitions, status = DEFAULT_STATUS } = props;
const importFeatureTitle =
alm === AlmKeys.GitLab
? translate('settings.almintegration.feature.mr_decoration.title')
: translate('settings.almintegration.feature.pr_decoration.title');
const importFeatureDescription =
alm === AlmKeys.GitLab
? translate('settings.almintegration.feature.mr_decoration.description')
: translate('settings.almintegration.feature.pr_decoration.description');
return (
<div className="boxed-group-inner bordered spacer-top spacer-bottom it__alm-binding-definition">
<div className="actions pull-right">
<Button onClick={() => props.onEdit(definition.key)}>
<EditIcon className="spacer-right" />
{translate('edit')}
</Button>
<Button className="button-red spacer-left" onClick={() => props.onDelete(definition.key)}>
<DeleteIcon className="spacer-right" />
{translate('delete')}
</Button>
</div>
<div className="big-spacer-bottom">
<h3>{definition.key}</h3>
{definition.url && <span>{definition.url}</span>}
</div>
{status.type === AlmSettingsBindingStatusType.Validating ? (
<>
<i className="spinner spacer-right" />
{translate('settings.almintegration.checking_configuration')}
</>
) : (
<>
{status.type !== AlmSettingsBindingStatusType.Warning && (
<div className="display-flex-row spacer-bottom">
<Tooltip overlay={importFeatureDescription}>
<div className="huge-spacer-right">
{importFeatureTitle}
{STATUS_ICON[status.type]}
</div>
</Tooltip>
<div>
<Tooltip
overlay={translate(
'settings.almintegration.feature.alm_repo_import.description'
)}>
<span>{translate('settings.almintegration.feature.alm_repo_import.title')}</span>
</Tooltip>
{getImportFeatureStatus(definition, multipleDefinitions, status.type)}
</div>
</div>
)}
<div className="width-50">
{status.type === AlmSettingsBindingStatusType.Warning && (
<Alert variant="warning">
{translate('settings.almintegration.could_not_validate')}
</Alert>
)}
{status.type === AlmSettingsBindingStatusType.Failure && (
<Alert variant="error">{status.failureMessage}</Alert>
)}
{status.type === AlmSettingsBindingStatusType.Success && status.alertSuccess && (
<Alert variant="success">
{translate('settings.almintegration.configuration_valid')}
</Alert>
)}
</div>
<Button className="big-spacer-top" onClick={() => props.onCheck(definition.key)}>
{translate('settings.almintegration.check_configuration')}
</Button>
</>
)}
</div>
);
}
|