Skip to content

Commit f22d5be

Browse files
committed
use new sdga nd geography field in all dataset and usecase pages/components
1 parent cb870ec commit f22d5be

File tree

8 files changed

+107
-42
lines changed

8 files changed

+107
-42
lines changed

app/[locale]/(user)/components/ListingComponent.tsx

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -529,11 +529,14 @@ const ListingComponent: React.FC<ListingProps> = ({
529529
? `${process.env.NEXT_PUBLIC_BACKEND_URL}/${item.organization.logo}`
530530
: '/org.png';
531531

532-
// Get geographies from the geographies field (new approach)
533532
const geographies = item.geographies && item.geographies.length > 0
534533
? item.geographies
535534
: null;
536535

536+
const sdgs = item.sdgs && item.sdgs.length > 0
537+
? item.sdgs
538+
: null;
539+
537540
const MetadataContent = [
538541
{
539542
icon: Icons.calendar,
@@ -554,12 +557,7 @@ const ListingComponent: React.FC<ListingProps> = ({
554557

555558
if (geographies && geographies.length > 0) {
556559
// Format geographies hierarchically for display
557-
const geoDisplay = geographies.map((geo: any) => {
558-
if (geo.parentId) {
559-
return `${geo.name} (${geo.parentId.name})`;
560-
}
561-
return geo.name;
562-
}).join(', ');
560+
const geoDisplay = geographies.join(', ');
563561

564562
MetadataContent.push({
565563
icon: Icons.globe,
@@ -569,6 +567,18 @@ const ListingComponent: React.FC<ListingProps> = ({
569567
});
570568
}
571569

570+
if (sdgs && sdgs.length > 0) {
571+
// Format SDGs for display
572+
const sdgDisplay = sdgs.map((sdg: any) => `${sdg.code} - ${sdg.name}`).join(', ');
573+
574+
MetadataContent.push({
575+
icon: Icons.target,
576+
label: 'SDG Goals',
577+
value: sdgDisplay,
578+
tooltip: sdgDisplay,
579+
});
580+
}
581+
572582
if (item.has_charts && view === 'expanded') {
573583
MetadataContent.push({
574584
icon: Icons.chart,

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ interface MetadataProps {
1313
}
1414

1515
const MetadataComponent: React.FC<MetadataProps> = ({ data, setOpen }) => {
16-
const Metadata = data.metadata.map((item: any) => ({
16+
const Metadata = (data.metadata || []).map((item: any) => ({
1717
label: item.metadataItem.label,
1818
value: item.value,
1919
type: item.metadataItem.dataType,
@@ -55,7 +55,7 @@ const MetadataComponent: React.FC<MetadataProps> = ({ data, setOpen }) => {
5555
useEffect(() => {
5656
const fetchTitle = async () => {
5757
try {
58-
const urlItem = data.metadata.find(
58+
const urlItem = (data.metadata || []).find(
5959
(item: any) => item.metadataItem?.dataType === 'URL'
6060
);
6161

@@ -186,8 +186,8 @@ const MetadataComponent: React.FC<MetadataProps> = ({ data, setOpen }) => {
186186
{data.geographies.map((geo: any, index: number) => (
187187
<Tag
188188
key={index}
189-
fillColor="var(--blue-secondary-color)"
190-
borderColor="var(--blue-secondary-text)"
189+
fillColor="var(--orange-secondary-color)"
190+
borderColor="var(--orange-secondary-text)"
191191
textColor="black"
192192
>
193193
{geo.name}

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,9 @@ const similarDatasetQuery: any = graphql(`
4949
}
5050
value
5151
}
52+
geographies {
53+
name
54+
}
5255
license
5356
resources {
5457
id
@@ -135,7 +138,7 @@ const SimilarDatasets: React.FC = () => {
135138
{
136139
icon: Icons.globe,
137140
label: 'Geography',
138-
value: 'India',
141+
value: item.geographies.join(', '),
139142
},
140143
]}
141144
tag={item.tags}

app/[locale]/(user)/usecases/components/Details.tsx

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -91,23 +91,6 @@ const PrimaryDetails = ({ data, isLoading }: { data: any; isLoading: any }) => {
9191
</div>
9292
</div>
9393
)}
94-
{data.useCase.sdgs && data.useCase.sdgs.length > 0 && (
95-
<div className="mt-6 lg:mt-10">
96-
<Text variant="headingXl">SDG Goals</Text>
97-
<div className="mt-4 flex flex-wrap gap-2">
98-
{data.useCase.sdgs.map((sdg: any, index: number) => (
99-
<Tag
100-
key={index}
101-
fillColor="var(--blue-secondary-color)"
102-
borderColor="var(--blue-secondary-text)"
103-
textColor="black"
104-
>
105-
{sdg.code} - {sdg.name}
106-
</Tag>
107-
))}
108-
</div>
109-
</div>
110-
)}
11194
<div className="mt-6 lg:mt-10">
11295
<Text variant="headingXl">Summary</Text>
11396
<div className="prose-h1:text-3xl prose-h2:text-2xl prose-h3:text-xl prose-p:leading-relaxed prose-a:text-blue-600 hover:prose-a:text-blue-700 prose-code:bg-gray-200 prose-code:rounded prose-pre:bg-gray-100 prose-pre:border prose-pre:border-gray-300 prose-blockquote:border-l-blue-500 prose-th:bg-gray-100 prose-img:rounded-lg prose prose-lg mt-4 max-w-none prose-headings:text-gray-900 prose-p:text-gray-800 prose-a:underline prose-blockquote:text-gray-700 prose-strong:text-gray-900 prose-em:text-gray-800 prose-code:px-1 prose-code:py-0.5 prose-code:text-gray-900 prose-code:before:content-none prose-code:after:content-none prose-pre:text-gray-900 prose-ol:text-gray-800 prose-ul:text-gray-800 prose-li:text-gray-800 prose-li:marker:text-gray-600 prose-table:text-gray-800 prose-thead:border-gray-300 prose-tr:border-gray-300 prose-th:border-gray-300 prose-th:text-gray-900 prose-td:border-gray-300 prose-td:text-gray-800 prose-hr:border-gray-300">

app/[locale]/dashboard/[entityType]/[entitySlug]/dataset/[id]/edit/components/EditMetadata.tsx

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -303,8 +303,8 @@ export function EditMetadata({ id }: { id: string }) {
303303
};
304304
}
305305

306-
dataset?.metadata.length > 0 &&
307-
dataset?.metadata?.map((field) => {
306+
(dataset?.metadata || []).length > 0 &&
307+
(dataset?.metadata || []).map((field) => {
308308
if (
309309
field.metadataItem.dataType === 'MULTISELECT' &&
310310
field.value !== ''
@@ -590,6 +590,7 @@ export function EditMetadata({ id }: { id: string }) {
590590
<>
591591
{!getTagsList?.isLoading &&
592592
!getSectorsList?.isLoading &&
593+
!getGeographiesList?.isLoading &&
593594
!getDatasetMetadata.isLoading ? (
594595
<Form
595596
formOptions={{

app/[locale]/dashboard/[entityType]/[entitySlug]/usecases/edit/[id]/metadata/page.tsx

Lines changed: 54 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
'use client';
22

3-
import { useEffect, useState } from 'react';
4-
import { useParams } from 'next/navigation';
53
import { graphql } from '@/gql';
64
import {
75
MetadataModels,
@@ -11,7 +9,9 @@ import {
119
UpdateUseCaseMetadataInput,
1210
} from '@/gql/generated/graphql';
1311
import { useMutation, useQuery } from '@tanstack/react-query';
12+
import { useParams } from 'next/navigation';
1413
import { Combobox, Spinner, toast } from 'opub-ui';
14+
import { useEffect, useState } from 'react';
1515

1616
import { GraphQL } from '@/lib/api';
1717
import { useEditStatus } from '../../context';
@@ -140,6 +140,16 @@ const tagsListQueryDoc: any = graphql(`
140140
}
141141
`);
142142

143+
const sdgsListQueryDoc: any = graphql(`
144+
query SDGList {
145+
sdgs {
146+
id
147+
code
148+
name
149+
}
150+
}
151+
`);
152+
143153
const Metadata = () => {
144154
const params = useParams<{
145155
entityType: string;
@@ -191,6 +201,7 @@ const Metadata = () => {
191201
sectors: [],
192202
geographies: [],
193203
tags: [],
204+
sdgs: [],
194205
};
195206
}
196207

@@ -225,6 +236,14 @@ const Metadata = () => {
225236
};
226237
}) || [];
227238

239+
defaultVal['sdgs'] =
240+
data?.sdgs?.map((sdg: any) => {
241+
return {
242+
label: `${sdg.code} - ${sdg.name}`,
243+
value: sdg.id,
244+
};
245+
}) || [];
246+
228247
defaultVal['tags'] =
229248
data?.tags?.map((tag: TypeTag) => {
230249
return {
@@ -271,6 +290,17 @@ const Metadata = () => {
271290
)
272291
);
273292

293+
const getSDGsList: { data: any; isLoading: boolean; error: any } =
294+
useQuery([`sdgs_list_query`], () =>
295+
GraphQL(
296+
sdgsListQueryDoc,
297+
{
298+
[params.entityType]: params.entitySlug,
299+
},
300+
[]
301+
)
302+
);
303+
274304
const getTagsList: {
275305
data: any;
276306
isLoading: boolean;
@@ -342,7 +372,7 @@ const Metadata = () => {
342372
...Object.keys(transformedValues)
343373
.filter(
344374
(valueItem) =>
345-
!['sectors', 'tags', 'geographies'].includes(valueItem) &&
375+
!['sectors', 'tags', 'geographies', 'sdgs'].includes(valueItem) &&
346376
transformedValues[valueItem] !== ''
347377
)
348378
.map((key) => {
@@ -354,6 +384,7 @@ const Metadata = () => {
354384
],
355385
sectors: updatedData.sectors?.map((item: any) => item.value) || [],
356386
tags: updatedData.tags?.map((item: any) => item.label) || [],
387+
sdgs: updatedData.sdgs?.map((item: any) => item.value) || [],
357388
geographies: updatedData.geographies?.map((item: any) => parseInt(item.value, 10)) || [],
358389
},
359390
});
@@ -363,6 +394,8 @@ const Metadata = () => {
363394
if (
364395
getSectorsList.isLoading ||
365396
getTagsList.isLoading ||
397+
getSDGsList.isLoading ||
398+
getGeographiesList.isLoading ||
366399
useCaseData.isLoading
367400
) {
368401
return (
@@ -422,6 +455,24 @@ const Metadata = () => {
422455
<div>
423456
<div>
424457
<div className="flex flex-wrap">
458+
<div className="w-full py-4 pr-4 sm:w-1/2 md:w-1/2 lg:w-1/2 xl:w-1/2">
459+
<Combobox
460+
displaySelected
461+
label="SDG Goals *"
462+
name="sdgs"
463+
list={
464+
getSDGsList?.data.sdgs?.map((item: any) => ({
465+
label: `${item.code} - ${item.name}`,
466+
value: item.id,
467+
})) || []
468+
}
469+
selectedValue={formData.sdgs}
470+
onChange={(value) => {
471+
handleChange('sdgs', value);
472+
handleSave({ ...formData, sdgs: value });
473+
}}
474+
/>
475+
</div>
425476
<div className="w-full py-4 pr-4 sm:w-1/2 md:w-1/2 lg:w-1/2 xl:w-1/2">
426477
<Combobox
427478
displaySelected

app/[locale]/dashboard/[entityType]/[entitySlug]/usecases/edit/[id]/publish/Details.tsx

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@ const Details = ({ data }: { data: any }) => {
4242
value: data?.useCases[0]?.completedOn,
4343
},
4444
{ label: 'Sector', value: data?.useCases[0]?.sectors[0]?.name },
45+
{ label: 'Geography', value: data?.useCases[0]?.geographies?.map((geo: any) => geo.name).join(', ') },
46+
{ label: 'SDG Goals', value: data?.useCases[0]?.sdgs?.map((sdg: any) => `${sdg.code} - ${sdg.name}`).join(', ') },
4547
{ label: 'Tags', value: data?.useCases[0]?.tags[0]?.value },
4648
...(data?.useCases[0]?.metadata?.map((meta: any) => ({
4749
label: meta.metadataItem?.label,
@@ -71,14 +73,18 @@ const Details = ({ data }: { data: any }) => {
7173
<Text variant="bodyMd">Platform URL:</Text>
7274
</div>
7375
<div>
74-
<Link
75-
className="text-primaryBlue underline"
76-
href={data.useCases[0].platformUrl}
77-
>
78-
<Text className="underline" color="highlight" variant="bodyLg">
79-
{platformTitle?.trim() ? platformTitle : 'Visit Platform'}
80-
</Text>
81-
</Link>
76+
{data.useCases[0].platformUrl ? (
77+
<Link
78+
className="text-primaryBlue underline"
79+
href={data.useCases[0].platformUrl}
80+
>
81+
<Text className="underline" color="highlight" variant="bodyLg">
82+
{platformTitle?.trim() ? platformTitle : 'Visit Platform'}
83+
</Text>
84+
</Link>
85+
) : (
86+
<Text variant="bodyMd">Not provided</Text>
87+
)}
8288
</div>
8389
</div>
8490

app/[locale]/dashboard/[entityType]/[entitySlug]/usecases/edit/[id]/publish/page.tsx

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,17 @@ const UseCaseDetails: any = graphql(`
4343
id
4444
name
4545
}
46+
geographies {
47+
id
48+
name
49+
code
50+
type
51+
}
52+
sdgs {
53+
id
54+
code
55+
name
56+
}
4657
runningStatus
4758
tags {
4859
id

0 commit comments

Comments
 (0)