diff --git a/app/api/leantime/status-labels/route.ts b/app/api/leantime/status-labels/route.ts index 3354f412..44ede180 100644 --- a/app/api/leantime/status-labels/route.ts +++ b/app/api/leantime/status-labels/route.ts @@ -107,38 +107,31 @@ export async function GET() { if (!data.result) { console.log('No result in Leantime response'); - return NextResponse.json({ statusLabels: [] }); + return NextResponse.json({ projects: [] }); } - // Create a map to store unique status labels - const uniqueLabels = new Map(); + // Transform the response into a more structured format while maintaining project grouping + const transformedProjects = Object.entries(data.result as Record>).map(([projectId, labels]) => { + // Convert the labels object to an array and sort by sortKey + const sortedLabels = Object.entries(labels).map(([id, label]) => ({ + id, + name: label.name, + statusType: label.statusType, + class: label.class, + sortKey: Number(label.sortKey) || 0, + kanbanCol: label.kanbanCol + })).sort((a, b) => a.sortKey - b.sortKey); - // Transform and deduplicate status labels - Object.entries(data.result as Record>).forEach(([projectId, labels]) => { - Object.entries(labels).forEach(([id, label]) => { - const key = label.name; - if (!uniqueLabels.has(key)) { - uniqueLabels.set(key, { - id, - name: label.name, - statusType: label.statusType, - class: label.class, - sortKey: Number(label.sortKey) || 0, // Convert to number, default to 0 if invalid - projects: [] - }); - } - uniqueLabels.get(key).projects.push({ - id: projectId, - name: projectId // You might want to fetch project names separately - }); - }); + return { + projectId, + labels: sortedLabels + }; }); - // Convert the map to an array and sort by sortKey numerically - const transformedLabels = Array.from(uniqueLabels.values()) - .sort((a, b) => a.sortKey - b.sortKey); + // Sort projects by ID for consistency + transformedProjects.sort((a, b) => a.projectId.localeCompare(b.projectId)); - return NextResponse.json({ statusLabels: transformedLabels }); + return NextResponse.json({ projects: transformedProjects }); } 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 bfc886fc..e6d504a7 100644 --- a/components/flow.tsx +++ b/components/flow.tsx @@ -7,22 +7,22 @@ import { RefreshCw } from "lucide-react"; import { useRouter } from "next/navigation"; import { useSession } from "next-auth/react"; -interface Project { - id: string; - name: string; -} - interface StatusLabel { id: string; name: string; statusType: string; class: string; - sortKey: string; - projects: Project[]; + sortKey: number; + kanbanCol: boolean; +} + +interface Project { + projectId: string; + labels: StatusLabel[]; } export function Flow() { - const [statusLabels, setStatusLabels] = useState([]); + const [projects, setProjects] = useState([]); const [loading, setLoading] = useState(true); const [error, setError] = useState(null); const [refreshing, setRefreshing] = useState(false); @@ -50,7 +50,7 @@ export function Flow() { } const data = await response.json(); - setStatusLabels(data.statusLabels); + setProjects(data.projects); setError(null); } catch (err) { console.error('Error fetching status labels:', err); @@ -110,38 +110,31 @@ export function Flow() { )} {!loading && !error && (
- {statusLabels.length === 0 ? ( + {projects.length === 0 ? (

No status labels found

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

{label.name}

- - {label.statusType} - -
- {label.projects.length > 0 && ( -
- {label.projects.map((project) => ( - - {project.name} + projects.map((project) => ( +
+

Project {project.projectId}

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

{label.name}

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