Skip to content

Commit fe67582

Browse files
committed
Refactor Datasets component to support conditional rendering based on type prop for organization and publisher datasets
1 parent 96f5d95 commit fe67582

File tree

1 file changed

+123
-64
lines changed

1 file changed

+123
-64
lines changed

app/[locale]/(user)/publishers/components/Datasets.tsx

Lines changed: 123 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -54,20 +54,81 @@ const userPublishedDatasetsDoc: any = graphql(`
5454
}
5555
`);
5656

57-
const Datasets = () => {
57+
const organizationPublishedDatasetsDoc: any = graphql(`
58+
query organizationPublishedDatasetsList($organizationId: ID!) {
59+
organizationPublishedDatasets(organizationId: $organizationId) {
60+
id
61+
title
62+
downloadCount
63+
id
64+
title
65+
tags {
66+
id
67+
value
68+
}
69+
description
70+
created
71+
modified
72+
isIndividualDataset
73+
user {
74+
fullName
75+
id
76+
profilePicture {
77+
url
78+
}
79+
}
80+
metadata {
81+
metadataItem {
82+
id
83+
label
84+
dataType
85+
}
86+
value
87+
}
88+
organization {
89+
name
90+
logo {
91+
url
92+
}
93+
slug
94+
id
95+
}
96+
sectors {
97+
name
98+
}
99+
formats
100+
}
101+
}
102+
`);
103+
104+
const Datasets = ({ type }: { type: 'organization' | 'Publisher' }) => {
58105
const params = useParams();
106+
59107
const PublishedDatasetsList: any = useQuery(
60-
[`userPublishedDataset_${params.publisherSlug}`],
108+
[`userDataset_${params.publisherSlug}`],
61109
() =>
62-
GraphQL(
63-
userPublishedDatasetsDoc,
64-
{
65-
// Entity Headers if present
66-
},
67-
{ userId: params.publisherSlug }
68-
)
110+
type === 'organization'
111+
? GraphQL(
112+
organizationPublishedDatasetsDoc,
113+
{
114+
// Entity Headers
115+
},
116+
{ organizationId: params.organizationSlug } // ✅ exact match for expected shape
117+
)
118+
: GraphQL(
119+
userPublishedDatasetsDoc,
120+
{
121+
// Entity Headers
122+
},
123+
{ userId: params.publisherSlug } // ✅ exact match for expected shape
124+
)
69125
);
70126

127+
const DatasetData =
128+
type === 'organization'
129+
? PublishedDatasetsList.data?.organizationPublishedDatasets
130+
: PublishedDatasetsList.data?.userPublishedDatasets;
131+
71132
return (
72133
<div>
73134
<div
@@ -80,61 +141,59 @@ const Datasets = () => {
80141
<Spinner />
81142
</div>
82143
) : (
83-
PublishedDatasetsList?.data?.userPublishedDatasets.length > 0 &&
84-
PublishedDatasetsList?.data?.userPublishedDatasets.map(
85-
(item: any, index: any) => (
86-
<Card
87-
type={[
88-
{
89-
label: 'Dataset',
90-
fillColor: '#E9EFF4',
91-
borderColor: '#F9C74F',
92-
},
93-
]}
94-
key={index}
95-
title={item.title}
96-
description={item.description}
97-
metadataContent={[
98-
{
99-
icon: Icons.calendar,
100-
label: 'Date',
101-
value: '19 July 2024',
102-
},
103-
{
104-
icon: Icons.download,
105-
label: 'Download',
106-
value: item.downloadCount.toString(),
107-
},
108-
{
109-
icon: Icons.globe,
110-
label: 'Geography',
111-
value: 'India',
112-
},
113-
]}
114-
tag={item.tags}
115-
formats={item.formats}
116-
footerContent={[
117-
{
118-
icon: `/Sectors/${item.sectors[0].name}.svg`,
119-
label: 'Sectors',
120-
},
121-
{
122-
icon: item.isIndividualDataset
123-
? item?.user?.profilePicture
124-
? `${process.env.NEXT_PUBLIC_BACKEND_URL}/${item.user.profilePicture.url}`
125-
: '/profile.png'
126-
: item?.organization?.logo
127-
? `${process.env.NEXT_PUBLIC_BACKEND_URL}/${item.organization.logo.url}`
128-
: '/org.png',
129-
label: 'Published by',
130-
},
131-
]}
132-
variation={'collapsed'}
133-
iconColor="warning"
134-
href={`/datasets/${item.id}`}
135-
/>
136-
)
137-
)
144+
DatasetData?.length > 0 &&
145+
DatasetData?.map((item: any, index: any) => (
146+
<Card
147+
type={[
148+
{
149+
label: 'Dataset',
150+
fillColor: '#E9EFF4',
151+
borderColor: '#F9C74F',
152+
},
153+
]}
154+
key={index}
155+
title={item.title}
156+
description={item.description}
157+
metadataContent={[
158+
{
159+
icon: Icons.calendar,
160+
label: 'Date',
161+
value: '19 July 2024',
162+
},
163+
{
164+
icon: Icons.download,
165+
label: 'Download',
166+
value: item.downloadCount.toString(),
167+
},
168+
{
169+
icon: Icons.globe,
170+
label: 'Geography',
171+
value: 'India',
172+
},
173+
]}
174+
tag={item.tags}
175+
formats={item.formats}
176+
footerContent={[
177+
{
178+
icon: `/Sectors/${item.sectors[0].name}.svg`,
179+
label: 'Sectors',
180+
},
181+
{
182+
icon: item.isIndividualDataset
183+
? item?.user?.profilePicture
184+
? `${process.env.NEXT_PUBLIC_BACKEND_URL}/${item.user.profilePicture.url}`
185+
: '/profile.png'
186+
: item?.organization?.logo
187+
? `${process.env.NEXT_PUBLIC_BACKEND_URL}/${item.organization.logo.url}`
188+
: '/org.png',
189+
label: 'Published by',
190+
},
191+
]}
192+
variation={'collapsed'}
193+
iconColor="warning"
194+
href={`/datasets/${item.id}`}
195+
/>
196+
))
138197
)}
139198
</div>
140199
</div>

0 commit comments

Comments
 (0)