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

fix(lxlweb): Continue showing error page for _invalid when not using Supersearch #1195

Merged
merged 2 commits into from
Dec 20, 2024
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
7 changes: 6 additions & 1 deletion lxl-web/src/lib/types/search.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ type MappingObj = { [key in SearchOperators]: SearchMapping[] | string | FramedD

export interface SearchMapping extends MappingObj {
alias: string;
property?: ObjectProperty | DatatypeProperty | PropertyChainAxiom;
property?: ObjectProperty | DatatypeProperty | PropertyChainAxiom | InvalidProperty;
object?: FramedData;
up: { '@id': string };
}
Expand All @@ -148,6 +148,11 @@ export interface DatatypeProperty {
'@id': string;
}

interface InvalidProperty {
'@type': '_Invalid';
label: string;
}

interface PropertyChainAxiom {
propertyChainAxiom: (ObjectProperty | DatatypeProperty)[];
label: string; // e.g. "instanceOf language"
Expand Down
14 changes: 13 additions & 1 deletion lxl-web/src/lib/utils/search.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ import { type LocaleCode as LangCode } from '$lib/i18n/locales';
import { bestImage, bestSize, toSecure } from '$lib/utils/auxd';
import getAtPath from '$lib/utils/getAtPath';
import { getUriSlug } from '$lib/utils/http';
import { error } from '@sveltejs/kit';
import { env } from '$env/dynamic/public';

export async function asResult(
view: PartialCollectionView,
Expand Down Expand Up @@ -90,6 +92,16 @@ export function displayMappings(
const operator = _hasOperator(m);

if ('property' in m && operator) {
// Mock old behaviour for 'classic' search GUI, i.e show error page
// when encountering an invalid property in order to provide feedback.
// TODO remove this when Supersearch is fully implemented.
const useSuperSearch = env?.PUBLIC_USE_SUPERSEARCH === 'true';
if (!useSuperSearch && m.property?.['@type'] === '_Invalid') {
error(400, {
message: `Invalid query, please check the documentation. Unrecognized property alias: ${m.property?.label ?? ''}`
});
}

const property = m[operator] as FramedData;
return {
...(isObject(m.property) && { '@id': m.property['@id'] }),
Expand All @@ -102,7 +114,7 @@ export function displayMappings(
'No label', // lensandformat?
property:
m.property?.librisQueryCode ||
m.property?.['@id'].replace('https://id.kb.se/vocab/', '') ||
m.property?.['@id']?.replace('https://id.kb.se/vocab/', '') ||
'', //TODO replace with something better
operator,
...('up' in m && { up: replacePath(m.up as Link, usePath) })
Expand Down
Loading