From f4f949f46aa72c9233158153a47741369440adbc Mon Sep 17 00:00:00 2001 From: Siegfried Ehret Date: Fri, 12 Jul 2019 11:03:47 +0200 Subject: [PATCH] SONAR-11007 Add disabled "Deactivate" button to rules list (#1913) --- .../coding-rules/components/RuleListItem.tsx | 13 ++++++++--- .../__tests__/RuleListItem-test.tsx | 10 +++++++- .../__snapshots__/RuleListItem-test.tsx.snap | 23 +++++++++++++++++++ .../resources/org/sonar/l10n/core.properties | 1 + 4 files changed, 43 insertions(+), 4 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 8c2b5c7f63d..2acb0a63683 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 @@ -131,7 +131,11 @@ export default class RuleListItem extends React.PureComponent { const canEdit = selectedProfile.actions && selectedProfile.actions.edit; if (!canEdit || selectedProfile.isBuiltIn) { - return null; + return ( + + {this.renderDeactivateButton('', 'coding_rules.need_extend_or_copy')} + + ); } return ( @@ -153,7 +157,10 @@ export default class RuleListItem extends React.PureComponent { ); }; - renderDeactivateButton = (inherit: string) => { + renderDeactivateButton = ( + inherit: string, + overlayTranslationKey = 'coding_rules.can_not_deactivate' + ) => { return inherit === 'NONE' ? ( { )} ) : ( - + 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 3d7b44dcb09..cc06721c692 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 @@ -33,8 +33,16 @@ it('should open rule', () => { expect(onOpen).toBeCalledWith('javascript:S1067'); }); +it('should render deactivate button', () => { + const wrapper = shallowRender(); + const instance = wrapper.instance(); + + expect(instance.renderDeactivateButton('NONE')).toMatchSnapshot(); + expect(instance.renderDeactivateButton('', 'coding_rules.need_extend_or_copy')).toMatchSnapshot(); +}); + function shallowRender(props?: Partial) { - return shallow( + return shallow( `; + +exports[`should render deactivate button 1`] = ` + + [Function] + +`; + +exports[`should render deactivate button 2`] = ` + + + +`; 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 08c54ee9a5b..4bb08dcb93c 100644 --- a/sonar-core/src/main/resources/org/sonar/l10n/core.properties +++ b/sonar-core/src/main/resources/org/sonar/l10n/core.properties @@ -1321,6 +1321,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.no_results=No Coding Rules coding_rules.no_tags=No tags coding_rules.original=Original: -- 2.39.5