From 7a66d356aa49acde7292425018a6426a0c952740 Mon Sep 17 00:00:00 2001 From: Alma Date: Sat, 12 Apr 2025 12:37:19 +0200 Subject: [PATCH] working leantime widget 5 --- app/api/leantime/status-labels/route.ts | 15 +++++++- components/flow.tsx | 47 +++++++++++++++++-------- 2 files changed, 47 insertions(+), 15 deletions(-) diff --git a/app/api/leantime/status-labels/route.ts b/app/api/leantime/status-labels/route.ts index e715ceb9..e41117bc 100644 --- a/app/api/leantime/status-labels/route.ts +++ b/app/api/leantime/status-labels/route.ts @@ -84,7 +84,20 @@ export async function GET() { return NextResponse.json({ statusLabels: [] }); } - return NextResponse.json({ statusLabels: data.result }); + // Transform the nested status labels into a flat array + const transformedLabels = Object.entries(data.result).flatMap(([projectId, labels]) => { + return Object.entries(labels).map(([id, label]: [string, any]) => ({ + id, + name: label.name, + projectId, + projectName: projectId, // You might want to fetch project names separately + statusType: label.statusType, + class: label.class, + sortKey: label.sortKey + })); + }); + + return NextResponse.json({ statusLabels: transformedLabels }); } catch (error) { console.error('Detailed error in status labels fetch:', error); return NextResponse.json( diff --git a/components/flow.tsx b/components/flow.tsx index 3abb8184..a25a7936 100644 --- a/components/flow.tsx +++ b/components/flow.tsx @@ -12,6 +12,9 @@ interface StatusLabel { name: string; projectId: string; projectName: string; + statusType: string; + class: string; + sortKey: string; } export function Flow() { @@ -64,6 +67,15 @@ export function Flow() { } }, [session]); + // Group status labels by project + const groupedLabels = statusLabels.reduce((acc, label) => { + if (!acc[label.projectId]) { + acc[label.projectId] = []; + } + acc[label.projectId].push(label); + return acc; + }, {} as Record); + return ( )} {!loading && !error && ( -
- {statusLabels.length === 0 ? ( +
+ {Object.entries(groupedLabels).length === 0 ? (

No status labels found

) : ( - statusLabels.map((label) => ( -
-
-
-

{label.name}

- - {label.projectName} - -
+ Object.entries(groupedLabels).map(([projectId, labels]) => ( +
+

{projectId}

+
+ {labels.map((label) => ( +
+
+
+

{label.name}

+ + {label.statusType} + +
+
+
+ ))}
))