Skip to content

Commit

Permalink
Merge pull request #3411 from alexandrevryghem/w2p-119207_fix-browse-…
Browse files Browse the repository at this point in the history
…startwith-options-not-loading_contribute-7_x

Fix browse by date's year dropdown being empty on DSpace 7.6.2+
  • Loading branch information
tdonohue authored Oct 11, 2024
2 parents e74dc22 + 4de3c58 commit f7063d4
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 10 deletions.
2 changes: 2 additions & 0 deletions src/app/shared/browse-by/browse-by.component.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
30 changes: 20 additions & 10 deletions src/app/shared/browse-by/browse-by.component.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -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}.
Expand Down Expand Up @@ -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');

Expand All @@ -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
});
}

}

0 comments on commit f7063d4

Please sign in to comment.