From 21a7cf7158e2d30d9a2369d3fb09a89ee3c1ab4f Mon Sep 17 00:00:00 2001 From: "Rajaa.BARHTAOUI" Date: Wed, 10 Apr 2019 14:35:58 +0200 Subject: [PATCH] fix(xo-web/menu/xoa): display icon when no notifications nor updates (#4068) Fixes #4012 --- CHANGELOG.unreleased.md | 1 + packages/xo-web/src/common/selectors.js | 2 ++ packages/xo-web/src/xo-app/menu/index.js | 40 +++++++++++++++--------- 3 files changed, 28 insertions(+), 15 deletions(-) diff --git a/CHANGELOG.unreleased.md b/CHANGELOG.unreleased.md index b776463e0..192bc5d6a 100644 --- a/CHANGELOG.unreleased.md +++ b/CHANGELOG.unreleased.md @@ -13,6 +13,7 @@ - [Continuous Replication] Fix VHD size guess for empty files [#4105](https://github.com/vatesfr/xen-orchestra/issues/4105) (PR [#4107](https://github.com/vatesfr/xen-orchestra/pull/4107)) - [Backup NG] Only display full backup interval in case of a delta backup (PR [#4125](https://github.com/vatesfr/xen-orchestra/pull/4107)) - [Dashboard/Health] fix 'an error has occurred' on the storage state table [#4128](https://github.com/vatesfr/xen-orchestra/issues/4128) (PR [#4132](https://github.com/vatesfr/xen-orchestra/pull/4132)) +- [Menu] XOA: Fixed empty slot when menu is collapsed [#4012](https://github.com/vatesfr/xen-orchestra/issues/4012) (PR [#4068](https://github.com/vatesfr/xen-orchestra/pull/4068) ### Released packages diff --git a/packages/xo-web/src/common/selectors.js b/packages/xo-web/src/common/selectors.js index 0ea80247a..4d3f8ef00 100644 --- a/packages/xo-web/src/common/selectors.js +++ b/packages/xo-web/src/common/selectors.js @@ -213,6 +213,8 @@ export const getStatus = state => state.status export const getUser = state => state.user +export const getXoaState = state => state.xoaUpdaterState + export const getCheckPermissions = invoke(() => { const getPredicate = create( state => state.permissions, diff --git a/packages/xo-web/src/xo-app/menu/index.js b/packages/xo-web/src/xo-app/menu/index.js index e468153b4..305876a6e 100644 --- a/packages/xo-web/src/xo-app/menu/index.js +++ b/packages/xo-web/src/xo-app/menu/index.js @@ -2,9 +2,7 @@ import _ from 'intl' import classNames from 'classnames' import Component from 'base-component' import Icon from 'icon' -import isEmpty from 'lodash/isEmpty' import Link from 'link' -import map from 'lodash/map' import React from 'react' import Tooltip from 'tooltip' import { UpdateTag } from '../xoa/update' @@ -13,6 +11,7 @@ import { addSubscriptions, connectStore, getXoaPlan, noop } from 'utils' import { connect, signOut, + subscribeNotifications, subscribePermissions, subscribeResourceSets, } from 'xo' @@ -23,8 +22,10 @@ import { getIsPoolAdmin, getStatus, getUser, + getXoaState, isAdmin, } from 'selectors' +import { every, identity, isEmpty, map } from 'lodash' import styles from './index.css' @@ -34,20 +35,22 @@ const returnTrue = () => true () => ({ isAdmin, isPoolAdmin: getIsPoolAdmin, + nHosts: createGetObjectsOfType('host').count(), nTasks: createGetObjectsOfType('task').count([ task => task.status === 'pending', ]), pools: createGetObjectsOfType('pool'), - nHosts: createGetObjectsOfType('host').count(), srs: createGetObjectsOfType('SR'), status: getStatus, user: getUser, + xoaState: getXoaState, }), { withRef: true, } ) @addSubscriptions({ + notifications: subscribeNotifications, permissions: subscribePermissions, resourceSets: subscribeResourceSets, }) @@ -88,6 +91,11 @@ export default class Menu extends Component { isEmpty ) + _getNoNotifications = createSelector( + () => this.props.notifications, + notifications => every(notifications, { read: true }) + ) + get height() { return this.refs.content.offsetHeight } @@ -118,9 +126,11 @@ export default class Menu extends Component { pools, nHosts, srs, + xoaState, } = this.props const noOperatablePools = this._getNoOperatablePools() const noResourceSets = this._getNoResourceSets() + const noNotifications = this._getNoNotifications() /* eslint-disable object-property-newline */ const items = [ @@ -247,16 +257,12 @@ export default class Menu extends Component { to: isAdmin ? 'xoa/update' : 'xoa/notifications', icon: 'menu-xoa', label: 'xoa', - extra: ( - - {isAdmin && ( - - {' '} - - )} - - - ), + extra: [ + !isAdmin || xoaState === 'upToDate' ? null : ( + + ), + noNotifications ? null : , + ], subMenu: [ isAdmin && { to: 'xoa/update', @@ -528,6 +534,7 @@ export default class Menu extends Component { const MenuLinkItem = props => { const { item } = props const { to, icon, label, subMenu, pill, extra } = item + const _extra = extra !== undefined ? extra.find(e => e !== null) : undefined return (
  • @@ -537,7 +544,7 @@ const MenuLinkItem = props => { to={to} > {   {pill > 0 && {pill}} - {extra} + {_extra} + + {extra !== undefined && extra.map(identity)} + {subMenu && }