Skip to content

Commit

Permalink
Merge pull request #505 from diggsweden/DIGG-463
Browse files Browse the repository at this point in the history
Digg 463
  • Loading branch information
MikaMunterud authored Nov 15, 2024
2 parents 900219e + e659bfe commit 60c96db
Show file tree
Hide file tree
Showing 12 changed files with 1,612 additions and 1,339 deletions.
18 changes: 11 additions & 7 deletions components/content/Search/SearchFilters/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ export const SearchFilters: React.FC<SearchFilterProps> = ({
aria-selected={selected(key, facetValue)}
>
<button
className={`focus--in group relative flex w-full items-center break-all py-md pl-md pr-[3rem] text-left hover:bg-brown-100 ${
className={`focus--in group relative flex w-full items-center break-words py-md pl-md pr-[3rem] text-left hover:bg-brown-100 ${
selected(key, facetValue) && "font-strong"
}`}
onClick={() => {
Expand Down Expand Up @@ -361,9 +361,11 @@ export const SearchFilters: React.FC<SearchFilterProps> = ({
name="API"
type="checkbox"
className="peer/hvd-only sr-only"
checked={search.request.facetValues?.some(
(t) => t.title == ESRdfType.hvd,
)}
checked={
search.request.facetValues?.some(
(t) => t.title == ESRdfType.hvd,
) || false
}
onChange={() => doSearch(key, facetValues[0])}
/>
<label
Expand Down Expand Up @@ -396,9 +398,11 @@ export const SearchFilters: React.FC<SearchFilterProps> = ({
name="National"
type="checkbox"
className="peer/national-only sr-only"
checked={search.request.facetValues?.some(
(t) => t.facet == ESRdfType.national_data,
)}
checked={
search.request.facetValues?.some(
(t) => t.facet == ESRdfType.national_data,
) || false
}
onChange={() => doSearch(key, facetValues[0])}
/>
<label
Expand Down
155 changes: 77 additions & 78 deletions components/content/Search/SearchPage/SearchPageEntryScape/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import SearchProvider, {
import { decode } from "qss";
import { useRouter } from "next/router";
import useTranslation from "next-translate/useTranslation";
import { useScript } from "@/hooks/useScript";
import Head from "next/head";
import { Container } from "@/components/layout/Container";
import { ESRdfType, ESType } from "@/utilities/entryScape";
Expand All @@ -33,11 +32,6 @@ export const SearchPageEntryScape: FC<SearchProps> = ({ searchType }) => {
const [query, setQuery] = useState("");
const [showFilter, setShowFilter] = useState(false);
const [showTip, setShowTip] = useState(false);
const postscribeStatus = useScript(
"/postscribe.min.js",
"sha384-1nPAWyZS0cvGLWSoWOrkTZAy8Xq8g6llEe985qo5NRPAeDi+F9h9U+0R8v56XWCM",
"anonymous",
);

const clearCurrentScrollPos = () => {
if (typeof localStorage != "undefined") {
Expand Down Expand Up @@ -140,12 +134,16 @@ export const SearchPageEntryScape: FC<SearchProps> = ({ searchType }) => {
},
{
resource: "http://purl.org/dc/terms/type",
dcatProperty: "dcterms:type",
dcatId: "adms:publishertype",
type: ESType.uri,
related: true,
dcatType: "choice",
indexOrder: 1,
},
{
resource: "http://purl.org/dc/terms/publisher",
dcatProperty: "dcterms:publisher",
type: ESType.uri,
indexOrder: 2,
},
Expand All @@ -159,6 +157,7 @@ export const SearchPageEntryScape: FC<SearchProps> = ({ searchType }) => {
},
{
resource: "http://purl.org/dc/terms/accrualPeriodicity",
dcatId: "dcat:dcterms:accrualPeriodicity_da",
type: ESType.uri,
dcatProperty: "dcterms:accrualPeriodicity",
dcatType: "choice",
Expand Down Expand Up @@ -232,6 +231,7 @@ export const SearchPageEntryScape: FC<SearchProps> = ({ searchType }) => {
},
{
resource: "http://purl.org/dc/terms/publisher",
dcatProperty: "dcterms:publisher",
type: ESType.uri,
indexOrder: 1,
},
Expand Down Expand Up @@ -260,6 +260,7 @@ export const SearchPageEntryScape: FC<SearchProps> = ({ searchType }) => {
{
resource: "http://www.w3.org/2004/02/skos/core#inScheme",
type: ESType.uri,
dcatProperty: "dcterms:type",
indexOrder: 0,
},
],
Expand All @@ -286,83 +287,81 @@ export const SearchPageEntryScape: FC<SearchProps> = ({ searchType }) => {
/>
</Head>

{postscribeStatus === "ready" && (
<SearchProvider
entryscapeUrl={
searchProviderSettings[
searchType as keyof typeof searchProviderSettings
].entryscapeUrl
}
hitSpecifications={
searchProviderSettings[
searchType as keyof typeof searchProviderSettings
].hitSpecifications
}
facetSpecification={
searchProviderSettings[
searchType as keyof typeof searchProviderSettings
].facetSpecification
}
initRequest={
searchProviderSettings[
searchType as keyof typeof searchProviderSettings
].initRequest
}
>
<SearchContext.Consumer>
{(search) => (
<Container>
<div className="flex max-w-md items-end justify-between">
<Heading level={1} size="lg" className="mb-none">
{pageTitle}
</Heading>
<SearchProvider
entryscapeUrl={
searchProviderSettings[
searchType as keyof typeof searchProviderSettings
].entryscapeUrl
}
hitSpecifications={
searchProviderSettings[
searchType as keyof typeof searchProviderSettings
].hitSpecifications
}
facetSpecification={
searchProviderSettings[
searchType as keyof typeof searchProviderSettings
].facetSpecification
}
initRequest={
searchProviderSettings[
searchType as keyof typeof searchProviderSettings
].initRequest
}
>
<SearchContext.Consumer>
{(search) => (
<Container>
<div className="flex max-w-md items-end justify-between">
<Heading level={1} size="lg" className="mb-none">
{pageTitle}
</Heading>

{searchType === "datasets" && (
<Button
aria-expanded={showTip}
variant="plain"
size="sm"
icon={ChevronDownIcon}
iconPosition="right"
className={showTip ? "active" : " "}
onClick={() => {
clearCurrentScrollPos();
setShowTip(!showTip);
}}
label={t("pages|search$search-tips")}
/>
)}
</div>
{searchType === "datasets" && (
<Button
aria-expanded={showTip}
variant="plain"
size="sm"
icon={ChevronDownIcon}
iconPosition="right"
className={showTip ? "active" : " "}
onClick={() => {
clearCurrentScrollPos();
setShowTip(!showTip);
}}
label={t("pages|search$search-tips")}
/>
)}
</div>

{searchType === "datasets" && <SearchTips showTip={showTip} />}
{searchType === "datasets" && <SearchTips showTip={showTip} />}

<SearchForm
search={search}
searchMode={searchType}
query={query}
setQuery={setQuery}
/>
<SearchForm
search={search}
searchMode={searchType}
query={query}
setQuery={setQuery}
/>

<SearchPageSelector query={query} />
<SearchPageSelector query={query} />

<SearchFilters
showFilter={showFilter}
searchMode={searchType}
search={search}
query={query}
setShowFilter={setShowFilter}
/>
<noscript>{t("common|no-js-text")}</noscript>
<SearchResults
showSorting={showFilter}
search={search}
searchMode="datasets"
/>
</Container>
)}
</SearchContext.Consumer>
</SearchProvider>
)}
<SearchFilters
showFilter={showFilter}
searchMode={searchType}
search={search}
query={query}
setShowFilter={setShowFilter}
/>
<noscript>{t("common|no-js-text")}</noscript>
<SearchResults
showSorting={showFilter}
search={search}
searchMode="datasets"
/>
</Container>
)}
</SearchContext.Consumer>
</SearchProvider>
</div>
);
};
29 changes: 10 additions & 19 deletions components/content/Search/SearchResults/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -292,21 +292,14 @@ export const SearchResults: FC<SearchResultsProps> = ({
{hit.metadata &&
search.allFacets &&
!search.loadingFacets &&
hit.metadata["inScheme_resource"] &&
search.getFacetValueTitle(
"http://www.w3.org/2004/02/skos/core#inScheme",
hit.metadata["inScheme_resource"][0],
) && (
<span>
{search.getFacetValueTitle(
"http://www.w3.org/2004/02/skos/core#inScheme",
hit.metadata["inScheme_resource"][0],
)}
</span>
hit.metadata["inScheme_resource"] && (
<span>{hit.metadata["inScheme_resource"]}</span>
)}

{isCompact && hit.descriptionLang && (
<p className="mb-xs break-words">{hit.description}</p>
<p className="mb-xs line-clamp-4 break-words md:line-clamp-2">
{hit.description}
</p>
)}

<div
Expand All @@ -321,13 +314,11 @@ export const SearchResults: FC<SearchResultsProps> = ({
{hit.metadata["theme_literal"].join(", ")}
</span>
)}
{hit.metadata &&
hit.metadata["organisation_literal"] &&
hit.metadata["organisation_literal"].length > 0 && (
<span className="organisation break-words">
{" | " + hit.metadata["organisation_literal"][0]}
</span>
)}
{hit.metadata && hit.metadata["organisation_literal"] && (
<span className="organisation break-words">
{" | " + hit.metadata["organisation_literal"]}
</span>
)}
</div>
<div className="formats space-x-md">
{hit.metadata &&
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
"@alfalab/winston3-logstash-transport": "^1.3.0",
"@apollo/client": "^3.6.9",
"@beam-australia/react-env": "^3.1.1",
"@entryscape/entrystore-js": "^4.14.3",
"@types/node-fetch": "^2.6.2",
"@types/swagger-ui-react": "^4.11.0",
"class-variance-authority": "^0.7.0",
Expand Down
Loading

0 comments on commit 60c96db

Please sign in to comment.