From 99a1dbeae165649cac3505c30f58852fc9ed774a Mon Sep 17 00:00:00 2001 From: rajaa-b Date: Wed, 21 Sep 2022 11:02:03 +0200 Subject: [PATCH] fix(xo-web/tasks): fix tasks filter (#6424) See zammad#9423 --- CHANGELOG.unreleased.md | 2 +- packages/xo-web/src/xo-app/tasks/index.js | 34 ++++++++--------------- 2 files changed, 13 insertions(+), 23 deletions(-) diff --git a/CHANGELOG.unreleased.md b/CHANGELOG.unreleased.md index 326f318f6..a0115c67c 100644 --- a/CHANGELOG.unreleased.md +++ b/CHANGELOG.unreleased.md @@ -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)) @@ -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 diff --git a/packages/xo-web/src/xo-app/tasks/index.js b/packages/xo-web/src/xo-app/tasks/index.js index 0088bf618..22a5abeb8 100644 --- a/packages/xo-web/src/xo-app/tasks/index.js +++ b/packages/xo-web/src/xo-app/tasks/index.js @@ -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, @@ -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, } } }) @@ -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 @@ -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