From: Jeremy Davis Date: Tue, 26 Sep 2023 12:22:59 +0000 (+0200) Subject: SONAR-20500 Migrate custom rule form to the new UI X-Git-Tag: 10.3.0.82913~272 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=4d5ab47cfc972316a074a1a7a269f7eb76548ace;p=sonarqube.git SONAR-20500 Migrate custom rule form to the new UI --- diff --git a/server/sonar-web/src/main/js/apps/coding-rules/components/CustomRuleFormModal.tsx b/server/sonar-web/src/main/js/apps/coding-rules/components/CustomRuleFormModal.tsx index 60daacdc04b..c81c1a1238c 100644 --- a/server/sonar-web/src/main/js/apps/coding-rules/components/CustomRuleFormModal.tsx +++ b/server/sonar-web/src/main/js/apps/coding-rules/components/CustomRuleFormModal.tsx @@ -17,23 +17,30 @@ * along with this program; if not, write to the Free Software Foundation, * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ +import { HttpStatusCode } from 'axios'; +import { + ButtonPrimary, + FlagMessage, + FormField, + InputField, + InputSelect, + InputTextArea, + LabelValueSelectOption, + LightLabel, + Modal, +} from 'design-system'; import * as React from 'react'; -import { components, OptionProps, SingleValueProps } from 'react-select'; +import { OptionProps, SingleValueProps, components } from 'react-select'; import { createRule, updateRule } from '../../../api/rules'; import FormattingTips from '../../../components/common/FormattingTips'; -import { ResetButtonLink, SubmitButton } from '../../../components/controls/buttons'; -import Modal from '../../../components/controls/Modal'; -import Select, { LabelValueSelectOption } from '../../../components/controls/Select'; import TypeHelper from '../../../components/shared/TypeHelper'; -import { Alert } from '../../../components/ui/Alert'; -import MandatoryFieldMarker from '../../../components/ui/MandatoryFieldMarker'; import MandatoryFieldsExplanation from '../../../components/ui/MandatoryFieldsExplanation'; import { RULE_STATUSES, RULE_TYPES } from '../../../helpers/constants'; import { csvEscape } from '../../../helpers/csv'; import { translate } from '../../../helpers/l10n'; import { sanitizeString } from '../../../helpers/sanitize'; import { latinize } from '../../../helpers/strings'; -import { Dict, RuleDetails, RuleParameter, RuleType } from '../../../types/types'; +import { Dict, RuleDetails, RuleParameter, RuleType, Status } from '../../../types/types'; import { SeveritySelect } from './SeveritySelect'; interface Props { @@ -56,28 +63,30 @@ interface State { type: RuleType; } +const FORM_ID = 'custom-rule-form'; + export default class CustomRuleFormModal extends React.PureComponent { mounted = false; constructor(props: Props) { super(props); const params: Dict = {}; - if (props.customRule && props.customRule.params) { + if (props.customRule?.params) { for (const param of props.customRule.params) { - params[param.key] = param.defaultValue || ''; + params[param.key] = param.defaultValue ?? ''; } } this.state = { - description: (props.customRule && props.customRule.mdDesc) || '', + description: props.customRule?.mdDesc ?? '', key: '', keyModifiedByUser: false, - name: (props.customRule && props.customRule.name) || '', + name: props.customRule?.name ?? '', params, reactivating: false, - severity: (props.customRule && props.customRule.severity) || props.templateRule.severity, - status: (props.customRule && props.customRule.status) || props.templateRule.status, + severity: props.customRule?.severity ?? props.templateRule.severity, + status: props.customRule?.status ?? props.templateRule.status, submitting: false, - type: (props.customRule && props.customRule.type) || props.templateRule.type, + type: props.customRule?.type ?? props.templateRule.type, }; } @@ -124,7 +133,10 @@ export default class CustomRuleFormModal extends React.PureComponent { if (this.mounted) { - this.setState({ reactivating: response.status === 409, submitting: false }); + this.setState({ + reactivating: response.status === HttpStatusCode.Conflict, + submitting: false, + }); } }, ); @@ -149,7 +161,8 @@ export default class CustomRuleFormModal extends React.PureComponent this.setState({ severity: value }); - handleStatusChange = ({ value }: LabelValueSelectOption) => this.setState({ status: value }); + handleStatusChange = ({ value }: LabelValueSelectOption) => + this.setState({ status: value }); handleParameterChange = (event: React.SyntheticEvent) => { const { name, value } = event.currentTarget; @@ -157,61 +170,66 @@ export default class CustomRuleFormModal extends React.PureComponent ( -
- - + -
+ ); renderKeyField = () => ( -
- - + {this.props.customRule ? ( - - {this.props.customRule.key} - + {this.props.customRule.key} ) : ( - )} -
+ ); renderDescriptionField = () => ( -
- -