Skip to content

Commit

Permalink
DIGG-439: Adding bagde for search result of dataset-series
Browse files Browse the repository at this point in the history
  • Loading branch information
MikaMunterud committed Dec 19, 2024
1 parent 33e5f5d commit b978748
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 5 deletions.
2 changes: 1 addition & 1 deletion components/file-format-badge/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -141,5 +141,5 @@ export const FileFormatBadge: FC<FileFormatBadgeProps> = ({ badgeName }) => {
break;
}

return <Badge text={text} className={className} />;
return <Badge text={text} className={`${className} bg-pink-200`} />;
};
10 changes: 10 additions & 0 deletions features/search/search-hit/index.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import Link from "next/link";
import useTranslation from "next-translate/useTranslation";
import { FC } from "react";

import { Badge } from "@/components/badge";
import { FileFormatBadge } from "@/components/file-format-badge";
import { Heading } from "@/components/typography/heading";
import { SearchHit as SearchHitType } from "@/types/search";
Expand All @@ -16,6 +18,8 @@ export const SearchHit: FC<SearchHitProps> = ({
isCompact,
onLinkClick,
}) => {
const { t } = useTranslation();

return (
<li className="group relative max-w-lg space-y-sm">
<Link
Expand Down Expand Up @@ -76,6 +80,12 @@ export const SearchHit: FC<SearchHitProps> = ({
)}
</div>
<div className="formats flex w-full flex-wrap gap-md">
{hit.url.startsWith("/dataset-series") && (
<Badge text={t("pages|dataset-series$data-serie")} />
)}
{hit.metadata?.custom_facet_literal?.map(
(m: string, index: number) => <Badge key={index} text={m} />,
)}
{hit.metadata?.format_literal?.map((m: string, index: number) => (
<FileFormatBadge key={index} badgeName={m} />
))}
Expand Down
7 changes: 3 additions & 4 deletions utilities/entrystore/entrystore.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -708,7 +708,7 @@ export class EntrystoreService {
.map((f: any) => this.t(f.getValue()));
}

// Adding custom facets with showInSearchResult true to format_literal if they are present in the metadata
// Adding custom facets with showInSearchResult true to custom_facet_literal if they are present in the metadata
const customFacets = this.facetSpecification?.facets?.filter(
(spec) => spec.showInSearchResult,
);
Expand All @@ -728,9 +728,8 @@ export class EntrystoreService {
);

if (hasResource) {
// Add the translated resource URI to format_literal array
values["format_literal"] = [
...(values["format_literal"] || []),
// Add the translated resource URI to custom_facet_literal array
values["custom_facet_literal"] = [
this.t(`resources|${facet.resource}`),
];
}
Expand Down

0 comments on commit b978748

Please sign in to comment.