diff options
author | Wouter Admiraal <wouter.admiraal@sonarsource.com> | 2021-02-22 12:21:36 +0100 |
---|---|---|
committer | sonartech <sonartech@sonarsource.com> | 2021-02-23 20:07:26 +0000 |
commit | aa23b46299f2ba3dd4977c4bb3b117c88c3e907c (patch) | |
tree | 7ec5336c3ed88b9cf1019338ac3499f41002438e | |
parent | c630234557ea147d2d560508b5f98856dfa63ca0 (diff) | |
download | sonarqube-aa23b46299f2ba3dd4977c4bb3b117c88c3e907c.tar.gz sonarqube-aa23b46299f2ba3dd4977c4bb3b117c88c3e907c.zip |
SONAR-14487 Fix misleading rules button label for built-in quality profiles
4 files changed, 61 insertions, 75 deletions
diff --git a/server/sonar-web/src/main/js/apps/coding-rules/components/RuleListItem.tsx b/server/sonar-web/src/main/js/apps/coding-rules/components/RuleListItem.tsx index 3d50a5490ff..7cfad2ffe36 100644 --- a/server/sonar-web/src/main/js/apps/coding-rules/components/RuleListItem.tsx +++ b/server/sonar-web/src/main/js/apps/coding-rules/components/RuleListItem.tsx @@ -136,7 +136,11 @@ export default class RuleListItem extends React.PureComponent<Props> { if (selectedProfile.isBuiltIn && canCopy) { return ( <td className="coding-rule-table-meta-cell coding-rule-activation-actions"> - {this.renderDeactivateButton('', 'coding_rules.need_extend_or_copy')} + <Tooltip overlay={translate('coding_rules.need_extend_or_copy')}> + <Button className="coding-rules-detail-quality-profile-deactivate button-red disabled"> + {translate('coding_rules', activation ? 'deactivate' : 'activate')} + </Button> + </Tooltip> </td> ); } @@ -146,48 +150,47 @@ export default class RuleListItem extends React.PureComponent<Props> { return null; } + if (activation) { + return ( + <td className="coding-rule-table-meta-cell coding-rule-activation-actions"> + {activation.inherit === 'NONE' ? ( + <ConfirmButton + confirmButtonText={translate('yes')} + modalBody={translate('coding_rules.deactivate.confirm')} + modalHeader={translate('coding_rules.deactivate')} + onConfirm={this.handleDeactivate}> + {({ onClick }) => ( + <Button + className="coding-rules-detail-quality-profile-deactivate button-red" + onClick={onClick}> + {translate('coding_rules.deactivate')} + </Button> + )} + </ConfirmButton> + ) : ( + <Tooltip overlay={translate('coding_rules.can_not_deactivate')}> + <Button className="coding-rules-detail-quality-profile-deactivate button-red disabled"> + {translate('coding_rules.deactivate')} + </Button> + </Tooltip> + )} + </td> + ); + } + return ( <td className="coding-rule-table-meta-cell coding-rule-activation-actions"> - {activation - ? this.renderDeactivateButton(activation.inherit) - : !rule.isTemplate && ( - <ActivationButton - buttonText={translate('coding_rules.activate')} - className="coding-rules-detail-quality-profile-activate" - modalHeader={translate('coding_rules.activate_in_quality_profile')} - onDone={this.handleActivate} - profiles={[selectedProfile]} - rule={rule} - /> - )} - </td> - ); - }; - - renderDeactivateButton = ( - inherit: string, - overlayTranslationKey = 'coding_rules.can_not_deactivate' - ) => { - return inherit === 'NONE' ? ( - <ConfirmButton - confirmButtonText={translate('yes')} - modalBody={translate('coding_rules.deactivate.confirm')} - modalHeader={translate('coding_rules.deactivate')} - onConfirm={this.handleDeactivate}> - {({ onClick }) => ( - <Button - className="coding-rules-detail-quality-profile-deactivate button-red" - onClick={onClick}> - {translate('coding_rules.deactivate')} - </Button> + {!rule.isTemplate && ( + <ActivationButton + buttonText={translate('coding_rules.activate')} + className="coding-rules-detail-quality-profile-activate" + modalHeader={translate('coding_rules.activate_in_quality_profile')} + onDone={this.handleActivate} + profiles={[selectedProfile]} + rule={rule} + /> )} - </ConfirmButton> - ) : ( - <Tooltip overlay={translate(overlayTranslationKey)}> - <Button className="coding-rules-detail-quality-profile-deactivate button-red disabled"> - {translate('coding_rules.deactivate')} - </Button> - </Tooltip> + </td> ); }; diff --git a/server/sonar-web/src/main/js/apps/coding-rules/components/__tests__/RuleListItem-test.tsx b/server/sonar-web/src/main/js/apps/coding-rules/components/__tests__/RuleListItem-test.tsx index 2908b0421be..5a70aa7be2a 100644 --- a/server/sonar-web/src/main/js/apps/coding-rules/components/__tests__/RuleListItem-test.tsx +++ b/server/sonar-web/src/main/js/apps/coding-rules/components/__tests__/RuleListItem-test.tsx @@ -71,18 +71,6 @@ it('handle deactivation', async () => { expect(onDeactivate).toBeCalledWith(profile.key, rule.key); }); -describe('#renderDeactivateButton', () => { - it('should render correctly', () => { - const wrapper = shallowRender(); - const instance = wrapper.instance(); - - expect(instance.renderDeactivateButton('NONE')).toMatchSnapshot(); - expect( - instance.renderDeactivateButton('', 'coding_rules.need_extend_or_copy') - ).toMatchSnapshot(); - }); -}); - describe('renderActions', () => { it('should be null when there is no selected profile', () => { const wrapper = shallowRender({ @@ -120,7 +108,9 @@ describe('renderActions', () => { }) }); - expect(wrapper.instance().renderActions()).toMatchSnapshot(); + expect(wrapper.instance().renderActions()).toMatchSnapshot('activate'); + wrapper.setProps({ activation: { inherit: 'INHERITED', severity: 'CRITICAL' } }); + expect(wrapper.instance().renderActions()).toMatchSnapshot('deactivate'); }); it('should render the deactivate button', () => { diff --git a/server/sonar-web/src/main/js/apps/coding-rules/components/__tests__/__snapshots__/RuleListItem-test.tsx.snap b/server/sonar-web/src/main/js/apps/coding-rules/components/__tests__/__snapshots__/RuleListItem-test.tsx.snap index b14e698cb93..8960c63b861 100644 --- a/server/sonar-web/src/main/js/apps/coding-rules/components/__tests__/__snapshots__/RuleListItem-test.tsx.snap +++ b/server/sonar-web/src/main/js/apps/coding-rules/components/__tests__/__snapshots__/RuleListItem-test.tsx.snap @@ -1,29 +1,22 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP -exports[`#renderDeactivateButton should render correctly 1`] = ` -<ConfirmButton - confirmButtonText="yes" - modalBody="coding_rules.deactivate.confirm" - modalHeader="coding_rules.deactivate" - onConfirm={[Function]} -> - [Function] -</ConfirmButton> -`; - -exports[`#renderDeactivateButton should render correctly 2`] = ` -<Tooltip - overlay="coding_rules.need_extend_or_copy" +exports[`renderActions should disable the button when I am on a built-in profile: activate 1`] = ` +<td + className="coding-rule-table-meta-cell coding-rule-activation-actions" > - <Button - className="coding-rules-detail-quality-profile-deactivate button-red disabled" + <Tooltip + overlay="coding_rules.need_extend_or_copy" > - coding_rules.deactivate - </Button> -</Tooltip> + <Button + className="coding-rules-detail-quality-profile-deactivate button-red disabled" + > + coding_rules.activate + </Button> + </Tooltip> +</td> `; -exports[`renderActions should disable the button when I am on a built-in profile 1`] = ` +exports[`renderActions should disable the button when I am on a built-in profile: deactivate 1`] = ` <td className="coding-rule-table-meta-cell coding-rule-activation-actions" > diff --git a/sonar-core/src/main/resources/org/sonar/l10n/core.properties b/sonar-core/src/main/resources/org/sonar/l10n/core.properties index 669eb617325..6fd9a323fca 100644 --- a/sonar-core/src/main/resources/org/sonar/l10n/core.properties +++ b/sonar-core/src/main/resources/org/sonar/l10n/core.properties @@ -1647,7 +1647,7 @@ coding_rules.bulk_change=Bulk Change coding_rules.bulk_change.success={2} rule(s) changed in profile {0} - {1} coding_rules.bulk_change.warning={2} rule(s) changed, {3} rule(s) ignored in profile {0} - {1} coding_rules.can_not_bulk_change=Bulk change is only available when you have a custom Quality Profile to target. You can create a customizable Quality Profile based on a built-in one by Copying or Extending it in the Quality Profiles list. -coding_rules.can_not_deactivate=This rule is inherited and can not be deactivated. +coding_rules.can_not_deactivate=This rule is inherited and cannot be deactivated. coding_rules.change_details=Change Details of Quality Profile coding_rules.create=Create coding_rules.create_custom_rule=Create Custom Rule @@ -1668,7 +1668,7 @@ coding_rules.inherits="{0}" inherits from "{1}" coding_rules.issues=Issues coding_rules.issues.only_main_branches=Only issues from the main project branches are included. coding_rules.most_violating_projects=Most Violating Projects -coding_rules.need_extend_or_copy=Rules in built-in Quality Profiles can't be deactivated. You can create a customizable Quality Profile based on a built-in one by Copying or Extending it in the Quality Profiles list. +coding_rules.need_extend_or_copy=Rules in built-in Quality Profiles can't be changed. You can create a customizable Quality Profile based on a built-in one by Copying or Extending it in the Quality Profiles list. coding_rules.no_results=No Coding Rules coding_rules.no_tags=No tags coding_rules.original=Original: |