Skip to content

Commit cd8986d

Browse files
committed
[DSC-1867] Optimize number of request for building the menu
1 parent c4e09bf commit cd8986d

1 file changed

Lines changed: 22 additions & 18 deletions

File tree

src/app/menu.resolver.ts

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import { RemoteData } from './core/data/remote-data';
1111
import { TextMenuItemModel } from './shared/menu/menu-item/models/text.model';
1212
import { MenuService } from './shared/menu/menu.service';
1313
import { filter, find, map, switchMap, take } from 'rxjs/operators';
14-
import { hasValue } from './shared/empty.util';
14+
import { hasValue, isNotEmpty } from './shared/empty.util';
1515
import { FeatureID } from './core/data/feature-authorization/feature-id';
1616
import {
1717
ThemedCreateCommunityParentSelectorComponent
@@ -532,11 +532,11 @@ export class MenuResolver implements Resolve<boolean> {
532532
];
533533
menuList.forEach((menuSection) => this.menuService.addSection(MenuID.ADMIN, menuSection));
534534

535-
observableCombineLatest([
536-
this.authorizationService.isAuthorized(FeatureID.AdministratorOf),
537-
this.scriptDataService.scriptWithNameExistsAndCanExecute(METADATA_EXPORT_SCRIPT_NAME)
538-
]).pipe(
539-
filter(([authorized, metadataExportScriptExists]: boolean[]) => authorized && metadataExportScriptExists),
535+
this.authorizationService.isAuthorized(FeatureID.AdministratorOf).pipe(
536+
filter((authorized: boolean) => authorized),
537+
take(1),
538+
switchMap(() => this.scriptDataService.scriptWithNameExistsAndCanExecute(METADATA_EXPORT_SCRIPT_NAME)),
539+
filter((metadataExportScriptExists: boolean) => metadataExportScriptExists),
540540
take(1)
541541
).subscribe(() => {
542542
// Hides the export menu for unauthorised people
@@ -617,20 +617,24 @@ export class MenuResolver implements Resolve<boolean> {
617617
* Add the DL Exporter menu item to the admin menu
618618
*/
619619
createDLExporterMenuItem() {
620-
observableCombineLatest([
621-
this.authorizationService.isAuthorized(FeatureID.AdministratorOf),
622-
this.getDLExporterURL(),
623-
this.getDLExporterAccessToken()
624-
]).subscribe(([authorized, url, accesstoken]) => {
625-
console.log(accesstoken);
620+
this.authorizationService.isAuthorized(FeatureID.AdministratorOf).pipe(
621+
filter((authorized: boolean) => authorized),
622+
take(1),
623+
switchMap(() => observableCombineLatest([
624+
this.getDLExporterURL(),
625+
this.getDLExporterAccessToken()
626+
])),
627+
filter(([url, accesstoken]) => isNotEmpty(url) && isNotEmpty(accesstoken)),
628+
take(1)
629+
).subscribe(([url, accesstoken]) => {
626630
const urlSegments = url.split('?');
627631
const queryParamSegments = urlSegments[1].split('=');
628632
this.menuService.addSection(MenuID.ADMIN,
629633
{
630634
id: 'loginmiur_dlexporter_url',
631635
index: 15,
632636
active: false,
633-
visible: authorized && (hasValue(url) && url.length > 0) && (hasValue(accesstoken) && accesstoken.length > 0),
637+
visible: true,
634638
model: {
635639
type: MenuItemType.LINK,
636640
text: 'menu.section.loginmiur_dlexporter_url',
@@ -655,11 +659,11 @@ export class MenuResolver implements Resolve<boolean> {
655659
const menuList = [];
656660
menuList.forEach((menuSection) => this.menuService.addSection(MenuID.ADMIN, menuSection));
657661

658-
observableCombineLatest([
659-
this.authorizationService.isAuthorized(FeatureID.AdministratorOf),
660-
this.scriptDataService.scriptWithNameExistsAndCanExecute(METADATA_IMPORT_SCRIPT_NAME)
661-
]).pipe(
662-
filter(([authorized, metadataImportScriptExists]: boolean[]) => authorized && metadataImportScriptExists),
662+
this.authorizationService.isAuthorized(FeatureID.AdministratorOf).pipe(
663+
filter((authorized: boolean) => authorized),
664+
take(1),
665+
switchMap(() => this.scriptDataService.scriptWithNameExistsAndCanExecute(METADATA_IMPORT_SCRIPT_NAME)),
666+
filter((metadataImportScriptExists: boolean) => metadataImportScriptExists),
663667
take(1)
664668
).subscribe(() => {
665669
// Hides the import menu for unauthorised people

0 commit comments

Comments
 (0)