]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-7191 Update the background tasks page to reflect latest WS changes
authorStas Vilchik <vilchiks@gmail.com>
Tue, 16 Feb 2016 15:23:18 +0000 (16:23 +0100)
committerStas Vilchik <vilchiks@gmail.com>
Tue, 16 Feb 2016 15:39:11 +0000 (16:39 +0100)
it/it-tests/src/test/resources/projectAdministration/BackgroundTasksTest/should_not_display_failing_and_search_and_filter_elements_on_project_level_page.html
server/sonar-web/src/main/js/apps/background-tasks/components/BackgroundTasksApp.js
server/sonar-web/src/main/js/apps/background-tasks/components/Task.js
server/sonar-web/src/main/js/apps/background-tasks/components/search.js
server/sonar-web/src/main/js/apps/background-tasks/components/tasks.js
server/sonar-web/src/main/js/apps/background-tasks/containers/BackgroundTasksAppContainer.js
server/sonar-web/src/main/js/apps/background-tasks/containers/SearchContainer.js
server/sonar-web/src/main/js/apps/background-tasks/containers/TasksContainer.js
server/sonar-web/src/main/js/apps/background-tasks/store/actions.js
server/sonar-web/src/main/js/apps/background-tasks/store/reducers.js
server/sonar-web/tests/apps/background-tasks-test.js

index 9f2192ab629d215aa969d0e50c238a365f1b9d5d..3418548c36e6652d57da96290fe16a07b33bf330 100644 (file)
@@ -30,7 +30,7 @@ import ListFooterContainer from '../containers/ListFooterContainer';
 
 export default class BackgroundTasksApp extends Component {
   componentDidMount () {
-    this.props.initApp();
+    this.props.initApp(this.props.options.component);
   }
 
   getComponentFilter () {
index 58daa47f6bb5899a5b3b0ee2df943094cd5e192b..c8bbf919a95dcc1bc935e27fceabb0b6b1e7d6a6 100644 (file)
@@ -26,21 +26,9 @@ import TaskDate from './TaskDate';
 import TaskExecutionTime from './TaskExecutionTime';
 import TaskCancelButton from './TaskCancelButton';
 import TaskLogsLink from './TaskLogsLink';
-
 import { STATUSES } from './../constants';
 
-
-function renderFilter (task) {
-  // if (this.props.options && this.props.options.component) {
-  //   return null;
-  // }
-  return <td className="thin nowrap">
-    <a onClick={this.handleFilter.bind(this, task)} className="icon-filter icon-half-transparent spacer-left" href="#"
-       title={`Show only "${task.componentName}" tasks`} data-toggle="tooltip"/>
-  </td>;
-}
-
-export default function Task ({ task, index, tasks, onCancelTask, onFilterTask }) {
+export default function Task ({ task, index, tasks, component, onCancelTask, onFilterTask }) {
   function handleFilterTask (task, e) {
     e.preventDefault();
     onFilterTask(task);
@@ -68,12 +56,14 @@ export default function Task ({ task, index, tasks, onCancelTask, onFilterTask }
         </td>
 
         <td className="thin nowrap">
-          <a
-              onClick={handleFilterTask.bind(this, task)}
-              className="icon-filter icon-half-transparent spacer-left"
-              href="#"
-              title={`Show only "${task.componentName}" tasks`}
-              data-toggle="tooltip"/>
+          {!component && (
+              <a
+                  onClick={handleFilterTask.bind(this, task)}
+                  className="icon-filter icon-half-transparent spacer-left"
+                  href="#"
+                  title={`Show only "${task.componentName}" tasks`}
+                  data-toggle="tooltip"/>
+          )}
         </td>
       </tr>
   );
index 349b62ad9c3ff8a2bbbd8a9a3b4d9045c85b432b..507cae227eadd5f429c3e8a09074b849e8888af0 100644 (file)
@@ -39,17 +39,23 @@ export default React.createClass({
   },
 
   renderSearchBox() {
-    if (this.props.options && this.props.options.component) {
+    if (this.props.component) {
       // do not render search form on the project-level page
       return null;
     }
     return (
-        <input onChange={this.onSearch}
-               value={this.props.query}
-               ref="searchInput"
-               className="input-large"
-               type="search"
-               placeholder="Search"/>
+        <li>
+          <h6 className="bt-search-form-label">
+            Component
+          </h6>
+
+          <input onChange={this.onSearch}
+                 value={this.props.query}
+                 ref="searchInput"
+                 className="js-search input-large"
+                 type="search"
+                 placeholder="Search"/>
+        </li>
     );
   },
 
@@ -97,12 +103,9 @@ export default React.createClass({
                   value={this.props.date}
                   onChange={this.props.onDateChange}/>
             </li>
-            <li>
-              <h6 className="bt-search-form-label">
-                Component
-              </h6>
-              {this.renderSearchBox()}
-            </li>
+
+            {this.renderSearchBox()}
+
             <li className="bt-search-form-right">
               <button
                   ref="reloadButton"
index 85b29bd53a13dabffc02897078857a864b89080a..6d3b225eb87d2d051c3eb4670409886246a935ec 100644 (file)
@@ -22,7 +22,7 @@ import React from 'react';
 import Task from './Task';
 import { translate } from '../../../helpers/l10n';
 
-export default function Tasks ({ tasks, onCancelTask, onFilterTask }) {
+export default function Tasks ({ tasks, component, onCancelTask, onFilterTask }) {
   return (
       <table className="data zebra zebra-hover background-tasks">
         <thead>
@@ -44,6 +44,7 @@ export default function Tasks ({ tasks, onCancelTask, onFilterTask }) {
                   task={task}
                   index={index}
                   tasks={tasks}
+                  component={component}
                   onCancelTask={onCancelTask}
                   onFilterTask={onFilterTask}/>
           ))}
index 75496136964bc0fb0b8d5a6158a6fb521a3402fb..88859c23ab386712397eb355a8011ca0178a9430 100644 (file)
@@ -28,7 +28,7 @@ function mapStateToProps () {
 
 function mapDispatchToProps (dispatch) {
   return {
-    initApp: () => dispatch(initApp())
+    initApp: (component) => dispatch(initApp(component))
   };
 }
 
index ccae8470dd27784d12060731a9805ad6ac31f6a5..d00631618bd2cd98c4699f38145be370c9011dc2 100644 (file)
@@ -30,7 +30,8 @@ function mapStateToProps (state) {
     date: state.date,
     query: state.query,
     taskType: state.taskType,
-    types: state.types
+    types: state.types,
+    component: state.component
   };
 }
 
index 0fc2989b98c3a6035b0f1e12d11d34a8c6805d56..fe962bc652c201d5e550b030e5b0dbd8c5918ae0 100644 (file)
@@ -25,7 +25,8 @@ import { cancelTask, filterTasks } from '../store/actions';
 function mapStateToProps (state) {
   return {
     fetching: state.fetching,
-    tasks: state.tasks
+    tasks: state.tasks,
+    component: state.component
   };
 }
 
index 511af5cdb29f08e2343d1a886cd10a8965dcbbd3..6dcd93afa4df29c175e2b562d1c8252b69b01e36 100644 (file)
@@ -33,9 +33,10 @@ export const CANCEL_ALL_PENDING = 'CANCEL_ALL_PENDING';
 export const CANCEL_TASK = 'CANCEL_TASK';
 export const FINISH_CANCEL_TASK = 'FINISH_CANCEL_TASK';
 
-export function init (types) {
+export function init (component, types) {
   return {
     type: INIT,
+    component,
     types
   };
 }
@@ -138,10 +139,16 @@ function getInProgressDuration (tasks) {
 }
 
 function fetchTasks (filters) {
-  return dispatch => {
+  return (dispatch, getState) => {
+    const { component } = getState();
     const parameters = mapFiltersToParameters(filters);
+
     parameters.ps = PAGE_SIZE;
 
+    if (component) {
+      parameters.componentId = component.id;
+    }
+
     dispatch(requestTasks(filters));
 
     return Promise.all([
@@ -200,10 +207,10 @@ export function cancelTask (task) {
   };
 }
 
-export function initApp () {
+export function initApp (component) {
   return dispatch => {
     getTypes().then(types => {
-      dispatch(init(types));
+      dispatch(init(component, types));
       dispatch(filterTasks());
     });
   };
index 5c00567011d7931bcaafa357e9fe66ac7e29d7e4..3774f5aebda5c15746ded96602452449773fa80f 100644 (file)
@@ -53,6 +53,7 @@ export default function (state = initialState, action) {
     case INIT:
       return {
         ...state,
+        component: action.component,
         types: action.types
       };
     case REQUEST_TASKS:
index 0d70aa18311d226135daa3b549421ffb349bab70..f72e3b41e69a0b02c1f52c5a62e59232d50104bb 100644 (file)
@@ -7,8 +7,8 @@ import Header from '../../src/main/js/apps/background-tasks/components/Header';
 import Stats from '../../src/main/js/apps/background-tasks/components/Stats';
 import Search from '../../src/main/js/apps/background-tasks/components/Search';
 import Tasks from '../../src/main/js/apps/background-tasks/components/Tasks';
-import {STATUSES, CURRENTS, DEBOUNCE_DELAY} from '../../src/main/js/apps/background-tasks/constants';
-import {formatDuration} from '../../src/main/js/apps/background-tasks/helpers';
+import { STATUSES, CURRENTS, DEBOUNCE_DELAY } from '../../src/main/js/apps/background-tasks/constants';
+import { formatDuration } from '../../src/main/js/apps/background-tasks/helpers';
 
 let chai = require('chai');
 let expect = chai.expect;
@@ -28,44 +28,37 @@ describe('Background Tasks', function () {
     });
   });
 
-  describe('Header', () => {
-    it('should render', () => {
-      let component = TestUtils.renderIntoDocument(<Header/>),
-          header = TestUtils.scryRenderedDOMComponentsWithTag(component, 'header');
-      expect(header.length).to.equal(1);
-    });
-  });
-
   describe('Search', () => {
     it('should render search form', () => {
-      let spy = sinon.spy();
-      let component = TestUtils.renderIntoDocument(<Search options={{}}
-                                                           onStatusChange={spy}
-                                                           onCurrentsChange={spy}
-                                                           onDateChange={spy}/>),
-          searchBox = TestUtils.scryRenderedDOMComponentsWithClass(component, 'search-box');
+      let component = TestUtils.renderIntoDocument(
+          <Search
+              types={[]}
+              date={{}}/>
+          ),
+          searchBox = TestUtils.scryRenderedDOMComponentsWithClass(component, 'js-search');
       expect(searchBox).to.have.length(1);
     });
 
     it('should not render search form', () => {
-      let spy = sinon.spy();
-      let component = TestUtils.renderIntoDocument(<Search options={{ component: { id: 'ABCD' } }}
-                                                           onStatusChange={spy}
-                                                           onCurrentsChange={spy}
-                                                           onDateChange={spy}/>),
-          searchBox = TestUtils.scryRenderedDOMComponentsWithClass(component, 'search-box');
+      let component = TestUtils.renderIntoDocument(
+          <Search
+              options={{ component: { id: 'ABCD' } }}
+              types={[]}
+              date={{}}/>
+          ),
+          searchBox = TestUtils.scryRenderedDOMComponentsWithClass(component, 'js-search');
       expect(searchBox).to.be.empty;
     });
 
     it('should search', (done) => {
-      let spy = sinon.spy(),
-          searchSpy = sinon.spy();
-      let component = TestUtils.renderIntoDocument(<Search options={{}}
-                                                           onStatusChange={spy}
-                                                           onCurrentsChange={spy}
-                                                           onDateChange={spy}
-                                                           onSearch={searchSpy}/>);
-      let searchInput = ReactDOM.findDOMNode(TestUtils.findRenderedDOMComponentWithClass(component, 'search-box-input'));
+      let searchSpy = sinon.spy();
+      let component = TestUtils.renderIntoDocument(
+          <Search
+              types={[]}
+              date={{}}
+              onSearch={searchSpy}/>);
+      let searchInput = ReactDOM.findDOMNode(
+          TestUtils.findRenderedDOMComponentWithClass(component, 'js-search'));
       searchInput.value = 'some search query';
       TestUtils.Simulate.change(searchInput);
       setTimeout(() => {
@@ -75,13 +68,13 @@ describe('Background Tasks', function () {
     });
 
     it('should reload', () => {
-      let spy = sinon.spy(),
-          reloadSpy = sinon.spy();
-      let component = TestUtils.renderIntoDocument(<Search options={{}}
-                                                           onStatusChange={spy}
-                                                           onCurrentsChange={spy}
-                                                           onDateChange={spy}
-                                                           refresh={reloadSpy}/>);
+      let reloadSpy = sinon.spy();
+      let component = TestUtils.renderIntoDocument(
+          <Search
+              types={[]}
+              date={{}}
+              onRefresh={reloadSpy}/>
+      );
       let reloadButton = component.refs.reloadButton;
       expect(reloadSpy).to.not.have.been.called;
       TestUtils.Simulate.click(reloadButton);
@@ -117,7 +110,7 @@ describe('Background Tasks', function () {
 
       it('should trigger cancelling pending', () => {
         let spy = sinon.spy();
-        let result = TestUtils.renderIntoDocument(<Stats pendingCount="5" cancelPending={spy}/>),
+        let result = TestUtils.renderIntoDocument(<Stats pendingCount="5" onCancelAllPending={spy}/>),
             cancelPending = result.refs.cancelPending;
         expect(spy).to.not.have.been.called;
         TestUtils.Simulate.click(cancelPending);
@@ -127,32 +120,32 @@ describe('Background Tasks', function () {
 
     describe('Failures', () => {
       it('should show zero failures', () => {
-        let result = TestUtils.renderIntoDocument(<Stats failuresCount="0"/>),
+        let result = TestUtils.renderIntoDocument(<Stats failingCount="0"/>),
             failureCounter = result.refs.failureCount;
         expect(failureCounter.textContent).to.contain('0');
       });
 
       it('should show 5 failures', () => {
-        let result = TestUtils.renderIntoDocument(<Stats failuresCount="5"/>),
+        let result = TestUtils.renderIntoDocument(<Stats failingCount="5"/>),
             failureCounter = result.refs.failureCount;
         expect(failureCounter.textContent).to.contain('5');
       });
 
       it('should not show link to failures', () => {
-        let result = TestUtils.renderIntoDocument(<Stats failuresCount="0"/>),
+        let result = TestUtils.renderIntoDocument(<Stats failingCount="0"/>),
             failureCounter = result.refs.failureCount;
         expect(failureCounter.tagName.toLowerCase()).to.not.equal('a');
       });
 
       it('should show link to failures', () => {
-        let result = TestUtils.renderIntoDocument(<Stats failuresCount="5"/>),
+        let result = TestUtils.renderIntoDocument(<Stats failingCount="5"/>),
             failureCounter = result.refs.failureCount;
         expect(failureCounter.tagName.toLowerCase()).to.equal('a');
       });
 
       it('should trigger filtering failures', () => {
         let spy = sinon.spy();
-        let result = TestUtils.renderIntoDocument(<Stats failuresCount="5" showFailures={spy}/>),
+        let result = TestUtils.renderIntoDocument(<Stats failingCount="5" onShowFailing={spy}/>),
             failureCounter = result.refs.failureCount;
         expect(spy).to.not.have.been.called;
         TestUtils.Simulate.click(failureCounter);
@@ -181,18 +174,6 @@ describe('Background Tasks', function () {
     });
   });
 
-  describe('Tasks', () => {
-    it('should show list', () => {
-      let tasks = [
-        { id: 'a' },
-        { id: 'b' },
-        { id: 'c' }
-      ];
-      let result = TestUtils.renderIntoDocument(<Tasks tasks={tasks}/>);
-      expect(TestUtils.scryRenderedDOMComponentsWithTag(result, 'tr')).to.have.length(3 + /* table header */ 1);
-    });
-  });
-
   describe('Helpers', () => {
     describe('#formatDuration()', () => {
       it('should format 173ms', () => {