From: Pascal Mugnier Date: Tue, 22 May 2018 09:42:17 +0000 (+0200) Subject: Fix after review X-Git-Tag: 7.5~1153 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=b09719d9242ddc9de16e2cf428cebaacf7b485c5;p=sonarqube.git Fix after review --- diff --git a/server/sonar-web/src/main/js/app/styles/components/modals.css b/server/sonar-web/src/main/js/app/styles/components/modals.css index f8416e932de..84cf5bb0230 100644 --- a/server/sonar-web/src/main/js/app/styles/components/modals.css +++ b/server/sonar-web/src/main/js/app/styles/components/modals.css @@ -177,6 +177,7 @@ ul.modal-head-metadata li { line-height: 1; } +.modal-field a.icon-checkbox, .modal-field input, .modal-large-field input, .modal-field select, @@ -189,6 +190,10 @@ ul.modal-head-metadata li { margin-bottom: 10px; } +.modal-field a.icon-checkbox { + height: 24px; +} + .modal-field input[type='radio'], .modal-large-field input[type='radio'], .modal-field input[type='checkbox'], diff --git a/server/sonar-web/src/main/js/apps/quality-gates/components/Condition.tsx b/server/sonar-web/src/main/js/apps/quality-gates/components/Condition.tsx index 7525fd4a9c3..fd05fb82324 100644 --- a/server/sonar-web/src/main/js/apps/quality-gates/components/Condition.tsx +++ b/server/sonar-web/src/main/js/apps/quality-gates/components/Condition.tsx @@ -21,7 +21,7 @@ import * as React from 'react'; import ConditionOperator from './ConditionOperator'; import Period from './Period'; import ConditionModal from './ConditionModal'; -import DeleteConditionForm from './DeleteConditionForm'; +import DeleteConditionModalForm from './DeleteConditionModalForm'; import { Condition as ICondition, Metric, QualityGate } from '../../../app/types'; import ActionsDropdown, { ActionsDropdownItem } from '../../../components/controls/ActionsDropdown'; import { translate, getLocalizedMetricName } from '../../../helpers/l10n'; @@ -38,6 +38,7 @@ interface Props { } interface State { + deleteFormOpen: boolean; error: string; modal: boolean; op?: string; @@ -49,11 +50,12 @@ export default class Condition extends React.PureComponent { constructor(props: Props) { super(props); this.state = { - period: props.condition.period, + deleteFormOpen: false, + error: props.condition.error || '', modal: false, op: props.condition.op, - warning: props.condition.warning || '', - error: props.condition.error || '' + period: props.condition.period, + warning: props.condition.warning || '' }; } @@ -69,6 +71,10 @@ export default class Condition extends React.PureComponent { handleUpdateClose = () => this.setState({ modal: false }); + handleDeleteClick = () => this.setState({ deleteFormOpen: true }); + + closeDeleteForm = () => this.setState({ deleteFormOpen: false }); + render() { const { condition, canEdit, metric, organization, qualityGate } = this.props; return ( @@ -98,12 +104,12 @@ export default class Condition extends React.PureComponent { {translate('update_details')} - + + {translate('delete')} + {this.state.modal && ( { qualityGate={qualityGate} /> )} + {this.state.deleteFormOpen && ( + + )} )} diff --git a/server/sonar-web/src/main/js/apps/quality-gates/components/DeleteConditionForm.tsx b/server/sonar-web/src/main/js/apps/quality-gates/components/DeleteConditionForm.tsx deleted file mode 100644 index 101d06cfc89..00000000000 --- a/server/sonar-web/src/main/js/apps/quality-gates/components/DeleteConditionForm.tsx +++ /dev/null @@ -1,67 +0,0 @@ -/* - * 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 { deleteCondition } from '../../../api/quality-gates'; -import { Metric, Condition } from '../../../app/types'; -import ConfirmButton from '../../../components/controls/ConfirmButton'; -import { ActionsDropdownItem } from '../../../components/controls/ActionsDropdown'; -import { getLocalizedMetricName, translate, translateWithParameters } from '../../../helpers/l10n'; - -interface Props { - condition: Condition; - metric: Metric; - onDelete: (condition: Condition) => void; - organization?: string; -} - -export default class DeleteConditionForm extends React.PureComponent { - onDelete = () => { - const { organization, condition } = this.props; - if (condition.id !== undefined) { - return deleteCondition({ id: condition.id, organization }).then(() => - this.props.onDelete(condition) - ); - } - return undefined; - }; - - render() { - return ( - - {({ onClick }) => ( - - {translate('delete')} - - )} - - ); - } -} diff --git a/server/sonar-web/src/main/js/apps/quality-gates/components/DeleteConditionModalForm.tsx b/server/sonar-web/src/main/js/apps/quality-gates/components/DeleteConditionModalForm.tsx new file mode 100644 index 00000000000..0477d1d6420 --- /dev/null +++ b/server/sonar-web/src/main/js/apps/quality-gates/components/DeleteConditionModalForm.tsx @@ -0,0 +1,102 @@ +/* + * 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 Modal from '../../../components/controls/Modal'; +import { SubmitButton, ResetButtonLink } from '../../../components/ui/buttons'; +import { translate, translateWithParameters, getLocalizedMetricName } from '../../../helpers/l10n'; +import { Condition, Metric } from '../../../app/types'; +import { deleteCondition } from '../../../api/quality-gates'; + +interface Props { + onClose: () => void; + condition: Condition; + metric: Metric; + onDelete: (condition: Condition) => void; + organization?: string; +} + +interface State { + loading: boolean; + name: string | null; +} + +export default class DeleteConditionModalForm extends React.PureComponent { + mounted = false; + state: State = { loading: false, name: null }; + + componentDidMount() { + this.mounted = true; + } + + componentWillUnmount() { + this.mounted = false; + } + + handleFormSubmit = (event: React.SyntheticEvent) => { + event.preventDefault(); + this.setState({ loading: true }); + const { organization, condition } = this.props; + if (condition.id !== undefined) { + deleteCondition({ id: condition.id, organization }).then( + () => this.props.onDelete(condition), + () => { + if (this.mounted) { + this.setState({ loading: false }); + } + } + ); + } + }; + + render() { + const header = translate('quality_gates.delete_condition'); + + return ( + +
+
+

{header}

+
+
+
+

+ {translateWithParameters( + 'quality_gates.delete_condition.confirm.message', + getLocalizedMetricName(this.props.metric) + )} +

+
+
+ {this.state.loading && } + + {translate('delete')} + + + {translate('cancel')} + +
+ + + ); + } +}