Skip to content

Commit 5eadcb1

Browse files
cbourgoisJoffrey LEVEUGLE
authored andcommitted
fix(server-sidebar): add empty item if no services (#702)
1 parent 8db5ac2 commit 5eadcb1

File tree

3 files changed

+64
-47
lines changed

3 files changed

+64
-47
lines changed

packages/manager/modules/server-sidebar/package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,13 @@
2727
"@ovh-ux/manager-config": "^0.2.0",
2828
"@ovh-ux/manager-core": "^5.2.5",
2929
"@ovh-ux/ng-ovh-cloud-universe-components": "^1.3.0-alpha.4",
30-
"@ovh-ux/ng-ovh-sidebar-menu": "git+https://github.com/ovh-ux/ng-ovh-sidebar-menu.git#fix/revert-old-style",
30+
"@ovh-ux/ng-ovh-sidebar-menu": "^8.1.0",
3131
"@ovh-ux/ng-translate-async-loader": "^2.0.0",
3232
"angular": "^1.7.8",
3333
"angular-translate": "^2.18.1",
3434
"ovh-api-services": "^6.18.1"
3535
},
3636
"dependencies": {
37-
"@ovh-ux/ng-ovh-sidebar-menu": "^8.1.0",
3837
"jsurl": "^0.1.5",
3938
"lodash": "^4.17.11"
4039
},

packages/manager/modules/server-sidebar/src/controller.js

Lines changed: 61 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import isString from 'lodash/isString';
1212
import map from 'lodash/map';
1313
import orderBy from 'lodash/orderBy';
1414
import reduce from 'lodash/reduce';
15+
import sumBy from 'lodash/sumBy';
1516
import zipObject from 'lodash/zipObject';
1617

1718
import { 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

packages/manager/modules/server-sidebar/src/translations/Messages_fr_FR.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
"server_sidebar_item_title_DEDICATED": "Server",
33
"server_sidebar_item_title_CLOUD": "Server",
44

5+
"server_sidebar_item_empty_title": "Aucun service",
6+
57
"server_sidebar_item_dedicatedServers_title": "Serveurs Dédiés",
68
"server_sidebar_item_dedicatedClouds_title": "Private Cloud",
79
"server_sidebar_item_networks_title": "NAS et CDN",

0 commit comments

Comments
 (0)