]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-11007 Add disabled "Deactivate" button to rules list (#1913)
authorSiegfried Ehret <siegfried.ehret@sonarsource.com>
Fri, 12 Jul 2019 09:03:47 +0000 (11:03 +0200)
committerSonarTech <sonartech@sonarsource.com>
Fri, 12 Jul 2019 18:21:16 +0000 (20:21 +0200)
server/sonar-web/src/main/js/apps/coding-rules/components/RuleListItem.tsx
server/sonar-web/src/main/js/apps/coding-rules/components/__tests__/RuleListItem-test.tsx
server/sonar-web/src/main/js/apps/coding-rules/components/__tests__/__snapshots__/RuleListItem-test.tsx.snap
sonar-core/src/main/resources/org/sonar/l10n/core.properties

index 8c2b5c7f63d4d3ec09a7312a89d3687f3c53792c..2acb0a63683dc75b0d4079c89569ea8db158eac7 100644 (file)
@@ -131,7 +131,11 @@ export default class RuleListItem extends React.PureComponent<Props> {
 
     const canEdit = selectedProfile.actions && selectedProfile.actions.edit;
     if (!canEdit || selectedProfile.isBuiltIn) {
-      return null;
+      return (
+        <td className="coding-rule-table-meta-cell coding-rule-activation-actions">
+          {this.renderDeactivateButton('', 'coding_rules.need_extend_or_copy')}
+        </td>
+      );
     }
 
     return (
@@ -153,7 +157,10 @@ export default class RuleListItem extends React.PureComponent<Props> {
     );
   };
 
-  renderDeactivateButton = (inherit: string) => {
+  renderDeactivateButton = (
+    inherit: string,
+    overlayTranslationKey = 'coding_rules.can_not_deactivate'
+  ) => {
     return inherit === 'NONE' ? (
       <ConfirmButton
         confirmButtonText={translate('yes')}
@@ -169,7 +176,7 @@ export default class RuleListItem extends React.PureComponent<Props> {
         )}
       </ConfirmButton>
     ) : (
-      <Tooltip overlay={translate('coding_rules.can_not_deactivate')}>
+      <Tooltip overlay={translate(overlayTranslationKey)}>
         <Button className="coding-rules-detail-quality-profile-deactivate button-red disabled">
           {translate('coding_rules.deactivate')}
         </Button>
index 3d7b44dcb09b38ac8122c2e236f398fdeab3445f..cc06721c69212ab29cced307675b8f1845614815 100644 (file)
@@ -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<RuleListItem['props']>) {
-  return shallow(
+  return shallow<RuleListItem>(
     <RuleListItem
       onActivate={jest.fn()}
       onDeactivate={jest.fn()}
index e1b94a8164a2690290e1bbef5100d4e6d9cae4fc..dd03a7730c325459dd97fa5567c69b2f740d3281 100644 (file)
@@ -96,3 +96,26 @@ exports[`should render 1`] = `
   </table>
 </div>
 `;
+
+exports[`should render deactivate button 1`] = `
+<ConfirmButton
+  confirmButtonText="yes"
+  modalBody="coding_rules.deactivate.confirm"
+  modalHeader="coding_rules.deactivate"
+  onConfirm={[Function]}
+>
+  [Function]
+</ConfirmButton>
+`;
+
+exports[`should render deactivate button 2`] = `
+<Tooltip
+  overlay="coding_rules.need_extend_or_copy"
+>
+  <Button
+    className="coding-rules-detail-quality-profile-deactivate button-red disabled"
+  >
+    coding_rules.deactivate
+  </Button>
+</Tooltip>
+`;
index 08c54ee9a5bbf3694f33b0323e2995352eb7100f..4bb08dcb93c30a939c7448041c770f6f6d559077 100644 (file)
@@ -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: