[ACS-5932] - Sidenav not able to expand when search page is closed (#3412)

This commit is contained in:
DominikIwanek 2023-09-05 16:45:49 +02:00 committed by GitHub
parent 4a8faeaa8e
commit 46ea85436b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 22 additions and 14 deletions

View File

@ -42,10 +42,12 @@ describe('SearchInputComponent', () => {
let searchInputService: SearchNavigationService;
const appServiceMock = {
appNavNarMode$: new BehaviorSubject('collapsed'),
setAppNavbarMode: jasmine.createSpy('setAppNavbarMode'),
toggleAppNavBar$: new Subject()
};
beforeEach(() => {
appServiceMock.setAppNavbarMode.calls.reset();
TestBed.configureTestingModule({
imports: [AppTestingModule, SearchInputComponent],
providers: [
@ -70,10 +72,9 @@ describe('SearchInputComponent', () => {
});
it('should collapsed sidenav by default', () => {
spyOn(appServiceMock.appNavNarMode$, 'next');
component.ngOnInit();
expect(appServiceMock.appNavNarMode$.next).toHaveBeenCalledWith('collapsed');
expect(appServiceMock.setAppNavbarMode).toHaveBeenCalledWith('collapsed');
});
it('should change flag on library400Error event', async () => {
@ -244,9 +245,8 @@ describe('SearchInputComponent', () => {
});
it('should sidenav expanded after the component is destroy', () => {
spyOn(appServiceMock.appNavNarMode$, 'next');
component.ngOnDestroy();
expect(appServiceMock.appNavNarMode$.next).toHaveBeenCalledWith('expanded');
expect(appServiceMock.setAppNavbarMode).toHaveBeenCalledWith('expanded');
});
});

View File

@ -139,7 +139,7 @@ export class SearchInputComponent implements OnInit, OnDestroy {
}
showInputValue() {
this.appService.appNavNarMode$.next('collapsed');
this.appService.setAppNavbarMode('collapsed');
this.has400LibraryError = false;
this.hasLibrariesConstraint = this.evaluateLibrariesConstraint();
this.searchedWord = this.getUrlSearchTerm();
@ -150,7 +150,7 @@ export class SearchInputComponent implements OnInit, OnDestroy {
}
ngOnDestroy(): void {
this.appService.appNavNarMode$.next('expanded');
this.appService.setAppNavbarMode('expanded');
this.onDestroy$.next(true);
this.onDestroy$.complete();
this.removeContentFilters();

View File

@ -37,10 +37,12 @@ describe('SearchLibrariesResultsComponent', () => {
const emptyPage = { list: { pagination: { totalItems: 0 }, entries: [] } };
const appServiceMock = {
appNavNarMode$: new BehaviorSubject('collapsed'),
toggleAppNavBar$: new Subject()
toggleAppNavBar$: new Subject(),
setAppNavbarMode: jasmine.createSpy('setAppNavbarMode')
};
beforeEach(() => {
appServiceMock.setAppNavbarMode.calls.reset();
TestBed.configureTestingModule({
imports: [AppTestingModule, SearchLibrariesResultsComponent],
schemas: [NO_ERRORS_SCHEMA],
@ -65,9 +67,8 @@ describe('SearchLibrariesResultsComponent', () => {
});
it('should collapsed sidenav by default', () => {
spyOn(appServiceMock.appNavNarMode$, 'next');
component.ngOnInit();
expect(appServiceMock.appNavNarMode$.next).toHaveBeenCalledWith('collapsed');
expect(appServiceMock.setAppNavbarMode).toHaveBeenCalledWith('collapsed');
});
});

View File

@ -92,7 +92,7 @@ export class SearchLibrariesResultsComponent extends PageComponent implements On
}
ngOnInit() {
this.appService.appNavNarMode$.next('collapsed');
this.appService.setAppNavbarMode('collapsed');
super.ngOnInit();
this.columns = this.extensions.documentListPresets.searchLibraries || [];

View File

@ -54,7 +54,8 @@ describe('SearchComponent', () => {
provide: AppService,
useValue: {
appNavNarMode$: new BehaviorSubject('expanded'),
toggleAppNavBar$: new Subject()
toggleAppNavBar$: new Subject(),
setAppNavbarMode: jasmine.createSpy('setAppNavbarMode')
}
},
{

View File

@ -44,7 +44,8 @@ describe('SidenavComponent', () => {
provide: AppService,
useValue: {
appNavNarMode$: new BehaviorSubject('expanded'),
toggleAppNavBar$: new Subject()
toggleAppNavBar$: new Subject(),
setAppNavbarMode: jasmine.createSpy('setAppNavbarMode')
}
},
SidenavLayoutComponent

View File

@ -64,7 +64,7 @@ export class SidenavComponent implements OnInit, OnDestroy {
this.groups = this.extensions.getApplicationNavigation(this.extensions.navbar);
});
this.appService.appNavNarMode$.next(this.data.mode);
this.appService.setAppNavbarMode(this.data.mode);
this.appService.toggleAppNavBar$.pipe(takeUntil(this.onDestroy$)).subscribe(() => this.toggleNavBar());
this.data.layout.expanded.pipe(takeUntil(this.onDestroy$)).subscribe(() => this.setNavBarMode());
}
@ -82,7 +82,7 @@ export class SidenavComponent implements OnInit, OnDestroy {
}
private setNavBarMode() {
this.appService.appNavNarMode$.next(this.data.layout.isMenuMinimized || this.data.layout.isHeaderInside ? 'collapsed' : 'expanded');
this.appService.setAppNavbarMode(this.data.layout.isMenuMinimized || this.data.layout.isHeaderInside ? 'collapsed' : 'expanded');
}
private toggleNavBar() {

View File

@ -174,6 +174,11 @@ export class AppService implements OnDestroy {
this.overlayContainer.getContainerElement().setAttribute('role', 'region');
}
setAppNavbarMode(mode: 'expanded' | 'collapsed'): void {
this.appNavNarMode$.next(mode);
this.preferencesService.set('expandedSidenav', mode === 'expanded');
}
private loadRepositoryStatus() {
this.contentApi.getRepositoryInformation().subscribe((response: DiscoveryEntry) => {
if (response?.entry?.repository) {