Skip to content

Commit

Permalink
fix(xo-web/tasks): fix tasks filter (#6424)
Browse files Browse the repository at this point in the history
See zammad#9423
  • Loading branch information
Rajaa-BARHTAOUI committed Sep 21, 2022
1 parent 2a71e28 commit 99a1dbe
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 23 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.unreleased.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
> Users must be able to say: “Nice enhancement, I'm eager to test it”
- [Backup/Restore file] Implement File level restore for s3 and encrypted backups (PR [#6409](https://github.com/vatesfr/xen-orchestra/pull/6409))

- [Backup] Improve listing speed by updating caches instead of regenerating them on backup creation/deletion (PR [#6411](https://github.com/vatesfr/xen-orchestra/pull/6411))
- [Backup] Add `mergeBlockConcurrency` and `writeBlockConcurrency` to allow tuning of backup resources consumptions (PR [#6416](https://github.com/vatesfr/xen-orchestra/pull/6416))

Expand All @@ -19,6 +18,7 @@
- [Plugin/auth-saml] Certificate input support multiline (PR [#6403](https://github.com/vatesfr/xen-orchestra/pull/6403))
- [Backup] Launch Health Check after a full backup (PR [#6401](https://github.com/vatesfr/xen-orchestra/pull/6401))
- [Backup] Fix `Lock file is already being held` error when deleting a VM backup while the VM is currently being backed up
- [Tasks] Fix the pool filter that did not display tasks even if they existed (PR [#6424](https://github.com/vatesfr/xen-orchestra/pull/6424))

### Packages to release

Expand Down
34 changes: 12 additions & 22 deletions packages/xo-web/src/xo-app/tasks/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { addSubscriptions, connectStore, resolveIds } from 'utils'
import { FormattedDate, FormattedRelative, injectIntl } from 'react-intl'
import { SelectPool } from 'select-objects'
import { Col, Container, Row } from 'grid'
import { differenceBy, flatMap, groupBy, isEmpty, keys, map, some } from 'lodash'
import { differenceBy, isEmpty, map, some } from 'lodash'
import {
createFilter,
createGetObject,
Expand Down Expand Up @@ -192,20 +192,18 @@ const GROUPED_ACTIONS = [
permissions: subscribePermissions,
})
@connectStore(() => {
const getResolvedPendingTasksByPool = createSelector(getResolvedPendingTasks, resolvedPendingTasks =>
groupBy(resolvedPendingTasks, '$pool')
const getPools = createGetObjectsOfType('pool').pick(
createSelector(getResolvedPendingTasks, resolvedPendingTasks => resolvedPendingTasks.map(task => task.$poolId))
)

const getPools = createGetObjectsOfType('pool').pick(createSelector(getResolvedPendingTasksByPool, keys))

return (state, props) => {
// true: useResourceSet to bypass permissions
const resolvedPendingTasksByPool = getResolvedPendingTasks(state, props, true)
const resolvedPendingTasks = getResolvedPendingTasks(state, props, true)
return {
isAdmin: isAdmin(state, props),
nResolvedTasks: resolvedPendingTasksByPool.length,
nResolvedTasks: resolvedPendingTasks.length,
pools: getPools(state, props, true),
resolvedPendingTasksByPool,
resolvedPendingTasks,
}
}
})
Expand All @@ -216,7 +214,7 @@ export default class Tasks extends Component {
}

componentWillReceiveProps(props) {
const finishedTasks = differenceBy(this.props.resolvedPendingTasksByPool, props.resolvedPendingTasksByPool, 'id')
const finishedTasks = differenceBy(this.props.resolvedPendingTasks, props.resolvedPendingTasks, 'id')
if (!isEmpty(finishedTasks)) {
this.setState({
finishedTasks: finishedTasks
Expand All @@ -226,22 +224,14 @@ export default class Tasks extends Component {
}
}

_getTasks = createSelector(
_getPoolFilter = createSelector(
createSelector(() => this.state.pools, resolveIds),
() => this.props.resolvedPendingTasksByPool,
(poolIds, resolvedPendingTasksByPool) =>
isEmpty(poolIds)
? resolvedPendingTasksByPool
: flatMap(poolIds, poolId => resolvedPendingTasksByPool[poolId] || [])
poolIds => (isEmpty(poolIds) ? null : ({ $poolId }) => poolIds.includes($poolId))
)

_getFinishedTasks = createFilter(
() => this.state.finishedTasks,
createSelector(
createSelector(() => this.state.pools, resolveIds),
poolIds => (isEmpty(poolIds) ? null : ({ $poolId }) => poolIds.includes($poolId))
)
)
_getTasks = createFilter(() => this.props.resolvedPendingTasks, this._getPoolFilter)

_getFinishedTasks = createFilter(() => this.state.finishedTasks, this._getPoolFilter)

_getItemsPerPageContainer = () => this.state.itemsPerPageContainer

Expand Down

0 comments on commit 99a1dbe

Please sign in to comment.