Skip to content

Commit b8bdfa4

Browse files
committed
add assigned dataset details
1 parent 32a9c8e commit b8bdfa4

File tree

1 file changed

+66
-29
lines changed
  • app/[locale]/manage/usecases/edit/[id]/publish

1 file changed

+66
-29
lines changed

app/[locale]/manage/usecases/edit/[id]/publish/page.tsx

Lines changed: 66 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import {
2020
} from 'opub-ui';
2121

2222
import { GraphQL } from '@/lib/api';
23+
import { formatDate } from '@/lib/utils';
2324
import { Icons } from '@/components/icons';
2425

2526
const UseCaseDetails: any = graphql(`
@@ -37,6 +38,10 @@ const UseCaseDetails: any = graphql(`
3738
datasets {
3839
title
3940
id
41+
categories {
42+
name
43+
}
44+
modified
4045
}
4146
contactEmail
4247
status
@@ -102,11 +107,20 @@ const Publish = () => {
102107
errorType: 'critical',
103108
},
104109

105-
// {
106-
// name: 'Assign',
107-
// data: UseCaseData.data.useCases,
108-
// error: '',
109-
// },
110+
{
111+
name: 'Assign',
112+
data: UseCaseData?.data?.useCases[0]?.datasets,
113+
error:
114+
UseCaseData.data && UseCaseData.data?.useCases[0]?.datasets.length === 0
115+
? 'No datasets assigned. Please assign to continue.'
116+
: '',
117+
},
118+
];
119+
120+
const columns = [
121+
{ accessorKey: 'title', header: 'Title' },
122+
{ accessorKey: 'category', header: 'Category' },
123+
{ accessorKey: 'modified', header: 'Last Modified' },
110124
];
111125

112126
const PrimaryDetails = [
@@ -128,6 +142,17 @@ const Publish = () => {
128142
},
129143
];
130144

145+
const generateTableData = (list: Array<any>) => {
146+
return list.map((item) => {
147+
return {
148+
title: item.title,
149+
id: item.id,
150+
category: item.categories[0]?.name,
151+
modified: formatDate(item.modified),
152+
};
153+
});
154+
};
155+
131156
return (
132157
<>
133158
<div className=" w-full py-6">
@@ -178,36 +203,48 @@ const Publish = () => {
178203
}}
179204
>
180205
<div className=" py-4">
181-
<div className="flex flex-col gap-4 px-8 py-4">
182-
{PrimaryDetails.map(
183-
(item, index) =>
184-
item.value && (
185-
<div
186-
className="flex flex-wrap gap-2"
187-
key={index}
188-
>
189-
<Text
190-
className="lg:basis-1/6"
191-
variant="bodyMd"
192-
>
193-
{item.label}:
194-
</Text>
195-
<Text
196-
variant="bodyMd"
197-
className="lg:basis-4/5"
206+
{item.name === 'Assign' ? (
207+
<Table
208+
columns={columns}
209+
rows={generateTableData(item.data)}
210+
hideFooter
211+
/>
212+
) : (
213+
<div className="flex flex-col gap-4 px-8 py-4">
214+
{PrimaryDetails.map(
215+
(item, index) =>
216+
item.value && (
217+
<div
218+
className="flex flex-wrap gap-2"
219+
key={index}
198220
>
199-
{item.value}
200-
</Text>
201-
</div>
202-
)
203-
)}
204-
</div>
221+
<Text
222+
className="lg:basis-1/6"
223+
variant="bodyMd"
224+
>
225+
{item.label}:
226+
</Text>
227+
<Text
228+
variant="bodyMd"
229+
className="lg:basis-4/5"
230+
>
231+
{item.value}
232+
</Text>
233+
</div>
234+
)
235+
)}
236+
</div>
237+
)}
205238
</div>
206239
</AccordionContent>
207240
</AccordionItem>
208241
</Accordion>
209242
))}
210-
<Button className="m-auto w-fit" onClick={() => mutate()}>
243+
<Button
244+
className="m-auto w-fit"
245+
onClick={() => mutate()}
246+
disabled={UseCaseData?.data?.useCases[0]?.datasets.length <= 0}
247+
>
211248
Publish
212249
</Button>
213250
</>

0 commit comments

Comments
 (0)