Commits
Giuseppe Digilio authored 6d1674cc8a3
1 1 | import { ChangeDetectionStrategy, Component, Injector, OnDestroy, OnInit } from '@angular/core'; |
2 - | import { BehaviorSubject, Observable, Subscription, of as observableOf } from 'rxjs'; |
2 + | import { BehaviorSubject, Observable, of as observableOf, Subscription } from 'rxjs'; |
3 3 | import { MenuService } from './menu.service'; |
4 4 | import { MenuID } from './initial-menus-state'; |
5 5 | import { MenuSection } from './menu.reducer'; |
6 - | import { distinctUntilChanged, map, switchMap, mergeMap, tap, isEmpty } from 'rxjs/operators'; |
6 + | import { distinctUntilChanged, map, mergeMap, switchMap } from 'rxjs/operators'; |
7 7 | import { GenericConstructor } from '../../core/shared/generic-constructor'; |
8 - | import { hasValue, isNotEmpty, hasValueOperator, isNotEmptyOperator } from '../empty.util'; |
8 + | import { hasValue, isNotEmptyOperator } from '../empty.util'; |
9 9 | import { MenuSectionComponent } from './menu-section/menu-section.component'; |
10 10 | import { getComponentForMenu } from './menu-section.decorator'; |
11 11 | import { compareArraysUsingIds } from '../../item-page/simple/item-types/shared/item-relationships-utils'; |
12 12 | import { ActivatedRoute } from '@angular/router'; |
13 13 | import { AuthorizationDataService } from '../../core/data/feature-authorization/authorization-data.service'; |
14 14 | import { FeatureID } from '../../core/data/feature-authorization/feature-id'; |
15 15 | |
16 16 | /** |
17 17 | * A basic implementation of a MenuComponent |
18 18 | */ |
83 83 | this.menuCollapsed = this.menuService.isMenuCollapsed(this.menuID); |
84 84 | this.menuPreviewCollapsed = this.menuService.isMenuPreviewCollapsed(this.menuID); |
85 85 | this.menuVisible = this.menuService.isMenuVisible(this.menuID); |
86 86 | this.sections = this.menuService.getMenuTopSections(this.menuID).pipe(distinctUntilChanged(compareArraysUsingIds())); |
87 87 | |
88 88 | this.subs.push( |
89 89 | this.sections.pipe( |
90 90 | // if you return an array from a switchMap it will emit each element as a separate event. |
91 91 | // So this switchMap is equivalent to a subscribe with a forEach inside |
92 92 | switchMap((sections: MenuSection[]) => sections), |
93 - | switchMap((section: MenuSection) => { |
93 + | mergeMap((section: MenuSection) => { |
94 94 | if (section.id.includes('statistics')) { |
95 95 | return this.getAuthorizedStatistics(section); |
96 96 | } |
97 97 | return observableOf(section); |
98 98 | }), |
99 99 | isNotEmptyOperator(), |
100 100 | switchMap((section: MenuSection) => this.getSectionComponent(section).pipe( |
101 101 | map((component: GenericConstructor<MenuSectionComponent>) => ({ section, component })) |
102 102 | )), |
103 103 | distinctUntilChanged((x, y) => x.section.id === y.section.id) |