Browse Source

SONAR-11053 add disabled "Activate more" button for built-in profiles

tags/7.5
Stas Vilchik 5 years ago
parent
commit
8347014507

+ 1
- 0
server/sonar-docs/src/tooltips/quality-profiles/activate-rules-in-built-in-profile.md View File

@@ -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.

+ 20
- 3
server/sonar-web/src/main/js/apps/quality-profiles/details/ProfileRules.tsx View 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

+ 11
- 1
server/sonar-web/src/main/js/apps/quality-profiles/details/__tests__/ProfileRules-test.tsx View 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 () => {

+ 8
- 0
server/sonar-web/src/main/js/apps/quality-profiles/details/__tests__/__snapshots__/ProfileRules-test.tsx.snap View 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>
`;

Loading…
Cancel
Save