@@ -12,6 +12,7 @@ import isString from 'lodash/isString';
1212import map from 'lodash/map' ;
1313import orderBy from 'lodash/orderBy' ;
1414import reduce from 'lodash/reduce' ;
15+ import sumBy from 'lodash/sumBy' ;
1516import zipObject from 'lodash/zipObject' ;
1617
1718import { MANAGER_URLS } from './constants' ;
@@ -170,66 +171,81 @@ export default class OvhManagerServerSidebarController {
170171 } , parent ) ;
171172
172173 if ( has ( service , 'types' ) ) {
173- menuItem . onLoad = ( ) => this . loadServices ( service . types , menuItem ) ;
174+ menuItem . onLoad = ( ) => this . loadServices ( service , menuItem ) ;
175+ } else {
176+ this . addItems ( get ( service , 'children' ) , menuItem ) ;
174177 }
175-
176- this . addItems ( get ( service , 'children' ) , menuItem ) ;
177178 }
178179 } ) ;
179180 }
180181
181- loadServices ( types , parent , params = { } ) {
182+ loadServices ( parentService , parent , params = { } ) {
182183 const promises = [ ] ;
183- each ( this . filterRegions ( types ) , ( typeDefinition ) => {
184+
185+ each ( this . filterRegions ( parentService . types ) , ( typeDefinition ) => {
184186 const parentParams = get ( parent , 'stateParams' , { } ) ;
185187 promises . push ( this . getTypeItems ( typeDefinition , { ...params , ...parentParams } ) ) ;
186188 } ) ;
187- return this . $q . all ( promises )
189+
190+ return this . $q
191+ . all ( promises )
188192 . then ( ( typesServices ) => {
189- each ( typesServices , ( typeServices ) => {
190- const hasSubItems = has ( typeServices . type , 'types' ) ;
191- each ( orderBy ( typeServices . items , 'displayName ') , ( service ) => {
192- const isExternal = ! includes ( typeServices . type . app , this . universe )
193- && ! isEmpty ( service . url ) ;
194-
195- let stateParams = zipObject ( get ( typeServices . type , 'stateParams' , [ ] ) , get ( service , 'stateParams' , [ ] ) ) ;
196- if ( has ( typeServices . type , 'stateParamsTransformer' ) && isFunction ( typeServices . type . stateParamsTransformer ) ) {
197- stateParams = typeServices . type . stateParamsTransformer ( stateParams ) ;
198- }
193+ if ( sumBy ( typesServices , typeServices => typeServices . items . length ) === 0 ) {
194+ this . SidebarMenu . addMenuItem ( {
195+ title : this . $translate . instant ( 'server_sidebar_item_empty_title ') ,
196+ allowSubItems : false ,
197+ infiniteScroll : false ,
198+ allowSearch : false ,
199+ } , parent ) ;
200+ } else {
201+ each ( typesServices , ( typeServices ) => {
202+ this . addItems ( get ( parentService , 'children' ) , parent ) ;
199203
200- let link = null ;
201- let state = null ;
202- if ( isExternal ) {
203- link = service . url ;
204- } else {
205- state = get ( typeServices . type , 'state' ) ;
206- if ( has ( typeServices . type , 'getState' ) && isFunction ( typeServices . type . getState ) ) {
207- state = typeServices . type . getState ( service . extraParams ) ;
204+ const hasSubItems = has ( typeServices . type , 'types' ) ;
205+
206+ each ( orderBy ( typeServices . items , 'displayName' ) , ( service ) => {
207+ const isExternal = ! includes ( typeServices . type . app , this . universe )
208+ && ! isEmpty ( service . url ) ;
209+
210+ let stateParams = zipObject ( get ( typeServices . type , 'stateParams' , [ ] ) , get ( service , 'stateParams' , [ ] ) ) ;
211+ if ( has ( typeServices . type , 'stateParamsTransformer' ) && isFunction ( typeServices . type . stateParamsTransformer ) ) {
212+ stateParams = typeServices . type . stateParamsTransformer ( stateParams ) ;
208213 }
209- }
210214
211- const menuItem = this . SidebarMenu . addMenuItem ( {
212- title : service . displayName ,
213- allowSubItems : hasSubItems && ! isExternal ,
214- infiniteScroll : hasSubItems && ! isExternal ,
215- allowSearch : false ,
216- state,
217- stateParams ,
218- url : link ,
219- target : isExternal ? '_self' : null ,
220- icon : get ( typeServices . type , 'icon' ) ,
221- loadOnState : get ( typeServices . type , 'loadOnState' ) ,
222- } , parent ) ;
223-
224- if ( hasSubItems && ! isExternal ) {
225- menuItem . onLoad = ( ) => this . loadServices (
226- typeServices . type . types ,
227- menuItem ,
215+ let link = null ;
216+ let state = null ;
217+ if ( isExternal ) {
218+ link = service . url ;
219+ } else {
220+ state = get ( typeServices . type , 'state' ) ;
221+ if ( has ( typeServices . type , 'getState' ) && isFunction ( typeServices . type . getState ) ) {
222+ state = typeServices . type . getState ( service . extraParams ) ;
223+ }
224+ }
225+
226+ const menuItem = this . SidebarMenu . addMenuItem ( {
227+ title : service . displayName ,
228+ allowSubItems : hasSubItems && ! isExternal ,
229+ infiniteScroll : hasSubItems && ! isExternal ,
230+ allowSearch : false ,
231+ state ,
228232 stateParams,
229- ) ;
230- }
233+ url : link ,
234+ target : isExternal ? '_self' : null ,
235+ icon : get ( typeServices . type , 'icon' ) ,
236+ loadOnState : get ( typeServices . type , 'loadOnState' ) ,
237+ } , parent ) ;
238+
239+ if ( hasSubItems && ! isExternal ) {
240+ menuItem . onLoad = ( ) => this . loadServices (
241+ typeServices . type ,
242+ menuItem ,
243+ stateParams ,
244+ ) ;
245+ }
246+ } ) ;
231247 } ) ;
232- } ) ;
248+ }
233249 } ) ;
234250 }
235251
0 commit comments