working leantime widget 5
This commit is contained in:
parent
8217d7176a
commit
7a66d356aa
@ -84,7 +84,20 @@ export async function GET() {
|
|||||||
return NextResponse.json({ statusLabels: [] });
|
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) {
|
} catch (error) {
|
||||||
console.error('Detailed error in status labels fetch:', error);
|
console.error('Detailed error in status labels fetch:', error);
|
||||||
return NextResponse.json(
|
return NextResponse.json(
|
||||||
|
|||||||
@ -12,6 +12,9 @@ interface StatusLabel {
|
|||||||
name: string;
|
name: string;
|
||||||
projectId: string;
|
projectId: string;
|
||||||
projectName: string;
|
projectName: string;
|
||||||
|
statusType: string;
|
||||||
|
class: string;
|
||||||
|
sortKey: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function Flow() {
|
export function Flow() {
|
||||||
@ -64,6 +67,15 @@ export function Flow() {
|
|||||||
}
|
}
|
||||||
}, [session]);
|
}, [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<string, StatusLabel[]>);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Card
|
<Card
|
||||||
className="transition-transform duration-500 ease-in-out transform hover:scale-105 cursor-pointer bg-white/50 backdrop-blur-sm h-full"
|
className="transition-transform duration-500 ease-in-out transform hover:scale-105 cursor-pointer bg-white/50 backdrop-blur-sm h-full"
|
||||||
@ -102,22 +114,29 @@ export function Flow() {
|
|||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
{!loading && !error && (
|
{!loading && !error && (
|
||||||
<div className="space-y-2 max-h-[300px] overflow-y-auto">
|
<div className="space-y-4 max-h-[300px] overflow-y-auto">
|
||||||
{statusLabels.length === 0 ? (
|
{Object.entries(groupedLabels).length === 0 ? (
|
||||||
<p className="text-center text-muted-foreground">No status labels found</p>
|
<p className="text-center text-muted-foreground">No status labels found</p>
|
||||||
) : (
|
) : (
|
||||||
statusLabels.map((label) => (
|
Object.entries(groupedLabels).map(([projectId, labels]) => (
|
||||||
<div
|
<div key={projectId} className="space-y-2">
|
||||||
key={`${label.projectId}-${label.id}`}
|
<h3 className="text-sm font-medium text-gray-500">{projectId}</h3>
|
||||||
className="flex items-start space-x-2 hover:bg-gray-50 p-2 rounded-lg transition-colors"
|
<div className="space-y-1">
|
||||||
>
|
{labels.map((label) => (
|
||||||
<div className="flex-1 min-w-0">
|
<div
|
||||||
<div className="flex items-baseline justify-between">
|
key={`${label.projectId}-${label.id}`}
|
||||||
<p className="text-sm font-medium truncate">{label.name}</p>
|
className="flex items-start space-x-2 hover:bg-gray-50 p-2 rounded-lg transition-colors"
|
||||||
<span className="text-xs text-gray-500">
|
>
|
||||||
{label.projectName}
|
<div className="flex-1 min-w-0">
|
||||||
</span>
|
<div className="flex items-baseline justify-between">
|
||||||
</div>
|
<p className="text-sm font-medium truncate">{label.name}</p>
|
||||||
|
<span className={`text-xs px-2 py-1 rounded ${label.class}`}>
|
||||||
|
{label.statusType}
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
))}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
))
|
))
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user