Skip to content

Commit a6e36e1

Browse files
authored
Merge pull request #491 from diggsweden/DIGG-440
Digg 440
2 parents db96dad + 1c514af commit a6e36e1

File tree

13 files changed

+150
-71
lines changed

13 files changed

+150
-71
lines changed

components/content/Entryscape/DataServicePage/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ export const DataServicePage: React.FC<{
9999
},
100100
101101
blocks: [
102-
${customIndicators},
102+
${customIndicators(t)},
103103
${exploreApiLink},
104104
${keyword(t)},
105105
${theme(t)},

components/content/Entryscape/DataSetPage/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ export const DataSetPage: React.FC = () => {
189189
],
190190
191191
blocks: [
192-
${customIndicators},
192+
${customIndicators(t)},
193193
${exploreApiLink(cid, eid, t)},
194194
${keyword(t)},
195195
${theme(t)},

components/content/Entryscape/DatasetExploreApiPage/index.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ export const DataSetExploreApiPage: React.FC<{
153153
],
154154
155155
blocks: [
156-
${customIndicators},
156+
${customIndicators(t)},
157157
]
158158
}]
159159
</script>

components/content/Search/SearchFilters/index.tsx

Lines changed: 109 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,10 @@ export const SearchFilters: React.FC<SearchFilterProps> = ({
163163
const containHVD = !search.request.facetValues?.find(
164164
(d) => d.facet === hvd && search.request.facetValues?.length === 1,
165165
);
166+
const national = "http://purl.org/dc/terms/subject";
167+
const containNational = !search.request.facetValues?.find(
168+
(d) => d.facet === national && search.request.facetValues?.length === 1,
169+
);
166170

167171
const clearCurrentScrollPos = () => {
168172
if (typeof localStorage != "undefined" && typeof location != "undefined") {
@@ -243,7 +247,7 @@ export const SearchFilters: React.FC<SearchFilterProps> = ({
243247
)
244248
: value?.facetValues.slice(0, show);
245249

246-
if (key !== hvd) {
250+
if (key !== hvd && key !== national) {
247251
return (
248252
<li key={"box" + value.title + idx} role="listitem">
249253
<SearchFilter
@@ -349,7 +353,7 @@ export const SearchFilters: React.FC<SearchFilterProps> = ({
349353
</SearchFilter>
350354
</li>
351355
);
352-
} else {
356+
} else if (key === hvd) {
353357
return (
354358
<div key={value.title} className="relative max-w-fit">
355359
<input
@@ -384,29 +388,52 @@ export const SearchFilters: React.FC<SearchFilterProps> = ({
384388
/>
385389
</div>
386390
);
391+
} else if (key === national) {
392+
return (
393+
<div key={value.title} className="relative max-w-fit">
394+
<input
395+
id="national_only"
396+
name="National"
397+
type="checkbox"
398+
className="peer/national-only sr-only"
399+
checked={search.request.facetValues?.some(
400+
(t) => t.facet == ESRdfType.national_data,
401+
)}
402+
onChange={() => doSearch(key, facetValues[0])}
403+
/>
404+
<label
405+
className="button button--small button--secondary z-2 focus--outline focus--primary relative cursor-pointer pr-xl
406+
peer-checked:after:translate-x-full peer-focus-visible/national-only:bg-whiteOpaque5 peer-focus-visible/national-only:outline-dashed peer-focus-visible/national-only:outline-[3px]
407+
peer-focus-visible/national-only:outline-offset-2 peer-focus-visible/national-only:outline-primary md:pr-xl"
408+
htmlFor="national_only"
409+
>
410+
{t(`resources|${key}`)}
411+
</label>
412+
<CheckboxIcon
413+
height={iconSize * 1.5}
414+
width={iconSize * 1.5}
415+
viewBox="0 0 24 24"
416+
className="pointer-events-none absolute right-sm top-1/4 peer-checked/national-only:hidden"
417+
/>
418+
<CheckboxCheckedIcon
419+
height={iconSize * 1.5}
420+
width={iconSize * 1.5}
421+
viewBox="0 0 24 24"
422+
className="pointer-events-none absolute right-sm top-1/4 hidden peer-checked/national-only:block"
423+
/>
424+
</div>
425+
);
387426
}
388427
})}
389428
{searchMode == "datasets" && (
390-
<div className="relative max-w-fit">
391-
<input
392-
id="api_only"
393-
name="API"
394-
type="checkbox"
395-
className="peer/api-only sr-only"
396-
checked={
397-
search.request.esRdfTypes?.some(
398-
(t) => t == ESRdfType.esterms_ServedByDataService,
399-
) &&
400-
search.request.esRdfTypes?.some(
401-
(t) => t == ESRdfType.esterms_IndependentDataService,
402-
) &&
403-
!search.request.esRdfTypes?.some(
404-
(t) => t == ESRdfType.dataset,
405-
)
406-
}
407-
onChange={() => {
408-
clearCurrentScrollPos();
409-
if (
429+
<>
430+
<div className="relative max-w-fit">
431+
<input
432+
id="api_only"
433+
name="API"
434+
type="checkbox"
435+
className="peer/api-only sr-only"
436+
checked={
410437
search.request.esRdfTypes?.some(
411438
(t) => t == ESRdfType.esterms_ServedByDataService,
412439
) &&
@@ -416,67 +443,83 @@ export const SearchFilters: React.FC<SearchFilterProps> = ({
416443
!search.request.esRdfTypes?.some(
417444
(t) => t == ESRdfType.dataset,
418445
)
419-
) {
420-
search
421-
.set({
422-
esRdfTypes: [
423-
ESRdfType.dataset,
424-
ESRdfType.esterms_IndependentDataService,
425-
ESRdfType.esterms_ServedByDataService,
426-
],
427-
query: query,
428-
})
429-
.then(() => search.doSearch());
430-
} else {
431-
search
432-
.set({
433-
esRdfTypes: [
434-
ESRdfType.esterms_IndependentDataService,
435-
ESRdfType.esterms_ServedByDataService,
436-
],
437-
query: query,
438-
})
439-
.then(() => search.doSearch());
440446
}
441-
}}
442-
/>
443-
<label
444-
className="button button--small button--secondary z-2 focus--outline focus--primary relative cursor-pointer pr-xl
447+
onChange={() => {
448+
clearCurrentScrollPos();
449+
if (
450+
search.request.esRdfTypes?.some(
451+
(t) => t == ESRdfType.esterms_ServedByDataService,
452+
) &&
453+
search.request.esRdfTypes?.some(
454+
(t) => t == ESRdfType.esterms_IndependentDataService,
455+
) &&
456+
!search.request.esRdfTypes?.some(
457+
(t) => t == ESRdfType.dataset,
458+
)
459+
) {
460+
search
461+
.set({
462+
esRdfTypes: [
463+
ESRdfType.dataset,
464+
ESRdfType.esterms_IndependentDataService,
465+
ESRdfType.esterms_ServedByDataService,
466+
],
467+
query: query,
468+
})
469+
.then(() => search.doSearch());
470+
} else {
471+
search
472+
.set({
473+
esRdfTypes: [
474+
ESRdfType.esterms_IndependentDataService,
475+
ESRdfType.esterms_ServedByDataService,
476+
],
477+
query: query,
478+
})
479+
.then(() => search.doSearch());
480+
}
481+
}}
482+
/>
483+
<label
484+
className="button button--small button--secondary z-2 focus--outline focus--primary relative cursor-pointer pr-xl
445485
peer-checked:after:translate-x-full peer-focus-visible/api-only:bg-whiteOpaque5 peer-focus-visible/api-only:outline-dashed
446486
peer-focus-visible/api-only:outline-[3px] peer-focus-visible/api-only:outline-offset-2 peer-focus-visible/api-only:outline-primary md:pr-xl"
447-
htmlFor="api_only"
448-
>
449-
API
450-
</label>
451-
<CheckboxIcon
452-
height={iconSize * 1.5}
453-
width={iconSize * 1.5}
454-
viewBox="0 0 24 24"
455-
className="pointer-events-none absolute right-sm top-1/4 peer-checked/api-only:hidden"
456-
/>
457-
<CheckboxCheckedIcon
458-
height={iconSize * 1.5}
459-
width={iconSize * 1.5}
460-
viewBox="0 0 24 24"
461-
className="pointer-events-none absolute right-sm top-1/4 hidden peer-checked/api-only:block"
462-
/>
463-
</div>
487+
htmlFor="api_only"
488+
>
489+
API
490+
</label>
491+
<CheckboxIcon
492+
height={iconSize * 1.5}
493+
width={iconSize * 1.5}
494+
viewBox="0 0 24 24"
495+
className="pointer-events-none absolute right-sm top-1/4 peer-checked/api-only:hidden"
496+
/>
497+
<CheckboxCheckedIcon
498+
height={iconSize * 1.5}
499+
width={iconSize * 1.5}
500+
viewBox="0 0 24 24"
501+
className="pointer-events-none absolute right-sm top-1/4 hidden peer-checked/api-only:block"
502+
/>
503+
</div>
504+
</>
464505
)}
465506
</ul>
466507
</div>
467508
{search.request.facetValues && search.request.facetValues.length > 0 && (
468509
<div className="mt-lg flex flex-col justify-between gap-md md:flex-row md:items-baseline">
469510
<div className="flex flex-col flex-wrap gap-sm md:flex-row md:gap-md">
470-
{containHVD && (
511+
{(containHVD || containNational) && (
471512
<span className="text-textSecondary">
472513
{t("common|active-filters")}
473514
</span>
474515
)}
516+
475517
{search.request &&
476518
search.request.facetValues &&
477519
(search.request.facetValues as SearchFacetValue[]).map(
478520
(facetValue: SearchFacetValue, index: number) =>
479-
facetValue.facet !== hvd && (
521+
facetValue.facet !== hvd &&
522+
facetValue.facet !== national && (
480523
<Button
481524
variant="filter"
482525
size="xs"

components/content/Search/SearchPage/SearchPageEntryScape/index.tsx

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,14 @@ export const SearchPageEntryScape: FC<SearchProps> = ({ searchType }) => {
181181
dcatFilterEnabled: false,
182182
indexOrder: 6,
183183
},
184+
{
185+
resource: "http://purl.org/dc/terms/subject",
186+
type: ESType.uri,
187+
dcatProperty: "dcterms:subject",
188+
dcatType: "choice",
189+
dcatFilterEnabled: false,
190+
indexOrder: 7,
191+
},
184192
],
185193
},
186194
initRequest: {

components/content/Search/SearchResults/index.tsx

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,7 @@ export const SearchResults: FC<SearchResultsProps> = ({
183183
const [lastUpdate, setLastUpdate] = useState<string>("");
184184
const { t } = useTranslation();
185185
const hvd = "http://data.europa.eu/r5r/applicableLegislation";
186+
const national = "http://purl.org/dc/terms/subject";
186187
const searchKey = typeof location != "undefined" ? location.search : "server";
187188
const posY =
188189
typeof localStorage != "undefined"
@@ -232,6 +233,13 @@ export const SearchResults: FC<SearchResultsProps> = ({
232233
return isHvd.includes(true);
233234
}
234235

236+
function isNational(dataset: object) {
237+
const isNational = Object.values(dataset).map((ds) =>
238+
ds.hasOwnProperty(national),
239+
);
240+
return isNational.includes(true);
241+
}
242+
235243
return (
236244
<div id="search-result" className="my-lg md:my-xl">
237245
<div className="mb-lg flex flex-col-reverse justify-between md:flex-row">
@@ -339,6 +347,13 @@ export const SearchResults: FC<SearchResultsProps> = ({
339347
{t("common|high-value-dataset")}
340348
</span>
341349
)}
350+
{isNational(hit.esEntry._metadata._graph) && (
351+
<span
352+
className={`bg-green-200 px-sm py-xs text-sm uppercase`}
353+
>
354+
{t("common|national-dataset")}
355+
</span>
356+
)}
342357
</div>
343358
</div>
344359
</li>

locales/en/common.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@
5454
"menu-anchor": "On-page navigation",
5555
"menu-form": "Form steps",
5656
"menu-form-bottom": "Form actions",
57+
"national-dataset": "National basic data",
5758
"no-js-text": "JavaScript must be enabled for the search page to work.",
5859
"of": "of",
5960
"to": "to",

locales/en/resources.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
"http://purl.org/dc/terms/accessRights": "Access",
77
"http://purl.org/dc/terms/license": "License",
88
"http://data.europa.eu/r5r/applicableLegislation": "High-value dataset",
9+
"http://purl.org/dc/terms/subject": "National basic data",
910

1011
"https://dataportal.se/concepts/licensecategories/otherlicense": "Other licenses",
1112
"https://dataportal.se/concepts/licensecategories/nolicense": "License missing",

locales/sv/common.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@
5454
"menu-anchor": "Sidinnehållsnavigation",
5555
"menu-form": "Formulärsteg",
5656
"menu-form-bottom": "Formuläråtgärder",
57+
"national-dataset": "Nationella grunddata",
5758
"no-js-text": "JavaScript måste vara aktiverat för att söksidan ska fungera.",
5859
"seo-title": "Sveriges Dataportal",
5960
"search": "Sök",

locales/sv/resources.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
"http://purl.org/dc/terms/accessRights": "Åtkomsträttigheter",
77
"http://purl.org/dc/terms/license": "Licens",
88
"http://data.europa.eu/r5r/applicableLegislation": "Värdefulla datamängder",
9+
"http://purl.org/dc/terms/subject": "Nationella grunddata",
910

1011
"https://dataportal.se/concepts/licensecategories/otherlicense": "Övriga licenser",
1112
"https://dataportal.se/concepts/licensecategories/nolicense": "Saknar licens",

utilities/entryScape.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ export enum ESRdfType {
3636
esterms_ServedByDataService = "esterms:ServedByDataService",
3737
hvd = "http://data.europa.eu/eli/reg_impl/2023/138/oj",
3838
agent = "http://xmlns.com/foaf/0.1/Agent",
39+
national_data = "http://purl.org/dc/terms/subject",
3940
}
4041

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

utilities/entryscape_blocks.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { Translate } from "next-translate";
22

3-
export const customIndicators = `
3+
export const customIndicators = (t: Translate) => `
44
{
55
block: 'customIndicators',
66
extends: 'template',
@@ -58,6 +58,14 @@ export const customIndicators = `
5858
'<span>{{label}}</span>' +
5959
'</span>{{/eachprop}}' +
6060
61+
'{{#ifprop "dcterms:subject"}}' +
62+
'<span class="indicator" title="Nationell datamängd">' +
63+
'<svg width="24" height="24" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">' +
64+
'<path d="M12 21C9.48333 21 7.35417 20.6125 5.6125 19.8375C3.87083 19.0625 3 18.1167 3 17V7C3 5.9 3.87917 4.95833 5.6375 4.175C7.39583 3.39167 9.51667 3 12 3C14.4833 3 16.6042 3.39167 18.3625 4.175C20.1208 4.95833 21 5.9 21 7V17C21 18.1167 20.1292 19.0625 18.3875 19.8375C16.6458 20.6125 14.5167 21 12 21ZM12 9.025C13.4833 9.025 14.975 8.8125 16.475 8.3875C17.975 7.9625 18.8167 7.50833 19 7.025C18.8167 6.54167 17.9792 6.08333 16.4875 5.65C14.9958 5.21667 13.5 5 12 5C10.4833 5 8.99583 5.2125 7.5375 5.6375C6.07917 6.0625 5.23333 6.525 5 7.025C5.23333 7.525 6.07917 7.98333 7.5375 8.4C8.99583 8.81667 10.4833 9.025 12 9.025ZM12 14C12.7 14 13.375 13.9667 14.025 13.9C14.675 13.8333 15.2958 13.7375 15.8875 13.6125C16.4792 13.4875 17.0375 13.3333 17.5625 13.15C18.0875 12.9667 18.5667 12.7583 19 12.525V9.525C18.5667 9.75833 18.0875 9.96667 17.5625 10.15C17.0375 10.3333 16.4792 10.4875 15.8875 10.6125C15.2958 10.7375 14.675 10.8333 14.025 10.9C13.375 10.9667 12.7 11 12 11C11.3 11 10.6167 10.9667 9.95 10.9C9.28333 10.8333 8.65417 10.7375 8.0625 10.6125C7.47083 10.4875 6.91667 10.3333 6.4 10.15C5.88333 9.96667 5.41667 9.75833 5 9.525V12.525C5.41667 12.7583 5.88333 12.9667 6.4 13.15C6.91667 13.3333 7.47083 13.4875 8.0625 13.6125C8.65417 13.7375 9.28333 13.8333 9.95 13.9C10.6167 13.9667 11.3 14 12 14ZM12 19C12.7667 19 13.5458 18.9417 14.3375 18.825C15.1292 18.7083 15.8583 18.5542 16.525 18.3625C17.1917 18.1708 17.75 17.9542 18.2 17.7125C18.65 17.4708 18.9167 17.225 19 16.975V14.525C18.5667 14.7583 18.0875 14.9667 17.5625 15.15C17.0375 15.3333 16.4792 15.4875 15.8875 15.6125C15.2958 15.7375 14.675 15.8333 14.025 15.9C13.375 15.9667 12.7 16 12 16C11.3 16 10.6167 15.9667 9.95 15.9C9.28333 15.8333 8.65417 15.7375 8.0625 15.6125C7.47083 15.4875 6.91667 15.3333 6.4 15.15C5.88333 14.9667 5.41667 14.7583 5 14.525V17C5.08333 17.25 5.34583 17.4917 5.7875 17.725C6.22917 17.9583 6.78333 18.1708 7.45 18.3625C8.11667 18.5542 8.85 18.7083 9.65 18.825C10.45 18.9417 11.2333 19 12 19Z" fill="#6E615A"/>' +
65+
'</svg>' +
66+
'<span>${t("common|national-dataset")}</span>' +
67+
'</span>{{/ifprop}}' +
68+
6169
'{{#ifprop "schema:offers"}}' +
6270
'<span class="indicator" title="Avgift">' +
6371
'<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none">' +

utilities/generateCsp.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ const generateCSP = ({ nonce }: generateCSPProps = {}) => {
8787
"connect-src",
8888
`'self' https://* http://127.0.0.1:1300/ https://admin.dataportal.se https://editera.dataportal.se https://webbanalys.digg.se ${
8989
reactEnv("APOLLO_URL") || ""
90-
} https://* webbanalys.digg.se statsapi.screen9.com`,
90+
} https://* webbanalys.digg.se statsapi.screen9.com geo-inspire.trafikverket.se`,
9191
);
9292

9393
// Return the object in a formatted value

0 commit comments

Comments
 (0)