Skip to content

Commit e0f5b57

Browse files
committed
add conditions to publish dataset
1 parent 8b74120 commit e0f5b57

File tree

1 file changed

+67
-20
lines changed
  • app/[locale]/dashboard/[entityType]/[entitySlug]/dataset/[id]/edit/publish

1 file changed

+67
-20
lines changed

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

Lines changed: 67 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ import { GraphQL } from '@/lib/api';
2323
import { formatDate, toTitleCase } from '@/lib/utils';
2424
import { Icons } from '@/components/icons';
2525

26-
const datasetSummaryQuery:any = graphql(`
26+
const datasetSummaryQuery: any = graphql(`
2727
query datasetsSummary($filters: DatasetFilter) {
2828
datasets(filters: $filters) {
2929
metadata {
@@ -50,6 +50,10 @@ const datasetSummaryQuery:any = graphql(`
5050
id
5151
value
5252
}
53+
sectors {
54+
id
55+
name
56+
}
5357
id
5458
title
5559
description
@@ -163,15 +167,16 @@ const Page = () => {
163167
id: string;
164168
}>();
165169

166-
const getDatasetsSummary:{ data:any, isLoading:any, refetch:any } = useQuery([`summary_${params.id}`], () =>
167-
GraphQL(
168-
datasetSummaryQuery,
169-
{
170-
[params.entityType]: params.entitySlug,
171-
},
172-
{ filters: { id: params.id } }
173-
)
174-
);
170+
const getDatasetsSummary: { data: any; isLoading: any; refetch: any } =
171+
useQuery([`summary_${params.id}`], () =>
172+
GraphQL(
173+
datasetSummaryQuery,
174+
{
175+
[params.entityType]: params.entitySlug,
176+
},
177+
{ filters: { id: params.id } }
178+
)
179+
);
175180

176181
useEffect(() => {
177182
getDatasetsSummary.refetch();
@@ -182,7 +187,8 @@ const Page = () => {
182187
name: 'Resource',
183188
data: getDatasetsSummary.data?.datasets[0]?.resources,
184189
error:
185-
getDatasetsSummary.data && getDatasetsSummary.data?.datasets[0]?.resources.length === 0
190+
getDatasetsSummary.data &&
191+
getDatasetsSummary.data?.datasets[0]?.resources.length === 0
186192
? 'No Resources found. Please add to continue.'
187193
: '',
188194
errorType: 'critical',
@@ -193,7 +199,8 @@ const Page = () => {
193199
name: 'Access Type',
194200
data: getDatasetsSummary.data?.datasets[0]?.accessModels,
195201
error:
196-
getDatasetsSummary.data && getDatasetsSummary.data?.datasets[0]?.accessModels.length === 0
202+
getDatasetsSummary.data &&
203+
getDatasetsSummary.data?.datasets[0]?.accessModels.length === 0
197204
? 'No Access Type found. Please add to continue.'
198205
: '',
199206
errorType: 'critical',
@@ -208,9 +215,18 @@ const Page = () => {
208215
];
209216

210217
const PrimaryMetadata = [
211-
{ label: 'Dataset Name', value: getDatasetsSummary.data?.datasets[0].title },
212-
{ label: 'Description', value: getDatasetsSummary.data?.datasets[0].description },
213-
{ label: 'Date of Creation', value: formatDate(getDatasetsSummary.data?.datasets[0].created) },
218+
{
219+
label: 'Dataset Name',
220+
value: getDatasetsSummary.data?.datasets[0].title,
221+
},
222+
{
223+
label: 'Description',
224+
value: getDatasetsSummary.data?.datasets[0].description,
225+
},
226+
{
227+
label: 'Date of Creation',
228+
value: formatDate(getDatasetsSummary.data?.datasets[0].created),
229+
},
214230
{
215231
label: 'Date of Last Update',
216232
value: formatDate(getDatasetsSummary.data?.datasets[0].modified),
@@ -240,6 +256,27 @@ const Page = () => {
240256
}
241257
);
242258

259+
const isPublishDisabled = (dataset: any) => {
260+
if (!dataset) return true;
261+
262+
const hasResources = dataset.resources.length > 0;
263+
const hasAccessModels = dataset.accessModels?.length > 0;
264+
const isAccessModelEnabled =
265+
process.env.NEXT_PUBLIC_ENABLE_ACCESSMODEL === 'true';
266+
const hasRequiredMetadata =
267+
dataset.sectors.length > 0 &&
268+
dataset.description.length > 10 &&
269+
dataset.tags.length > 0;
270+
271+
// No resources
272+
if (!hasResources) return true;
273+
274+
// Access model check if enabled
275+
if (isAccessModelEnabled && !hasAccessModels) return true;
276+
277+
// Required metadata check
278+
return !hasRequiredMetadata;
279+
};
243280
return (
244281
<>
245282
<div className=" w-full py-6">
@@ -335,6 +372,18 @@ const Page = () => {
335372
</Text>
336373
</div>
337374
))}
375+
<div className="flex flex-wrap gap-2">
376+
<Text className="lg:basis-1/6" variant="bodyMd">
377+
Sectors:
378+
</Text>
379+
<div className="flex gap-2 lg:basis-4/5">
380+
{getDatasetsSummary.data?.datasets[0]?.sectors?.map(
381+
(item: any, index: any) => (
382+
<Tag key={index}>{item.name}</Tag>
383+
)
384+
)}
385+
</div>
386+
</div>
338387
<div className="flex flex-wrap gap-2">
339388
<Text className="lg:basis-1/6" variant="bodyMd">
340389
Tags:
@@ -356,11 +405,9 @@ const Page = () => {
356405
))}
357406
<Button
358407
className="m-auto w-fit"
359-
disabled={
360-
!getDatasetsSummary.data?.datasets[0]?.resources.length ||
361-
(process.env.NEXT_PUBLIC_ENABLE_ACCESSMODEL === 'true' &&
362-
!getDatasetsSummary.data?.datasets[0]?.accessModels.length)
363-
}
408+
disabled={isPublishDisabled(
409+
getDatasetsSummary.data?.datasets[0]
410+
)}
364411
onClick={() => mutate()}
365412
>
366413
Publish

0 commit comments

Comments
 (0)