Merge pull request #3411 from alexandrevryghem/w2p-119207_fix-browse-startwith-options-not-loading_contribute-7_x

Fix browse by date's year dropdown being empty on DSpace 7.6.2+
This commit is contained in:
Tim Donohue
2024-10-11 15:03:16 -05:00
committed by GitHub
2 changed files with 22 additions and 10 deletions

View File

@@ -142,6 +142,8 @@ describe('BrowseByComponent', () => {
{ provide: RouteService, useValue: routeServiceStub},
{ provide: SelectableListService, useValue: {} },
{ provide: HostWindowService, useValue: new HostWindowServiceStub(800) },
{ provide: 'startsWithOptions', useValue: [] },
{ provide: 'paginationId', useValue: 'bbm' },
],
schemas: [NO_ERRORS_SCHEMA]
}).compileComponents();

View File

@@ -1,4 +1,4 @@
import { Component, EventEmitter, Injector, Input, OnDestroy, OnInit, Output } from '@angular/core';
import { Component, EventEmitter, Injector, Input, OnDestroy, OnInit, Output, SimpleChanges, OnChanges } from '@angular/core';
import { RemoteData } from '../../core/data/remote-data';
import { PaginatedList } from '../../core/data/paginated-list.model';
import { PaginationComponentOptions } from '../pagination/pagination-component-options.model';
@@ -26,7 +26,7 @@ import { TranslateService } from '@ngx-translate/core';
/**
* Component to display a browse-by page for any ListableObject
*/
export class BrowseByComponent implements OnInit, OnDestroy {
export class BrowseByComponent implements OnInit, OnDestroy, OnChanges {
/**
* ViewMode that should be passed to {@link ListableObjectComponentLoaderComponent}.
@@ -182,14 +182,7 @@ export class BrowseByComponent implements OnInit, OnDestroy {
}
ngOnInit(): void {
this.objectInjector = Injector.create({
providers: [
{ provide: 'startsWithOptions', useFactory: () => (this.startsWithOptions), deps:[] },
{ provide: 'paginationId', useFactory: () => (this.paginationConfig?.id), deps:[] }
],
parent: this.injector
});
this.generateInjector();
const startsWith$ = this.routeService.getQueryParameterValue('startsWith');
const value$ = this.routeService.getQueryParameterValue('value');
@@ -199,9 +192,26 @@ export class BrowseByComponent implements OnInit, OnDestroy {
this.sub = this.routeService.getQueryParameterValue(this.paginationConfig.id + '.return').subscribe(this.previousPage$);
}
ngOnChanges(changes: SimpleChanges): void {
if (changes.startsWithOptions || changes.paginationId) {
this.generateInjector();
}
}
ngOnDestroy(): void {
if (this.sub) {
this.sub.unsubscribe();
}
}
generateInjector(): void {
this.objectInjector = Injector.create({
providers: [
{ provide: 'startsWithOptions', useFactory: () => (this.startsWithOptions), deps:[] },
{ provide: 'paginationId', useFactory: () => (this.paginationConfig?.id), deps:[] }
],
parent: this.injector
});
}
}