]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-6551 warn about deprecated rules on project overview (#1059)
authorStas Vilchik <vilchiks@gmail.com>
Fri, 1 Jul 2016 15:08:15 +0000 (17:08 +0200)
committerGitHub <noreply@github.com>
Fri, 1 Jul 2016 15:08:15 +0000 (17:08 +0200)
server/sonar-web/src/main/js/apps/overview/meta/MetaQualityProfiles.js
server/sonar-web/src/main/js/apps/overview/styles.css
sonar-core/src/main/resources/org/sonar/l10n/core.properties

index fd3fb30216cdc6dcad50512363545ec5eef08eed..b72a1d9607897f760bb9f38de15b9dc25540769f 100644 (file)
  * 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>
+    );
+  }
+}
index d31c9a404c811d1721b79fc3f8754a2a0c04c357..204f0fe760dbfe9b7afcaa220381b87e650491c3 100644 (file)
   white-space: nowrap;
 }
 
+.overview-meta-list i {
+  position: relative;
+  top: -1px;
+}
+
 /*
  * Other
  */
index 224f9dac244189f4c9c419a0b1cdae03c2bf5f50..e2665b960ea6f7b84f4954ed7428c81bbba95b2e 100644 (file)
@@ -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.
+
 
 #------------------------------------------------------------------------------
 #