Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WEBDEV-6909 Ensure radio searches are properly read/written to URL #380

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
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 @@ -31,7 +31,7 @@
"@internetarchive/ia-dropdown": "^1.3.8",
"@internetarchive/infinite-scroller": "1.0.1",
"@internetarchive/modal-manager": "^0.2.8",
"@internetarchive/search-service": "^1.3.2",
"@internetarchive/search-service": "1.3.3-alpha.0",
"@internetarchive/shared-resize-observer": "^0.2.0",
"@lit/localize": "^0.11.2",
"dompurify": "^2.3.6",
Expand Down
13 changes: 12 additions & 1 deletion src/models.ts
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ export class TileModel {
this.href = collapseRepeatedQuotes(
result.review?.__href__ ?? result.__href__?.value
);
this.identifier = result.identifier;
this.identifier = TileModel.cleanIdentifier(result.identifier);
this.issue = result.issue?.value;
this.itemCount = result.item_count?.value ?? 0;
this.mediatype = resolveMediatype(result);
Expand Down Expand Up @@ -210,6 +210,17 @@ export class TileModel {

return flags;
}

private static cleanIdentifier(
identifier: string | undefined
): string | undefined {
// Some identifiers (e.g., from Whisper) represent documents rather than items, and
// are suffixed with values that need to be stripped. Those values are separated
// from the item identifier itself with '|'.
const barIndex = identifier?.indexOf('|') ?? -1;
const cleaned = barIndex > 0 ? identifier?.slice(0, barIndex) : identifier;
return cleaned;
}
}

export type RequestKind = 'full' | 'hits' | 'aggregations';
Expand Down
5 changes: 5 additions & 0 deletions src/restoration-state-handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,8 @@ export class RestorationStateHandler

if (state.searchType === SearchType.FULLTEXT) {
newParams.set('sin', 'TXT');
} else if (state.searchType === SearchType.RADIO) {
newParams.set('sin', 'RADIO');
}
if (oldParams.get('sin') === '') {
// Treat empty sin the same as no sin at all
Expand Down Expand Up @@ -264,6 +266,9 @@ export class RestorationStateHandler
case 'TXT':
restorationState.searchType = SearchType.FULLTEXT;
break;
case 'RADIO':
restorationState.searchType = SearchType.RADIO;
break;
default:
restorationState.searchType = SearchType.METADATA;
break;
Expand Down
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -211,10 +211,10 @@
resolved "https://registry.npmjs.org/@internetarchive/result-type/-/result-type-0.0.1.tgz"
integrity sha512-sWahff5oP1xAK1CwAu1/5GTG2RXsdx/sQKn4SSOWH0r0vU2QoX9kAom/jSXeBsmgK0IjTc+9Ty9407SMORi+nQ==

"@internetarchive/search-service@^1.3.2":
version "1.3.2"
resolved "https://registry.yarnpkg.com/@internetarchive/search-service/-/search-service-1.3.2.tgz#713b1172ee13b3e3f3c72c85eb37b7c5e27b2b53"
integrity sha512-FiGZ13QWreeKZQ9Cpfr2cy2i9t9NRFa7pQMwVA9y+fZZwY/PyoWlPQKQySAmnjv3OKrq1I9LdZUkZ9EP4LNhxw==
"@internetarchive/[email protected].3-alpha.1":
version "1.3.3-alpha.1"
resolved "https://registry.yarnpkg.com/@internetarchive/search-service/-/search-service-1.3.3-alpha.1.tgz#966ac0ec307ed67824f48691adcd52a7c71e0fc8"
integrity sha512-idSD1Qf5zZwEytwI3auwyGm6erUeiMZBUruMeaNQKQlA1WUqmnWcCuVXU93Tckh2mkqqphu4J3XJIXPCTEzVgQ==
dependencies:
"@internetarchive/field-parsers" "^0.1.4"
"@internetarchive/result-type" "^0.0.1"
Expand Down
Loading