Skip to content

Commit 57b4f78

Browse files
authored
Merge pull request #268 from CivicDataLab/267-fix-bugs
267 fix bugs
2 parents 53d27e6 + 6c0998c commit 57b4f78

File tree

15 files changed

+268
-70
lines changed

15 files changed

+268
-70
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ const SimilarDatasets: React.FC<Props> = ({ showCharts }) => {
104104
) : (
105105
<>
106106
<div
107-
className={`flex flex-col gap-1 ${showCharts ? 'lg:px-10' : 'lg:px-0'}`}
107+
className={`flex flex-col gap-1 ${showCharts ? ' px-6 lg:px-10' : ' lg:px-0'}`}
108108
>
109109
<Text variant="headingXl">Similar Datasets</Text>
110110
<Text variant="bodyLg">Similar Datasets that you may like </Text>
@@ -120,7 +120,7 @@ const SimilarDatasets: React.FC<Props> = ({ showCharts }) => {
120120
<CarouselItem
121121
key={item.id}
122122
className={cn(
123-
'h-2/4 basis-full pl-4 sm:basis-1/2 lg:basis-1/3',
123+
'h-2/4 basis-full pl-4 md:basis-1/2 xl:basis-1/3',
124124
Styles.List
125125
)}
126126
>
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
import { usePathname, useRouter } from 'next/navigation';
2+
import { Button, Icon, Text } from 'opub-ui';
3+
4+
import { Icons } from '@/components/icons';
5+
6+
interface StepNavigationProps {
7+
steps: string[]; // Array of steps (e.g., ['metadata', 'details', 'publish'])
8+
}
9+
10+
const StepNavigation = ({ steps }: StepNavigationProps) => {
11+
const pathname = usePathname(); // Get the current URL path
12+
const router = useRouter();
13+
console.log(pathname);
14+
15+
// Find the current step's index based on the pathname (without query params)
16+
const currentIndex = steps.findIndex((step) =>
17+
pathname.split('?')[0].endsWith(step)
18+
);
19+
20+
if (currentIndex === -1) {
21+
return null; // In case no valid step is found
22+
}
23+
24+
const goToPrevious = () => {
25+
if (currentIndex > 0) {
26+
const newPath = pathname.replace(
27+
steps[currentIndex],
28+
steps[currentIndex - 1]
29+
);
30+
router.push(newPath); // Update the URL to the previous step
31+
}
32+
};
33+
34+
const goToNext = () => {
35+
if (currentIndex < steps.length - 1) {
36+
const newPath = pathname.replace(
37+
steps[currentIndex],
38+
steps[currentIndex + 1]
39+
);
40+
router.push(newPath); // Update the URL to the next step
41+
}
42+
};
43+
44+
return (
45+
<div className="flex items-center justify-center gap-10">
46+
<Button
47+
onClick={goToPrevious}
48+
disabled={currentIndex === 0} // Disable if at the first step
49+
kind="tertiary"
50+
>
51+
<div className="flex items-center gap-1">
52+
<Icon
53+
source={Icons.back}
54+
size={24}
55+
color={currentIndex === 0 ? 'disabled' : 'warning'}
56+
/>
57+
<Text color={currentIndex === 0 ? 'disabled' : 'medium'}>
58+
Previous
59+
</Text>
60+
</div>
61+
</Button>
62+
<Text>
63+
Step <b>{currentIndex + 1}</b> of {steps.length}
64+
</Text>
65+
<Button
66+
onClick={goToNext}
67+
disabled={currentIndex === steps.length - 1} // Disable if at the last step
68+
kind="tertiary"
69+
className="flex gap-1"
70+
>
71+
<div className="flex items-center gap-1">
72+
<Text
73+
color={currentIndex === steps.length - 1 ? 'disabled' : 'medium'}
74+
>
75+
{' '}
76+
Next
77+
</Text>
78+
<Icon
79+
source={Icons.arrowRight}
80+
size={24}
81+
color={currentIndex === steps.length - 1 ? 'disabled' : 'warning'}
82+
/>
83+
</div>
84+
</Button>
85+
</div>
86+
);
87+
};
88+
89+
export default StepNavigation;

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import { Tab, TabList, Tabs, toast } from 'opub-ui';
1010
import { GraphQL } from '@/lib/api';
1111
import TitleBar from '../../../../components/title-bar';
1212
import { useDatasetEditStatus } from '../context';
13+
import StepNavigation from '../../../../components/StepNavigation';
1314

1415
const datasetQueryDoc: any = graphql(`
1516
query datasetTitleQuery($filters: DatasetFilter) {
@@ -146,6 +147,9 @@ export function EditLayout({ children, params }: LayoutProps) {
146147
<div className="bg-surface border-l-divider rounded-tl-none my-6 flex-grow">
147148
{children}
148149
</div>
150+
<div>
151+
<StepNavigation steps={['metadata','resources','publish']}/>
152+
</div>
149153
</div>
150154
</div>
151155
);

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

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -215,9 +215,7 @@ export function EditMetadata({ id }: { id: string }) {
215215
`metadata_fields_list_${id}`,
216216
],
217217
});
218-
const updatedData = defaultValuesPrepFn(
219-
res.addUpdateDatasetMetadata
220-
);
218+
const updatedData = defaultValuesPrepFn(res.addUpdateDatasetMetadata);
221219
setFormData(updatedData);
222220
setPreviousFormData(updatedData);
223221
// getDatasetMetadata.refetch();
@@ -235,13 +233,18 @@ export function EditMetadata({ id }: { id: string }) {
235233

236234
dataset?.metadata.length > 0 &&
237235
dataset?.metadata?.map((field) => {
238-
if (field.metadataItem.dataType === 'MULTISELECT') {
236+
if (
237+
field.metadataItem.dataType === 'MULTISELECT' &&
238+
field.value !== ''
239+
) {
239240
defaultVal[field.metadataItem.id] = field.value
240241
.split(', ')
241242
.map((value: string) => ({
242243
label: value,
243244
value: value,
244245
}));
246+
} else if (!field.value) {
247+
defaultVal[field.metadataItem.id] = null;
245248
} else {
246249
defaultVal[field.metadataItem.id] = field.value;
247250
}

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

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

3-
import { useEffect } from 'react';
3+
import { useEffect, useState } from 'react';
4+
import Link from 'next/link';
45
import { useParams, useRouter } from 'next/navigation';
56
import { graphql } from '@/gql';
67
import { useMutation, useQuery } from '@tanstack/react-query';
@@ -20,7 +21,7 @@ import {
2021
} from 'opub-ui';
2122

2223
import { GraphQL } from '@/lib/api';
23-
import { formatDate, toTitleCase } from '@/lib/utils';
24+
import { formatDate, getWebsiteTitle, toTitleCase } from '@/lib/utils';
2425
import { Icons } from '@/components/icons';
2526

2627
const datasetSummaryQuery: any = graphql(`
@@ -30,6 +31,7 @@ const datasetSummaryQuery: any = graphql(`
3031
metadataItem {
3132
id
3233
label
34+
dataType
3335
}
3436
id
3537
value
@@ -279,11 +281,35 @@ const Page = () => {
279281

280282
// Access model check if enabled
281283
if (isAccessModelEnabled && !hasAccessModels) return true;
282-
console.log(hasRequiredMetadata);
283284

284285
// Required metadata check
285286
return !hasRequiredMetadata;
286287
};
288+
289+
const [sourceTitle, setSourceTitle] = useState<string | null>(null);
290+
291+
useEffect(() => {
292+
const fetchTitle = async () => {
293+
try {
294+
const urlItem = getDatasetsSummary.data?.datasets[0]?.metadata.find(
295+
(item: any) => item.metadataItem?.dataType === 'URL'
296+
);
297+
298+
if (urlItem && urlItem.value) {
299+
const title = await getWebsiteTitle(urlItem.value);
300+
setSourceTitle(title);
301+
}
302+
} catch (error) {
303+
console.error('Error fetching website title:', error);
304+
}
305+
};
306+
307+
fetchTitle();
308+
}, [
309+
getDatasetsSummary.data?.datasets[0]?.metadata,
310+
getDatasetsSummary.isLoading,
311+
]);
312+
287313
return (
288314
<>
289315
<div className=" w-full py-6">
@@ -373,10 +399,27 @@ const Page = () => {
373399
<Text className="lg:basis-1/6" variant="bodyMd">
374400
{toTitleCase(item.metadataItem.label)}:
375401
</Text>
376-
<Text variant="bodyMd" className="lg:basis-4/5">
377-
{' '}
378-
{item.value === '' ? 'NA' : item.value}
379-
</Text>
402+
403+
{item.metadataItem.dataType !== 'URL' ? (
404+
<Text
405+
variant="bodyMd"
406+
className="lg:basis-4/5"
407+
>
408+
{' '}
409+
{item.value === '' ? 'NA' : item.value}
410+
</Text>
411+
) : (
412+
<Link href={item.value} target="_blank">
413+
<Text
414+
className="underline"
415+
color="highlight"
416+
>
417+
{sourceTitle?.trim()
418+
? sourceTitle
419+
: 'Source'}
420+
</Text>
421+
</Link>
422+
)}
380423
</div>
381424
))}
382425
<div className="flex flex-wrap gap-2">

app/[locale]/dashboard/[entityType]/[entitySlug]/dataset/page.tsx

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,6 @@ export default function DatasetPage({
8585
},
8686
];
8787

88-
8988
const AllDatasetsQuery: { data: any; isLoading: boolean; refetch: any } =
9089
useQuery(
9190
[`fetch_datasets_org_dashboard`],
@@ -155,7 +154,7 @@ export default function DatasetPage({
155154
);
156155
},
157156
onError: (err: any) => {
158-
console.log('Error ::: ', err);
157+
toast('Error: ' + err.message.split(':')[0]);
159158
},
160159
}
161160
);
@@ -207,7 +206,7 @@ export default function DatasetPage({
207206
navigationTab === 'published' ? (
208207
<Button
209208
size="medium"
210-
kind='tertiary'
209+
kind="tertiary"
211210
onClick={() => {
212211
UnpublishDatasetMutation.mutate({
213212
datasetId: row.original?.id,

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ const Assign = () => {
123123
onSuccess: (data: any) => {
124124
toast('Dataset Assigned Successfully');
125125
UseCaseDetails.refetch();
126-
router.push(`/dashboard/${params.entityType}/${params.entitySlug}/usecases/edit/${params.id}/publish`);
126+
router.push(`/dashboard/${params.entityType}/${params.entitySlug}/usecases/edit/${params.id}/contributors`);
127127
},
128128
onError: (err: any) => {
129129
toast(`Received ${err} on dataset publish `);

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ const Details = () => {
102102
{
103103
onSuccess: (res: any) => {
104104
toast('Contributor added successfully');
105+
UseCaseData.refetch();
105106
},
106107
onError: (error: any) => {
107108
toast(`Error: ${error.message}`);
@@ -129,6 +130,7 @@ const Details = () => {
129130
{
130131
onSuccess: (res: any) => {
131132
toast('Supporter added successfully');
133+
UseCaseData.refetch();
132134
},
133135
onError: (error: any) => {
134136
toast(`Error: ${error.message}`);
@@ -156,6 +158,7 @@ const Details = () => {
156158
{
157159
onSuccess: (res: any) => {
158160
toast('Partner added successfully');
161+
UseCaseData.refetch();
159162
},
160163
onError: (error: any) => {
161164
toast(`Error: ${error.message}`);

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

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,6 @@ const Details = () => {
210210
}, [editMutationLoading]);
211211

212212
return (
213-
<div>
214213
<div className=" flex flex-col gap-6">
215214
<div>
216215
<TextField
@@ -308,7 +307,6 @@ const Details = () => {
308307
/>
309308
</div> */}
310309
</div>
311-
</div>
312310
);
313311
};
314312

0 commit comments

Comments
 (0)