diff options
author | stanislavh <stanislav.honcharov@sonarsource.com> | 2023-08-09 13:11:09 +0200 |
---|---|---|
committer | sonartech <sonartech@sonarsource.com> | 2023-08-18 20:02:49 +0000 |
commit | 09a45741162362db5fcf1cdf55fbd43b89785523 (patch) | |
tree | 82d8df27a639c17250c2aadfaecb92ec1988c9b9 /server | |
parent | d41ab5c049a2634df40294d019cb689880ab20a2 (diff) | |
download | sonarqube-09a45741162362db5fcf1cdf55fbd43b89785523.tar.gz sonarqube-09a45741162362db5fcf1cdf55fbd43b89785523.zip |
SONAR-20023 Disable severity change in rules page
Diffstat (limited to 'server')
4 files changed, 21 insertions, 25 deletions
diff --git a/server/sonar-web/src/main/js/api/mocks/CodingRulesServiceMock.ts b/server/sonar-web/src/main/js/api/mocks/CodingRulesServiceMock.ts index 0ced6d90130..74a3b51f0a1 100644 --- a/server/sonar-web/src/main/js/api/mocks/CodingRulesServiceMock.ts +++ b/server/sonar-web/src/main/js/api/mocks/CodingRulesServiceMock.ts @@ -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]; 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 53628be7fc6..15777d0dffb 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 @@ -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()); 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 60cae4ab9cc..99bb67dac32 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 @@ -20,15 +20,15 @@ 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> 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 a424a638e35..e2b7b9790cf 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 @@ -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)} |