]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-8689 Add confirm dialog before reseting a setting in the administration
authorGrégoire Aubert <gregoire.aubert@sonarsource.com>
Tue, 15 Aug 2017 09:35:08 +0000 (11:35 +0200)
committerGrégoire Aubert <gregoire.aubert@sonarsource.com>
Thu, 17 Aug 2017 14:42:15 +0000 (16:42 +0200)
server/sonar-web/src/main/js/apps/settings/components/DefinitionDefaults.js
sonar-core/src/main/resources/org/sonar/l10n/core.properties

index 6fc6808bdb6da1b680cd9c72845fce1de4fc5a59..8c2061a9b7ca13a1a13521cc930195d671fba733 100644 (file)
  */
 // @flow
 import React from 'react';
-import PropTypes from 'prop-types';
+import Modal from 'react-modal';
 import { getSettingValue, isEmptyValue, getDefaultValue } from '../utils';
 import { translate } from '../../../helpers/l10n';
 
+/*::
+type Props = {
+  isDefault: boolean,
+  onReset: () => void,
+  setting: Object
+};
+*/
+/*::
+type State = { reseting: boolean };
+*/
+
 export default class DefinitionDefaults extends React.PureComponent {
-  static propTypes = {
-    setting: PropTypes.object.isRequired,
-    isDefault: PropTypes.bool.isRequired,
-    onReset: PropTypes.func.isRequired
+  /*:: props: Props; */
+  state /*: State*/ = { reseting: false };
+
+  handleClose = () => {
+    this.setState({ reseting: false });
   };
 
-  handleReset(e /*: Object */) {
+  handleReset = (e /*: Event & {target: HTMLElement} */) => {
     e.preventDefault();
     e.target.blur();
+    this.setState({ reseting: true });
+  };
+
+  handleSubmit = (event /*: Event */) => {
+    event.preventDefault();
     this.props.onReset();
+    this.handleClose();
+  };
+
+  renderModal() {
+    const header = translate('settings.reset_confirm.title');
+    return (
+      <Modal
+        isOpen={true}
+        contentLabel={header}
+        className="modal"
+        overlayClassName="modal-overlay"
+        onRequestClose={this.handleClose}>
+        <header className="modal-head">
+          <h2>
+            {header}
+          </h2>
+        </header>
+        <form onSubmit={this.handleSubmit}>
+          <div className="modal-body">
+            <p>
+              {translate('settings.reset_confirm.description')}
+            </p>
+          </div>
+          <footer className="modal-foot">
+            <button className="button-red">
+              {translate('reset_verb')}
+            </button>
+            <button type="reset" className="button-link" onClick={this.handleClose}>
+              {translate('cancel')}
+            </button>
+          </footer>
+        </form>
+      </Modal>
+    );
   }
 
   render() {
@@ -51,7 +102,7 @@ export default class DefinitionDefaults extends React.PureComponent {
 
         {isExplicitlySet &&
           <div className="spacer-top nowrap">
-            <button onClick={e => this.handleReset(e)}>
+            <button onClick={this.handleReset}>
               {translate('reset_verb')}
             </button>
             <span className="spacer-left note">
@@ -60,6 +111,7 @@ export default class DefinitionDefaults extends React.PureComponent {
               {getDefaultValue(setting)}
             </span>
           </div>}
+        {this.state.reseting && this.renderModal()}
       </div>
     );
   }
index 0d10ae67275ce427aa1eeb644ce569d56e22f4f3..7875f5ea995325d4d63895b6784c484dd28a02ad 100644 (file)
@@ -1003,6 +1003,8 @@ settings.boolean.false=False
 settings.default.no_value=<no value>
 settings.default.complex_value=<complex value>
 settings.default.password=<password>
+settings.reset_confirm.title=Reset Setting
+settings.reset_confirm.description=Are you sure that you want to reset this setting ?
 
 property.category.general=General
 property.category.general.email=Email