diff options
author | Stas Vilchik <stas.vilchik@sonarsource.com> | 2017-10-11 13:42:24 +0200 |
---|---|---|
committer | Stas Vilchik <stas.vilchik@sonarsource.com> | 2017-10-12 10:23:25 +0200 |
commit | 7a230c2fa98532eb79d2efcd30c31d608f9fa108 (patch) | |
tree | 24dc6ccf076be8d1972d91fb90537bb47b19dd42 | |
parent | 11517022de14138e106d1420944f79bb4426b5fa (diff) | |
download | sonarqube-7a230c2fa98532eb79d2efcd30c31d608f9fa108.tar.gz sonarqube-7a230c2fa98532eb79d2efcd30c31d608f9fa108.zip |
SONAR-9927 Project admins see "Cancel All" button on Background Tasks page
5 files changed, 73 insertions, 33 deletions
diff --git a/server/sonar-web/src/main/js/apps/background-tasks/__tests__/background-tasks-test.js b/server/sonar-web/src/main/js/apps/background-tasks/__tests__/background-tasks-test.js index 9ab30012448..c6c69e6757f 100644 --- a/server/sonar-web/src/main/js/apps/background-tasks/__tests__/background-tasks-test.js +++ b/server/sonar-web/src/main/js/apps/background-tasks/__tests__/background-tasks-test.js @@ -102,7 +102,12 @@ describe('Stats', () => { it('should show cancel pending button', () => { const result = shallow( - <Stats pendingCount={5} onCancelAllPending={stub} onShowFailing={stub} /> + <Stats + isSystemAdmin={true} + pendingCount={5} + onCancelAllPending={stub} + onShowFailing={stub} + /> ); expect(result.find('.js-cancel-pending').length).toBe(1); }); @@ -110,7 +115,12 @@ describe('Stats', () => { it('should trigger cancelling pending', () => { const spy = jest.fn(); const result = shallow( - <Stats pendingCount={5} onCancelAllPending={spy} onShowFailing={stub} /> + <Stats + isSystemAdmin={true} + pendingCount={5} + onCancelAllPending={spy} + onShowFailing={stub} + /> ); expect(spy).not.toBeCalled(); click(result.find('.js-cancel-pending')); diff --git a/server/sonar-web/src/main/js/apps/background-tasks/components/BackgroundTasksApp.js b/server/sonar-web/src/main/js/apps/background-tasks/components/BackgroundTasksApp.js index 8128a3827e3..ee20d1ade15 100644 --- a/server/sonar-web/src/main/js/apps/background-tasks/components/BackgroundTasksApp.js +++ b/server/sonar-web/src/main/js/apps/background-tasks/components/BackgroundTasksApp.js @@ -26,7 +26,7 @@ import { connect } from 'react-redux'; import { DEFAULT_FILTERS, DEBOUNCE_DELAY, STATUSES, CURRENTS } from './../constants'; import Header from './Header'; import Footer from './Footer'; -import Stats from '../components/Stats'; +import StatsContainer from '../components/StatsContainer'; import Search from '../components/Search'; import Tasks from '../components/Tasks'; import { @@ -220,7 +220,7 @@ class BackgroundTasksApp extends React.PureComponent { <Helmet title={translate('background_tasks.page')} /> <Header component={component} /> - <Stats + <StatsContainer component={component} pendingCount={pendingCount} failingCount={failingCount} diff --git a/server/sonar-web/src/main/js/apps/background-tasks/components/Stats.js b/server/sonar-web/src/main/js/apps/background-tasks/components/Stats.js index 3021b5af21b..22c58b2902a 100644 --- a/server/sonar-web/src/main/js/apps/background-tasks/components/Stats.js +++ b/server/sonar-web/src/main/js/apps/background-tasks/components/Stats.js @@ -19,11 +19,13 @@ */ /* @flow */ import React from 'react'; +import Tooltip from '../../../components/controls/Tooltip'; import { translate } from '../../../helpers/l10n'; /*:: type Props = { failingCount: number, + isSystemAdmin?: boolean, pendingCount: number, onShowFailing: () => void, onCancelAllPending: () => void @@ -38,17 +40,17 @@ export default class Stats extends React.PureComponent { /*:: props: Props; */ /*:: state: State; */ - handleCancelAllPending(e /*: Object */) { - e.preventDefault(); - e.target.blur(); + handleCancelAllPending = (event /*: Object */) => { + event.preventDefault(); + event.currentTarget.blur(); this.props.onCancelAllPending(); - } + }; - handleShowFailing(e /*: Object */) { - e.preventDefault(); - e.target.blur(); + handleShowFailing = (event /*: Object */) => { + event.preventDefault(); + event.currentTarget.blur(); this.props.onShowFailing(); - } + }; renderPending() { if (this.props.pendingCount == null) { @@ -60,13 +62,15 @@ export default class Stats extends React.PureComponent { <span className="js-pending-count emphasised-measure">{this.props.pendingCount}</span> {translate('background_tasks.pending')} - <a - onClick={this.handleCancelAllPending.bind(this)} - className="js-cancel-pending icon-delete spacer-left" - title={translate('background_tasks.cancel_all_tasks')} - data-toggle="tooltip" - href="#" - /> + {this.props.isSystemAdmin && ( + <Tooltip overlay={translate('background_tasks.cancel_all_tasks')}> + <a + className="js-cancel-pending icon-delete spacer-left" + href="#" + onClick={this.handleCancelAllPending} + /> + </Tooltip> + )} </span> ); } else { @@ -92,14 +96,14 @@ export default class Stats extends React.PureComponent { if (this.props.failingCount > 0) { return ( <span> - <a - onClick={this.handleShowFailing.bind(this)} - className="js-failures-count emphasised-measure" - data-toggle="tooltip" - title="Count of projects where processing of most recent analysis report failed" - href="#"> - {this.props.failingCount} - </a> + <Tooltip overlay={translate('background_tasks.failing_count')}> + <a + className="js-failures-count emphasised-measure" + href="#" + onClick={this.handleShowFailing}> + {this.props.failingCount} + </a> + </Tooltip> {translate('background_tasks.failures')} </span> @@ -107,12 +111,9 @@ export default class Stats extends React.PureComponent { } else { return ( <span> - <span - className="js-failures-count emphasised-measure" - data-toggle="tooltip" - title="Count of projects where processing of most recent analysis report failed"> - {this.props.failingCount} - </span> + <Tooltip overlay={translate('background_tasks.failing_count')}> + <span className="js-failures-count emphasised-measure">{this.props.failingCount}</span> + </Tooltip> {translate('background_tasks.failures')} </span> diff --git a/server/sonar-web/src/main/js/apps/background-tasks/components/StatsContainer.tsx b/server/sonar-web/src/main/js/apps/background-tasks/components/StatsContainer.tsx new file mode 100644 index 00000000000..da3eb9c9a28 --- /dev/null +++ b/server/sonar-web/src/main/js/apps/background-tasks/components/StatsContainer.tsx @@ -0,0 +1,28 @@ +/* + * 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 { connect } from 'react-redux'; +import Stats from './Stats'; +import { getAppState } from '../../../store/rootReducer'; + +const mapStateToProps = (state: any) => ({ + isSystemAdmin: !!getAppState(state).canAdmin +}); + +export default connect(mapStateToProps)(Stats as any); diff --git a/sonar-core/src/main/resources/org/sonar/l10n/core.properties b/sonar-core/src/main/resources/org/sonar/l10n/core.properties index 359bc7632b4..0e3f376dfb6 100644 --- a/sonar-core/src/main/resources/org/sonar/l10n/core.properties +++ b/sonar-core/src/main/resources/org/sonar/l10n/core.properties @@ -2213,6 +2213,7 @@ background_tasks.change_number_of_workers=Edit CE Workers background_tasks.change_number_of_workers.hint=If your queue backs up behind the analysis reports from large projects, increasing the number of Compute Engine workers will allow you to take full advantage of having configured increased Compute Engine memory on a multi-core server (vertical scaling). background_tasks.add_more_with_governance=Add more with Governance background_tasks.search_by_task_or_component=Search by Task or Component +background_tasks.failing_count=Count of projects where processing of most recent analysis report failed |