diff options
author | 7PH <benjamin.raymond@sonarsource.com> | 2023-10-31 16:00:58 +0100 |
---|---|---|
committer | sonartech <sonartech@sonarsource.com> | 2023-11-02 20:02:42 +0000 |
commit | 40676ad36508fdc175afcf1c739a31c475188bc0 (patch) | |
tree | 460d1320bbca6c0820eab7beb520ce37fe88be21 /server/sonar-web | |
parent | f05332a75d430c3b8899c5e4efad56e1d534bf33 (diff) | |
download | sonarqube-40676ad36508fdc175afcf1c739a31c475188bc0.tar.gz sonarqube-40676ad36508fdc175afcf1c739a31c475188bc0.zip |
SONAR-20931 Reintroduce changing rule severity in quality profiles
Diffstat (limited to 'server/sonar-web')
7 files changed, 40 insertions, 15 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<string>; profile?: ProfileWithDepth; submitting: boolean; + severity: IssueSeverity; } const MIN_PROFILES_TO_ENABLE_SELECT = 2; @@ -69,6 +72,9 @@ export default class ActivationFormModal extends React.PureComponent<Props, Stat params: this.getParams(props), profile: profilesWithDepth.length > 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<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: 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<Props, Stat this.setState({ profile: value.value }); }; + handleSeverityChange = ({ value }: LabelValueSelectOption<IssueSeverity>) => { + 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<Props, Stat )} <FlagMessage className="sw-mb-4" variant="info"> - {translate('coding_rules.severity_cannot_be_modified')} - <DocumentationLink className="sw-ml-2" to="/user-guide/clean-code/"> + {translate('coding_rules.severity_deprecated')} + <DocLink className="sw-ml-2 sw-whitespace-nowrap" to="/user-guide/clean-code/"> {translate('learn_more')} - </DocumentationLink> + </DocLink> </FlagMessage> <FormField @@ -203,6 +212,19 @@ export default class ActivationFormModal extends React.PureComponent<Props, Stat value={profileOptions.find(({ value }) => value.key === profile?.key)} /> </FormField> + + <FormField + ariaLabel={translate('severity')} + label={translate('severity')} + htmlFor="coding-rules-severity-select" + > + <SeveritySelect + isDisabled={submitting} + onChange={this.handleSeverityChange} + severity={severity} + /> + </FormField> + {isCustomRule ? ( <Note as="p" className="sw-my-4"> {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<Props> { <ActionCell> {canEdit && ( <> - {!ruleDetails.isTemplate && !!ruleDetails.params?.length && ( + {!ruleDetails.isTemplate && ( <ActivationButton activation={activation} ariaLabel={translateWithParameters('coding_rules.change_details_x', profile.name)} 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 e3aa374c81b..cb8a484168f 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 @@ -145,7 +145,7 @@ const selectors = { qpLink: (name: string) => 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 ( <div className="nowrap"> - {translate('quality_profiles.severity_set_to')} <SeverityHelper severity={severity} /> + {translate('quality_profiles.deprecated_severity_set_to')}{' '} + <SeverityHelper severity={severity} /> </div> ); } 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 ( <span className={className}> - <SeverityIcon className="little-spacer-right" fill={fill} severity={severity} aria-hidden /> + <SeverityIcon className="sw-mr-1" fill={fill} severity={severity} aria-hidden /> {translate('severity', severity)} </span> ); |