diff options
author | Stas Vilchik <stas.vilchik@sonarsource.com> | 2018-08-22 14:57:06 +0200 |
---|---|---|
committer | SonarTech <sonartech@sonarsource.com> | 2018-08-24 20:21:20 +0200 |
commit | 83470145072a37c0d0b8728322a44bddf2fbde21 (patch) | |
tree | 617987966fea7d6c04ec805408a34742cbc4b650 /server | |
parent | fae8b544d6c105606bb8a6c584bbe24ee2d94834 (diff) | |
download | sonarqube-83470145072a37c0d0b8728322a44bddf2fbde21.tar.gz sonarqube-83470145072a37c0d0b8728322a44bddf2fbde21.zip |
SONAR-11053 add disabled "Activate more" button for built-in profiles
Diffstat (limited to 'server')
4 files changed, 40 insertions, 4 deletions
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 index 00000000000..4a023892bfa --- /dev/null +++ b/server/sonar-docs/src/tooltips/quality-profiles/activate-rules-in-built-in-profile.md @@ -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. diff --git a/server/sonar-web/src/main/js/apps/quality-profiles/details/ProfileRules.tsx b/server/sonar-web/src/main/js/apps/quality-profiles/details/ProfileRules.tsx index 880002c8914..038499c0fb2 100644 --- a/server/sonar-web/src/main/js/apps/quality-profiles/details/ProfileRules.tsx +++ b/server/sonar-web/src/main/js/apps/quality-profiles/details/ProfileRules.tsx @@ -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 diff --git a/server/sonar-web/src/main/js/apps/quality-profiles/details/__tests__/ProfileRules-test.tsx b/server/sonar-web/src/main/js/apps/quality-profiles/details/__tests__/ProfileRules-test.tsx index ccb699c48fd..ef964aa5b01 100644 --- a/server/sonar-web/src/main/js/apps/quality-profiles/details/__tests__/ProfileRules-test.tsx +++ b/server/sonar-web/src/main/js/apps/quality-profiles/details/__tests__/ProfileRules-test.tsx @@ -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 () => { diff --git a/server/sonar-web/src/main/js/apps/quality-profiles/details/__tests__/__snapshots__/ProfileRules-test.tsx.snap b/server/sonar-web/src/main/js/apps/quality-profiles/details/__tests__/__snapshots__/ProfileRules-test.tsx.snap index ea82cabc5dc..83bc3ede515 100644 --- a/server/sonar-web/src/main/js/apps/quality-profiles/details/__tests__/__snapshots__/ProfileRules-test.tsx.snap +++ b/server/sonar-web/src/main/js/apps/quality-profiles/details/__tests__/__snapshots__/ProfileRules-test.tsx.snap @@ -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> +`; |