Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
"@internetarchive/iaux-item-metadata": "^1.0.4",
"@internetarchive/infinite-scroller": "^1.0.1",
"@internetarchive/modal-manager": "^2.0.1",
"@internetarchive/search-service": "^2.0.0",
"@internetarchive/search-service": "^2.1.0",
"@internetarchive/shared-resize-observer": "^0.2.0",
"@lit/localize": "^0.12.2",
"dompurify": "^3.2.4",
Expand Down
5 changes: 5 additions & 0 deletions src/assets/img/icons/close-circle-dark.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { svg } from 'lit';

export default svg`
<svg viewBox="0 0 100 100" xmlns="http://www.w3.org/2000/svg"><path d="m50 0c27.6142375 0 50 22.3857625 50 50s-22.3857625 50-50 50-50-22.3857625-50-50 22.3857625-50 50-50zm23.8159475 26.1840525c-1.4033215-1.4033215-3.5816761-1.5592461-5.1572272-.4677738l-.5598841.4677738-18.0988362 18.0989475-18.0988362-18.0989475-.5598841-.4677738c-1.5755511-1.0914723-3.7539057-.9355477-5.1572272.4677738-1.5787367 1.5787367-1.5787367 4.1383746 0 5.7171113l18.0989475 18.0988362-18.0989475 18.0988362c-1.5787367 1.5787367-1.5787367 4.1383746 0 5.7171113 1.4033215 1.4033215 3.5816761 1.5592461 5.1572272.4677738l.5598841-.4677738 18.0988362-18.0989475 18.0988362 18.0989475.5598841.4677738c1.5755511 1.0914723 3.7539057.9355477 5.1572272-.4677738 1.5787367-1.5787367 1.5787367-4.1383746 0-5.7171113l-18.0989475-18.0988362 18.0989475-18.0988362c1.5787367-1.5787367 1.5787367-4.1383746 0-5.7171113z" fill-rule="evenodd"/></svg>
`;
42 changes: 35 additions & 7 deletions src/collection-browser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@
import { log } from './utils/log';
import type { PlaceholderType } from './empty-placeholder';
import type { ManageBar } from './manage/manage-bar';
import type { SmartFacetBar } from './collection-facets/smart-facets/smart-facet-bar';

import './empty-placeholder';
import './tiles/tile-dispatcher';
Expand Down Expand Up @@ -250,6 +251,8 @@
/** Whether to display a smart results carousel above the full results */
@property({ type: Boolean, reflect: true }) showSmartResults = false;

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

/**
* The maximum number of pages we will load when a privileged user clicks
* the "Manage" button on the search page. Limited to 15 pages.
Expand Down Expand Up @@ -304,6 +307,8 @@

@query('manage-bar') private manageBar?: ManageBar;

@query('smart-facet-bar') private smartFacetBar?: SmartFacetBar;

@property({ type: Object, attribute: false })
analyticsHandler?: AnalyticsManagerInterface;

Expand Down Expand Up @@ -507,7 +512,7 @@
render() {
return html`
${this.showSmartFacetBar
? html` <smart-facet-bar
? html`<smart-facet-bar
.query=${this.baseQuery}
.aggregations=${this.dataSource.aggregations}
.selectedFacets=${this.selectedFacets}
Expand All @@ -516,6 +521,7 @@
@facetsChanged=${this.facetsChanged}
@filtersToggled=${() => {
this.facetPaneVisible = !this.facetPaneVisible;
this.emitFacetPaneVisibilityChanged();

Check warning on line 524 in src/collection-browser.ts

View check run for this annotation

Codecov / codecov/patch

src/collection-browser.ts#L524

Added line #L524 was not covered by tests
}}
></smart-facet-bar>`
: nothing}
Expand Down Expand Up @@ -682,18 +688,21 @@
* tiles and sort/filter bar are shown.
*/
private get rightColumnTemplate(): TemplateResult {
const rightColumnClasses = classMap({
column: true,
'full-width': this.showSmartFacetBar && !this.facetPaneVisible,
'smart-results-spacing': !!this.showSmartResults,
});

return html`
<div
id="right-column"
class="column ${this.showSmartResults ? 'smart-results-spacing' : ''}"
>
<div id="right-column" class=${rightColumnClasses}>
${this.showSmartResults
? html`<slot name="smart-results"></slot>`
: nothing}
<section id="results">
${this.showSmartResults
? html`<h2 class="results-section-heading">
${msg('All results')}
${this.resultsHeader ?? msg('All results')}
</h2>`
: nothing}
<div id="cb-top-view">
Expand Down Expand Up @@ -841,6 +850,10 @@
);
}

refreshSmartFacets(): void {
this.smartFacetBar?.refresh();
}

Check warning on line 855 in src/collection-browser.ts

View check run for this annotation

Codecov / codecov/patch

src/collection-browser.ts#L854-L855

Added lines #L854 - L855 were not covered by tests

/**
* Handler to show processing modal while removing item
*/
Expand Down Expand Up @@ -1663,6 +1676,18 @@
);
}

/**
* Emits a `facetPaneVisibilityChanged` event indicating that the facet pane has
* been toggled open or closed.
*/
private emitFacetPaneVisibilityChanged(): void {
this.dispatchEvent(
new CustomEvent<boolean>('facetPaneVisibilityChanged', {
detail: this.facetPaneVisible,
}),
);
}

Check warning on line 1689 in src/collection-browser.ts

View check run for this annotation

Codecov / codecov/patch

src/collection-browser.ts#L1684-L1689

Added lines #L1684 - L1689 were not covered by tests

/**
* Emits a `queryStateChanged` event indicating that one or more of this component's
* properties have changed in a way that could affect the set of search results.
Expand Down Expand Up @@ -2207,13 +2232,16 @@
flex: 1;
position: relative;
min-height: 90vh;
border-left: 1px solid rgb(232, 232, 232);
border-right: 1px solid rgb(232, 232, 232);
margin-top: var(--rightColumnMarginTop, 0);
padding-top: 2rem;
background: #fff;
}

#left-column:not([hidden]) + #right-column {
border-left: 1px solid rgb(232, 232, 232);
}

#right-column.smart-results-spacing {
padding-top: 0.5rem;
border-right: none;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,10 @@
facets: smartFacet.facets.map(facet => {
const replaced = {
...facet,
bucketKey: facet.bucketKey.replace('__QUERY', query),
bucketKey: facet.bucketKey.replace(
'__QUERY',
query.toLowerCase(),
),

Check warning on line 50 in src/collection-facets/smart-facets/heuristics/wikidata/wikidata-heuristic.ts

View check run for this annotation

Codecov / codecov/patch

src/collection-facets/smart-facets/heuristics/wikidata/wikidata-heuristic.ts#L47-L50

Added lines #L47 - L50 were not covered by tests
};

if (facet.displayText) {
Expand Down
54 changes: 38 additions & 16 deletions src/collection-facets/smart-facets/smart-facet-bar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
} from 'lit';
import { repeat } from 'lit/directives/repeat.js';
import { customElement, property, state } from 'lit/decorators.js';
import { msg } from '@lit/localize';
import type { Aggregation, Bucket } from '@internetarchive/search-service';
import type { CollectionTitles } from '../../data-source/models';
import type { FacetOption, SelectedFacets } from '../../models';
Expand All @@ -18,11 +19,11 @@
import type { SmartFacet, SmartFacetEvent } from './models';
import { smartFacetEquals } from './smart-facet-equals';
import { dedupe } from './dedupe';
import { log } from '../../utils/log';
import filterIcon from '../../assets/img/icons/filter';

import './smart-facet-button';
import './smart-facet-dropdown';
import { log } from '../../utils/log';

const fieldPrefixes: Partial<Record<FacetOption, string>> = {
collection: 'Collection: ',
Expand Down Expand Up @@ -59,9 +60,14 @@
//

render() {
if (!this.query) return nothing;

Check warning on line 64 in src/collection-facets/smart-facets/smart-facet-bar.ts

View check run for this annotation

Codecov / codecov/patch

src/collection-facets/smart-facets/smart-facet-bar.ts#L63-L64

Added lines #L63 - L64 were not covered by tests
return html`
<div id="smart-facets-container">
${this.filtersToggleTemplate}
${this.smartFacets.length > 0
? html`<p id="filters-label">${msg('Insights:')}</p>`
: nothing}

Check warning on line 70 in src/collection-facets/smart-facets/smart-facet-bar.ts

View check run for this annotation

Codecov / codecov/patch

src/collection-facets/smart-facets/smart-facet-bar.ts#L68-L70

Added lines #L68 - L70 were not covered by tests
${repeat(
this.smartFacets,
f =>
Expand Down Expand Up @@ -98,6 +104,11 @@
}
}

refresh(): void {
this.lastAggregations = this.aggregations;
this.updateSmartFacets();
}

Check warning on line 111 in src/collection-facets/smart-facets/smart-facet-bar.ts

View check run for this annotation

Codecov / codecov/patch

src/collection-facets/smart-facets/smart-facet-bar.ts#L107-L111

Added lines #L107 - L111 were not covered by tests
private async updateSmartFacets(): Promise<void> {
log('updating smart facets');
if (this.query) {
Expand Down Expand Up @@ -164,6 +175,10 @@

if (this.heuristicRecs.length > 0) {
for (const rec of this.heuristicRecs) {
// Suppress mediatype-only facets for now.
if (rec.facets.length === 1 && rec.facets[0].facetType === 'mediatype')
continue;

Check warning on line 181 in src/collection-facets/smart-facets/smart-facet-bar.ts

View check run for this annotation

Codecov / codecov/patch

src/collection-facets/smart-facets/smart-facet-bar.ts#L178-L181

Added lines #L178 - L181 were not covered by tests
facets.push([rec]);
}
}
Expand Down Expand Up @@ -206,10 +221,8 @@
});

if (facetType === 'mediatype') {
facets.push(
[this.toSmartFacet(facetType, [unusedBuckets[0]])],
[this.toSmartFacet(facetType, [unusedBuckets[1]])],
);
continue;
// Don't include mediatype bubbles

Check warning on line 225 in src/collection-facets/smart-facets/smart-facet-bar.ts

View check run for this annotation

Codecov / codecov/patch

src/collection-facets/smart-facets/smart-facet-bar.ts#L224-L225

Added lines #L224 - L225 were not covered by tests
} else if (facetType === 'collection' || facetType === 'subject') {
const topBuckets = unusedBuckets.slice(0, 5);
facets.push(topBuckets.map(b => this.toSmartFacet(facetType, [b])));
Expand Down Expand Up @@ -320,33 +333,42 @@
display: flex;
align-items: center;
flex-wrap: wrap;
gap: 5px;
gap: 5px 10px;
padding: 10px 0;
}

#filters-toggle {
margin: 0;
border: 0;
padding: 5px 10px;
border-radius: 15px;
background: #194880;
color: white;
font-size: 1.6rem;
padding: 5px 8px;
border-radius: 50%;
background: white;
color: #2c2c2c;
border: 1px solid #194880;
font-size: 1.4rem;
font-family: inherit;
text-decoration: none;
box-shadow: 1px 1px rgba(0, 0, 0, 0.4);
cursor: pointer;
}

#filters-toggle.active {
background: #09294d;
box-shadow: -1px -1px rgba(0, 0, 0, 0.1);
background: #194880;
color: white;
}

#filters-toggle > svg {
width: 15px;
width: 12px;
filter: invert(0.16667);
vertical-align: -1px;
}

#filters-toggle.active > svg {
filter: invert(1);
vertical-align: text-bottom;
}

#filters-label {
font-weight: bold;
margin: 0 -5px 0 0;
}
`;
}
Expand Down
37 changes: 27 additions & 10 deletions src/collection-facets/smart-facets/smart-facet-button.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import { mediatypeConfig } from '../../mediatype/mediatype-config';
import type { SmartFacet, SmartFacetEvent } from './models';

import closeCircleDark from '../../assets/img/icons/close-circle-dark';

function capitalize(str?: string): string | undefined {
if (!str) return str;
return str.charAt(0).toLocaleUpperCase() + str.slice(1);
Expand Down Expand Up @@ -47,7 +49,7 @@
>
${icon} ${displayText}
${this.selected
? html`<span style="margin-left: 5px;">×</span>`
? html`<span class="unselect-button">${closeCircleDark}</span>`

Check warning on line 52 in src/collection-facets/smart-facets/smart-facet-button.ts

View check run for this annotation

Codecov / codecov/patch

src/collection-facets/smart-facets/smart-facet-button.ts#L52

Added line #L52 was not covered by tests
: nothing}
</a>
`;
Expand Down Expand Up @@ -101,24 +103,39 @@
static get styles(): CSSResultGroup {
return css`
.smart-facet-button {
padding: 5px 10px;
border-radius: 15px;
background: #194880;
color: white;
font-size: 1.6rem;
display: inline-flex;
align-items: center;
column-gap: 5px;
padding: 5px 5px;
border-radius: 5px;
background: white;
color: #2c2c2c;
border: 1px solid #194880;
font-size: 1.4rem;
font-family: inherit;
line-height: normal;
text-decoration: none;
box-shadow: 1px 1px rgba(0, 0, 0, 0.4);
}

.smart-facet-button.selected {
background: #4c76aa;
background: #194880;
color: white;
}

.unselect-button > svg {
width: 10px;
height: 10px;
filter: invert(1);
}

.smart-facet-button > svg {
width: 15px;
width: 12px;
height: 12px;
filter: invert(0.16667);
}

.smart-facet-button.selected > svg {
filter: invert(1);
vertical-align: text-top;
}
`;
}
Expand Down
31 changes: 21 additions & 10 deletions src/collection-facets/smart-facets/smart-facet-dropdown.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@
displayCaret
openViaButton
closeOnSelect
closeOnEscape
closeOnBackdropClick

Check warning on line 37 in src/collection-facets/smart-facets/smart-facet-dropdown.ts

View check run for this annotation

Codecov / codecov/patch

src/collection-facets/smart-facets/smart-facet-dropdown.ts#L36-L37

Added lines #L36 - L37 were not covered by tests
includeSelectedOption
.options=${this.dropdownOptions}
.selectedOption=${this.activeDropdownOption}
Expand All @@ -57,8 +59,11 @@
const firstFacet = smartFacet.facets[0];
return {
id: firstFacet.bucketKey,
label:
smartFacet.label ?? firstFacet.displayText ?? firstFacet.bucketKey,
label: html`<span>
${smartFacet.label ??
firstFacet.displayText ??
firstFacet.bucketKey}
</span>`,

Check warning on line 66 in src/collection-facets/smart-facets/smart-facet-dropdown.ts

View check run for this annotation

Codecov / codecov/patch

src/collection-facets/smart-facets/smart-facet-dropdown.ts#L62-L66

Added lines #L62 - L66 were not covered by tests
};
}) ?? []
);
Expand Down Expand Up @@ -127,23 +132,29 @@
static get styles(): CSSResultGroup {
return css`
.dropdown-container {
padding: 5px 8px;
padding: 5px 5px;
border-radius: 5px;
background: #194880;
color: white;
font-size: 1.6rem;
background: white;
color: #2c2c2c;
border: 1px solid #194880;
font-size: 1.4rem;
font-family: inherit;
box-shadow: 1px 1px rgba(0, 0, 0, 0.4);
}

.dropdown-label {
font-size: 1.6rem;
font-size: 1.4rem;
font-family: inherit;
}

.dropdown {
--dropdownBorderWidth: 5px;
--dropdownBorderColor: transparent;
--dropdownBorderColor: #194880;
--dropdownBorderWidth: 1px;
--dropdownBgColor: white;
--dropdownHoverBgColor: #f8f8f8;
--dropdownTextColor: #2c2c2c;
--dropdownHoverTextColor: #2c2c2c;
--dropdownCaretColor: #2c2c2c;
--dropdownWhiteSpace: nowrap;
--caretWidth: 14px;
--caretHeight: 14px;
}
Expand Down
Loading
Loading