Skip to content

Commit b240b2c

Browse files
108588: Fixed scope not being set when browsing by taxonomy on community/collection pages
1 parent ca5fc82 commit b240b2c

2 files changed

Lines changed: 49 additions & 8 deletions

File tree

src/app/browse-by/browse-by-taxonomy/browse-by-taxonomy.component.spec.ts

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ describe('BrowseByTaxonomyComponent', () => {
4343
beforeEach(() => {
4444
fixture = TestBed.createComponent(BrowseByTaxonomyComponent);
4545
component = fixture.componentInstance;
46+
spyOn(component, 'updateQueryParams').and.callThrough();
4647
fixture.detectChanges();
4748
detail1 = new VocabularyEntryDetail();
4849
detail2 = new VocabularyEntryDetail();
@@ -62,6 +63,7 @@ describe('BrowseByTaxonomyComponent', () => {
6263
expect(component.selectedItems).toContain(detail1);
6364
expect(component.selectedItems.length).toBe(1);
6465
expect(component.filterValues).toEqual(['HUMANITIES and RELIGION,equals'] );
66+
expect(component.updateQueryParams).toHaveBeenCalled();
6567
});
6668

6769
it('should handle select event with multiple selected items', () => {
@@ -71,6 +73,7 @@ describe('BrowseByTaxonomyComponent', () => {
7173
expect(component.selectedItems).toContain(detail1, detail2);
7274
expect(component.selectedItems.length).toBe(2);
7375
expect(component.filterValues).toEqual(['HUMANITIES and RELIGION,equals', 'TECHNOLOGY,equals'] );
76+
expect(component.updateQueryParams).toHaveBeenCalled();
7477
});
7578

7679
it('should handle deselect event', () => {
@@ -83,6 +86,33 @@ describe('BrowseByTaxonomyComponent', () => {
8386
expect(component.selectedItems).toContain(detail2);
8487
expect(component.selectedItems.length).toBe(1);
8588
expect(component.filterValues).toEqual(['TECHNOLOGY,equals'] );
89+
expect(component.updateQueryParams).toHaveBeenCalled();
90+
});
91+
92+
describe('updateQueryParams', () => {
93+
beforeEach(() => {
94+
component.facetType = 'subject';
95+
component.filterValues = ['HUMANITIES and RELIGION,equals', 'TECHNOLOGY,equals'];
96+
});
97+
98+
it('should update the queryParams with the selected filterValues', () => {
99+
component.updateQueryParams();
100+
101+
expect(component.queryParams).toEqual({
102+
'f.subject': ['HUMANITIES and RELIGION,equals', 'TECHNOLOGY,equals'],
103+
});
104+
});
105+
106+
it('should include the scope if present', () => {
107+
component.scope = '67f849f1-2499-4872-8c61-9e2b47d71068';
108+
109+
component.updateQueryParams();
110+
111+
expect(component.queryParams).toEqual({
112+
'f.subject': ['HUMANITIES and RELIGION,equals', 'TECHNOLOGY,equals'],
113+
'scope': '67f849f1-2499-4872-8c61-9e2b47d71068',
114+
});
115+
});
86116
});
87117

88118
afterEach(() => {

src/app/browse-by/browse-by-taxonomy/browse-by-taxonomy.component.ts

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
import { Component, OnInit, OnChanges, OnDestroy, Input } from '@angular/core';
22
import { VocabularyOptions } from '../../core/submission/vocabularies/models/vocabulary-options.model';
33
import { VocabularyEntryDetail } from '../../core/submission/vocabularies/models/vocabulary-entry-detail.model';
4-
import { ActivatedRoute } from '@angular/router';
4+
import { ActivatedRoute, Params } from '@angular/router';
55
import { BehaviorSubject, Observable, Subscription } from 'rxjs';
66
import { BrowseDefinition } from '../../core/shared/browse-definition.model';
77
import { rendersBrowseBy } from '../browse-by-switcher/browse-by-decorator';
88
import { map } from 'rxjs/operators';
99
import { HierarchicalBrowseDefinition } from '../../core/shared/hierarchical-browse-definition.model';
1010
import { BrowseByDataType } from '../browse-by-switcher/browse-by-data-type';
1111
import { Context } from '../../core/shared/context.model';
12+
import { hasValue } from '../../shared/empty.util';
1213

1314
@Component({
1415
selector: 'ds-browse-by-taxonomy',
@@ -71,7 +72,7 @@ export class BrowseByTaxonomyComponent implements OnInit, OnChanges, OnDestroy {
7172
/**
7273
* The parameters used in the URL
7374
*/
74-
queryParams: any;
75+
queryParams: Params;
7576

7677
/**
7778
* Resolved browse-by definition
@@ -99,6 +100,9 @@ export class BrowseByTaxonomyComponent implements OnInit, OnChanges, OnDestroy {
99100
this.vocabularyName = browseDefinition.vocabulary;
100101
this.vocabularyOptions = { name: this.vocabularyName, closed: true };
101102
}));
103+
this.subs.push(this.scope$.subscribe(() => {
104+
this.updateQueryParams();
105+
}));
102106
}
103107

104108
ngOnChanges(): void {
@@ -112,9 +116,9 @@ export class BrowseByTaxonomyComponent implements OnInit, OnChanges, OnDestroy {
112116
* @param detail VocabularyEntryDetail to be added
113117
*/
114118
onSelect(detail: VocabularyEntryDetail): void {
115-
this.selectedItems.push(detail);
116-
this.filterValues = this.selectedItems
117-
.map((item: VocabularyEntryDetail) => `${item.value},equals`);
119+
this.selectedItems.push(detail);
120+
this.filterValues = this.selectedItems
121+
.map((item: VocabularyEntryDetail) => `${item.value},equals`);
118122
this.updateQueryParams();
119123
}
120124

@@ -124,18 +128,25 @@ export class BrowseByTaxonomyComponent implements OnInit, OnChanges, OnDestroy {
124128
* @param detail VocabularyEntryDetail to be removed
125129
*/
126130
onDeselect(detail: VocabularyEntryDetail): void {
127-
this.selectedItems = this.selectedItems.filter((entry: VocabularyEntryDetail) => { return entry.id !== detail.id; });
128-
this.filterValues = this.filterValues.filter((value: string) => { return value !== `${detail.value},equals`; });
131+
this.selectedItems = this.selectedItems.filter((entry: VocabularyEntryDetail) => {
132+
return entry.id !== detail.id;
133+
});
134+
this.filterValues = this.filterValues.filter((value: string) => {
135+
return value !== `${detail.value},equals`;
136+
});
129137
this.updateQueryParams();
130138
}
131139

132140
/**
133141
* Updates queryParams based on the current facetType and filterValues.
134142
*/
135-
private updateQueryParams(): void {
143+
updateQueryParams(): void {
136144
this.queryParams = {
137145
['f.' + this.facetType]: this.filterValues
138146
};
147+
if (hasValue(this.scope)) {
148+
this.queryParams.scope = this.scope;
149+
}
139150
}
140151

141152
ngOnDestroy(): void {

0 commit comments

Comments
 (0)