diff options
author | Stas Vilchik <stas.vilchik@sonarsource.com> | 2017-09-25 15:59:36 +0200 |
---|---|---|
committer | Stas Vilchik <stas.vilchik@sonarsource.com> | 2017-10-02 17:18:15 +0200 |
commit | e52aa133123efef9ae7b9099b1a620bad795e010 (patch) | |
tree | 4e0e4b58934743927168bae6de468e2a95a960d5 /server/sonar-web/src/main/js/components/controls/SimpleModal.tsx | |
parent | ffd619eff86cc391c826bfc9b2df98ab51d54ff5 (diff) | |
download | sonarqube-e52aa133123efef9ae7b9099b1a620bad795e010.tar.gz sonarqube-e52aa133123efef9ae7b9099b1a620bad795e010.zip |
SONAR-1330 add widget to manage quality profile permissions
Diffstat (limited to 'server/sonar-web/src/main/js/components/controls/SimpleModal.tsx')
-rw-r--r-- | server/sonar-web/src/main/js/components/controls/SimpleModal.tsx | 90 |
1 files changed, 90 insertions, 0 deletions
diff --git a/server/sonar-web/src/main/js/components/controls/SimpleModal.tsx b/server/sonar-web/src/main/js/components/controls/SimpleModal.tsx new file mode 100644 index 00000000000..825ace80a34 --- /dev/null +++ b/server/sonar-web/src/main/js/components/controls/SimpleModal.tsx @@ -0,0 +1,90 @@ +/* + * SonarQube + * Copyright (C) 2009-2016 SonarSource SA + * mailto:contact 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 'react-modal'; + +export interface ChildrenProps { + onCloseClick: (event: React.SyntheticEvent<HTMLElement>) => void; + onSubmitClick: (event: React.SyntheticEvent<HTMLElement>) => void; + submitting: boolean; +} + +interface Props { + children: (props: ChildrenProps) => React.ReactNode; + header: string; + onClose: () => void; + onSubmit: () => void | Promise<void>; +} + +interface State { + submitting: boolean; +} + +export default class SimpleModal extends React.PureComponent<Props, State> { + mounted: boolean; + state: State = { submitting: false }; + + componentDidMount() { + this.mounted = true; + } + + componentWillUnmount() { + this.mounted = false; + } + + stopSubmitting = () => { + if (this.mounted) { + this.setState({ submitting: false }); + } + }; + + handleCloseClick = (event: React.SyntheticEvent<HTMLElement>) => { + event.preventDefault(); + event.currentTarget.blur(); + this.props.onClose(); + }; + + handleSubmitClick = (event: React.SyntheticEvent<HTMLElement>) => { + event.preventDefault(); + event.currentTarget.blur(); + const result = this.props.onSubmit(); + if (result) { + this.setState({ submitting: true }); + result.then(this.stopSubmitting, this.stopSubmitting); + } + }; + + render() { + return ( + <Modal + isOpen={true} + contentLabel={this.props.header} + className="modal" + overlayClassName="modal-overlay" + onRequestClose={this.props.onClose}> + {this.props.children({ + onCloseClick: this.handleCloseClick, + onSubmitClick: this.handleSubmitClick, + submitting: this.state.submitting + })} + </Modal> + ); + } +} |