From ad8afa515b0dddeedd6a37e91c6bcda914d1c309 Mon Sep 17 00:00:00 2001 From: Stas Vilchik Date: Mon, 29 May 2017 10:49:12 +0200 Subject: rework some modals (#2113) --- .../main/js/app/components/nav/global/GlobalNav.js | 20 ++- .../js/app/components/nav/global/ShortcutsHelp.js | 188 +++++++++++++++++++++ .../app/components/nav/global/ShortcutsHelpView.js | 26 --- .../nav/templates/nav-shortcuts-help.hbs | 70 -------- .../background-tasks/components/ScannerContext.js | 102 +++++++++++ .../apps/background-tasks/components/Stacktrace.js | 114 +++++++++++++ .../background-tasks/components/TaskActions.js | 22 ++- .../background-tasks/views/ScannerContextView.hbs | 17 -- .../background-tasks/views/ScannerContextView.js | 46 ----- .../apps/background-tasks/views/StacktraceView.hbs | 23 --- .../apps/background-tasks/views/StacktraceView.js | 49 ------ .../project-admin/deletion/ConfirmationModal.js | 48 ------ .../deletion/ConfirmationModalTemplate.hbs | 14 -- .../main/js/apps/project-admin/deletion/Form.js | 91 ++++++++-- .../js/apps/settings/licenses/LicenseChangeForm.js | 75 +++++++- .../main/js/apps/settings/licenses/LicenseRow.js | 8 +- .../js/apps/settings/licenses/LicenseValueView.hbs | 16 -- .../js/apps/settings/licenses/LicenseValueView.js | 41 ----- .../js/apps/settings/store/licenses/actions.js | 6 +- 19 files changed, 585 insertions(+), 391 deletions(-) create mode 100644 server/sonar-web/src/main/js/app/components/nav/global/ShortcutsHelp.js delete mode 100644 server/sonar-web/src/main/js/app/components/nav/global/ShortcutsHelpView.js delete mode 100644 server/sonar-web/src/main/js/app/components/nav/templates/nav-shortcuts-help.hbs create mode 100644 server/sonar-web/src/main/js/apps/background-tasks/components/ScannerContext.js create mode 100644 server/sonar-web/src/main/js/apps/background-tasks/components/Stacktrace.js delete mode 100644 server/sonar-web/src/main/js/apps/background-tasks/views/ScannerContextView.hbs delete mode 100644 server/sonar-web/src/main/js/apps/background-tasks/views/ScannerContextView.js delete mode 100644 server/sonar-web/src/main/js/apps/background-tasks/views/StacktraceView.hbs delete mode 100644 server/sonar-web/src/main/js/apps/background-tasks/views/StacktraceView.js delete mode 100644 server/sonar-web/src/main/js/apps/project-admin/deletion/ConfirmationModal.js delete mode 100644 server/sonar-web/src/main/js/apps/project-admin/deletion/ConfirmationModalTemplate.hbs delete mode 100644 server/sonar-web/src/main/js/apps/settings/licenses/LicenseValueView.hbs delete mode 100644 server/sonar-web/src/main/js/apps/settings/licenses/LicenseValueView.js diff --git a/server/sonar-web/src/main/js/app/components/nav/global/GlobalNav.js b/server/sonar-web/src/main/js/app/components/nav/global/GlobalNav.js index 86ed0974c5c..2e2659d7125 100644 --- a/server/sonar-web/src/main/js/app/components/nav/global/GlobalNav.js +++ b/server/sonar-web/src/main/js/app/components/nav/global/GlobalNav.js @@ -23,10 +23,12 @@ import GlobalNavBranding from './GlobalNavBranding'; import GlobalNavMenu from './GlobalNavMenu'; import GlobalNavUserContainer from './GlobalNavUserContainer'; import Search from '../../search/Search'; -import ShortcutsHelpView from './ShortcutsHelpView'; +import ShortcutsHelp from './ShortcutsHelp'; import { getCurrentUser, getAppState } from '../../../../store/rootReducer'; class GlobalNav extends React.PureComponent { + state = { helpOpen: false }; + componentDidMount() { window.addEventListener('keypress', this.onKeyPress); } @@ -46,13 +48,15 @@ class GlobalNav extends React.PureComponent { } }; - openHelp = e => { - if (e) { - e.preventDefault(); - } - new ShortcutsHelpView().render(); + handleHelpClick = event => { + event.preventDefault(); + this.openHelp(); }; + openHelp = () => this.setState({ helpOpen: true }); + + closeHelp = () => this.setState({ helpOpen: false }); + render() { /* eslint-disable max-len */ return ( @@ -65,7 +69,7 @@ class GlobalNav extends React.PureComponent { + + {this.state.helpOpen && } ); } diff --git a/server/sonar-web/src/main/js/app/components/nav/global/ShortcutsHelp.js b/server/sonar-web/src/main/js/app/components/nav/global/ShortcutsHelp.js new file mode 100644 index 00000000000..273b370f17a --- /dev/null +++ b/server/sonar-web/src/main/js/app/components/nav/global/ShortcutsHelp.js @@ -0,0 +1,188 @@ +/* + * SonarQube + * Copyright (C) 2009-2017 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. + */ +// @flow +import React from 'react'; +import Modal from 'react-modal'; +import { Link } from 'react-router'; +import { translate } from '../../../../helpers/l10n'; + +type Props = { + onClose: () => void +}; + +export default class ShortcutsHelp extends React.PureComponent { + props: Props; + + handleCloseClick = (event: Event) => { + event.preventDefault(); + this.props.onClose(); + }; + + render() { + return ( + + +
+

{translate('help')}

+
+ +
+
+ {translate('footer.community')}{' - '} + + {translate('footer.documentation')} + + {' - '} + + {translate('footer.support')} + + {' - '} + + {translate('footer.plugins')} + + {' - '} + {translate('footer.web_api')} + {' - '} + {translate('footer.about')} +
+ +

{translate('shortcuts.modal_title')}

+ +
+
+
+

{translate('shortcuts.section.global')}

+
    +
  • + s + {translate('shortcuts.section.global.search')} +
  • +
  • + ? + {translate('shortcuts.section.global.shortcuts')} +
  • +
+
+ +

{translate('shortcuts.section.rules')}

+
    +
  • + + + {translate('shortcuts.section.rules.navigate_between_rules')} +
  • +
  • + + {translate('shortcuts.section.rules.open_details')} +
  • +
  • + + {translate('shortcuts.section.rules.return_to_list')} +
  • +
  • + a + {translate('shortcuts.section.rules.activate')} +
  • +
  • + d + {translate('shortcuts.section.rules.deactivate')} +
  • +
+
+ +
+

{translate('shortcuts.section.issues')}

+
    +
  • + + + {translate('shortcuts.section.issues.navigate_between_issues')} +
  • +
  • + + {translate('shortcuts.section.issues.open_details')} +
  • +
  • + + {translate('shortcuts.section.issues.return_to_list')} +
  • +
  • + alt + + + + + {translate('issues.to_navigate_issue_locations')} +
  • +
  • + alt + + + + + {translate('issues.to_switch_flows')} +
  • +
  • + f + {translate('shortcuts.section.issue.do_transition')} +
  • +
  • + a + {translate('shortcuts.section.issue.assign')} +
  • +
  • + m + {translate('shortcuts.section.issue.assign_to_me')} +
  • +
  • + i + {translate('shortcuts.section.issue.change_severity')} +
  • +
  • + c + {translate('shortcuts.section.issue.comment')} +
  • +
  • + ctrl + enter + {translate('shortcuts.section.issue.submit_comment')} +
  • +
  • + t + {translate('shortcuts.section.issue.change_tags')} +
  • +
+
+
+
+ +
+ + {translate('close')} + +
+ + + ); + } +} diff --git a/server/sonar-web/src/main/js/app/components/nav/global/ShortcutsHelpView.js b/server/sonar-web/src/main/js/app/components/nav/global/ShortcutsHelpView.js deleted file mode 100644 index 893e4930ad6..00000000000 --- a/server/sonar-web/src/main/js/app/components/nav/global/ShortcutsHelpView.js +++ /dev/null @@ -1,26 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2017 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 ModalView from '../../../../components/common/modals'; -import ShortcutsHelpTemplate from '../templates/nav-shortcuts-help.hbs'; - -export default ModalView.extend({ - className: 'modal modal-large', - template: ShortcutsHelpTemplate -}); diff --git a/server/sonar-web/src/main/js/app/components/nav/templates/nav-shortcuts-help.hbs b/server/sonar-web/src/main/js/app/components/nav/templates/nav-shortcuts-help.hbs deleted file mode 100644 index 00f5519d887..00000000000 --- a/server/sonar-web/src/main/js/app/components/nav/templates/nav-shortcuts-help.hbs +++ /dev/null @@ -1,70 +0,0 @@ - - - - - \ No newline at end of file diff --git a/server/sonar-web/src/main/js/apps/background-tasks/components/ScannerContext.js b/server/sonar-web/src/main/js/apps/background-tasks/components/ScannerContext.js new file mode 100644 index 00000000000..f83644560cc --- /dev/null +++ b/server/sonar-web/src/main/js/apps/background-tasks/components/ScannerContext.js @@ -0,0 +1,102 @@ +/* + * SonarQube + * Copyright (C) 2009-2017 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. + */ +// @flow +import React from 'react'; +import Modal from 'react-modal'; +import { getTask } from '../../../api/ce'; +import { translate } from '../../../helpers/l10n'; + +type Props = { + onClose: () => void, + task: { componentName: string, id: string, type: string } +}; + +type State = { + scannerContext: ?string +}; + +export default class ScannerContext extends React.PureComponent { + mounted: boolean; + props: Props; + state: State = { + scannerContext: null + }; + + componentDidMount() { + this.mounted = true; + this.loadScannerContext(); + } + + componentWillUnmount() { + this.mounted = false; + } + + loadScannerContext() { + getTask(this.props.task.id, ['scannerContext']).then(task => { + if (this.mounted) { + this.setState({ scannerContext: task.scannerContext }); + } + }); + } + + handleCloseClick = (event: Event) => { + event.preventDefault(); + this.props.onClose(); + }; + + render() { + const { task } = this.props; + const { scannerContext } = this.state; + + return ( + + +
+

+ {translate('background_tasks.scanner_context')} + {': '} + {task.componentName} + {' ['} + {translate('background_task.type', task.type)} + {']'} +

+
+ +
+ {scannerContext != null + ?
{scannerContext}
+ : } +
+ +
+ + {translate('close')} + +
+ +
+ ); + } +} diff --git a/server/sonar-web/src/main/js/apps/background-tasks/components/Stacktrace.js b/server/sonar-web/src/main/js/apps/background-tasks/components/Stacktrace.js new file mode 100644 index 00000000000..d6da81e314c --- /dev/null +++ b/server/sonar-web/src/main/js/apps/background-tasks/components/Stacktrace.js @@ -0,0 +1,114 @@ +/* + * SonarQube + * Copyright (C) 2009-2017 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. + */ +// @flow +import React from 'react'; +import Modal from 'react-modal'; +import { getTask } from '../../../api/ce'; +import { translate } from '../../../helpers/l10n'; + +type Props = { + onClose: () => void, + task: { componentName: string, errorMessage: string, id: string, type: string } +}; + +type State = { + loading: boolean, + stacktrace: ?string +}; + +export default class Stacktrace extends React.PureComponent { + mounted: boolean; + props: Props; + state: State = { + loading: true, + stacktrace: null + }; + + componentDidMount() { + this.mounted = true; + this.loadStacktrace(); + } + + componentWillUnmount() { + this.mounted = false; + } + + loadStacktrace() { + getTask(this.props.task.id, ['stacktrace']).then(task => { + if (this.mounted) { + this.setState({ loading: false, stacktrace: task.errorStacktrace }); + } + }); + } + + handleCloseClick = (event: Event) => { + event.preventDefault(); + this.props.onClose(); + }; + + render() { + const { task } = this.props; + const { loading, stacktrace } = this.state; + + return ( + + +
+

+ {translate('background_tasks.error_stacktrace')} + {': '} + {task.componentName} + {' ['} + {translate('background_task.type', task.type)} + {']'} +

+
+ +
+ {loading + ? + : stacktrace + ?
+

+ {translate('background_tasks.error_stacktrace')} +

+
{stacktrace}
+
+ :
+

{translate('background_tasks.error_message')}

+
{task.errorMessage}
+
} +
+ +
+ + {translate('close')} + +
+ +
+ ); + } +} diff --git a/server/sonar-web/src/main/js/apps/background-tasks/components/TaskActions.js b/server/sonar-web/src/main/js/apps/background-tasks/components/TaskActions.js index 1acde211d5f..03b8be8455d 100644 --- a/server/sonar-web/src/main/js/apps/background-tasks/components/TaskActions.js +++ b/server/sonar-web/src/main/js/apps/background-tasks/components/TaskActions.js @@ -18,12 +18,17 @@ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ import React from 'react'; -import ScannerContextView from '../views/ScannerContextView'; -import StacktraceView from '../views/StacktraceView'; +import ScannerContext from './ScannerContext'; +import Stacktrace from './Stacktrace'; import { STATUSES } from './../constants'; import { translate, translateWithParameters } from '../../../helpers/l10n'; export default class TaskActions extends React.PureComponent { + state = { + scannerContextOpen: false, + stacktraceOpen: false + }; + handleFilterClick(e) { e.preventDefault(); this.props.onFilterTask(this.props.task); @@ -36,14 +41,18 @@ export default class TaskActions extends React.PureComponent { handleShowScannerContextClick(e) { e.preventDefault(); - new ScannerContextView({ task: this.props.task }).render(); + this.setState({ scannerContextOpen: true }); } + closeScannerContext = () => this.setState({ scannerContextOpen: false }); + handleShowStacktraceClick(e) { e.preventDefault(); - new StacktraceView({ task: this.props.task }).render(); + this.setState({ stacktraceOpen: true }); } + closeStacktrace = () => this.setState({ stacktraceOpen: false }); + render() { const { component, task } = this.props; @@ -102,6 +111,11 @@ export default class TaskActions extends React.PureComponent { } + + {this.state.scannerContextOpen && + } + + {this.state.stacktraceOpen && } ); } diff --git a/server/sonar-web/src/main/js/apps/background-tasks/views/ScannerContextView.hbs b/server/sonar-web/src/main/js/apps/background-tasks/views/ScannerContextView.hbs deleted file mode 100644 index d1de3da84c7..00000000000 --- a/server/sonar-web/src/main/js/apps/background-tasks/views/ScannerContextView.hbs +++ /dev/null @@ -1,17 +0,0 @@ -
- - - -
diff --git a/server/sonar-web/src/main/js/apps/background-tasks/views/ScannerContextView.js b/server/sonar-web/src/main/js/apps/background-tasks/views/ScannerContextView.js deleted file mode 100644 index ef35cf57125..00000000000 --- a/server/sonar-web/src/main/js/apps/background-tasks/views/ScannerContextView.js +++ /dev/null @@ -1,46 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2017 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 Modal from '../../../components/common/modals'; -import Template from './ScannerContextView.hbs'; -import { getTask } from '../../../api/ce'; - -export default Modal.extend({ - template: Template, - className: 'modal modal-large', - - initialize() { - this.scannerContext = null; - this.loadScannerContext(); - }, - - loadScannerContext() { - getTask(this.options.task.id, ['scannerContext']).then(task => { - this.scannerContext = task.scannerContext; - this.render(); - }); - }, - - serializeData() { - return { - task: this.options.task, - scannerContext: this.scannerContext - }; - } -}); diff --git a/server/sonar-web/src/main/js/apps/background-tasks/views/StacktraceView.hbs b/server/sonar-web/src/main/js/apps/background-tasks/views/StacktraceView.hbs deleted file mode 100644 index 21ce604acb2..00000000000 --- a/server/sonar-web/src/main/js/apps/background-tasks/views/StacktraceView.hbs +++ /dev/null @@ -1,23 +0,0 @@ -
- - - -
diff --git a/server/sonar-web/src/main/js/apps/background-tasks/views/StacktraceView.js b/server/sonar-web/src/main/js/apps/background-tasks/views/StacktraceView.js deleted file mode 100644 index 866d9a487eb..00000000000 --- a/server/sonar-web/src/main/js/apps/background-tasks/views/StacktraceView.js +++ /dev/null @@ -1,49 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2017 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 Modal from '../../../components/common/modals'; -import Template from './StacktraceView.hbs'; -import { getTask } from '../../../api/ce'; - -export default Modal.extend({ - template: Template, - className: 'modal modal-large', - - initialize() { - this.loaded = false; - this.stacktrace = null; - this.loadStacktrace(); - }, - - loadStacktrace() { - getTask(this.options.task.id, ['stacktrace']).then(task => { - this.loaded = true; - this.stacktrace = task.errorStacktrace; - this.render(); - }); - }, - - serializeData() { - return { - task: this.options.task, - stacktrace: this.stacktrace, - loaded: this.loaded - }; - } -}); diff --git a/server/sonar-web/src/main/js/apps/project-admin/deletion/ConfirmationModal.js b/server/sonar-web/src/main/js/apps/project-admin/deletion/ConfirmationModal.js deleted file mode 100644 index 273850ea38b..00000000000 --- a/server/sonar-web/src/main/js/apps/project-admin/deletion/ConfirmationModal.js +++ /dev/null @@ -1,48 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2017 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 ModalForm from '../../../components/common/modal-form'; -import Template from './ConfirmationModalTemplate.hbs'; -import { deleteProject } from '../../../api/components'; - -export default ModalForm.extend({ - template: Template, - - onFormSubmit() { - ModalForm.prototype.onFormSubmit.apply(this, arguments); - this.disableForm(); - this.showSpinner(); - - deleteProject(this.options.project.key) - .then(() => { - this.trigger('done'); - }) - .catch(function(e) { - e.response.json().then(r => { - this.hideSpinner(); - this.showErrors(r.errors, r.warnings); - this.enableForm(); - }); - }); - }, - - serializeData() { - return { project: this.options.project }; - } -}); diff --git a/server/sonar-web/src/main/js/apps/project-admin/deletion/ConfirmationModalTemplate.hbs b/server/sonar-web/src/main/js/apps/project-admin/deletion/ConfirmationModalTemplate.hbs deleted file mode 100644 index 749e408d5bc..00000000000 --- a/server/sonar-web/src/main/js/apps/project-admin/deletion/ConfirmationModalTemplate.hbs +++ /dev/null @@ -1,14 +0,0 @@ -
- - - -
diff --git a/server/sonar-web/src/main/js/apps/project-admin/deletion/Form.js b/server/sonar-web/src/main/js/apps/project-admin/deletion/Form.js index 1a848accaee..ac8ca55598b 100644 --- a/server/sonar-web/src/main/js/apps/project-admin/deletion/Form.js +++ b/server/sonar-web/src/main/js/apps/project-admin/deletion/Form.js @@ -18,30 +18,97 @@ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ import React from 'react'; -import ConfirmationModal from './ConfirmationModal'; -import { translate } from '../../../helpers/l10n'; +import Modal from 'react-modal'; +import { deleteProject } from '../../../api/components'; +import { translate, translateWithParameters } from '../../../helpers/l10n'; export default class Form extends React.PureComponent { static propTypes = { component: React.PropTypes.object.isRequired }; - handleDelete(e) { - e.preventDefault(); - new ConfirmationModal({ project: this.props.component }) - .on('done', () => { - window.location = window.baseUrl + '/'; - }) - .render(); + static contextTypes = { + router: React.PropTypes.object + }; + + state = { loading: false, modalOpen: false }; + + componentDidMount() { + this.mounted = true; + } + + componentWillUnmount() { + this.mounted = false; } + handleDeleteClick = event => { + event.preventDefault(); + this.setState({ modalOpen: true }); + }; + + closeModal = () => this.setState({ modalOpen: false }); + + stopLoading = () => { + if (this.mounted) { + this.setState({ loading: false }); + } + }; + + handleSubmit = event => { + event.preventDefault(); + this.setState({ loading: true }); + deleteProject(this.props.component.key) + .then(() => this.context.router.replace('/')) + .catch(this.stopLoading); + }; + + handleCloseClick = (event: Event) => { + event.preventDefault(); + this.closeModal(); + }; + render() { + const { component } = this.props; + return ( -
- -
+ + {this.state.modalOpen && + +
+
+

{translate('qualifiers.delete.TRK')}

+
+
+
+ {translateWithParameters( + 'project_deletion.delete_resource_confirmation', + component.name + )} +
+
+ {this.state.loading && } + + + {translate('cancel')} + +
+ + } +
); } } diff --git a/server/sonar-web/src/main/js/apps/settings/licenses/LicenseChangeForm.js b/server/sonar-web/src/main/js/apps/settings/licenses/LicenseChangeForm.js index e3e443e51b6..ff068c49d98 100644 --- a/server/sonar-web/src/main/js/apps/settings/licenses/LicenseChangeForm.js +++ b/server/sonar-web/src/main/js/apps/settings/licenses/LicenseChangeForm.js @@ -18,8 +18,8 @@ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. */ import React from 'react'; -import LicenseValueView from './LicenseValueView'; -import { translate } from '../../../helpers/l10n'; +import Modal from 'react-modal'; +import { translate, translateWithParameters } from '../../../helpers/l10n'; export default class LicenseChangeForm extends React.PureComponent { static propTypes = { @@ -27,23 +27,80 @@ export default class LicenseChangeForm extends React.PureComponent { onChange: React.PropTypes.func.isRequired }; + state = { + loading: false, + modalOpen: false + }; + onClick(e) { e.preventDefault(); e.target.blur(); + this.setState({ modalOpen: true }); + } - const { license, onChange } = this.props; + closeModal = () => this.setState({ modalOpen: false }); - new LicenseValueView({ - productName: license.name || license.key, - value: license.value, - onChange - }).render(); - } + handleSubmit = event => { + event.preventDefault(); + if (this.textarea) { + const { value } = this.textarea; + this.setState({ loading: true }); + this.props + .onChange(value) + .then( + () => this.setState({ loading: false, modalOpen: false }), + () => this.setState({ loading: false }) + ); + } + }; + + handleCancelClick = event => { + event.preventDefault(); + this.closeModal(); + }; render() { + const { license } = this.props; + const productName = license.name || license.key; + return ( - {{t 'cancel'}} - - diff --git a/server/sonar-web/src/main/js/apps/settings/licenses/LicenseValueView.js b/server/sonar-web/src/main/js/apps/settings/licenses/LicenseValueView.js deleted file mode 100644 index 22b4e3a155b..00000000000 --- a/server/sonar-web/src/main/js/apps/settings/licenses/LicenseValueView.js +++ /dev/null @@ -1,41 +0,0 @@ -/* - * SonarQube - * Copyright (C) 2009-2017 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 ModalForm from '../../../components/common/modal-form'; -import Template from './LicenseValueView.hbs'; - -export default ModalForm.extend({ - template: Template, - - onFormSubmit() { - ModalForm.prototype.onFormSubmit.apply(this, arguments); - this.disableForm(); - this.showSpinner(); - - const value = this.$('textarea').val(); - this.options.onChange(value).then(() => this.destroy()); - }, - - serializeData() { - return { - productName: this.options.productName, - value: this.options.value - }; - } -}); diff --git a/server/sonar-web/src/main/js/apps/settings/store/licenses/actions.js b/server/sonar-web/src/main/js/apps/settings/store/licenses/actions.js index c24cae2d6d2..9ef043c73c7 100644 --- a/server/sonar-web/src/main/js/apps/settings/store/licenses/actions.js +++ b/server/sonar-web/src/main/js/apps/settings/store/licenses/actions.js @@ -56,7 +56,7 @@ export const setLicense = (key, value) => dispatch => { const request = value ? licenses.setLicense(key, value) : licenses.resetLicense(key); return request - .then(() => { + .then(() => licenses.getLicenses().then(licenses => { dispatch(receiveLicenses(licenses)); if (isLicenseFromListInvalid(licenses, key)) { @@ -64,7 +64,7 @@ export const setLicense = (key, value) => dispatch => { } else { dispatch(addGlobalSuccessMessage(translate('licenses.success_message'))); } - }); - }) + }) + ) .catch(handleError(dispatch)); }; -- cgit v1.2.3