From: Viktor Vorona Date: Thu, 17 Oct 2024 08:35:49 +0000 (+0200) Subject: SONAR-23189 Adjust Rule customization modal with Mode setting X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=cd9ce2d757b33a9725ad4a1dc4d3724aef3d0c21;p=sonarqube.git SONAR-23189 Adjust Rule customization modal with Mode setting --- diff --git a/server/sonar-web/src/main/js/apps/coding-rules/__tests__/CodingRuleDetails-it.ts b/server/sonar-web/src/main/js/apps/coding-rules/__tests__/CodingRuleDetails-it.ts index e9b4b398af5..fdf7ede0ade 100644 --- a/server/sonar-web/src/main/js/apps/coding-rules/__tests__/CodingRuleDetails-it.ts +++ b/server/sonar-web/src/main/js/apps/coding-rules/__tests__/CodingRuleDetails-it.ts @@ -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(), diff --git a/server/sonar-web/src/main/js/apps/coding-rules/__tests__/CodingRules-it.ts b/server/sonar-web/src/main/js/apps/coding-rules/__tests__/CodingRules-it.ts index 6af1e298d4d..711e7dbafb9 100644 --- a/server/sonar-web/src/main/js/apps/coding-rules/__tests__/CodingRules-it.ts +++ b/server/sonar-web/src/main/js/apps/coding-rules/__tests__/CodingRules-it.ts @@ -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', ); diff --git a/server/sonar-web/src/main/js/apps/coding-rules/components/ActivationFormModal.tsx b/server/sonar-web/src/main/js/apps/coding-rules/components/ActivationFormModal.tsx index d4ab8d8557d..34a2c6750f1 100644 --- a/server/sonar-web/src/main/js/apps/coding-rules/components/ActivationFormModal.tsx +++ b/server/sonar-web/src/main/js/apps/coding-rules/components/ActivationFormModal.tsx @@ -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) { const [changedImpactSeveritiesMap, setChangedImpactSeverities] = React.useState< Map >(new Map()); - const [isMQRMode, setIsMQRMode] = React.useState(false); + const { data: isStandardMode } = useStandardExperienceMode(); const profilesWithDepth = React.useMemo(() => { return getQualityProfilesWithDepth(profiles, rule.lang); @@ -126,9 +126,9 @@ export default function ActivationFormModal(props: Readonly) { 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) : undefined, }; @@ -238,11 +238,7 @@ export default function ActivationFormModal(props: Readonly) { )} - - - - - {!isMQRMode && ( + {isStandardMode && ( <> @@ -281,7 +277,7 @@ export default function ActivationFormModal(props: Readonly) { )} - {isMQRMode && ( + {!isStandardMode && ( <> diff --git a/server/sonar-web/src/main/js/apps/coding-rules/components/RuleDetailsProfiles.tsx b/server/sonar-web/src/main/js/apps/coding-rules/components/RuleDetailsProfiles.tsx index 29b0f06e319..ca442e52907 100644 --- a/server/sonar-web/src/main/js/apps/coding-rules/components/RuleDetailsProfiles.tsx +++ b/server/sonar-web/src/main/js/apps/coding-rules/components/RuleDetailsProfiles.tsx @@ -171,7 +171,7 @@ export default function RuleDetailsProfiles(props: Readonly) { )} {!isStandardMode && - activation.impacts && + Boolean(activation.impacts?.length) && !isEqual( [...activation.impacts].sort(sortImpacts), [...ruleDetails.impacts].sort(sortImpacts), diff --git a/server/sonar-web/src/main/js/apps/coding-rules/utils-tests.tsx b/server/sonar-web/src/main/js/apps/coding-rules/utils-tests.tsx index 6ae58cfd19a..171143c0eac 100644 --- a/server/sonar-web/src/main/js/apps/coding-rules/utils-tests.tsx +++ b/server/sonar-web/src/main/js/apps/coding-rules/utils-tests.tsx @@ -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'),