Skip to content

Commit 3c68068

Browse files
committed
feat(Metadata): enhance metadata handling to include data types and licenses
1 parent 6668026 commit 3c68068

File tree

2 files changed

+59
-22
lines changed

2 files changed

+59
-22
lines changed

app/[locale]/(user)/datasets/[datasetIdentifier]/components/Metadata/index.tsx

Lines changed: 57 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1+
import React, { useState } from 'react';
12
import Image from 'next/image';
3+
import Link from 'next/link';
24
import { Button, Divider, Icon, Text } from 'opub-ui';
3-
import React, { useState } from 'react';
45

56
import { Icons } from '@/components/icons';
67

@@ -10,24 +11,42 @@ interface MetadataProps {
1011
}
1112

1213
const MetadataComponent: React.FC<MetadataProps> = ({ data, setOpen }) => {
13-
14-
const Metadata = (
15-
data.metadata as Array<{ metadataItem: { label: string }; value: string }>
16-
)
17-
.filter((item) =>
18-
['Geography', 'Update Frequency', 'License'].includes(
19-
item.metadataItem.label
20-
)
21-
)
22-
.map((item) => ({
23-
label:
24-
item.metadataItem.label === 'Geography'
25-
? 'Location'
26-
: item.metadataItem.label,
27-
value: item.value,
28-
}));
14+
const Metadata = data.metadata.map((item: any) => ({
15+
label: item.metadataItem.label,
16+
value: item.value,
17+
type: item.metadataItem.dataType,
18+
}));
2919
const [isexpanded, setIsexpanded] = useState(false);
3020
const toggleDescription = () => setIsexpanded(!isexpanded);
21+
22+
const licenseOptions = [
23+
{
24+
label: 'Government Open Data License',
25+
value: 'GOVERNMENT_OPEN_DATA_LICENSE',
26+
},
27+
{
28+
label: 'CC BY 4.0 (Attribution)',
29+
value: 'CC_BY_4_0_ATTRIBUTION',
30+
},
31+
{
32+
label: 'CC BY-SA 4.0 (Attribution-ShareAlike)',
33+
value: 'CC_BY_SA_4_0_ATTRIBUTION_SHARE_ALIKE',
34+
},
35+
{
36+
label: 'Open Data Commons By Attribution',
37+
value: 'OPEN_DATA_COMMONS_BY_ATTRIBUTION',
38+
},
39+
{
40+
label: 'Open Database License',
41+
value: 'OPEN_DATABASE_LICENSE',
42+
},
43+
];
44+
45+
const getLicenseLabel = (value: string): string => {
46+
const option = licenseOptions.find((option) => option.value === value);
47+
return option ? option.label : value; // fallback to value if no match
48+
};
49+
3150
return (
3251
<div className="flex flex-col gap-10">
3352
<div className=" flex items-center justify-between">
@@ -51,7 +70,7 @@ const MetadataComponent: React.FC<MetadataProps> = ({ data, setOpen }) => {
5170
</div>
5271
<Divider />
5372
<div className=" flex flex-col gap-8">
54-
<div className=" rounded-2 border-1 border-solid border-greyExtralight p-2 hidden lg:block">
73+
<div className=" hidden rounded-2 border-1 border-solid border-greyExtralight p-2 lg:block">
5574
{data?.organization?.logo?.url ? (
5675
<Image
5776
height={140}
@@ -94,19 +113,35 @@ const MetadataComponent: React.FC<MetadataProps> = ({ data, setOpen }) => {
94113
{data.sectors[0].name}
95114
</Text>
96115
</div>
97-
{Metadata.map((item, index) => (
116+
{Metadata.map((item: any, index: any) => (
98117
<div className="flex items-center gap-2 " key={index}>
99118
<Text
100119
className="min-w-[120px] basis-1/4 uppercase"
101120
variant="bodyMd"
102121
>
103122
{item.label}
104123
</Text>
105-
<Text className="max-w-xs " variant="bodyLg" fontWeight="medium">
106-
{item.value}
107-
</Text>
124+
{item.type !== 'URL' ? (
125+
<Text className="max-w-xs " variant="bodyLg" fontWeight="medium">
126+
{item.value}
127+
</Text>
128+
) : (
129+
<Link href={item.value} target="_blank">
130+
<Text className="underline" color="highlight">
131+
Source
132+
</Text>
133+
</Link>
134+
)}
108135
</div>
109136
))}
137+
<div className="flex items-center gap-2 ">
138+
<Text className="min-w-[120px] basis-1/4 uppercase" variant="bodyMd">
139+
License
140+
</Text>
141+
<Text className="" variant="bodyLg" fontWeight="medium">
142+
{getLicenseLabel(data.license)}
143+
</Text>
144+
</div>
110145
<div className="flex flex-col gap-4">
111146
<Text variant="bodyMd">Description</Text>
112147
<Text variant="bodyMd">

app/[locale]/(user)/datasets/[datasetIdentifier]/page.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,11 @@ const datasetQuery: any = graphql(`
3030
metadataItem {
3131
id
3232
label
33+
dataType
3334
}
3435
value
3536
}
37+
license
3638
resources {
3739
id
3840
created

0 commit comments

Comments
 (0)