@internetarchive/collection-browser 1.14.17-alpha.2 → 1.14.17-alpha.21

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (87) hide show
  1. package/dist/index.js +1 -1
  2. package/dist/index.js.map +1 -1
  3. package/dist/src/app-root.d.ts +1 -0
  4. package/dist/src/app-root.js +38 -0
  5. package/dist/src/app-root.js.map +1 -1
  6. package/dist/src/collection-browser.d.ts +2 -15
  7. package/dist/src/collection-browser.js +22 -29
  8. package/dist/src/collection-browser.js.map +1 -1
  9. package/dist/src/data-source/collection-browser-data-source.d.ts +55 -32
  10. package/dist/src/data-source/collection-browser-data-source.js +155 -162
  11. package/dist/src/data-source/collection-browser-data-source.js.map +1 -1
  12. package/dist/src/data-source/models.d.ts +6 -3
  13. package/dist/src/data-source/models.js.map +1 -1
  14. package/dist/src/manage/manage-bar.d.ts +1 -1
  15. package/dist/src/manage/manage-bar.js.map +1 -1
  16. package/dist/src/models.d.ts +20 -4
  17. package/dist/src/models.js +105 -0
  18. package/dist/src/models.js.map +1 -1
  19. package/dist/src/sort-filter-bar/sort-filter-bar.js +25 -16
  20. package/dist/src/sort-filter-bar/sort-filter-bar.js.map +1 -1
  21. package/dist/src/tiles/grid/item-tile.d.ts +1 -0
  22. package/dist/src/tiles/grid/item-tile.js +28 -1
  23. package/dist/src/tiles/grid/item-tile.js.map +1 -1
  24. package/dist/src/tiles/grid/tile-stats.js +13 -8
  25. package/dist/src/tiles/grid/tile-stats.js.map +1 -1
  26. package/dist/src/tiles/list/tile-list-compact.js +1 -1
  27. package/dist/src/tiles/list/tile-list-compact.js.map +1 -1
  28. package/dist/src/tiles/list/tile-list.d.ts +1 -0
  29. package/dist/src/tiles/list/tile-list.js +32 -1
  30. package/dist/src/tiles/list/tile-list.js.map +1 -1
  31. package/dist/src/tiles/tile-dispatcher.js +3 -2
  32. package/dist/src/tiles/tile-dispatcher.js.map +1 -1
  33. package/dist/src/tiles/tile-display-value-provider.d.ts +6 -2
  34. package/dist/src/tiles/tile-display-value-provider.js +15 -1
  35. package/dist/src/tiles/tile-display-value-provider.js.map +1 -1
  36. package/dist/src/utils/collapse-repeated-quotes.d.ts +11 -0
  37. package/dist/src/utils/collapse-repeated-quotes.js +14 -0
  38. package/dist/src/utils/collapse-repeated-quotes.js.map +1 -0
  39. package/dist/src/utils/resolve-mediatype.d.ts +8 -0
  40. package/dist/src/utils/resolve-mediatype.js +24 -0
  41. package/dist/src/utils/resolve-mediatype.js.map +1 -0
  42. package/dist/test/collection-browser.test.js +39 -19
  43. package/dist/test/collection-browser.test.js.map +1 -1
  44. package/dist/test/collection-facets/more-facets-content.test.js +2 -2
  45. package/dist/test/collection-facets/more-facets-content.test.js.map +1 -1
  46. package/dist/test/collection-facets.test.js +5 -0
  47. package/dist/test/collection-facets.test.js.map +1 -1
  48. package/dist/test/item-image.test.js +33 -34
  49. package/dist/test/item-image.test.js.map +1 -1
  50. package/dist/test/mocks/mock-search-responses.d.ts +1 -0
  51. package/dist/test/mocks/mock-search-responses.js +62 -0
  52. package/dist/test/mocks/mock-search-responses.js.map +1 -1
  53. package/dist/test/sort-filter-bar/sort-filter-bar.test.js +41 -4
  54. package/dist/test/sort-filter-bar/sort-filter-bar.test.js.map +1 -1
  55. package/dist/test/tiles/hover/hover-pane-controller.test.js +18 -17
  56. package/dist/test/tiles/hover/hover-pane-controller.test.js.map +1 -1
  57. package/package.json +2 -2
  58. package/src/app-root.ts +39 -0
  59. package/src/collection-browser.ts +24 -40
  60. package/src/data-source/collection-browser-data-source.ts +160 -132
  61. package/src/data-source/models.ts +6 -2
  62. package/src/manage/manage-bar.ts +1 -1
  63. package/src/models.ts +154 -3
  64. package/src/sort-filter-bar/sort-filter-bar.ts +26 -16
  65. package/src/tiles/grid/item-tile.ts +36 -1
  66. package/src/tiles/grid/tile-stats.ts +12 -7
  67. package/src/tiles/list/tile-list-compact.ts +1 -1
  68. package/src/tiles/list/tile-list.ts +43 -5
  69. package/src/tiles/tile-dispatcher.ts +2 -1
  70. package/src/tiles/tile-display-value-provider.ts +20 -2
  71. package/src/utils/collapse-repeated-quotes.ts +13 -0
  72. package/src/utils/resolve-mediatype.ts +26 -0
  73. package/test/collection-browser.test.ts +74 -19
  74. package/test/collection-facets/more-facets-content.test.ts +4 -2
  75. package/test/collection-facets.test.ts +5 -0
  76. package/test/item-image.test.ts +34 -36
  77. package/test/mocks/mock-search-responses.ts +66 -0
  78. package/test/sort-filter-bar/sort-filter-bar.test.ts +50 -4
  79. package/test/tiles/hover/hover-pane-controller.test.ts +19 -17
  80. package/dist/src/data-source/data-source-fetch-provider.d.ts +0 -13
  81. package/dist/src/data-source/data-source-fetch-provider.js +0 -61
  82. package/dist/src/data-source/data-source-fetch-provider.js.map +0 -1
  83. package/dist/src/selected-facets.d.ts +0 -67
  84. package/dist/src/selected-facets.js +0 -149
  85. package/dist/src/selected-facets.js.map +0 -1
  86. package/src/data-source/data-source-fetch-provider.ts +0 -79
  87. package/src/selected-facets.ts +0 -216
@@ -1,67 +0,0 @@
1
- import { type FacetBucket, type FacetGroup, type FacetOption, type FacetValue } from './models';
2
- /**
3
- * A record of all the facet buckets for a particular facet type, indexed by their bucket key
4
- */
5
- export declare type FacetBucketsRecord = Record<FacetValue, FacetBucket>;
6
- declare type SelectedFacetsModel = Record<FacetOption, FacetBucketsRecord>;
7
- /**
8
- * A class to hold, query, and manipulate state about selected/hidden facets.
9
- */
10
- export declare class SelectedFacets implements SelectedFacetsModel {
11
- readonly collection: FacetBucketsRecord;
12
- readonly creator: FacetBucketsRecord;
13
- readonly language: FacetBucketsRecord;
14
- readonly lending: FacetBucketsRecord;
15
- readonly mediatype: FacetBucketsRecord;
16
- readonly subject: FacetBucketsRecord;
17
- readonly year: FacetBucketsRecord;
18
- constructor(initValues?: Partial<SelectedFacetsModel>);
19
- /**
20
- * Executes the given function on every facet bucket within the current SelectedFacets object.
21
- * @param fn The function to execute for each facet bucket
22
- */
23
- forEach(fn: (bucket: FacetBucket, bucketKey: FacetValue, facetType: FacetOption) => unknown): void;
24
- /**
25
- * Executes the given function on every facet type within the current SelectedFacets object.
26
- * Similar to `SelectedFacets.forEach`, but operating on the full set of buckets for each type
27
- * (rather than individual buckets).
28
- * @param fn The function to execute for each facet type
29
- */
30
- forEachFacetType(fn: (buckets: FacetBucketsRecord, facetType: FacetOption) => unknown): void;
31
- /**
32
- * Like `Array.some`, returns whether the given predicate function returns true for
33
- * any of the facet buckets contained in this object.
34
- * @param predicate Function returning a boolean for each bucket
35
- * @returns Whether any of the facet buckets satisfy the predicate
36
- */
37
- some(predicate: (bucket: FacetBucket, bucketKey: FacetValue, facetType: FacetOption) => boolean): boolean;
38
- /**
39
- * Like `Array.every`, returns whether the given predicate function returns true for
40
- * *all* of the facet buckets contained in this object.
41
- * @param predicate Function returning a boolean for each bucket
42
- * @returns Whether all of the facet buckets satisfy the predicate
43
- */
44
- every(predicate: (bucket: FacetBucket, bucketKey: FacetValue, facetType: FacetOption) => boolean): boolean;
45
- /**
46
- * Returns a new SelectedFacets object deeply cloned from this one (same contents).
47
- */
48
- clone(): SelectedFacets;
49
- /**
50
- * Returns a new SelectedFacets object cloned from this one with all of the given `otherFacets`
51
- * applied overtop. Facets from this object will be overwritten by those in `otherFacets`
52
- * that have the same facet type and bucket key.
53
- *
54
- * @param otherFacets The other SelectedFacets object to merge into this one.
55
- */
56
- merge(otherFacets?: SelectedFacets): SelectedFacets;
57
- /**
58
- * Returns a new SelectedFacets object with facet buckets normalized, such that any
59
- * buckets with a state of 'none' are removed entirely.
60
- */
61
- normalize(): SelectedFacets;
62
- /**
63
- * Converts this SelectedFacets object into an array of equivalent FacetGroups.
64
- */
65
- toFacetGroups(): FacetGroup[];
66
- }
67
- export {};
@@ -1,149 +0,0 @@
1
- import { facetTitles, lendingFacetDisplayNames, } from './models';
2
- const VALID_FACET_OPTIONS = new Set([
3
- 'collection',
4
- 'creator',
5
- 'language',
6
- 'lending',
7
- 'mediatype',
8
- 'subject',
9
- 'year',
10
- ]);
11
- /**
12
- * A class to hold, query, and manipulate state about selected/hidden facets.
13
- */
14
- export class SelectedFacets {
15
- constructor(initValues) {
16
- this.collection = {};
17
- this.creator = {};
18
- this.language = {};
19
- this.lending = {};
20
- this.mediatype = {};
21
- this.subject = {};
22
- this.year = {};
23
- if (initValues) {
24
- for (const [facetType, buckets] of Object.entries(initValues)) {
25
- if (VALID_FACET_OPTIONS.has(facetType)) {
26
- for (const [bucketKey, bucket] of Object.entries(buckets)) {
27
- this[facetType][bucketKey] = { ...bucket };
28
- }
29
- }
30
- }
31
- }
32
- }
33
- /**
34
- * Executes the given function on every facet bucket within the current SelectedFacets object.
35
- * @param fn The function to execute for each facet bucket
36
- */
37
- forEach(fn) {
38
- for (const [facetType, buckets] of Object.entries(this)) {
39
- for (const [bucketKey, bucket] of Object.entries(buckets)) {
40
- fn(bucket, bucketKey, facetType);
41
- }
42
- }
43
- }
44
- /**
45
- * Executes the given function on every facet type within the current SelectedFacets object.
46
- * Similar to `SelectedFacets.forEach`, but operating on the full set of buckets for each type
47
- * (rather than individual buckets).
48
- * @param fn The function to execute for each facet type
49
- */
50
- forEachFacetType(fn) {
51
- for (const [facetType, buckets] of Object.entries(this)) {
52
- fn(buckets, facetType);
53
- }
54
- }
55
- /**
56
- * Like `Array.some`, returns whether the given predicate function returns true for
57
- * any of the facet buckets contained in this object.
58
- * @param predicate Function returning a boolean for each bucket
59
- * @returns Whether any of the facet buckets satisfy the predicate
60
- */
61
- some(predicate) {
62
- for (const [facetType, buckets] of Object.entries(this)) {
63
- for (const [bucketKey, bucket] of Object.entries(buckets)) {
64
- if (predicate(bucket, bucketKey, facetType))
65
- return true;
66
- }
67
- }
68
- return false;
69
- }
70
- /**
71
- * Like `Array.every`, returns whether the given predicate function returns true for
72
- * *all* of the facet buckets contained in this object.
73
- * @param predicate Function returning a boolean for each bucket
74
- * @returns Whether all of the facet buckets satisfy the predicate
75
- */
76
- every(predicate) {
77
- for (const [facetType, buckets] of Object.entries(this)) {
78
- for (const [bucketKey, bucket] of Object.entries(buckets)) {
79
- if (!predicate(bucket, bucketKey, facetType))
80
- return false;
81
- }
82
- }
83
- return true;
84
- }
85
- /**
86
- * Returns a new SelectedFacets object deeply cloned from this one (same contents).
87
- */
88
- clone() {
89
- return new SelectedFacets(this);
90
- }
91
- /**
92
- * Returns a new SelectedFacets object cloned from this one with all of the given `otherFacets`
93
- * applied overtop. Facets from this object will be overwritten by those in `otherFacets`
94
- * that have the same facet type and bucket key.
95
- *
96
- * @param otherFacets The other SelectedFacets object to merge into this one.
97
- */
98
- merge(otherFacets) {
99
- const merged = this.clone();
100
- otherFacets === null || otherFacets === void 0 ? void 0 : otherFacets.forEach((bucket, bucketKey, facetType) => {
101
- merged[facetType][bucketKey] = { ...bucket };
102
- });
103
- return merged;
104
- }
105
- /**
106
- * Returns a new SelectedFacets object with facet buckets normalized, such that any
107
- * buckets with a state of 'none' are removed entirely.
108
- */
109
- normalize() {
110
- const normalized = this.clone();
111
- normalized.forEach((bucket, bucketKey, facetType) => {
112
- if (bucket.state === 'none') {
113
- delete normalized[facetType][bucketKey];
114
- }
115
- });
116
- return normalized;
117
- }
118
- /**
119
- * Converts this SelectedFacets object into an array of equivalent FacetGroups.
120
- */
121
- toFacetGroups() {
122
- const facetGroups = {};
123
- this.forEach((bucket, bucketKey, facetType) => {
124
- var _a;
125
- const title = facetTitles[facetType];
126
- let displayText = bucketKey;
127
- // For lending facets, convert the key to a more readable format
128
- if (facetType === 'lending') {
129
- displayText =
130
- (_a = lendingFacetDisplayNames[bucketKey]) !== null && _a !== void 0 ? _a : bucketKey;
131
- }
132
- if (!facetGroups[facetType]) {
133
- facetGroups[facetType] = {
134
- title,
135
- key: facetType,
136
- buckets: [],
137
- };
138
- }
139
- facetGroups[facetType].buckets.push({
140
- displayText,
141
- key: bucketKey,
142
- count: bucket.count,
143
- state: bucket.state,
144
- });
145
- });
146
- return Object.values(facetGroups);
147
- }
148
- }
149
- //# sourceMappingURL=selected-facets.js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B,CAAC,CAAC;QACL,CAAC,CAAC,CAAC;QAEH,OAAO,MAAM,CAAC,MAAM,CAAC,WAAW,CAAC,CAAC;IACpC,CAAC;CACF","sourcesContent":["import {\n facetTitles,\n type FacetBucket,\n type FacetGroup,\n type FacetOption,\n type FacetValue,\n lendingFacetDisplayNames,\n LendingFacetKey,\n} from './models';\n\n/**\n * A record of all the facet buckets for a particular facet type, indexed by their bucket key\n */\nexport type FacetBucketsRecord = Record<FacetValue, FacetBucket>;\n\n// Implementing this model ensures that every facet type is accounted for\ntype SelectedFacetsModel = Record<FacetOption, FacetBucketsRecord>;\n\nconst VALID_FACET_OPTIONS: Set<FacetOption> = new Set([\n 'collection',\n 'creator',\n 'language',\n 'lending',\n 'mediatype',\n 'subject',\n 'year',\n]);\n\n/**\n * A class to hold, query, and manipulate state about selected/hidden facets.\n */\nexport class SelectedFacets implements SelectedFacetsModel {\n readonly collection: FacetBucketsRecord = {};\n\n readonly creator: FacetBucketsRecord = {};\n\n readonly language: FacetBucketsRecord = {};\n\n readonly lending: FacetBucketsRecord = {};\n\n readonly mediatype: FacetBucketsRecord = {};\n\n readonly subject: FacetBucketsRecord = {};\n\n readonly year: FacetBucketsRecord = {};\n\n constructor(initValues?: Partial<SelectedFacetsModel>) {\n if (initValues) {\n for (const [facetType, buckets] of Object.entries(initValues)) {\n if (VALID_FACET_OPTIONS.has(facetType as FacetOption)) {\n for (const [bucketKey, bucket] of Object.entries(buckets)) {\n this[facetType as FacetOption][bucketKey] = { ...bucket };\n }\n }\n }\n }\n }\n\n /**\n * Executes the given function on every facet bucket within the current SelectedFacets object.\n * @param fn The function to execute for each facet bucket\n */\n forEach(\n fn: (\n bucket: FacetBucket,\n bucketKey: FacetValue,\n facetType: FacetOption\n ) => unknown\n ): void {\n for (const [facetType, buckets] of Object.entries(\n this as SelectedFacetsModel\n )) {\n for (const [bucketKey, bucket] of Object.entries(buckets)) {\n fn(bucket, bucketKey, facetType as FacetOption);\n }\n }\n }\n\n /**\n * Executes the given function on every facet type within the current SelectedFacets object.\n * Similar to `SelectedFacets.forEach`, but operating on the full set of buckets for each type\n * (rather than individual buckets).\n * @param fn The function to execute for each facet type\n */\n forEachFacetType(\n fn: (buckets: FacetBucketsRecord, facetType: FacetOption) => unknown\n ): void {\n for (const [facetType, buckets] of Object.entries(\n this as SelectedFacetsModel\n )) {\n fn(buckets, facetType as FacetOption);\n }\n }\n\n /**\n * Like `Array.some`, returns whether the given predicate function returns true for\n * any of the facet buckets contained in this object.\n * @param predicate Function returning a boolean for each bucket\n * @returns Whether any of the facet buckets satisfy the predicate\n */\n some(\n predicate: (\n bucket: FacetBucket,\n bucketKey: FacetValue,\n facetType: FacetOption\n ) => boolean\n ): boolean {\n for (const [facetType, buckets] of Object.entries(\n this as SelectedFacetsModel\n )) {\n for (const [bucketKey, bucket] of Object.entries(buckets)) {\n if (predicate(bucket, bucketKey, facetType as FacetOption)) return true;\n }\n }\n\n return false;\n }\n\n /**\n * Like `Array.every`, returns whether the given predicate function returns true for\n * *all* of the facet buckets contained in this object.\n * @param predicate Function returning a boolean for each bucket\n * @returns Whether all of the facet buckets satisfy the predicate\n */\n every(\n predicate: (\n bucket: FacetBucket,\n bucketKey: FacetValue,\n facetType: FacetOption\n ) => boolean\n ): boolean {\n for (const [facetType, buckets] of Object.entries(\n this as SelectedFacetsModel\n )) {\n for (const [bucketKey, bucket] of Object.entries(buckets)) {\n if (!predicate(bucket, bucketKey, facetType as FacetOption))\n return false;\n }\n }\n\n return true;\n }\n\n /**\n * Returns a new SelectedFacets object deeply cloned from this one (same contents).\n */\n clone(): SelectedFacets {\n return new SelectedFacets(this);\n }\n\n /**\n * Returns a new SelectedFacets object cloned from this one with all of the given `otherFacets`\n * applied overtop. Facets from this object will be overwritten by those in `otherFacets`\n * that have the same facet type and bucket key.\n *\n * @param otherFacets The other SelectedFacets object to merge into this one.\n */\n merge(otherFacets?: SelectedFacets): SelectedFacets {\n const merged = this.clone();\n otherFacets?.forEach((bucket, bucketKey, facetType) => {\n merged[facetType][bucketKey] = { ...bucket };\n });\n\n return merged;\n }\n\n /**\n * Returns a new SelectedFacets object with facet buckets normalized, such that any\n * buckets with a state of 'none' are removed entirely.\n */\n normalize(): SelectedFacets {\n const normalized = this.clone();\n normalized.forEach((bucket, bucketKey, facetType) => {\n if (bucket.state === 'none') {\n delete normalized[facetType][bucketKey];\n }\n });\n\n return normalized;\n }\n\n /**\n * Converts this SelectedFacets object into an array of equivalent FacetGroups.\n */\n toFacetGroups(): FacetGroup[] {\n const facetGroups: Record<string, FacetGroup> = {};\n\n this.forEach((bucket, bucketKey, facetType) => {\n const title = facetTitles[facetType];\n let displayText = bucketKey;\n\n // For lending facets, convert the key to a more readable format\n if (facetType === 'lending') {\n displayText =\n lendingFacetDisplayNames[bucketKey as LendingFacetKey] ?? bucketKey;\n }\n\n if (!facetGroups[facetType]) {\n facetGroups[facetType] = {\n title,\n key: facetType,\n buckets: [],\n };\n }\n\n facetGroups[facetType].buckets.push({\n displayText,\n key: bucketKey,\n count: bucket.count,\n state: bucket.state,\n });\n });\n\n return Object.values(facetGroups);\n }\n}\n"]}
@@ -1,79 +0,0 @@
1
- import type { CollectionBrowserDataSourceInterface } from "./collection-browser-data-source";
2
-
3
- export interface DataSourceFetchProviderInterface {
4
- fetchPage(dataSource: CollectionBrowserDataSourceInterface, pageNumber: number, initialPageNumber?: number): Promise<void>;
5
- fetchFacets(dataSource: CollectionBrowserDataSourceInterface): Promise<void>;
6
- fetchPrefixFilterBuckets(dataSource: CollectionBrowserDataSourceInterface): Promise<void>;
7
- }
8
-
9
- export class DataSourceFetchProvider {
10
- /**
11
- * Fires a backend request to fetch a set of aggregations (representing UI facets) for
12
- * the current search state.
13
- */
14
- private async fetchFacets(dataSource: CollectionBrowserDataSourceInterface): Promise<void> {
15
- // const trimmedQuery = dataSource.host.baseQuery?.trim();
16
- // if (!dataSource.canPerformSearch) return;
17
-
18
- // const { facetFetchQueryKey } = this;
19
-
20
- // const sortParams = this.host.sortParam ? [this.host.sortParam] : [];
21
- // const params: SearchParams = {
22
- // ...this.collectionParams,
23
- // query: trimmedQuery || '',
24
- // rows: 0,
25
- // filters: this.filterMap,
26
- // // Fetch a few extra buckets beyond the 6 we show, in case some get suppressed
27
- // aggregationsSize: 10,
28
- // // Note: we don't need an aggregations param to fetch the default aggregations from the PPS.
29
- // // The default aggregations for the search_results page type should be what we need here.
30
- // };
31
- // params.uid = await this.requestUID(
32
- // { ...params, sort: sortParams },
33
- // 'aggregations'
34
- // );
35
-
36
- // this.host.setFacetsLoading(true);
37
- // const searchResponse = await this.host.searchService?.search(
38
- // params,
39
- // this.host.searchType
40
- // );
41
- // const success = searchResponse?.success;
42
-
43
- // // This is checking to see if the query has changed since the data was fetched.
44
- // // If so, we just want to discard this set of aggregations because they are
45
- // // likely no longer valid for the newer query.
46
- // const queryChangedSinceFetch =
47
- // facetFetchQueryKey !== this.facetFetchQueryKey;
48
- // if (queryChangedSinceFetch) return;
49
-
50
- // if (!success) {
51
- // const errorMsg = searchResponse?.error?.message;
52
- // const detailMsg = searchResponse?.error?.details?.message;
53
-
54
- // if (!errorMsg && !detailMsg) {
55
- // // @ts-ignore: Property 'Sentry' does not exist on type 'Window & typeof globalThis'
56
- // window?.Sentry?.captureMessage?.(
57
- // 'Missing or malformed facet response from backend',
58
- // 'error'
59
- // );
60
- // }
61
-
62
- // return;
63
- // }
64
-
65
- // const { aggregations, collectionTitles } = success.response;
66
- // this.aggregations = aggregations;
67
-
68
- // if (collectionTitles) {
69
- // for (const [id, title] of Object.entries(collectionTitles)) {
70
- // this.collectionTitles.set(id, title);
71
- // }
72
- // }
73
-
74
- // this.yearHistogramAggregation =
75
- // success?.response?.aggregations?.year_histogram;
76
-
77
- // this.host.setFacetsLoading(false);
78
- }
79
- }
@@ -1,216 +0,0 @@
1
- import {
2
- facetTitles,
3
- type FacetBucket,
4
- type FacetGroup,
5
- type FacetOption,
6
- type FacetValue,
7
- lendingFacetDisplayNames,
8
- LendingFacetKey,
9
- } from './models';
10
-
11
- /**
12
- * A record of all the facet buckets for a particular facet type, indexed by their bucket key
13
- */
14
- export type FacetBucketsRecord = Record<FacetValue, FacetBucket>;
15
-
16
- // Implementing this model ensures that every facet type is accounted for
17
- type SelectedFacetsModel = Record<FacetOption, FacetBucketsRecord>;
18
-
19
- const VALID_FACET_OPTIONS: Set<FacetOption> = new Set([
20
- 'collection',
21
- 'creator',
22
- 'language',
23
- 'lending',
24
- 'mediatype',
25
- 'subject',
26
- 'year',
27
- ]);
28
-
29
- /**
30
- * A class to hold, query, and manipulate state about selected/hidden facets.
31
- */
32
- export class SelectedFacets implements SelectedFacetsModel {
33
- readonly collection: FacetBucketsRecord = {};
34
-
35
- readonly creator: FacetBucketsRecord = {};
36
-
37
- readonly language: FacetBucketsRecord = {};
38
-
39
- readonly lending: FacetBucketsRecord = {};
40
-
41
- readonly mediatype: FacetBucketsRecord = {};
42
-
43
- readonly subject: FacetBucketsRecord = {};
44
-
45
- readonly year: FacetBucketsRecord = {};
46
-
47
- constructor(initValues?: Partial<SelectedFacetsModel>) {
48
- if (initValues) {
49
- for (const [facetType, buckets] of Object.entries(initValues)) {
50
- if (VALID_FACET_OPTIONS.has(facetType as FacetOption)) {
51
- for (const [bucketKey, bucket] of Object.entries(buckets)) {
52
- this[facetType as FacetOption][bucketKey] = { ...bucket };
53
- }
54
- }
55
- }
56
- }
57
- }
58
-
59
- /**
60
- * Executes the given function on every facet bucket within the current SelectedFacets object.
61
- * @param fn The function to execute for each facet bucket
62
- */
63
- forEach(
64
- fn: (
65
- bucket: FacetBucket,
66
- bucketKey: FacetValue,
67
- facetType: FacetOption
68
- ) => unknown
69
- ): void {
70
- for (const [facetType, buckets] of Object.entries(
71
- this as SelectedFacetsModel
72
- )) {
73
- for (const [bucketKey, bucket] of Object.entries(buckets)) {
74
- fn(bucket, bucketKey, facetType as FacetOption);
75
- }
76
- }
77
- }
78
-
79
- /**
80
- * Executes the given function on every facet type within the current SelectedFacets object.
81
- * Similar to `SelectedFacets.forEach`, but operating on the full set of buckets for each type
82
- * (rather than individual buckets).
83
- * @param fn The function to execute for each facet type
84
- */
85
- forEachFacetType(
86
- fn: (buckets: FacetBucketsRecord, facetType: FacetOption) => unknown
87
- ): void {
88
- for (const [facetType, buckets] of Object.entries(
89
- this as SelectedFacetsModel
90
- )) {
91
- fn(buckets, facetType as FacetOption);
92
- }
93
- }
94
-
95
- /**
96
- * Like `Array.some`, returns whether the given predicate function returns true for
97
- * any of the facet buckets contained in this object.
98
- * @param predicate Function returning a boolean for each bucket
99
- * @returns Whether any of the facet buckets satisfy the predicate
100
- */
101
- some(
102
- predicate: (
103
- bucket: FacetBucket,
104
- bucketKey: FacetValue,
105
- facetType: FacetOption
106
- ) => boolean
107
- ): boolean {
108
- for (const [facetType, buckets] of Object.entries(
109
- this as SelectedFacetsModel
110
- )) {
111
- for (const [bucketKey, bucket] of Object.entries(buckets)) {
112
- if (predicate(bucket, bucketKey, facetType as FacetOption)) return true;
113
- }
114
- }
115
-
116
- return false;
117
- }
118
-
119
- /**
120
- * Like `Array.every`, returns whether the given predicate function returns true for
121
- * *all* of the facet buckets contained in this object.
122
- * @param predicate Function returning a boolean for each bucket
123
- * @returns Whether all of the facet buckets satisfy the predicate
124
- */
125
- every(
126
- predicate: (
127
- bucket: FacetBucket,
128
- bucketKey: FacetValue,
129
- facetType: FacetOption
130
- ) => boolean
131
- ): boolean {
132
- for (const [facetType, buckets] of Object.entries(
133
- this as SelectedFacetsModel
134
- )) {
135
- for (const [bucketKey, bucket] of Object.entries(buckets)) {
136
- if (!predicate(bucket, bucketKey, facetType as FacetOption))
137
- return false;
138
- }
139
- }
140
-
141
- return true;
142
- }
143
-
144
- /**
145
- * Returns a new SelectedFacets object deeply cloned from this one (same contents).
146
- */
147
- clone(): SelectedFacets {
148
- return new SelectedFacets(this);
149
- }
150
-
151
- /**
152
- * Returns a new SelectedFacets object cloned from this one with all of the given `otherFacets`
153
- * applied overtop. Facets from this object will be overwritten by those in `otherFacets`
154
- * that have the same facet type and bucket key.
155
- *
156
- * @param otherFacets The other SelectedFacets object to merge into this one.
157
- */
158
- merge(otherFacets?: SelectedFacets): SelectedFacets {
159
- const merged = this.clone();
160
- otherFacets?.forEach((bucket, bucketKey, facetType) => {
161
- merged[facetType][bucketKey] = { ...bucket };
162
- });
163
-
164
- return merged;
165
- }
166
-
167
- /**
168
- * Returns a new SelectedFacets object with facet buckets normalized, such that any
169
- * buckets with a state of 'none' are removed entirely.
170
- */
171
- normalize(): SelectedFacets {
172
- const normalized = this.clone();
173
- normalized.forEach((bucket, bucketKey, facetType) => {
174
- if (bucket.state === 'none') {
175
- delete normalized[facetType][bucketKey];
176
- }
177
- });
178
-
179
- return normalized;
180
- }
181
-
182
- /**
183
- * Converts this SelectedFacets object into an array of equivalent FacetGroups.
184
- */
185
- toFacetGroups(): FacetGroup[] {
186
- const facetGroups: Record<string, FacetGroup> = {};
187
-
188
- this.forEach((bucket, bucketKey, facetType) => {
189
- const title = facetTitles[facetType];
190
- let displayText = bucketKey;
191
-
192
- // For lending facets, convert the key to a more readable format
193
- if (facetType === 'lending') {
194
- displayText =
195
- lendingFacetDisplayNames[bucketKey as LendingFacetKey] ?? bucketKey;
196
- }
197
-
198
- if (!facetGroups[facetType]) {
199
- facetGroups[facetType] = {
200
- title,
201
- key: facetType,
202
- buckets: [],
203
- };
204
- }
205
-
206
- facetGroups[facetType].buckets.push({
207
- displayText,
208
- key: bucketKey,
209
- count: bucket.count,
210
- state: bucket.state,
211
- });
212
- });
213
-
214
- return Object.values(facetGroups);
215
- }
216
- }