]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-23189 Adjust Rule customization modal with Mode setting
authorViktor Vorona <viktor.vorona@sonarsource.com>
Thu, 17 Oct 2024 08:35:49 +0000 (10:35 +0200)
committersonartech <sonartech@sonarsource.com>
Thu, 17 Oct 2024 20:02:52 +0000 (20:02 +0000)
server/sonar-web/src/main/js/apps/coding-rules/__tests__/CodingRuleDetails-it.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
server/sonar-web/src/main/js/apps/coding-rules/utils-tests.tsx

index e9b4b398af5308a526bbec4227a13c4a2dbe72d3..fdf7ede0adea5481936ce1753eecb60fe5a18ca2 100644 (file)
@@ -219,7 +219,6 @@ it('can activate/change/deactivate rule in quality profile', async () => {
   await user.click(ui.activateButton.get());
 
   await user.click(ui.prioritizedSwitch.get());
-  await user.click(ui.mqrSwitch.get());
   await user.click(ui.newSeveritySelect(SoftwareQuality.Maintainability).get());
   await user.click(byRole('option', { name: 'severity_impact.LOW' }).get());
   await user.click(ui.activateButton.get(ui.activateQPDialog.get()));
@@ -241,7 +240,6 @@ it('can activate/change/deactivate rule in quality profile', async () => {
   await user.click(ui.changeButton('QP FooBaz').get());
   await user.clear(ui.paramInput('1').get());
   await user.type(ui.paramInput('1').get(), 'New');
-  await user.click(ui.mqrSwitch.get());
   await user.click(ui.newSeveritySelect(SoftwareQuality.Maintainability).get());
   await user.click(byRole('option', { name: 'severity_impact.BLOCKER' }).get());
   await user.click(ui.saveButton.get(ui.changeQPDialog.get()));
@@ -345,7 +343,6 @@ it('should show multiple customized severities', async () => {
   );
 
   await user.click(ui.changeButton('QP Bar').get());
-  await user.click(ui.mqrSwitch.get());
   await user.click(ui.newSeveritySelect(SoftwareQuality.Reliability).get());
   await user.click(
     byRole('option', { name: /coding_rules.custom_severity.severity_with_recommended/ }).get(),
index 6af1e298d4d25c4f41194bd35f4ab954da747020..711e7dbafb964105ed8a36bf7c2cdb50b7d046f7 100644 (file)
@@ -405,6 +405,10 @@ describe('Rules app list', () => {
   });
 
   describe('old severity', () => {
+    beforeEach(() => {
+      settingsHandler.set(SettingsKey.MQRMode, 'false');
+    });
+
     it('can activate/change/deactivate specific rule for quality profile', async () => {
       const { ui, user } = getPageObjects();
       rulesHandler.setIsAdmin();
@@ -565,8 +569,6 @@ describe('Rules app list', () => {
       // Activate Rule for qp
       await user.click(ui.activateButton.getAll()[1]);
 
-      await user.click(ui.mqrSwitch.get(ui.activateQPDialog.get()));
-
       expect(ui.newSeveritySelect(SoftwareQuality.Maintainability).get()).toHaveValue(
         'coding_rules.custom_severity.severity_with_recommended.severity_impact.MEDIUM',
       );
@@ -589,10 +591,6 @@ describe('Rules app list', () => {
       expect(ui.deactivateButton.getAll()).toHaveLength(1);
 
       await user.click(ui.changeButton('QP Bar').get());
-      expect(ui.oldSeveritySelect.get(ui.changeQPDialog.get())).toHaveValue('severity.MINOR');
-      expect(ui.notRecommendedSeverity.get()).toBeInTheDocument();
-      expect(ui.notRecommendedSeverity.get()).toHaveTextContent('severity.MAJOR');
-      await user.click(ui.mqrSwitch.get());
 
       expect(ui.newSeveritySelect(SoftwareQuality.Maintainability).get()).toHaveValue(
         'severity_impact.LOW',
@@ -613,11 +611,6 @@ describe('Rules app list', () => {
 
       // Check that new severity is saved
       await user.click(ui.changeButton('QP Bar').get());
-      await user.click(ui.mqrSwitch.get());
-      expect(ui.oldSeveritySelect.get(ui.changeQPDialog.get())).toHaveValue('severity.MINOR');
-      expect(ui.notRecommendedSeverity.get()).toBeInTheDocument();
-      expect(ui.notRecommendedSeverity.get()).toHaveTextContent('severity.MAJOR');
-      await user.click(ui.mqrSwitch.get());
 
       expect(ui.newSeveritySelect(SoftwareQuality.Maintainability).get()).toHaveValue(
         'severity_impact.LOW',
@@ -656,7 +649,6 @@ describe('Rules app list', () => {
 
       // Check that severity is reflected correctly
       await user.click(ui.changeButton('QP Bar').get());
-      await user.click(ui.mqrSwitch.get(ui.changeQPDialog.get()));
       expect(ui.newSeveritySelect(SoftwareQuality.Maintainability).get()).toHaveValue(
         'severity_impact.MEDIUM',
       );
@@ -710,7 +702,6 @@ describe('Rules app list', () => {
 
       // Check that severity is reflected correctly
       await user.click(ui.changeButton('QP Bar').get());
-      await user.click(ui.mqrSwitch.get(ui.changeQPDialog.get()));
       expect(ui.newSeveritySelect(SoftwareQuality.Reliability).get()).toHaveValue(
         'severity_impact.MEDIUM',
       );
@@ -737,7 +728,6 @@ describe('Rules app list', () => {
       expect(ui.changeButton('QP Bar').get()).toBeInTheDocument();
 
       await user.click(ui.changeButton('QP Bar').get());
-      await user.click(ui.mqrSwitch.get(ui.changeQPDialog.get()));
       expect(ui.newSeveritySelect(SoftwareQuality.Maintainability).get()).toHaveValue(
         'severity_impact.MEDIUM',
       );
index d4ab8d8557dacea1732369b9a8d0d7f003bd7ad2..34a2c6750f160c28e292ad91b71aac5a8cdda654 100644 (file)
@@ -27,7 +27,6 @@ import {
   Note,
   SafeHTMLInjection,
   SanitizeLevel,
-  Switch,
 } from 'design-system';
 import * as React from 'react';
 import { FormattedMessage, useIntl } from 'react-intl';
@@ -36,6 +35,7 @@ import { useAvailableFeatures } from '../../../app/components/available-features
 import DocumentationLink from '../../../components/common/DocumentationLink';
 import { DocLink } from '../../../helpers/doc-links';
 import { useActivateRuleMutation } from '../../../queries/quality-profiles';
+import { useStandardExperienceMode } from '../../../queries/settings';
 import { SoftwareImpactSeverity, SoftwareQuality } from '../../../types/clean-code-taxonomy';
 import { Feature } from '../../../types/features';
 import { IssueSeverity } from '../../../types/issues';
@@ -82,7 +82,7 @@ export default function ActivationFormModal(props: Readonly<Props>) {
   const [changedImpactSeveritiesMap, setChangedImpactSeverities] = React.useState<
     Map<SoftwareQuality, SoftwareImpactSeverity>
   >(new Map());
-  const [isMQRMode, setIsMQRMode] = React.useState<boolean>(false);
+  const { data: isStandardMode } = useStandardExperienceMode();
 
   const profilesWithDepth = React.useMemo(() => {
     return getQualityProfilesWithDepth(profiles, rule.lang);
@@ -126,9 +126,9 @@ export default function ActivationFormModal(props: Readonly<Props>) {
       key: profile?.key ?? '',
       params,
       rule: rule.key,
-      severity: !isMQRMode ? severity : undefined,
+      severity: isStandardMode ? severity : undefined,
       prioritizedRule,
-      impacts: isMQRMode
+      impacts: !isStandardMode
         ? (Object.fromEntries(impacts) as Record<SoftwareQuality, SoftwareImpactSeverity>)
         : undefined,
     };
@@ -238,11 +238,7 @@ export default function ActivationFormModal(props: Readonly<Props>) {
             </FormField>
           )}
 
-          <FormField label="MQR Mode">
-            <Switch value={isMQRMode} onChange={setIsMQRMode} />
-          </FormField>
-
-          {!isMQRMode && (
+          {isStandardMode && (
             <>
               <FormField label={intl.formatMessage({ id: 'coding_rules.custom_severity.title' })}>
                 <Text>
@@ -281,7 +277,7 @@ export default function ActivationFormModal(props: Readonly<Props>) {
             </>
           )}
 
-          {isMQRMode && (
+          {!isStandardMode && (
             <>
               <FormField label={intl.formatMessage({ id: 'coding_rules.custom_severity.title' })}>
                 <Text>
index 29b0f06e319ca12a3e0852c6c93b6e66737d4df4..ca442e529077343909abe52c83b4edc3392fb491 100644 (file)
@@ -171,7 +171,7 @@ export default function RuleDetailsProfiles(props: Readonly<Props>) {
               </>
             )}
             {!isStandardMode &&
-              activation.impacts &&
+              Boolean(activation.impacts?.length) &&
               !isEqual(
                 [...activation.impacts].sort(sortImpacts),
                 [...ruleDetails.impacts].sort(sortImpacts),
index 6ae58cfd19a73d91d3f052059a17df94b23b7f92..171143c0eaca053e00a645a8f035895a79aa7dd5 100644 (file)
@@ -163,7 +163,6 @@ const selectors = {
   }),
   qualityProfileSelect: byRole('combobox', { name: 'coding_rules.quality_profile' }),
   oldSeveritySelect: byRole('combobox', { name: 'coding_rules.custom_severity.choose_severity' }),
-  mqrSwitch: byRole('switch'),
   newSeveritySelect: (quality: SoftwareQuality) =>
     byRole('combobox', { name: `software_quality.${quality}` }),
   notRecommendedSeverity: byText('coding_rules.custom_severity.not_recommended'),