@internetarchive/collection-browser 1.14.9-alpha1 → 1.14.9-alpha10
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.
- package/dist/src/app-root.d.ts +1 -0
- package/dist/src/app-root.js +154 -82
- package/dist/src/app-root.js.map +1 -1
- package/dist/src/collection-browser.d.ts +2 -2
- package/dist/src/collection-browser.js +23 -18
- package/dist/src/collection-browser.js.map +1 -1
- package/dist/src/collection-facets/facet-row.d.ts +30 -0
- package/dist/src/collection-facets/facet-row.js +245 -0
- package/dist/src/collection-facets/facet-row.js.map +1 -0
- package/dist/src/collection-facets/facets-template.d.ts +1 -4
- package/dist/src/collection-facets/facets-template.js +40 -182
- package/dist/src/collection-facets/facets-template.js.map +1 -1
- package/dist/src/models.d.ts +18 -2
- package/dist/src/models.js.map +1 -1
- package/dist/test/collection-browser.test.js +36 -4
- package/dist/test/collection-browser.test.js.map +1 -1
- package/dist/test/collection-facets/facet-row.test.d.ts +1 -0
- package/dist/test/collection-facets/facet-row.test.js +235 -0
- package/dist/test/collection-facets/facet-row.test.js.map +1 -0
- package/dist/test/collection-facets/facets-template.test.js +65 -96
- package/dist/test/collection-facets/facets-template.test.js.map +1 -1
- package/dist/test/collection-facets.test.js +39 -70
- package/dist/test/collection-facets.test.js.map +1 -1
- package/package.json +2 -2
- package/src/app-root.ts +159 -82
- package/src/collection-browser.ts +23 -20
- package/src/collection-facets/facet-row.ts +274 -0
- package/src/collection-facets/facets-template.ts +49 -196
- package/src/models.ts +18 -2
- package/test/collection-browser.test.ts +36 -4
- package/test/collection-facets/facet-row.test.ts +328 -0
- package/test/collection-facets/facets-template.test.ts +72 -110
- package/test/collection-facets.test.ts +69 -101
|
@@ -1,18 +1,22 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
css,
|
|
3
|
+
html,
|
|
4
|
+
LitElement,
|
|
5
|
+
TemplateResult,
|
|
6
|
+
CSSResultGroup,
|
|
7
|
+
nothing,
|
|
8
|
+
} from 'lit';
|
|
2
9
|
import { customElement, property } from 'lit/decorators.js';
|
|
3
10
|
import { repeat } from 'lit/directives/repeat.js';
|
|
4
11
|
import type { CollectionNameCacheInterface } from '@internetarchive/collection-name-cache';
|
|
5
|
-
import eyeIcon from '../assets/img/icons/eye';
|
|
6
|
-
import eyeClosedIcon from '../assets/img/icons/eye-closed';
|
|
7
12
|
import {
|
|
8
13
|
FacetGroup,
|
|
9
|
-
FacetOption,
|
|
10
14
|
FacetBucket,
|
|
11
15
|
SelectedFacets,
|
|
12
16
|
getDefaultSelectedFacets,
|
|
13
17
|
FacetEventDetails,
|
|
14
|
-
FacetState,
|
|
15
18
|
} from '../models';
|
|
19
|
+
import { FacetRow } from './facet-row';
|
|
16
20
|
|
|
17
21
|
@customElement('facets-template')
|
|
18
22
|
export class FacetsTemplate extends LitElement {
|
|
@@ -22,34 +26,24 @@ export class FacetsTemplate extends LitElement {
|
|
|
22
26
|
|
|
23
27
|
@property({ type: String }) renderOn?: string;
|
|
24
28
|
|
|
25
|
-
@property({ type: String }) collectionPagePath: string = '/details/';
|
|
26
|
-
|
|
27
29
|
@property({ type: Object })
|
|
28
30
|
collectionNameCache?: CollectionNameCacheInterface;
|
|
29
31
|
|
|
30
|
-
private facetClicked(e:
|
|
31
|
-
const
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
this.facetChecked(name as FacetOption, value, count, negative);
|
|
32
|
+
private facetClicked(e: CustomEvent<FacetEventDetails>) {
|
|
33
|
+
const { bucket, negative } = e.detail;
|
|
34
|
+
if (bucket.state === 'none') {
|
|
35
|
+
this.facetUnchecked(bucket);
|
|
35
36
|
} else {
|
|
36
|
-
this.
|
|
37
|
+
this.facetChecked(bucket, negative);
|
|
37
38
|
}
|
|
38
39
|
|
|
39
|
-
this.dispatchFacetClickEvent(
|
|
40
|
-
name as FacetOption,
|
|
41
|
-
this.getFacetState(checked, negative),
|
|
42
|
-
negative
|
|
43
|
-
);
|
|
40
|
+
this.dispatchFacetClickEvent(e.detail);
|
|
44
41
|
}
|
|
45
42
|
|
|
46
|
-
private facetChecked(
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
negative: boolean
|
|
51
|
-
) {
|
|
52
|
-
const { selectedFacets } = this;
|
|
43
|
+
private facetChecked(bucket: FacetBucket, negative: boolean) {
|
|
44
|
+
const { facetGroup, selectedFacets } = this;
|
|
45
|
+
if (!facetGroup) return;
|
|
46
|
+
|
|
53
47
|
let newFacets: SelectedFacets;
|
|
54
48
|
if (selectedFacets) {
|
|
55
49
|
newFacets = {
|
|
@@ -58,17 +52,19 @@ export class FacetsTemplate extends LitElement {
|
|
|
58
52
|
} else {
|
|
59
53
|
newFacets = getDefaultSelectedFacets();
|
|
60
54
|
}
|
|
61
|
-
newFacets[key][
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
}
|
|
55
|
+
newFacets[facetGroup.key][bucket.key] = {
|
|
56
|
+
...bucket,
|
|
57
|
+
state: FacetRow.getFacetState(true, negative),
|
|
58
|
+
};
|
|
65
59
|
|
|
66
60
|
this.selectedFacets = newFacets;
|
|
67
61
|
this.dispatchSelectedFacetsChanged();
|
|
68
62
|
}
|
|
69
63
|
|
|
70
|
-
private facetUnchecked(
|
|
71
|
-
const { selectedFacets } = this;
|
|
64
|
+
private facetUnchecked(bucket: FacetBucket) {
|
|
65
|
+
const { facetGroup, selectedFacets } = this;
|
|
66
|
+
if (!facetGroup) return;
|
|
67
|
+
|
|
72
68
|
let newFacets: SelectedFacets;
|
|
73
69
|
if (selectedFacets) {
|
|
74
70
|
newFacets = {
|
|
@@ -77,30 +73,15 @@ export class FacetsTemplate extends LitElement {
|
|
|
77
73
|
} else {
|
|
78
74
|
newFacets = getDefaultSelectedFacets();
|
|
79
75
|
}
|
|
80
|
-
delete newFacets[key][
|
|
76
|
+
delete newFacets[facetGroup.key][bucket.key];
|
|
81
77
|
|
|
82
78
|
this.selectedFacets = newFacets;
|
|
83
79
|
this.dispatchSelectedFacetsChanged();
|
|
84
80
|
}
|
|
85
81
|
|
|
86
|
-
|
|
87
|
-
private getFacetState(checked: boolean, negative: boolean): FacetState {
|
|
88
|
-
let state: FacetState;
|
|
89
|
-
if (checked) {
|
|
90
|
-
state = negative ? 'hidden' : 'selected';
|
|
91
|
-
} else {
|
|
92
|
-
state = 'none';
|
|
93
|
-
}
|
|
94
|
-
return state;
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
private dispatchFacetClickEvent(
|
|
98
|
-
key: FacetOption,
|
|
99
|
-
state: FacetState,
|
|
100
|
-
negative: boolean
|
|
101
|
-
) {
|
|
82
|
+
private dispatchFacetClickEvent(detail: FacetEventDetails) {
|
|
102
83
|
const event = new CustomEvent<FacetEventDetails>('facetClick', {
|
|
103
|
-
detail
|
|
84
|
+
detail,
|
|
104
85
|
composed: true,
|
|
105
86
|
});
|
|
106
87
|
this.dispatchEvent(event);
|
|
@@ -115,8 +96,11 @@ export class FacetsTemplate extends LitElement {
|
|
|
115
96
|
this.dispatchEvent(event);
|
|
116
97
|
}
|
|
117
98
|
|
|
118
|
-
private
|
|
119
|
-
|
|
99
|
+
private get facetsTemplate(): TemplateResult | typeof nothing {
|
|
100
|
+
const { facetGroup } = this;
|
|
101
|
+
if (!facetGroup) return nothing;
|
|
102
|
+
|
|
103
|
+
let facetBuckets = facetGroup.buckets as FacetBucket[];
|
|
120
104
|
|
|
121
105
|
/**
|
|
122
106
|
* sorting FacetBucket before render page / modal
|
|
@@ -124,105 +108,34 @@ export class FacetsTemplate extends LitElement {
|
|
|
124
108
|
* - second, suppressed/hidden items should be after selected having sorted
|
|
125
109
|
* - and then no-selected / not suppressed items should render having sorted
|
|
126
110
|
*/
|
|
127
|
-
|
|
128
|
-
...
|
|
111
|
+
facetBuckets = [
|
|
112
|
+
...facetBuckets
|
|
129
113
|
.filter(x => x.state === 'selected')
|
|
130
114
|
.sort((a, b) => (a.count < b.count ? 1 : -1)),
|
|
131
|
-
...
|
|
115
|
+
...facetBuckets
|
|
132
116
|
.filter(x => x.state === 'hidden')
|
|
133
117
|
.sort((a, b) => (a.count < b.count ? 1 : -1)),
|
|
134
|
-
...
|
|
118
|
+
...facetBuckets.filter(x => x.state === 'none'),
|
|
135
119
|
];
|
|
136
120
|
|
|
137
121
|
return html`
|
|
138
122
|
<div class="facets-on-${this.renderOn}">
|
|
139
123
|
${repeat(
|
|
140
|
-
|
|
124
|
+
facetBuckets,
|
|
141
125
|
bucket => `${facetGroup.key}:${bucket.key}`,
|
|
142
|
-
bucket =>
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
const bucketTextDisplay =
|
|
149
|
-
facetGroup.key !== 'collection'
|
|
150
|
-
? html`${bucket.displayText ?? bucket.key}`
|
|
151
|
-
: html`<a href="${this.collectionPagePath}${bucket.key}">
|
|
152
|
-
<async-collection-name
|
|
153
|
-
.collectionNameCache=${this.collectionNameCache}
|
|
154
|
-
.identifier=${bucket.key}
|
|
155
|
-
placeholder="-"
|
|
156
|
-
></async-collection-name>
|
|
157
|
-
</a> `;
|
|
158
|
-
const facetHidden = bucket.state === 'hidden';
|
|
159
|
-
const facetSelected = bucket.state === 'selected';
|
|
160
|
-
const titleText = `${facetGroup.key}: ${
|
|
161
|
-
bucket.displayText ?? bucket.key
|
|
162
|
-
}`;
|
|
163
|
-
const onlyShowText = facetSelected
|
|
164
|
-
? `Show all ${facetGroup.key}s`
|
|
165
|
-
: `Only show ${titleText}`;
|
|
166
|
-
const hideText = `Hide ${titleText}`;
|
|
167
|
-
const unhideText = `Unhide ${titleText}`;
|
|
168
|
-
const showHideText = facetHidden ? unhideText : hideText;
|
|
169
|
-
const ariaLabel = `${titleText}, ${bucket.count} results`;
|
|
170
|
-
return html`
|
|
171
|
-
<div class="facet-row">
|
|
172
|
-
<div class="facet-checkbox">
|
|
173
|
-
<input
|
|
174
|
-
type="checkbox"
|
|
175
|
-
.name=${facetGroup.key}
|
|
176
|
-
.value=${bucket.key}
|
|
177
|
-
@click=${(e: Event) => {
|
|
178
|
-
this.facetClicked(e, bucket.count, false);
|
|
179
|
-
}}
|
|
180
|
-
.checked=${facetSelected}
|
|
181
|
-
class="select-facet-checkbox"
|
|
182
|
-
title=${onlyShowText}
|
|
183
|
-
id=${showOnlyCheckboxId}
|
|
184
|
-
/>
|
|
185
|
-
<input
|
|
186
|
-
type="checkbox"
|
|
187
|
-
id=${negativeCheckboxId}
|
|
188
|
-
.name=${facetGroup.key}
|
|
189
|
-
.value=${bucket.key}
|
|
190
|
-
@click=${(e: Event) => {
|
|
191
|
-
this.facetClicked(e, bucket.count, true);
|
|
192
|
-
}}
|
|
193
|
-
.checked=${facetHidden}
|
|
194
|
-
class="hide-facet-checkbox"
|
|
195
|
-
/>
|
|
196
|
-
<label
|
|
197
|
-
for=${negativeCheckboxId}
|
|
198
|
-
class="hide-facet-icon${facetHidden ? ' active' : ''}"
|
|
199
|
-
title=${showHideText}
|
|
200
|
-
>
|
|
201
|
-
<span class="eye">${eyeIcon}</span>
|
|
202
|
-
<span class="eye-closed">${eyeClosedIcon}</span>
|
|
203
|
-
</label>
|
|
204
|
-
</div>
|
|
205
|
-
<label
|
|
206
|
-
for=${showOnlyCheckboxId}
|
|
207
|
-
class="facet-info-display"
|
|
208
|
-
title=${onlyShowText}
|
|
209
|
-
aria-label=${ariaLabel}
|
|
210
|
-
>
|
|
211
|
-
<div class="facet-title">${bucketTextDisplay}</div>
|
|
212
|
-
<div class="facet-count">
|
|
213
|
-
${bucket.count.toLocaleString()}
|
|
214
|
-
</div>
|
|
215
|
-
</label>
|
|
216
|
-
</div>
|
|
217
|
-
`;
|
|
218
|
-
}
|
|
126
|
+
bucket => html`<facet-row
|
|
127
|
+
.facetType=${facetGroup.key}
|
|
128
|
+
.bucket=${bucket}
|
|
129
|
+
.collectionNameCache=${this.collectionNameCache}
|
|
130
|
+
@facetClick=${this.facetClicked}
|
|
131
|
+
></facet-row>`
|
|
219
132
|
)}
|
|
220
133
|
</div>
|
|
221
134
|
`;
|
|
222
135
|
}
|
|
223
136
|
|
|
224
137
|
render() {
|
|
225
|
-
return html`${this.
|
|
138
|
+
return html`${this.facetsTemplate}`;
|
|
226
139
|
}
|
|
227
140
|
|
|
228
141
|
static get styles(): CSSResultGroup {
|
|
@@ -236,9 +149,7 @@ export class FacetsTemplate extends LitElement {
|
|
|
236
149
|
column-gap: 15px;
|
|
237
150
|
column-count: 3;
|
|
238
151
|
}
|
|
239
|
-
|
|
240
|
-
display: contents;
|
|
241
|
-
}
|
|
152
|
+
|
|
242
153
|
ul.facet-list {
|
|
243
154
|
list-style: none;
|
|
244
155
|
margin: 0;
|
|
@@ -248,19 +159,7 @@ export class FacetsTemplate extends LitElement {
|
|
|
248
159
|
margin-bottom: 0.2rem;
|
|
249
160
|
display: grid;
|
|
250
161
|
}
|
|
251
|
-
|
|
252
|
-
margin: 0 5px 0 0;
|
|
253
|
-
display: flex;
|
|
254
|
-
height: 15px;
|
|
255
|
-
}
|
|
256
|
-
.facet-checkbox input:first-child {
|
|
257
|
-
margin-right: 5px;
|
|
258
|
-
}
|
|
259
|
-
.facet-checkbox input {
|
|
260
|
-
height: 15px;
|
|
261
|
-
width: 15px;
|
|
262
|
-
margin: 0;
|
|
263
|
-
}
|
|
162
|
+
|
|
264
163
|
.facet-row {
|
|
265
164
|
display: flex;
|
|
266
165
|
font-weight: 500;
|
|
@@ -271,52 +170,6 @@ export class FacetsTemplate extends LitElement {
|
|
|
271
170
|
border-bottom: var(--facet-row-border-bottom, 1px solid transparent);
|
|
272
171
|
overflow: hidden;
|
|
273
172
|
}
|
|
274
|
-
.facet-info-display {
|
|
275
|
-
display: flex;
|
|
276
|
-
flex: 1 1 0%;
|
|
277
|
-
cursor: pointer;
|
|
278
|
-
flex-wrap: wrap;
|
|
279
|
-
}
|
|
280
|
-
.facet-title {
|
|
281
|
-
word-break: break-word;
|
|
282
|
-
display: inline-block;
|
|
283
|
-
flex: 1 1 0%;
|
|
284
|
-
}
|
|
285
|
-
.facet-count {
|
|
286
|
-
text-align: right;
|
|
287
|
-
}
|
|
288
|
-
.select-facet-checkbox {
|
|
289
|
-
cursor: pointer;
|
|
290
|
-
display: inline-block;
|
|
291
|
-
}
|
|
292
|
-
.hide-facet-checkbox {
|
|
293
|
-
display: none;
|
|
294
|
-
}
|
|
295
|
-
.hide-facet-icon {
|
|
296
|
-
width: 15px;
|
|
297
|
-
height: 15px;
|
|
298
|
-
cursor: pointer;
|
|
299
|
-
opacity: 0.3;
|
|
300
|
-
display: inline-block;
|
|
301
|
-
}
|
|
302
|
-
.hide-facet-icon:hover,
|
|
303
|
-
.active {
|
|
304
|
-
opacity: 1;
|
|
305
|
-
}
|
|
306
|
-
.hide-facet-icon:hover .eye,
|
|
307
|
-
.hide-facet-icon .eye-closed {
|
|
308
|
-
display: none;
|
|
309
|
-
}
|
|
310
|
-
.hide-facet-icon:hover .eye-closed,
|
|
311
|
-
.hide-facet-icon.active .eye-closed {
|
|
312
|
-
display: inline;
|
|
313
|
-
}
|
|
314
|
-
.hide-facet-icon.active .eye {
|
|
315
|
-
display: none;
|
|
316
|
-
}
|
|
317
|
-
.sorting-icon {
|
|
318
|
-
cursor: pointer;
|
|
319
|
-
}
|
|
320
173
|
|
|
321
174
|
a:link,
|
|
322
175
|
a:visited {
|
package/src/models.ts
CHANGED
|
@@ -295,6 +295,9 @@ export const prefixFilterAggregationKeys: Record<PrefixFilterType, string> = {
|
|
|
295
295
|
creator: 'firstCreator',
|
|
296
296
|
};
|
|
297
297
|
|
|
298
|
+
/**
|
|
299
|
+
* Union of the facet types that are available in the sidebar.
|
|
300
|
+
*/
|
|
298
301
|
export type FacetOption =
|
|
299
302
|
| 'subject'
|
|
300
303
|
| 'lending'
|
|
@@ -322,9 +325,22 @@ export interface FacetGroup {
|
|
|
322
325
|
buckets: FacetBucket[];
|
|
323
326
|
}
|
|
324
327
|
|
|
328
|
+
/**
|
|
329
|
+
* Information about a user interaction event on a facet.
|
|
330
|
+
*/
|
|
325
331
|
export type FacetEventDetails = {
|
|
326
|
-
|
|
327
|
-
|
|
332
|
+
/**
|
|
333
|
+
* The type of facet that was interacted with (e.g., 'mediatype', 'language', ...).
|
|
334
|
+
*/
|
|
335
|
+
facetType: FacetOption;
|
|
336
|
+
/**
|
|
337
|
+
* The bucket corresponding to the facet that was interacted with, including the
|
|
338
|
+
* updated state of the facet after the interaction.
|
|
339
|
+
*/
|
|
340
|
+
bucket: FacetBucket;
|
|
341
|
+
/**
|
|
342
|
+
* Whether the interaction occurred on a negative facet.
|
|
343
|
+
*/
|
|
328
344
|
negative: boolean;
|
|
329
345
|
};
|
|
330
346
|
|
|
@@ -177,7 +177,15 @@ describe('Collection Browser', () => {
|
|
|
177
177
|
|
|
178
178
|
el.facetClickHandler(
|
|
179
179
|
new CustomEvent('facetClick', {
|
|
180
|
-
detail: {
|
|
180
|
+
detail: {
|
|
181
|
+
facetType: 'mediatype',
|
|
182
|
+
bucket: {
|
|
183
|
+
key: '',
|
|
184
|
+
state: 'selected',
|
|
185
|
+
count: 123,
|
|
186
|
+
},
|
|
187
|
+
negative: false,
|
|
188
|
+
},
|
|
181
189
|
})
|
|
182
190
|
);
|
|
183
191
|
expect(mockAnalyticsHandler.callCategory).to.equal('search-service');
|
|
@@ -186,7 +194,15 @@ describe('Collection Browser', () => {
|
|
|
186
194
|
|
|
187
195
|
el.facetClickHandler(
|
|
188
196
|
new CustomEvent('facetClick', {
|
|
189
|
-
detail: {
|
|
197
|
+
detail: {
|
|
198
|
+
facetType: 'mediatype',
|
|
199
|
+
bucket: {
|
|
200
|
+
key: '',
|
|
201
|
+
state: 'none',
|
|
202
|
+
count: 123,
|
|
203
|
+
},
|
|
204
|
+
negative: false,
|
|
205
|
+
},
|
|
190
206
|
})
|
|
191
207
|
);
|
|
192
208
|
expect(el.selectedFacets).to.equal(mockedSelectedFacets);
|
|
@@ -219,7 +235,15 @@ describe('Collection Browser', () => {
|
|
|
219
235
|
|
|
220
236
|
el.facetClickHandler(
|
|
221
237
|
new CustomEvent('facetClick', {
|
|
222
|
-
detail: {
|
|
238
|
+
detail: {
|
|
239
|
+
facetType: 'mediatype',
|
|
240
|
+
bucket: {
|
|
241
|
+
key: '',
|
|
242
|
+
state: 'hidden',
|
|
243
|
+
count: 123,
|
|
244
|
+
},
|
|
245
|
+
negative: true,
|
|
246
|
+
},
|
|
223
247
|
})
|
|
224
248
|
);
|
|
225
249
|
expect(mockAnalyticsHandler.callCategory).to.equal('beta-search-service');
|
|
@@ -228,7 +252,15 @@ describe('Collection Browser', () => {
|
|
|
228
252
|
|
|
229
253
|
el.facetClickHandler(
|
|
230
254
|
new CustomEvent('facetClick', {
|
|
231
|
-
detail: {
|
|
255
|
+
detail: {
|
|
256
|
+
facetType: 'mediatype',
|
|
257
|
+
bucket: {
|
|
258
|
+
key: '',
|
|
259
|
+
state: 'none',
|
|
260
|
+
count: 123,
|
|
261
|
+
},
|
|
262
|
+
negative: true,
|
|
263
|
+
},
|
|
232
264
|
})
|
|
233
265
|
);
|
|
234
266
|
expect(el.selectedFacets).to.equal(mockedSelectedFacets);
|