Skip to content

Commit e50a163

Browse files
authored
WEBDEV-7738 Use TV channel-network mapping provided by PPS (#475)
* Add tv channel aliases to data source * Remove old temporary list & swap in new PPS-derived mapping * Add unit test
1 parent fb95a5e commit e50a163

10 files changed

+116
-48
lines changed

src/collection-browser.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1144,6 +1144,7 @@ export class CollectionBrowser
11441144
.selectedFacets=${this.selectedFacets}
11451145
.baseNavigationUrl=${this.baseNavigationUrl}
11461146
.collectionTitles=${this.dataSource.collectionTitles}
1147+
.tvChannelAliases=${this.dataSource.tvChannelAliases}
11471148
.showHistogramDatePicker=${this.showHistogramDatePicker}
11481149
.allowExpandingDatePicker=${!this.mobileView}
11491150
.allowDatePickerMonths=${shouldUseTvInterface}

src/collection-facets.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,11 @@ import {
4545
suppressedCollections,
4646
defaultFacetSort,
4747
FacetEventDetails,
48-
tvChannelFacetLabels,
4948
} from './models';
5049
import type {
5150
CollectionTitles,
5251
PageSpecifierParams,
52+
TVChannelAliases,
5353
} from './data-source/models';
5454
import {
5555
analyticsActions,
@@ -137,6 +137,9 @@ export class CollectionFacets extends LitElement {
137137
@property({ type: Object, attribute: false })
138138
collectionTitles?: CollectionTitles;
139139

140+
@property({ type: Object, attribute: false })
141+
tvChannelAliases?: TVChannelAliases;
142+
140143
@state() openFacets: Record<FacetOption, boolean> = {
141144
subject: false,
142145
lending: false,
@@ -536,7 +539,7 @@ export class CollectionFacets extends LitElement {
536539
bucketsWithCount.forEach(b => {
537540
b.displayText = (b.displayText ?? b.key)?.toLocaleUpperCase();
538541
539-
const channelLabel = tvChannelFacetLabels[b.displayText];
542+
const channelLabel = this.tvChannelAliases?.get(b.displayText);
540543
if (channelLabel && channelLabel !== b.displayText) {
541544
b.extraNote = `(${channelLabel})`;
542545
}
@@ -772,6 +775,7 @@ export class CollectionFacets extends LitElement {
772775
.searchService=${this.searchService}
773776
.searchType=${this.searchType}
774777
.collectionTitles=${this.collectionTitles}
778+
.tvChannelAliases=${this.tvChannelAliases}
775779
.selectedFacets=${this.selectedFacets}
776780
.sortedBy=${sortedBy}
777781
.isTvSearch=${this.isTvSearch}

src/collection-facets/more-facets-content.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,11 @@ import {
3232
defaultFacetSort,
3333
getDefaultSelectedFacets,
3434
FacetEventDetails,
35-
tvChannelFacetLabels,
3635
} from '../models';
3736
import type {
3837
CollectionTitles,
3938
PageSpecifierParams,
39+
TVChannelAliases,
4040
} from '../data-source/models';
4141
import '@internetarchive/ia-activity-indicator';
4242
import './more-facets-pagination';
@@ -68,6 +68,9 @@ export class MoreFacetsContent extends LitElement {
6868
@property({ type: Object })
6969
collectionTitles?: CollectionTitles;
7070

71+
@property({ type: Object })
72+
tvChannelAliases?: TVChannelAliases;
73+
7174
/**
7275
* Maximum number of facets to show per page within the modal.
7376
*/
@@ -287,7 +290,7 @@ export class MoreFacetsContent extends LitElement {
287290
bucketsWithCount.forEach(b => {
288291
b.displayText = (b.displayText ?? b.key)?.toLocaleUpperCase();
289292

290-
const channelLabel = tvChannelFacetLabels[b.displayText];
293+
const channelLabel = this.tvChannelAliases?.get(b.displayText);
291294
if (channelLabel && channelLabel !== b.displayText) {
292295
b.extraNote = `(${channelLabel})`;
293296
}

src/data-source/collection-browser-data-source-interface.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,11 @@ import type {
1212
PrefixFilterCounts,
1313
TileModel,
1414
} from '../models';
15-
import type { PageSpecifierParams, CollectionTitles } from './models';
15+
import type {
16+
PageSpecifierParams,
17+
CollectionTitles,
18+
TVChannelAliases,
19+
} from './models';
1620

1721
export interface CollectionBrowserDataSourceInterface
1822
extends ReactiveController {
@@ -88,6 +92,12 @@ export interface CollectionBrowserDataSourceInterface
8892
*/
8993
readonly collectionTitles: CollectionTitles;
9094

95+
/**
96+
* A map from TV channel names appearing in `creator` aggregations, to their
97+
* more human-readable network names.
98+
*/
99+
readonly tvChannelAliases: TVChannelAliases;
100+
91101
/**
92102
* The "extra info" package provided by the PPS for collection pages, including details
93103
* used to populate the target collection header & About tab content.

src/data-source/collection-browser-data-source.ts

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,11 @@ export class CollectionBrowserDataSource
121121
*/
122122
collectionTitles = new Map<string, string>();
123123

124+
/**
125+
* @inheritdoc
126+
*/
127+
tvChannelAliases = new Map<string, string>();
128+
124129
/**
125130
* @inheritdoc
126131
*/
@@ -1031,19 +1036,25 @@ export class CollectionBrowserDataSource
10311036
return;
10321037
}
10331038

1034-
const { aggregations, collectionTitles } = success.response;
1039+
const { aggregations, collectionTitles, tvChannelAliases } =
1040+
success.response;
10351041
this.aggregations = aggregations;
10361042

1043+
this.histogramAggregation =
1044+
this.host.searchType === SearchType.TV
1045+
? aggregations?.date_histogram
1046+
: aggregations?.year_histogram;
1047+
10371048
if (collectionTitles) {
10381049
for (const [id, title] of Object.entries(collectionTitles)) {
10391050
this.collectionTitles.set(id, title);
10401051
}
10411052
}
1042-
1043-
this.histogramAggregation =
1044-
this.host.searchType === SearchType.TV
1045-
? aggregations?.date_histogram
1046-
: aggregations?.year_histogram;
1053+
if (tvChannelAliases) {
1054+
for (const [channel, network] of Object.entries(tvChannelAliases)) {
1055+
this.tvChannelAliases.set(channel, network);
1056+
}
1057+
}
10471058

10481059
this.setFacetsLoading(false);
10491060
this.requestHostUpdate();
@@ -1191,7 +1202,7 @@ export class CollectionBrowserDataSource
11911202
this.pageElements = success.response.pageElements;
11921203
}
11931204

1194-
const { results, collectionTitles } = success.response;
1205+
const { results, collectionTitles, tvChannelAliases } = success.response;
11951206
if (results && results.length > 0) {
11961207
// Load any collection titles present on the response into the cache,
11971208
// or queue up preload fetches for them if none were present.
@@ -1207,6 +1218,12 @@ export class CollectionBrowserDataSource
12071218
}
12081219
}
12091220

1221+
if (tvChannelAliases) {
1222+
for (const [channel, network] of Object.entries(tvChannelAliases)) {
1223+
this.tvChannelAliases.set(channel, network);
1224+
}
1225+
}
1226+
12101227
// Update the data source for each returned page.
12111228
// For loans and web archives, we must account for receiving more pages than we asked for.
12121229
const isUnpagedElement = ['lending', 'web_archives'].includes(

src/data-source/models.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,11 @@ import type {
88
*/
99
export type CollectionTitles = Map<string, string>;
1010

11+
/**
12+
* A Map from channel names to their corresponding, more human-readable network name.
13+
*/
14+
export type TVChannelAliases = Map<string, string>;
15+
1116
/**
1217
* The subset of search service params that uniquely specify the type of results
1318
* that are sought by an instance of collection browser.

src/models.ts

Lines changed: 0 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -750,42 +750,6 @@ export const valueFacetSort: Record<FacetOption, AggregationSortType> = {
750750
sponsor: AggregationSortType.ALPHABETICAL,
751751
};
752752

753-
/**
754-
* Extra parenthesized labels to show next to certain TV channel facets
755-
*
756-
* TODO: This is only needed until we can receive the appropriate mapping via PPS,
757-
* and can be removed/replaced once that is set up.
758-
*/
759-
export const tvChannelFacetLabels: Record<string, string> = Object.fromEntries(
760-
// prettier-ignore
761-
Object.entries({
762-
'Al Jazeera' : ['ALJAZAM', 'ALJAZ'],
763-
'Bloomberg' : ['BLOOMBERG'],
764-
'BBC' : ['BBC', 'BBC1', 'BBC2'],
765-
'BBC America' : ['BBCAMERICA'],
766-
'BBC News' : ['BBCNEWS'],
767-
'GB News' : ['GBN'],
768-
'BET' : ['BETW'],
769-
'CNBC' : ['CNBC'],
770-
'CNN' : ['CNNW', 'CNN'],
771-
'Comedy Central' : ['COM', 'COMW'],
772-
'CSPAN' : ['CSPAN', 'CSPAN2', 'CSPAN3'],
773-
'Current' : ['CURRENT'],
774-
'Deutsche Welle' : ['DW'],
775-
'France 24' : ['FRANCE24'],
776-
'FOX Business' : ['FBC'],
777-
'FOX News' : ['FOXNEWSW', 'FOXNEWS'],
778-
'LINKTV' : ['LINKTV'],
779-
'MSNBC' : ['MSNBCW', 'MSNBC'],
780-
'NHK World' : ['NHK'],
781-
'RT' : ['RT'],
782-
'Sky News' : ['SKY'],
783-
}).reduce(
784-
(acc, [label, channels]) => acc.concat(channels.map(ch => [ch, label])),
785-
[] as [string, string][],
786-
),
787-
);
788-
789753
export type LendingFacetKey =
790754
| 'is_lendable'
791755
| 'is_borrowable'

test/collection-browser.test.ts

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -744,6 +744,22 @@ describe('Collection Browser', () => {
744744
);
745745
});
746746

747+
it('adds tv channel aliases to cache when present on response', async () => {
748+
const searchService = new MockSearchService();
749+
750+
const el = await fixture<CollectionBrowser>(
751+
html`<collection-browser .searchService=${searchService}>
752+
</collection-browser>`,
753+
);
754+
755+
el.baseQuery = 'channel-aliases';
756+
await el.updateComplete;
757+
await el.initialSearchComplete;
758+
759+
expect(el.dataSource.tvChannelAliases.get('foo')).to.equal('Foo Network');
760+
expect(el.dataSource.tvChannelAliases.get('bar')).to.equal('Bar Network');
761+
});
762+
747763
it('keeps search results from fetch if no change to query or sort param', async () => {
748764
const resultsSpy = sinon.spy();
749765
const searchService = new MockSearchService({

test/mocks/mock-search-responses.ts

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -565,6 +565,52 @@ export const getMockSuccessWithCollectionTitles: () => Result<
565565
},
566566
});
567567

568+
export const getMockSuccessWithChannelAliases: () => Result<
569+
SearchResponse,
570+
SearchServiceError
571+
> = () => ({
572+
success: {
573+
request: {
574+
kind: 'hits',
575+
clientParameters: {
576+
user_query: 'collection:foo',
577+
sort: [],
578+
},
579+
backendRequests: {
580+
primary: {
581+
kind: 'hits',
582+
finalized_parameters: {
583+
user_query: 'collection:foo',
584+
sort: [],
585+
},
586+
},
587+
},
588+
},
589+
rawResponse: {},
590+
sessionContext: {},
591+
response: {
592+
totalResults: 1,
593+
returnedCount: 1,
594+
results: [
595+
new TvClipHit({
596+
fields: {
597+
identifier: 'foo',
598+
creator: ['foo', 'bar'],
599+
},
600+
}),
601+
],
602+
tvChannelAliases: {
603+
foo: 'Foo Network',
604+
bar: 'Bar Network',
605+
},
606+
},
607+
responseHeader: {
608+
succeeded: true,
609+
query_time: 0,
610+
},
611+
},
612+
});
613+
568614
export const getMockSuccessWithCollectionAggregations: () => Result<
569615
SearchResponse,
570616
SearchServiceError

test/mocks/mock-search-service.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import {
2121
getMockErrorResult,
2222
getMockMalformedResult,
2323
getMockSuccessWithCollectionTitles,
24+
getMockSuccessWithChannelAliases,
2425
getMockSuccessWithCollectionAggregations,
2526
getMockSuccessExtraQuotedHref,
2627
getMockSuccessWithDefaultSort,
@@ -49,6 +50,7 @@ const responses: Record<
4950
'first-title': getMockSuccessFirstTitleResult,
5051
'first-creator': getMockSuccessFirstCreatorResult,
5152
'collection-titles': getMockSuccessWithCollectionTitles,
53+
'channel-aliases': getMockSuccessWithChannelAliases,
5254
'collection-aggregations': getMockSuccessWithCollectionAggregations,
5355
'extra-quoted-href': getMockSuccessExtraQuotedHref,
5456
'default-sort': getMockSuccessWithDefaultSort,

0 commit comments

Comments
 (0)