From 562b9dacb912c64a4c048c03bdc9a7e2505a4bbe Mon Sep 17 00:00:00 2001 From: Pascal Mugnier Date: Wed, 9 May 2018 07:27:30 +0200 Subject: [PATCH] Fix SONAR-10640 --- .../components/AddConditionButton.tsx | 70 +++++++++++++ .../components/AddConditionSelect.tsx | 14 ++- .../components/ConditionModal.tsx | 97 +++++++++++++++++++ .../components/ConditionOperator.tsx | 63 ++++++++++++ .../quality-gates/components/Conditions.tsx | 4 + 5 files changed, 240 insertions(+), 8 deletions(-) create mode 100644 server/sonar-web/src/main/js/apps/quality-gates/components/AddConditionButton.tsx create mode 100644 server/sonar-web/src/main/js/apps/quality-gates/components/ConditionModal.tsx create mode 100644 server/sonar-web/src/main/js/apps/quality-gates/components/ConditionOperator.tsx diff --git a/server/sonar-web/src/main/js/apps/quality-gates/components/AddConditionButton.tsx b/server/sonar-web/src/main/js/apps/quality-gates/components/AddConditionButton.tsx new file mode 100644 index 00000000000..48943131904 --- /dev/null +++ b/server/sonar-web/src/main/js/apps/quality-gates/components/AddConditionButton.tsx @@ -0,0 +1,70 @@ +/* + * SonarQube + * Copyright (C) 2009-2018 SonarSource SA + * mailto:info AT sonarsource DOT com + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ +import * as React from 'react'; +import ConditionModal from './ConditionModal'; +import { Button } from '../../../components/ui/buttons'; +import { translate } from '../../../helpers/l10n'; +import { Metric } from '../../../app/types'; + +interface Props { + metrics: Metric[]; +} + +interface State { + modal: boolean; +} + +export default class AddConditionButton extends React.PureComponent { + mounted = false; + state: State = { modal: false }; + + componentDidMount() { + this.mounted = true; + } + + componentWillUnmount() { + this.mounted = false; + } + + handleClick = () => { + this.setState({ modal: true }); + }; + + handleModalClose = () => { + if (this.mounted) { + this.setState({ modal: false }); + } + }; + + render() { + return ( + <> + + {this.state.modal && ( + + )} + + ); + } +} diff --git a/server/sonar-web/src/main/js/apps/quality-gates/components/AddConditionSelect.tsx b/server/sonar-web/src/main/js/apps/quality-gates/components/AddConditionSelect.tsx index ef67bfd1554..8539232bb3f 100644 --- a/server/sonar-web/src/main/js/apps/quality-gates/components/AddConditionSelect.tsx +++ b/server/sonar-web/src/main/js/apps/quality-gates/components/AddConditionSelect.tsx @@ -67,14 +67,12 @@ export default class AddConditionSelect extends React.PureComponent { }); return ( -
- ); } } diff --git a/server/sonar-web/src/main/js/apps/quality-gates/components/ConditionModal.tsx b/server/sonar-web/src/main/js/apps/quality-gates/components/ConditionModal.tsx new file mode 100644 index 00000000000..f0c27021af4 --- /dev/null +++ b/server/sonar-web/src/main/js/apps/quality-gates/components/ConditionModal.tsx @@ -0,0 +1,97 @@ +/* + * SonarQube + * Copyright (C) 2009-2018 SonarSource SA + * mailto:info AT sonarsource DOT com + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ +import * as React from 'react'; +import AddConditionSelect from './AddConditionSelect'; +import ConditionOperator from './ConditionOperator'; +import Modal from '../../../components/controls/Modal'; +import { SubmitButton, ResetButtonLink } from '../../../components/ui/buttons'; +import { translate } from '../../../helpers/l10n'; +import { Metric } from '../../../app/types'; + +interface Props { + metrics: Metric[]; + header: string; + onClose: () => void; +} + +interface State { + metric: string; + submitting: boolean; +} + +export default class ConditionModal extends React.PureComponent { + state = { metric: '', submitting: false }; + + handleFormSubmit = (event: React.SyntheticEvent) => { + event.preventDefault(); + this.setState({ submitting: true }); + }; + + handleChooseType = (metric: string) => { + this.setState({ metric }); + }; + + render() { + const { header, metrics, onClose } = this.props; + const { submitting } = this.state; + return ( + +
+
+

{header}

+
+ +
+
+ + +
+
+ + {}} + /> +
+
+ +
+ {submitting && } + + {header} + + + {translate('cancel')} + +
+ +
+ ); + } +} diff --git a/server/sonar-web/src/main/js/apps/quality-gates/components/ConditionOperator.tsx b/server/sonar-web/src/main/js/apps/quality-gates/components/ConditionOperator.tsx new file mode 100644 index 00000000000..55c8d3c54d1 --- /dev/null +++ b/server/sonar-web/src/main/js/apps/quality-gates/components/ConditionOperator.tsx @@ -0,0 +1,63 @@ +/* + * SonarQube + * Copyright (C) 2009-2018 SonarSource SA + * mailto:info AT sonarsource DOT com + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ +import * as React from 'react'; +import Select from '../../../components/controls/Select'; +import { Condition as ICondition, Metric } from '../../../app/types'; +import { translate } from '../../../helpers/l10n'; + +interface Props { + condition: ICondition; + canEdit: boolean; + metric: Metric; + onOperatorChange: ({ value }: any) => void; +} + +export default function ConditionOperator({ condition, canEdit, metric, onOperatorChange }: Props) { + if (!canEdit && condition.op) { + return metric.type === 'RATING' ? ( + {translate('quality_gates.operator', condition.op, 'rating')} + ) : ( + {translate('quality_gates.operator', condition.op)} + ); + } + + if (metric.type === 'RATING') { + return {translate('quality_gates.operator.GT.rating')}; + } + + const operators = ['LT', 'GT', 'EQ', 'NE']; + const operatorOptions = operators.map(op => { + const label = translate('quality_gates.operator', op); + return { label, value: op }; + }); + + return ( +