]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-20023 Disable severity change in rules page
authorstanislavh <stanislav.honcharov@sonarsource.com>
Wed, 9 Aug 2023 11:11:09 +0000 (13:11 +0200)
committersonartech <sonartech@sonarsource.com>
Fri, 18 Aug 2023 20:02:49 +0000 (20:02 +0000)
server/sonar-web/src/main/js/api/mocks/CodingRulesServiceMock.ts
server/sonar-web/src/main/js/apps/coding-rules/__tests__/CodingRules-it.ts
server/sonar-web/src/main/js/apps/coding-rules/components/ActivationFormModal.tsx
server/sonar-web/src/main/js/apps/coding-rules/components/RuleDetailsProfiles.tsx
sonar-core/src/main/resources/org/sonar/l10n/core.properties

index 0ced6d90130dbb648b375af9ce6c349b27894026..74a3b51f0a126efce5f0aa5dfc98af413fc3a9bc 100644 (file)
@@ -474,7 +474,11 @@ export default class CodingRulesServiceMock {
     rule: string;
     severity?: string;
   }) => {
-    const nextActivation = mockRuleActivation({ qProfile: data.key, severity: data.severity });
+    const nextActivation = mockRuleActivation({
+      qProfile: data.key,
+      severity: data.severity,
+      params: Object.entries(data.params ?? {}).map(([key, value]) => ({ key, value })),
+    });
 
     if (!this.rulesActivations[data.rule]) {
       this.rulesActivations[data.rule] = [nextActivation];
index 53628be7fc66c0799da10cb27ccf1eb39f5be5bf..15777d0dffb3c83239134a4edd4a57e27ecd09e3 100644 (file)
@@ -502,17 +502,16 @@ describe('Rule app details', () => {
     // Activate rule in quality profile
     await user.click(ui.activateButton.get());
     await selectEvent.select(ui.qualityProfileSelect.get(), 'QP FooBar');
-    await selectEvent.select(ui.severitySelect.get(), 'severity.MINOR');
-    await user.type(ui.paramInput('1').get(), 'OK');
+    await user.type(ui.paramInput('1').get(), 'paramInput');
 
     await act(() => user.click(ui.activateButton.get(ui.activateQPDialog.get())));
     expect(ui.qpLink('QP FooBar').get()).toBeInTheDocument();
 
     // Change rule details in quality profile
     await user.click(ui.changeButton('QP FooBar').get());
-    await selectEvent.select(ui.severitySelect.get(), 'severity.BLOCKER');
+    await user.type(ui.paramInput('1').get(), 'New');
     await act(() => user.click(ui.saveButton.get(ui.changeQPDialog.get())));
-    expect(screen.getByText('severity.BLOCKER')).toBeInTheDocument();
+    expect(screen.getByText('paramInputNew')).toBeInTheDocument();
 
     // activate last java rule
     await user.click(ui.activateButton.get());
index 60cae4ab9cc4abf06a27af6e96574c9b0f86a2f6..99bb67dac32f293b4d2398ce2f8eccd468139d2e 100644 (file)
 import classNames from 'classnames';
 import * as React from 'react';
 import { activateRule, Profile } from '../../../api/quality-profiles';
+import DocLink from '../../../components/common/DocLink';
 import { ResetButtonLink, SubmitButton } from '../../../components/controls/buttons';
 import Modal from '../../../components/controls/Modal';
-import Select, { LabelValueSelectOption } from '../../../components/controls/Select';
+import Select from '../../../components/controls/Select';
 import { Alert } from '../../../components/ui/Alert';
 import { translate } from '../../../helpers/l10n';
 import { sanitizeString } from '../../../helpers/sanitize';
 import { Dict, Rule, RuleActivation, RuleDetails } from '../../../types/types';
 import { sortProfiles } from '../../quality-profiles/utils';
-import { SeveritySelect } from './SeveritySelect';
 
 interface Props {
   activation?: RuleActivation;
@@ -47,7 +47,6 @@ interface ProfileWithDeph extends Profile {
 interface State {
   params: Dict<string>;
   profile?: ProfileWithDeph;
-  severity: string;
   submitting: boolean;
 }
 
@@ -60,7 +59,6 @@ export default class ActivationFormModal extends React.PureComponent<Props, Stat
     this.state = {
       params: this.getParams(props),
       profile: profilesWithDepth.length > 0 ? profilesWithDepth[0] : undefined,
-      severity: props.activation ? props.activation.severity : props.rule.severity,
       submitting: false,
     };
   }
@@ -106,13 +104,14 @@ export default class ActivationFormModal extends React.PureComponent<Props, Stat
   };
 
   handleFormSubmit = (event: React.SyntheticEvent<HTMLFormElement>) => {
+    const { activation, rule } = this.props;
     event.preventDefault();
     this.setState({ submitting: true });
     const data = {
       key: this.state.profile?.key || '',
       params: this.state.params,
       rule: this.props.rule.key,
-      severity: this.state.severity,
+      severity: activation ? activation.severity : rule.severity,
     };
     activateRule(data)
       .then(() => this.props.onDone(data.severity))
@@ -140,13 +139,9 @@ export default class ActivationFormModal extends React.PureComponent<Props, Stat
     this.setState({ profile });
   };
 
-  handleSeverityChange = ({ value }: LabelValueSelectOption) => {
-    this.setState({ severity: value });
-  };
-
   render() {
     const { activation, rule } = this.props;
-    const { profile, severity, submitting } = this.state;
+    const { profile, submitting } = this.state;
     const { params = [] } = rule;
     const profilesWithDepth = this.getQualityProfilesWithDepth();
     const isCustomRule = !!(rule as RuleDetails).templateKey;
@@ -165,6 +160,13 @@ export default class ActivationFormModal extends React.PureComponent<Props, Stat
               <Alert variant="info">{translate('coding_rules.active_in_all_profiles')}</Alert>
             )}
 
+            <Alert variant="info">
+              {translate('coding_rules.severity_cannot_be_modified')}
+              <DocLink className="spacer-left" to="/user-guide/clean-code/">
+                {translate('learn_more')}
+              </DocLink>
+            </Alert>
+
             <div className="modal-field">
               <label id="coding-rules-quality-profile-select-label">
                 {translate('coding_rules.quality_profile')}
@@ -180,15 +182,6 @@ export default class ActivationFormModal extends React.PureComponent<Props, Stat
                 value={profile}
               />
             </div>
-            <div className="modal-field">
-              <label id="coding-rules-severity-select-label">{translate('severity')}</label>
-              <SeveritySelect
-                isDisabled={submitting}
-                ariaLabelledby="coding-rules-severity-select-label"
-                onChange={this.handleSeverityChange}
-                severity={severity}
-              />
-            </div>
             {isCustomRule ? (
               <div className="modal-field">
                 <p className="note">{translate('coding_rules.custom_rule.activation_notice')}</p>
index a424a638e357957b6127d27f3e6e3237912b4ff7..e2b7b9790cfa26286ed04126a5ed201ee0ab6023 100644 (file)
@@ -132,7 +132,7 @@ export default class RuleDetailsProfiles extends React.PureComponent<Props> {
       <td className="coding-rules-detail-quality-profile-actions">
         {canEdit && (
           <>
-            {!ruleDetails.isTemplate && (
+            {!ruleDetails.isTemplate && !!ruleDetails.params?.length && (
               <ActivationButton
                 activation={activation}
                 ariaLabel={translateWithParameters('coding_rules.change_details_x', profile.name)}
index 0e5e2afacc0a13ef6089b76e6073d4679eaa3eb6..75c058e9e8191dc09762f24ae96ecaffcf221d5c 100644 (file)
@@ -2204,6 +2204,7 @@ rules.status.REMOVED.help=The rule that generated this issue has been removed. S
 #
 #------------------------------------------------------------------------------
 coding_rules.active_in_all_profiles=The rule is already activated on all available Quality Profiles.
+coding_rules.severity_cannot_be_modified=Severity can no longer me modified.
 coding_rules.activate=Activate
 coding_rules.activate_in=Activate In
 coding_rules.activate_in_quality_profile=Activate In Quality Profile