3 * Copyright (C) 2009-2023 SonarSource SA
4 * mailto:info AT sonarsource DOT com
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.
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.
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.
20 import * as React from 'react';
21 import { searchRules } from '../../../../../../api/rules';
22 import Link from '../../../../../../components/common/Link';
23 import Tooltip from '../../../../../../components/controls/Tooltip';
24 import { translate, translateWithParameters } from '../../../../../../helpers/l10n';
25 import { getQualityProfileUrl } from '../../../../../../helpers/urls';
26 import { Languages } from '../../../../../../types/languages';
27 import { ComponentQualityProfile, Dict } from '../../../../../../types/types';
28 import withLanguagesContext from '../../../../languages/withLanguagesContext';
31 headerClassName?: string;
33 profiles: ComponentQualityProfile[];
37 deprecatedByKey: Dict<number>;
40 export class MetaQualityProfiles extends React.PureComponent<Props, State> {
42 state: State = { deprecatedByKey: {} };
46 this.loadDeprecatedRules();
49 componentWillUnmount() {
53 loadDeprecatedRules() {
54 const existingProfiles = this.props.profiles.filter((p) => !p.deleted);
55 const requests = existingProfiles.map((profile) =>
56 this.loadDeprecatedRulesForProfile(profile.key)
58 Promise.all(requests).then(
61 const deprecatedByKey: Dict<number> = {};
62 responses.forEach((count, i) => {
63 const profileKey = existingProfiles[i].key;
64 deprecatedByKey[profileKey] = count;
66 this.setState({ deprecatedByKey });
73 loadDeprecatedRulesForProfile(profileKey: string) {
78 statuses: 'DEPRECATED',
80 return searchRules(data).then((r) => r.total);
83 getDeprecatedRulesCount(profile: { key: string }) {
84 const count = this.state.deprecatedByKey[profile.key];
88 renderProfile(profile: ComponentQualityProfile) {
89 const languageFromStore = this.props.languages[profile.language];
90 const languageName = languageFromStore ? languageFromStore.name : profile.language;
93 <div className="text-ellipsis">
94 <span className="spacer-right">({languageName})</span>
98 <Link to={getQualityProfileUrl(profile.name, profile.language)}>
100 aria-label={translateWithParameters(
101 'overview.link_to_x_profile_y',
113 if (profile.deleted) {
114 const tooltip = translateWithParameters('overview.deleted_profile', profile.name);
116 <Tooltip key={profile.key} overlay={tooltip}>
117 <li className="project-info-deleted-profile">{inner}</li>
122 const count = this.getDeprecatedRulesCount(profile);
125 const tooltip = translateWithParameters('overview.deprecated_profile', count);
127 <Tooltip key={profile.key} overlay={tooltip}>
128 <li className="project-info-deprecated-rules">{inner}</li>
133 return <li key={profile.key}>{inner}</li>;
137 const { headerClassName, profiles } = this.props;
141 <h3 className={headerClassName}>{translate('overview.quality_profiles')}</h3>
143 <ul className="project-info-list">
144 {profiles.map((profile) => this.renderProfile(profile))}
151 export default withLanguagesContext(MetaQualityProfiles);