From 40676ad36508fdc175afcf1c739a31c475188bc0 Mon Sep 17 00:00:00 2001 From: 7PH Date: Tue, 31 Oct 2023 16:00:58 +0100 Subject: [PATCH] SONAR-20931 Reintroduce changing rule severity in quality profiles --- .../coding-rules/__tests__/CodingRules-it.ts | 4 ++- .../components/ActivationFormModal.tsx | 36 +++++++++++++++---- .../components/RuleDetailsProfiles.tsx | 2 +- .../main/js/apps/coding-rules/utils-tests.tsx | 2 +- .../changelog/SeverityChange.tsx | 3 +- .../__tests__/ChangelogContainer-it.tsx | 6 ++-- .../js/components/shared/SeverityHelper.tsx | 2 +- .../resources/org/sonar/l10n/core.properties | 6 ++-- 8 files changed, 43 insertions(+), 18 deletions(-) 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 cc55cd5439c..625feb6b9fa 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 @@ -363,7 +363,9 @@ describe('Rules app list', () => { // Activate Rule for qp await user.click(ui.activateButton.getAll()[0]); + await selectEvent.select(ui.oldSeveritySelect.get(), 'severity.MINOR'); await user.click(ui.activateButton.get(ui.activateQPDialog.get())); + expect(ui.activateButton.getAll()).toHaveLength(1); expect(ui.deactivateButton.getAll()).toHaveLength(1); @@ -707,7 +709,7 @@ describe('Rule app details', () => { await user.type(ui.keyTextbox.get(), 'new_custom_rule'); await selectEvent.select(ui.typeSelect.get(), 'issue.type.BUG'); - await selectEvent.select(ui.severitySelect.get(), 'severity.MINOR'); + await selectEvent.select(ui.oldSeveritySelect.get(), 'severity.MINOR'); await selectEvent.select(ui.statusSelect.get(), 'rules.status.BETA'); await user.type(ui.descriptionTextbox.get(), 'Some description for custom rule'); 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 364ff9b39ab..f1edb4ec687 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 @@ -30,11 +30,13 @@ import { } from 'design-system'; import * as React from 'react'; import { Profile, activateRule } from '../../../api/quality-profiles'; -import DocumentationLink from '../../../components/common/DocumentationLink'; +import DocLink from '../../../components/common/DocLink'; import { translate } from '../../../helpers/l10n'; import { sanitizeString } from '../../../helpers/sanitize'; +import { IssueSeverity } from '../../../types/issues'; import { Dict, Rule, RuleActivation, RuleDetails } from '../../../types/types'; import { sortProfiles } from '../../quality-profiles/utils'; +import { SeveritySelect } from './SeveritySelect'; interface Props { activation?: RuleActivation; @@ -54,6 +56,7 @@ interface State { params: Dict; profile?: ProfileWithDepth; submitting: boolean; + severity: IssueSeverity; } const MIN_PROFILES_TO_ENABLE_SELECT = 2; @@ -69,6 +72,9 @@ export default class ActivationFormModal extends React.PureComponent 0 ? profilesWithDepth[0] : undefined, submitting: false, + severity: (props.activation + ? props.activation.severity + : props.rule.severity) as IssueSeverity, }; } @@ -113,14 +119,13 @@ export default class ActivationFormModal extends React.PureComponent) => { - 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: activation ? activation.severity : rule.severity, + severity: this.state.severity, }; activateRule(data) .then(() => this.props.onDone(data.severity)) @@ -148,9 +153,13 @@ export default class ActivationFormModal extends React.PureComponent) => { + this.setState({ severity: value }); + }; + render() { const { activation, rule } = this.props; - const { profile, submitting } = this.state; + const { profile, severity, submitting } = this.state; const { params = [] } = rule; const profilesWithDepth = this.getQualityProfilesWithDepth(); const profileOptions = profilesWithDepth.map((p) => ({ label: p.name, value: p })); @@ -179,10 +188,10 @@ export default class ActivationFormModal extends React.PureComponent - {translate('coding_rules.severity_cannot_be_modified')} - + {translate('coding_rules.severity_deprecated')} + {translate('learn_more')} - + value.key === profile?.key)} /> + + + + + {isCustomRule ? ( {translate('coding_rules.custom_rule.activation_notice')} 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 8bb95b02829..f1776c6052f 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 @@ -138,7 +138,7 @@ export default class RuleDetailsProfiles extends React.PureComponent { {canEdit && ( <> - {!ruleDetails.isTemplate && !!ruleDetails.params?.length && ( + {!ruleDetails.isTemplate && ( byRole('link', { name }), activateButton: byRole('button', { name: 'coding_rules.activate' }), deactivateButton: byRole('button', { name: 'coding_rules.deactivate' }), - severitySelect: byRole('combobox', { name: 'severity' }), + oldSeveritySelect: byRole('combobox', { name: 'severity' }), qualityProfileSelect: byRole('combobox', { name: 'coding_rules.quality_profile' }), activateQPDialog: byRole('dialog', { name: 'coding_rules.activate_in_quality_profile' }), changeButton: (profile: string) => diff --git a/server/sonar-web/src/main/js/apps/quality-profiles/changelog/SeverityChange.tsx b/server/sonar-web/src/main/js/apps/quality-profiles/changelog/SeverityChange.tsx index b9908cdcb1c..23b3c96e39f 100644 --- a/server/sonar-web/src/main/js/apps/quality-profiles/changelog/SeverityChange.tsx +++ b/server/sonar-web/src/main/js/apps/quality-profiles/changelog/SeverityChange.tsx @@ -28,7 +28,8 @@ interface Props { export default function SeverityChange({ severity }: Props) { return (
- {translate('quality_profiles.severity_set_to')} + {translate('quality_profiles.deprecated_severity_set_to')}{' '} +
); } diff --git a/server/sonar-web/src/main/js/apps/quality-profiles/changelog/__tests__/ChangelogContainer-it.tsx b/server/sonar-web/src/main/js/apps/quality-profiles/changelog/__tests__/ChangelogContainer-it.tsx index a7cb0ce7fa3..b2e05bc57ec 100644 --- a/server/sonar-web/src/main/js/apps/quality-profiles/changelog/__tests__/ChangelogContainer-it.tsx +++ b/server/sonar-web/src/main/js/apps/quality-profiles/changelog/__tests__/ChangelogContainer-it.tsx @@ -93,7 +93,7 @@ it('should see the changelog', async () => { 'System', 'quality_profiles.changelog.DEACTIVATED', 'Rule 0issue.clean_code_attribute_category.RESPONSIBLE.title_shortsoftware_quality.SECURITYsoftware_quality.MAINTAINABILITY', - [/quality_profiles.severity_set_to severity.MAJOR/], + [/quality_profiles.deprecated_severity_set_to severity.MAJOR/], ); ui.checkRow( 3, @@ -102,7 +102,7 @@ it('should see the changelog', async () => { '', 'Rule 1issue.clean_code_attribute_category.RESPONSIBLE.title_shortsoftware_quality.SECURITYsoftware_quality.MAINTAINABILITY', [ - /quality_profiles.severity_set_to severity.CRITICAL/, + /quality_profiles.deprecated_severity_set_to severity.CRITICAL/, /quality_profiles.changelog.cca_and_category_changed.*COMPLETE.*INTENTIONAL.*LAWFUL.*RESPONSIBLE/, /quality_profiles.changelog.impact_added.severity.*MEDIUM.*RELIABILITY/, /quality_profiles.changelog.impact_removed.severity.HIGH.*MAINTAINABILITY/, @@ -153,7 +153,7 @@ it('should see short changelog for php', async () => { const rows = await ui.row.findAll(); expect(rows).toHaveLength(2); ui.checkRow(1, 'May 23, 2019', 'System', 'quality_profiles.changelog.DEACTIVATED', 'PHP Rule', [ - /quality_profiles.severity_set_to severity.CRITICAL/, + /quality_profiles.deprecated_severity_set_to severity.CRITICAL/, /quality_profiles.changelog.cca_and_category_changed.*COMPLETE.*INTENTIONAL.*CLEAR.*RESPONSIBLE/, ]); expect(ui.showMore.query()).not.toBeInTheDocument(); diff --git a/server/sonar-web/src/main/js/components/shared/SeverityHelper.tsx b/server/sonar-web/src/main/js/components/shared/SeverityHelper.tsx index c88881d28ba..242c4933422 100644 --- a/server/sonar-web/src/main/js/components/shared/SeverityHelper.tsx +++ b/server/sonar-web/src/main/js/components/shared/SeverityHelper.tsx @@ -33,7 +33,7 @@ export default function SeverityHelper({ className, severity, fill }: Props) { } return ( - + {translate('severity', severity)} ); 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 30f8f348584..f24fae9f333 100644 --- a/sonar-core/src/main/resources/org/sonar/l10n/core.properties +++ b/sonar-core/src/main/resources/org/sonar/l10n/core.properties @@ -2016,7 +2016,7 @@ quality_profiles.copy_x_title=Copy Profile "{0}" - {1} quality_profiles.extend_x_title=Extend Profile "{0}" - {1} quality_profiles.rename_x_title=Rename Profile {0} - {1} quality_profiles.deprecated=deprecated -quality_profiles.severity_set_to=Severity set to +quality_profiles.deprecated_severity_set_to=Old severity set to quality_profiles.changelog.ACTIVATED=Activated quality_profiles.changelog.DEACTIVATED=Deactivated quality_profiles.changelog.UPDATED=Updated @@ -2266,7 +2266,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 be modified. +coding_rules.severity_deprecated=Changing rule severities is deprecated and will not be possible in the future. coding_rules.activate=Activate coding_rules.activate_in=Activate In coding_rules.activate_in_quality_profile=Activate In Quality Profile @@ -2343,7 +2343,7 @@ coding_rules.to_select_rules=Select rules coding_rules.to_navigate=Navigate to rule coding_rules.type.deprecation.title=Types of detection rules are deprecated. coding_rules.type.deprecation.filter_by=You can now filter rules by Clean Code Attribute and Software Quality. -coding_rules.severity.deprecation.title=Severities are now directly tied to the software quality impacted. This old severity is deprecated and can no longer be modified. +coding_rules.severity.deprecation.title=Severities are now directly tied to the software quality impacted. This old severity is deprecated and it will no longer be possible to change it in the future. coding_rules.severity.deprecation.filter_by=You can now filter rules by Software Quality and new Severity. coding_rules.update_custom_rule=Update Custom Rule -- 2.39.5