From b5cbc1d5b142b64cd406badfb15a011ec344fecf Mon Sep 17 00:00:00 2001 From: Mathieu Suen Date: Fri, 25 Mar 2022 12:04:10 +0100 Subject: [PATCH] SONAR-16085 Migrating custom rule modal to new react-select --- .../components/ActivationFormModal.tsx | 36 +-- .../components/CustomRuleFormModal.tsx | 127 +++++----- .../components/SeveritySelect.tsx | 69 ++++++ .../ActivationFormModal-test.tsx.snap | 220 ++---------------- .../CustomRuleFormModal-test.tsx.snap | 164 ++++++------- .../src/main/js/apps/coding-rules/styles.css | 3 +- 6 files changed, 227 insertions(+), 392 deletions(-) create mode 100644 server/sonar-web/src/main/js/apps/coding-rules/components/SeveritySelect.tsx 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 97a0c93be8e..d405bbd13eb 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 @@ -19,18 +19,17 @@ */ import classNames from 'classnames'; import * as React from 'react'; -import { components, OptionProps, OptionTypeBase, SingleValueProps } from 'react-select'; +import { OptionTypeBase } from 'react-select'; import { activateRule, Profile } from '../../../api/quality-profiles'; import { ResetButtonLink, SubmitButton } from '../../../components/controls/buttons'; import Modal from '../../../components/controls/Modal'; import Select from '../../../components/controls/Select'; -import SeverityHelper from '../../../components/shared/SeverityHelper'; import { Alert } from '../../../components/ui/Alert'; -import { SEVERITIES } from '../../../helpers/constants'; 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; @@ -153,26 +152,6 @@ export default class ActivationFormModal extends React.PureComponent ({ - label: translate('severity', severity), - value: severity - })); - - function Option(props: OptionProps) { - return ( - - - - ); - } - - function SingleValue(props: SingleValueProps) { - return ( - - - - ); - } return ( @@ -203,16 +182,11 @@ export default class ActivationFormModal extends React.PureComponent
- t.value === this.state.type)} + /> +
+ ); + }; renderSeverityField = () => (
- - {translate('severity')} + ({ - label: translate('severity', severity), - value: severity - }))} - searchable={false} - value={this.state.severity} - valueRenderer={this.renderSeverityOption} + severity={this.state.severity} />
); - renderStatusField = () => ( -
- - ({ - label: translate('rules.status', status), - value: status - }))} - searchable={false} - value={this.state.status} - /> -
- ); + renderStatusField = () => { + const statusesOptions = RULE_STATUSES.map(status => ({ + label: translate('rules.status', status), + value: status + })); + return ( +
+ + s.value === severity)} + /> + ); +} diff --git a/server/sonar-web/src/main/js/apps/coding-rules/components/__tests__/__snapshots__/ActivationFormModal-test.tsx.snap b/server/sonar-web/src/main/js/apps/coding-rules/components/__tests__/__snapshots__/ActivationFormModal-test.tsx.snap index ccfb4ebf108..8806948181a 100644 --- a/server/sonar-web/src/main/js/apps/coding-rules/components/__tests__/__snapshots__/ActivationFormModal-test.tsx.snap +++ b/server/sonar-web/src/main/js/apps/coding-rules/components/__tests__/__snapshots__/ActivationFormModal-test.tsx.snap @@ -50,49 +50,11 @@ exports[`should render correctly: custom rule 1`] = ` > severity -
severity -
severity -