diff options
3 files changed, 99 insertions, 25 deletions
diff --git a/server/sonar-web/src/main/js/apps/overview/meta/MetaQualityProfiles.js b/server/sonar-web/src/main/js/apps/overview/meta/MetaQualityProfiles.js index fd3fb30216c..b72a1d96078 100644 --- a/server/sonar-web/src/main/js/apps/overview/meta/MetaQualityProfiles.js +++ b/server/sonar-web/src/main/js/apps/overview/meta/MetaQualityProfiles.js @@ -18,30 +18,97 @@ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ import React from 'react'; -import { translate } from '../../../helpers/l10n'; +import { TooltipsContainer } from '../../../components/mixins/tooltips-mixin'; +import { translate, translateWithParameters } from '../../../helpers/l10n'; import { getQualityProfileUrl } from '../../../helpers/urls'; +import { searchRules } from '../../../api/rules'; +import { getRulesUrl } from '../../../helpers/urls'; -const MetaQualityProfiles = ({ profiles }) => { - return ( - <div> - <h4 className="overview-meta-header"> - {translate('overview.quality_profiles')} - </h4> - - <ul className="overview-meta-list"> - {profiles.map(profile => ( - <li key={profile.key}> - <span className="note spacer-right"> - {'(' + profile.language + ')'} - </span> - <a href={getQualityProfileUrl(profile.key)}> - {profile.name} - </a> - </li> - ))} - </ul> - </div> - ); -}; - -export default MetaQualityProfiles; +export default class MetaQualityProfiles extends React.Component { + state = { + deprecatedByKey: {} + }; + + componentDidMount () { + this.mounted = true; + this.loadDeprecatedRules(); + } + + componentWillUnmount () { + this.mounted = false; + } + + loadDeprecatedRules () { + const requests = this.props.profiles.map(profile => ( + this.loadDeprecatedRulesForProfile(profile.key) + )); + Promise.all(requests).then(responses => { + if (this.mounted) { + const deprecatedByKey = {}; + responses.forEach((count, i) => { + const profileKey = this.props.profiles[i].key; + deprecatedByKey[profileKey] = count; + }); + this.setState({ deprecatedByKey }); + } + }); + } + + loadDeprecatedRulesForProfile (profileKey) { + const data = { + qprofile: profileKey, + activation: 'true', + statuses: 'DEPRECATED', + ps: 1 + }; + return searchRules(data).then(r => r.total); + } + + renderDeprecated (profile) { + const count = this.state.deprecatedByKey[profile.key]; + if (!count) { + return null; + } + + const url = getRulesUrl({ + qprofile: profile.key, + activation: 'true', + statuses: 'DEPRECATED' + }); + + return ( + <a className="icon-alert-warn spacer-right" + href={url} + title={translateWithParameters('overview.deprecated_profile', count)} + data-toggle="tooltip"/> + ); + } + + render () { + const { profiles } = this.props; + + return ( + <TooltipsContainer> + <div> + <h4 className="overview-meta-header"> + {translate('overview.quality_profiles')} + </h4> + + <ul className="overview-meta-list"> + {profiles.map(profile => ( + <li key={profile.key}> + {this.renderDeprecated(profile)} + <span className="note spacer-right"> + {'(' + profile.language + ')'} + </span> + <a href={getQualityProfileUrl(profile.key)}> + {profile.name} + </a> + </li> + ))} + </ul> + </div> + </TooltipsContainer> + ); + } +} diff --git a/server/sonar-web/src/main/js/apps/overview/styles.css b/server/sonar-web/src/main/js/apps/overview/styles.css index d31c9a404c8..204f0fe760d 100644 --- a/server/sonar-web/src/main/js/apps/overview/styles.css +++ b/server/sonar-web/src/main/js/apps/overview/styles.css @@ -260,6 +260,11 @@ white-space: nowrap; } +.overview-meta-list i { + position: relative; + top: -1px; +} + /* * Other */ diff --git a/sonar-core/src/main/resources/org/sonar/l10n/core.properties b/sonar-core/src/main/resources/org/sonar/l10n/core.properties index 224f9dac244..e2665b960ea 100644 --- a/sonar-core/src/main/resources/org/sonar/l10n/core.properties +++ b/sonar-core/src/main/resources/org/sonar/l10n/core.properties @@ -3009,6 +3009,8 @@ overview.domain.size=Size overview.complexity_tooltip.function={0} functions have complexity around {1} overview.complexity_tooltip.file={0} files have complexity around {1} +overview.deprecated_profile=This quality profile uses {0} deprecated rules and should be updated. + #------------------------------------------------------------------------------ # |