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;
{ qprofile: profile.key, activation: 'false' },
organization
);
+ const { actions = {} } = profile;
return (
<div className="boxed-group quality-profile-rules">
</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}>
</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
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
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 () => {