]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-9927 Project admins see "Cancel All" button on Background Tasks page
authorStas Vilchik <stas.vilchik@sonarsource.com>
Wed, 11 Oct 2017 11:42:24 +0000 (13:42 +0200)
committerStas Vilchik <stas.vilchik@sonarsource.com>
Thu, 12 Oct 2017 08:23:25 +0000 (10:23 +0200)
server/sonar-web/src/main/js/apps/background-tasks/__tests__/background-tasks-test.js
server/sonar-web/src/main/js/apps/background-tasks/components/BackgroundTasksApp.js
server/sonar-web/src/main/js/apps/background-tasks/components/Stats.js
server/sonar-web/src/main/js/apps/background-tasks/components/StatsContainer.tsx [new file with mode: 0644]
sonar-core/src/main/resources/org/sonar/l10n/core.properties

index 9ab30012448c128bd1381e54dbc0ea8c71c6a3a9..c6c69e6757fe9ed8d1338ed74b2e747a22329ece 100644 (file)
@@ -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'));
index 8128a3827e3c4259b72b715f8abd15e0d97656e4..ee20d1ade1528386d82153b8b2902407d0732627 100644 (file)
@@ -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}
index 3021b5af21b9a48e8066af61e431a50492190081..22c58b2902a1a2ec3471e467b355dcdd00674539 100644 (file)
  */
 /* @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>
           &nbsp;
           {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>
           &nbsp;
           {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>
           &nbsp;
           {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 (file)
index 0000000..da3eb9c
--- /dev/null
@@ -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);
index 359bc7632b4d496f0ec706abe0196f5b50e38c02..0e3f376dfb671ee1048054b7d85d4d6415ef201d 100644 (file)
@@ -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