Skip to content

Commit

Permalink
WEBDEV-6738 Propagate profile params to more-facets component (#361)
Browse files Browse the repository at this point in the history
* Propagate profile params to more-facets component

* Pass collection/account params wholesale rather than piecemeal

* Update unit tests

* Fix types and more facets sorting bug
  • Loading branch information
latonv authored Mar 11, 2024
1 parent 7cff6c9 commit 6a0d144
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 27 deletions.
2 changes: 1 addition & 1 deletion src/collection-browser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -932,7 +932,7 @@ export class CollectionBrowser
@histogramDateRangeUpdated=${this.histogramDateRangeUpdated}
.collectionPagePath=${this.collectionPagePath}
.parentCollections=${this.dataSource.parentCollections}
.withinCollection=${this.withinCollection}
.pageSpecifierParams=${this.dataSource.pageSpecifierParams}
.searchService=${this.searchService}
.featureFeedbackService=${this.featureFeedbackService}
.recaptchaManager=${this.recaptchaManager}
Expand Down
12 changes: 7 additions & 5 deletions src/collection-facets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,10 @@ import {
suppressedCollections,
defaultFacetSort,
} from './models';
import type { CollectionTitles } from './data-source/models';
import type {
CollectionTitles,
PageSpecifierParams,
} from './data-source/models';
import './collection-facets/more-facets-content';
import './collection-facets/facets-template';
import './collection-facets/facet-tombstone-row';
Expand Down Expand Up @@ -89,7 +92,7 @@ export class CollectionFacets extends LitElement {

@property({ type: String }) query?: string;

@property({ type: String }) withinCollection?: string;
@property({ type: Object }) pageSpecifierParams?: PageSpecifierParams;

@property({ type: Array }) parentCollections: string[] = [];

Expand Down Expand Up @@ -165,8 +168,7 @@ export class CollectionFacets extends LitElement {

private get collectionPartOfTemplate(): TemplateResult | typeof nothing {
// We only display the "Part Of" section on collection pages
if (!this.withinCollection || this.parentCollections.length === 0)
return nothing;
if (!this.parentCollections?.length) return nothing;

const headingId = 'partof-heading';
return html`
Expand Down Expand Up @@ -645,7 +647,7 @@ export class CollectionFacets extends LitElement {
.facetAggregationKey=${facetAggrKey}
.query=${this.query}
.filterMap=${this.filterMap}
.withinCollection=${this.withinCollection}
.pageSpecifierParams=${this.pageSpecifierParams}
.modalManager=${this.modalManager}
.searchService=${this.searchService}
.searchType=${this.searchType}
Expand Down
34 changes: 21 additions & 13 deletions src/collection-facets/more-facets-content.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ import { customElement, property, state } from 'lit/decorators.js';
import {
Aggregation,
Bucket,
PageType,
SearchServiceInterface,
SearchParams,
SearchType,
AggregationSortType,
FilterMap,
PageType,
} from '@internetarchive/search-service';
import type { ModalManagerInterface } from '@internetarchive/modal-manager';
import type { AnalyticsManagerInterface } from '@internetarchive/analytics-manager';
Expand All @@ -32,7 +32,10 @@ import {
valueFacetSort,
defaultFacetSort,
} from '../models';
import type { CollectionTitles } from '../data-source/models';
import type {
CollectionTitles,
PageSpecifierParams,
} from '../data-source/models';
import '@internetarchive/ia-activity-indicator/ia-activity-indicator';
import './more-facets-pagination';
import './facets-template';
Expand All @@ -59,7 +62,7 @@ export class MoreFacetsContent extends LitElement {

@property({ type: String }) searchType?: SearchType;

@property({ type: String }) withinCollection?: string;
@property({ type: Object }) pageSpecifierParams?: PageSpecifierParams;

@property({ type: Object })
collectionTitles?: CollectionTitles;
Expand Down Expand Up @@ -101,6 +104,7 @@ export class MoreFacetsContent extends LitElement {
) {
this.facetsLoading = true;
this.pageNumber = 1;
this.sortedBy = defaultFacetSort[this.facetKey as FacetOption];

this.updateSpecificFacets();
}
Expand Down Expand Up @@ -129,28 +133,31 @@ export class MoreFacetsContent extends LitElement {
}
}

/**
* Whether facet requests are for the search_results page type (either defaulted or explicitly).
*/
private get isSearchResultsPage(): boolean {
// Default page type is search_results when none is specified, so we check
// for undefined as well.
const pageType: PageType | undefined = this.pageSpecifierParams?.pageType;
return pageType === undefined || pageType === 'search_results';
}

/**
* Get specific facets data from search-service API based of currently query params
* - this.aggregations - hold result of search service and being used for further processing.
*/
async updateSpecificFacets(): Promise<void> {
const trimmedQuery = this.query?.trim();
if (!trimmedQuery && !this.withinCollection) return;
if (!trimmedQuery && this.isSearchResultsPage) return; // The search page _requires_ a query

const aggregations = {
simpleParams: [this.facetAggregationKey as string],
};
const aggregationsSize = 65535; // todo - do we want to have all the records at once?

const collectionParams = this.withinCollection
? {
pageType: 'collection_details' as PageType,
pageTarget: this.withinCollection,
}
: null;

const params: SearchParams = {
...collectionParams,
...this.pageSpecifierParams,
query: trimmedQuery || '',
filters: this.filterMap,
aggregations,
Expand Down Expand Up @@ -391,7 +398,8 @@ export class MoreFacetsContent extends LitElement {
}

private get getModalHeaderTemplate(): TemplateResult {
const facetSort = defaultFacetSort[this.facetKey as FacetOption];
const facetSort =
this.sortedBy ?? defaultFacetSort[this.facetKey as FacetOption];
const defaultSwitchSide =
facetSort === AggregationSortType.COUNT ? 'left' : 'right';

Expand Down
2 changes: 1 addition & 1 deletion src/data-source/collection-browser-data-source.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1099,7 +1099,7 @@ export class CollectionBrowserDataSource
// When we reach the end of the data, we can set the infinite scroller's
// item count to the real total number of results (rather than the
// temporary estimates based on pages rendered so far).
if (results.length === 0) {
if (this.size >= this.totalResults || results.length === 0) {
this.endOfDataReached = true;
if (this.activeOnHost) this.host.setTileCount(this.size);
}
Expand Down
8 changes: 3 additions & 5 deletions test/collection-facets.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -808,12 +808,10 @@ describe('Collection Facets', () => {
expect(partOfLinks?.[1]?.getAttribute('href')).to.equal('/details/baz');
});

it('does not include Part Of section outside of collections', async () => {
// No withinCollection prop
it('does not include Part Of section without parent collections', async () => {
// No parentCollections prop
const el = await fixture<CollectionFacets>(
html`<collection-facets
.parentCollections=${['bar', 'baz']}
></collection-facets>`
html`<collection-facets .withinCollection=${'foo'}></collection-facets>`
);

const partOfSection = el.shadowRoot?.querySelector('.partof-collections');
Expand Down
10 changes: 8 additions & 2 deletions test/collection-facets/more-facets-content.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,10 @@ describe('More facets content', () => {
const el = await fixture<MoreFacetsContent>(
html`<more-facets-content
.searchService=${searchService}
.withinCollection=${'foobar'}
.pageSpecifierParams=${{
pageType: 'collection_details',
pageTarget: 'foobar',
}}
></more-facets-content>`
);

Expand All @@ -111,7 +114,10 @@ describe('More facets content', () => {
const el = await fixture<MoreFacetsContent>(
html`<more-facets-content
.searchService=${searchService}
.withinCollection=${'foobar'}
.pageSpecifierParams=${{
pageType: 'collection_details',
pageTarget: 'foobar',
}}
></more-facets-content>`
);

Expand Down

0 comments on commit 6a0d144

Please sign in to comment.