diff --git a/packages/xo-web/src/xo-app/logs/index.js b/packages/xo-web/src/xo-app/logs/index.js index 437ad7030..9f572a3d8 100644 --- a/packages/xo-web/src/xo-app/logs/index.js +++ b/packages/xo-web/src/xo-app/logs/index.js @@ -9,15 +9,16 @@ import NoObjects from 'no-objects' import propTypes from 'prop-types-decorator' import React, { Component } from 'react' import renderXoItem from 'render-xo-item' +import Select from 'form/select' import SortedTable from 'sorted-table' import Tooltip from 'tooltip' import { alert, confirm } from 'modal' -import { createGetObject } from 'selectors' -import { FormattedDate } from 'react-intl' -import { connectStore, formatSize, formatSpeed } from 'utils' import { Card, CardHeader, CardBlock } from 'card' -import { forEach, get, includes, isEmpty, map, orderBy } from 'lodash' +import { connectStore, formatSize, formatSpeed } from 'utils' +import { createFilter, createGetObject, createSelector } from 'selectors' import { deleteJobsLog, subscribeJobsLogs } from 'xo' +import { forEach, get, includes, isEmpty, map, orderBy } from 'lodash' +import { FormattedDate } from 'react-intl' // =================================================================== @@ -103,8 +104,9 @@ const JobDataInfos = ({ ) +const DEFAULT_CALL_FILTER = { label: 'allJobCalls', value: 'all' } const CALL_FILTER_OPTIONS = [ - { label: 'allJobCalls', value: 'all' }, + DEFAULT_CALL_FILTER, { label: 'failedJobCall', value: 'error' }, { label: 'jobCallInProgess', value: 'running' }, { label: 'jobCallSkipped', value: 'skipped' }, @@ -128,31 +130,44 @@ const isSkippedError = error => error.message === UNHEALTHY_VDI_CHAIN_ERROR || error.message === NO_SUCH_OBJECT_ERROR +const filterOptionRenderer = ({ label }) => _(label) + class Log extends BaseComponent { state = { - filter: 'all', + filter: DEFAULT_CALL_FILTER, } - render () { - const { props, state } = this - const predicate = PREDICATES[state.filter] + _getFilteredCalls = createFilter( + () => this.props.log.calls, + createSelector(() => this.state.filter.value, value => PREDICATES[value]) + ) + _filterValueRenderer = createSelector( + () => this._getFilteredCalls().length, + ({ label }) => label, + (size, label) => ( + + {_(label)} ({size}) + + ) + ) + + render () { return (
- + optionRenderer={filterOptionRenderer} + options={CALL_FILTER_OPTIONS} + required + value={this.state.filter} + valueKey='value' + valueRenderer={this._filterValueRenderer} + />