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

spec-filter #533

Merged
merged 4 commits into from
Dec 9, 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
55 changes: 33 additions & 22 deletions features/search/search-filters/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,11 @@ import { SearchFilter } from "@/features/search/search-filters/search-filter";
import { SearchContextData } from "@/providers/search-provider";
import { SettingsContext } from "@/providers/settings-provider";
import { SearchFacet, SearchFacetValue } from "@/types/search";
import { ESRdfType, ESType } from "@/utilities/entryscape/entryscape";
import {
checkBoxFilterConfigs,
ESRdfType,
ESType,
} from "@/utilities/entryscape/entryscape";

import { SearchActiveFilters } from "./search-active-filters";
import {
Expand Down Expand Up @@ -280,7 +284,8 @@ export const SearchFilters: FC<SearchFilterProps> = ({
}, [search.allFacets]);

const hvd = "http://data.europa.eu/r5r/applicableLegislation";
const national = "http://purl.org/dc/terms/subject";
const national_data = "http://purl.org/dc/terms/subject";
const specifications = "http://purl.org/dc/terms/conformsTo";

const activeCheckboxFilters = useMemo(() => {
const filters = [];
Expand Down Expand Up @@ -308,13 +313,28 @@ export const SearchFilters: FC<SearchFilterProps> = ({
) {
filters.push({
id: "national_only",
label: t(`resources|${national}`),
label: t(`resources|${national_data}`),
facetValue: search.request.facetValues.find(
(t: SearchFacetValue) => t.facet === ESRdfType.national_data,
),
});
}

// Specification filter
if (
search.request.facetValues?.some(
(t: SearchFacetValue) => t.facet === ESRdfType.spec,
)
) {
filters.push({
id: "spec_only",
label: t(`resources|${specifications}`),
facetValue: search.request.facetValues.find(
(t) => t.facet === ESRdfType.spec,
),
});
}

// API only filter
if (
searchMode === "datasets" &&
Expand Down Expand Up @@ -409,7 +429,11 @@ export const SearchFilters: FC<SearchFilterProps> = ({
)
: value?.facetValues.slice(0, show);

if (key !== hvd && key !== national) {
if (
key !== hvd &&
key !== national_data &&
key !== specifications
) {
return (
<li
key={`${value.title}-${idx}`}
Expand Down Expand Up @@ -527,28 +551,15 @@ export const SearchFilters: FC<SearchFilterProps> = ({
</SearchFilter>
</li>
);
} else if (key === hvd) {
return (
<SearchCheckboxFilter
key={key}
id="hvd_only"
name="hvd"
checked={activeCheckboxFilters.some(
(filter) => filter.id === "hvd_only",
)}
onChange={() => doSearch(key, facetValues[0])}
label={t(`resources|${key}`)}
iconSize={iconSize}
/>
);
} else if (key === national) {
} else {
const filterConfig = checkBoxFilterConfigs[key];
return (
<SearchCheckboxFilter
key={key}
id="national_only"
name="National"
id={filterConfig.id}
name={filterConfig.name}
checked={activeCheckboxFilters.some(
(filter) => filter.id === "national_only",
(filter) => filter.id === filterConfig.id,
)}
onChange={() => doSearch(key, facetValues[0])}
label={t(`resources|${key}`)}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,8 @@ export function SearchActiveFilters({
(facetValue: SearchFacetValue, index: number) =>
facetValue.facet !==
"http://data.europa.eu/r5r/applicableLegislation" &&
facetValue.facet !== "http://purl.org/dc/terms/subject" && (
facetValue.facet !== "http://purl.org/dc/terms/subject" &&
facetValue.facet !== "http://purl.org/dc/terms/conformsTo" && (
<Button
variant="filter"
size="xs"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,15 @@ export function createSearchProviderSettings(env: EnvSettings, lang: string) {
indexOrder: 7,
group: "type",
},
{
resource: "http://purl.org/dc/terms/conformsTo",
type: ESType.uri,
dcatProperty: "dcterms:conformsTo",
dcatType: "choice",
dcatFilterEnabled: false,
indexOrder: 8,
group: "type",
},
],
},
initRequest: {
Expand Down
1 change: 1 addition & 0 deletions locales/en/resources.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
"http://publications.europa.eu/resource/authority/data-theme/TRAN": "Transport",
"http://purl.org/dc/terms/accessRights": "Access",
"http://purl.org/dc/terms/accrualPeriodicity": "Update frequency",
"http://purl.org/dc/terms/conformsTo": "Follows specification",
"http://purl.org/dc/terms/format": "Format",
"http://purl.org/dc/terms/license": "License",
"http://purl.org/dc/terms/publisher": "Organisation",
Expand Down
1 change: 1 addition & 0 deletions locales/sv/resources.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
"http://publications.europa.eu/resource/authority/data-theme/TRAN": "Transport",
"http://purl.org/dc/terms/accessRights": "Åtkomsträttigheter",
"http://purl.org/dc/terms/accrualPeriodicity": "Uppdateringsfrekvens",
"http://purl.org/dc/terms/conformsTo": "Följer specifikation",
"http://purl.org/dc/terms/format": "Format",
"http://purl.org/dc/terms/license": "Licens",
"http://purl.org/dc/terms/publisher": "Organisation",
Expand Down
23 changes: 20 additions & 3 deletions utilities/entryscape/entryscape.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,29 @@ export enum ESRdfType {
esterms_IndependentDataService = "esterms:IndependentDataService",
esterms_ServedByDataService = "esterms:ServedByDataService",
hvd = "http://data.europa.eu/eli/reg_impl/2023/138/oj",
agent = "http://xmlns.com/foaf/0.1/Agent",
national_data = "http://purl.org/dc/terms/subject",
agent = "http://xmlns.com/foaf/0.1/Agent",
spec = "http://purl.org/dc/terms/conformsTo",
}

export const checkBoxFilterConfigs: Record<
string,
{ id: string; name: string }
> = {
"http://data.europa.eu/r5r/applicableLegislation": {
id: "hvd_only",
name: "hvd",
},
"http://purl.org/dc/terms/conformsTo": {
id: "spec_only",
name: "Specification",
},
"http://purl.org/dc/terms/subject": {
id: "national_only",
name: "National data",
},
};

/* eslint-enable no-unused-vars */

export interface ESEntryField {
Expand Down Expand Up @@ -478,7 +497,6 @@ export class Entryscape {
);
break;
}

esQuery.uriProperty(
key,
fvalue.map((f) => f.resource),
Expand Down Expand Up @@ -533,7 +551,6 @@ export class Entryscape {
const facetSpec = this.facetSpecification?.facets?.find(
(spec) => spec.resource === fg.predicate,
);

if (facetSpec && facetSpec.dcatType !== "choice") {
await getUriNames(
fg.values
Expand Down
Loading