]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-11053 add disabled "Activate more" button for built-in profiles
authorStas Vilchik <stas.vilchik@sonarsource.com>
Wed, 22 Aug 2018 12:57:06 +0000 (14:57 +0200)
committerSonarTech <sonartech@sonarsource.com>
Fri, 24 Aug 2018 18:21:20 +0000 (20:21 +0200)
server/sonar-docs/src/tooltips/quality-profiles/activate-rules-in-built-in-profile.md [new file with mode: 0644]
server/sonar-web/src/main/js/apps/quality-profiles/details/ProfileRules.tsx
server/sonar-web/src/main/js/apps/quality-profiles/details/__tests__/ProfileRules-test.tsx
server/sonar-web/src/main/js/apps/quality-profiles/details/__tests__/__snapshots__/ProfileRules-test.tsx.snap

diff --git a/server/sonar-docs/src/tooltips/quality-profiles/activate-rules-in-built-in-profile.md b/server/sonar-docs/src/tooltips/quality-profiles/activate-rules-in-built-in-profile.md
new file mode 100644 (file)
index 0000000..4a02389
--- /dev/null
@@ -0,0 +1 @@
+This Quality Profile is built in, and cannot be updated manually. If you want to activate more rules, create a new profile that inherits from this one and add rules there.
index 880002c89140f28fc98d6940605cf716c86dd610..038499c0fb20fe8d8f8f934132303fcea69bce3e 100644 (file)
@@ -30,8 +30,10 @@ import { getRulesUrl } from '../../../helpers/urls';
 import { translate } from '../../../helpers/l10n';
 import { Profile } from '../types';
 import { RuleType } from '../../../app/types';
+import { Button } from '../../../components/ui/buttons';
+import DocTooltip from '../../../components/docs/DocTooltip';
 
-const TYPES = [RuleType.Bug, RuleType.Vulnerability, RuleType.CodeSmell, RuleType.Hotspot]
+const TYPES = [RuleType.Bug, RuleType.Vulnerability, RuleType.CodeSmell, RuleType.Hotspot];
 
 interface Props {
   organization: string | null;
@@ -151,6 +153,7 @@ export default class ProfileRules extends React.PureComponent<Props, State> {
       { qprofile: profile.key, activation: 'false' },
       organization
     );
+    const { actions = {} } = profile;
 
     return (
       <div className="boxed-group quality-profile-rules">
@@ -185,8 +188,7 @@ export default class ProfileRules extends React.PureComponent<Props, State> {
             </tbody>
           </table>
 
-          {profile.actions &&
-            profile.actions.edit &&
+          {actions.edit &&
             !profile.isBuiltIn && (
               <div className="text-right big-spacer-top">
                 <Link className="button js-activate-rules" to={activateMoreUrl}>
@@ -194,6 +196,21 @@ export default class ProfileRules extends React.PureComponent<Props, State> {
                 </Link>
               </div>
             )}
+
+          {/* if a user is allowed to `copy` a profile if they are a global or organization admin */}
+          {/* this user could potentially active more rules if the profile was not built-in */}
+          {/* in such cases it's better to show the button but disable it with a tooltip */}
+          {actions.copy &&
+            profile.isBuiltIn && (
+              <div className="text-right big-spacer-top">
+                <DocTooltip
+                  doc={import(/* webpackMode: "eager" */ 'Docs/tooltips/quality-profiles/activate-rules-in-built-in-profile.md')}>
+                  <Button className="disabled js-activate-rules">
+                    {translate('quality_profiles.activate_more')}
+                  </Button>
+                </DocTooltip>
+              </div>
+            )}
         </div>
         {profile.activeDeprecatedRuleCount > 0 && (
           <ProfileRulesDeprecatedWarning
index ccb699c48fdf0aac698c031011c1949c2fc4c7cd..ef964aa5b011bfaed555b574300fe08c2bdb420f 100644 (file)
@@ -100,6 +100,16 @@ it('should show a button to activate more rules for admins', () => {
   expect(wrapper.find('.js-activate-rules')).toMatchSnapshot();
 });
 
+it('should show a disabled button to activate more rules for built-in profiles', () => {
+  const wrapper = shallow(
+    <ProfileRules
+      organization={null}
+      profile={{ ...EDITABLE_PROFILE, actions: { copy: true }, isBuiltIn: true }}
+    />
+  );
+  expect(wrapper.find('.js-activate-rules')).toMatchSnapshot();
+});
+
 it('should show a deprecated rules warning message', () => {
   const wrapper = shallow(
     <ProfileRules
@@ -114,7 +124,7 @@ it('should not show a button to activate more rules on built in profiles', () =>
   const wrapper = shallow(
     <ProfileRules organization={null} profile={{ ...EDITABLE_PROFILE, isBuiltIn: true }} />
   );
-  expect(wrapper.find('.js-activate-rules')).toHaveLength(0);
+  expect(wrapper.find('.js-activate-rules').exists()).toBe(false);
 });
 
 it('should not show sonarway comparison for built in profiles', async () => {
index ea82cabc5dcbd654827c1881b1ea98bdd4cd8fdb..83bc3ede515d7733ba22ad56e869ef6cb8209211 100644 (file)
@@ -103,3 +103,11 @@ exports[`should show a deprecated rules warning message 1`] = `
   profile="foo"
 />
 `;
+
+exports[`should show a disabled button to activate more rules for built-in profiles 1`] = `
+<Button
+  className="disabled js-activate-rules"
+>
+  quality_profiles.activate_more
+</Button>
+`;