*/
import React, { Component } from 'react';
-import { formatDuration } from './../helpers';
import { translate } from '../../../helpers/l10n';
-
export default class Stats extends Component {
handleCancelAllPending (e) {
e.preventDefault();
this.props.onShowFailing();
}
- renderInProgressDuration () {
- if (!this.props.inProgressDuration) {
- return null;
- }
- return (
- <span
- className="huge-spacer-left"
- title={translate('background_tasks.in_progress_duration')}
- data-toggle="tooltip">
- <i
- className="spinner spacer-right"
- style={{ verticalAlign: 'text-top' }}/>
- <span
- ref="inProgressDuration"
- className="emphasised-measure">
- {formatDuration(this.props.inProgressDuration)}
- </span>
- </span>
- );
- }
-
renderPending () {
if (this.props.pendingCount == null) {
return null;
<span className="huge-spacer-left">
{this.renderFailures()}
</span>
- {this.renderInProgressDuration()}
</section>
);
return {
pendingCount: state.pendingCount,
failingCount: state.failingCount,
- inProgressDuration: state.inProgressDuration,
component: state.component
};
}
};
}
-export function receiveStats ({ pendingCount, failingCount, inProgressDuration }) {
+export function receiveStats ({ pendingCount, failingCount }) {
return {
type: RECEIVE_STATS,
pendingCount,
- failingCount,
- inProgressDuration
+ failingCount
};
}
return parameters;
}
-function getInProgressDuration (tasks) {
- return tasks.length ? tasks[0].executionTimeMs : null;
-}
-
function fetchTasks (filters) {
return (dispatch, getState) => {
const { component } = getState();
return Promise.all([
getActivity(parameters),
getActivity({ ps: 1, onlyCurrents: true, status: STATUSES.FAILED }),
- getActivity({ ps: 1, status: STATUSES.PENDING }),
- getActivity({ ps: 1, status: STATUSES.IN_PROGRESS })
+ getActivity({ ps: 1, status: STATUSES.PENDING })
]).then(responses => {
- const [activity, failingActivity, pendingActivity, inProgressActivity] = responses;
+ const [activity, failingActivity, pendingActivity] = responses;
const tasks = activity.tasks;
const total = activity.paging.total;
dispatch(receiveTasks(tasks, total));
const pendingCount = pendingActivity.paging.total;
- const inProgressDuration = getInProgressDuration(inProgressActivity.tasks);
const failingCount = failingActivity.paging.total;
- dispatch(receiveStats({ pendingCount, failingCount, inProgressDuration }));
+ dispatch(receiveStats({ pendingCount, failingCount }));
});
};
}
// stats
pendingCount: 0,
- failingCount: 0,
- inProgressDuration: null
+ failingCount: 0
};
function updateTask (tasks, newTask) {
return {
...state,
pendingCount: action.pendingCount,
- failingCount: action.failingCount,
- inProgressDuration: action.inProgressDuration
+ failingCount: action.failingCount
};
case CANCEL_ALL_PENDING:
return {
expect(spy).to.have.been.called;
});
});
-
- describe('In Progress Duration', () => {
- it('should show duration', () => {
- let result = TestUtils.renderIntoDocument(<Stats inProgressDuration="173"/>),
- inProgressDuration = result.refs.inProgressDuration;
- expect(inProgressDuration.textContent).to.include('173ms');
- });
-
- it('should format duration', () => {
- let result = TestUtils.renderIntoDocument(<Stats inProgressDuration="1073"/>),
- inProgressDuration = result.refs.inProgressDuration;
- expect(inProgressDuration.textContent).to.include('1s');
- });
-
- it('should not show duration', () => {
- let result = TestUtils.renderIntoDocument(<Stats/>),
- inProgressDuration = result.refs.inProgressDuration;
- expect(inProgressDuration).to.not.be.ok;
- });
- });
});
describe('Helpers', () => {