Skip to content

Commit e17ea22

Browse files
feat(builder): Aligning error and loading for NextJS best practices (#7894)
* feat(builder): Add skeleton loading components for Monitor views Introduce skeleton components for Agents, Flow Runs List, and Flow Runs Status sections to enhance loading state indication. These components help improve user experience by visually outlining content placeholders while data is being fetched. * feat(builder): Leveraging NextJS's error boundary with error.tsx Replace the basic error page with a more detailed and interactive error component. The new component includes a retry option, a link to the homepage, and logs the error details to the console. It also aligns with NextJS standards ---------
1 parent 6066990 commit e17ea22

File tree

6 files changed

+139
-3
lines changed

6 files changed

+139
-3
lines changed

rnd/autogpt_builder/src/app/error.tsx

+43
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
"use client";
2+
3+
import { useEffect } from "react";
4+
import { IconCircleAlert } from "@/components/ui/icons";
5+
import { Button } from "@/components/ui/button";
6+
import Link from "next/link";
7+
8+
export default function Error({
9+
error,
10+
reset,
11+
}: {
12+
error: Error & { digest?: string };
13+
reset: () => void;
14+
}) {
15+
useEffect(() => {
16+
console.error(error);
17+
}, [error]);
18+
19+
return (
20+
<div className="fixed inset-0 flex items-center justify-center bg-background">
21+
<div className="w-full max-w-md px-4 text-center sm:px-6">
22+
<div className="mx-auto flex size-12 items-center justify-center rounded-full bg-muted">
23+
<IconCircleAlert className="size-10" />
24+
</div>
25+
<h1 className="mt-8 text-2xl font-bold tracking-tight text-foreground">
26+
Oops, something went wrong!
27+
</h1>
28+
<p className="mt-4 text-muted-foreground">
29+
We're sorry, but an unexpected error has occurred. Please try again
30+
later or contact support if the issue persists.
31+
</p>
32+
<div className="mt-6 flex flex-row justify-center gap-4">
33+
<Button onClick={reset} variant="outline">
34+
Retry
35+
</Button>
36+
<Button>
37+
<Link href="/">Go to Homepage</Link>
38+
</Button>
39+
</div>
40+
</div>
41+
</div>
42+
);
43+
}

rnd/autogpt_builder/src/app/error/page.tsx

-3
This file was deleted.
+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import AgentFlowListSkeleton from "@/components/monitor/skeletons/AgentFlowListSkeleton";
2+
import React from "react";
3+
import FlowRunsListSkeleton from "@/components/monitor/skeletons/FlowRunsListSkeleton";
4+
import FlowRunsStatusSkeleton from "@/components/monitor/skeletons/FlowRunsStatusSkeleton";
5+
6+
export default function MonitorLoadingSkeleton() {
7+
return (
8+
<div className="space-y-4 p-4">
9+
<div className="grid grid-cols-1 gap-4 md:grid-cols-3">
10+
{/* Agents Section */}
11+
<AgentFlowListSkeleton />
12+
13+
{/* Runs Section */}
14+
<FlowRunsListSkeleton />
15+
16+
{/* Stats Section */}
17+
<FlowRunsStatusSkeleton />
18+
</div>
19+
</div>
20+
);
21+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
export default function AgentsFlowListSkeleton() {
2+
return (
3+
<div className="mx-auto max-w-4xl p-4">
4+
<div className="mb-4 flex items-center justify-between">
5+
<h1 className="text-2xl font-bold">Agents</h1>
6+
<div className="h-10 w-24 animate-pulse rounded bg-gray-200"></div>
7+
</div>
8+
<div className="rounded-lg bg-white p-4 shadow">
9+
<div className="mb-4 grid grid-cols-3 gap-4 font-medium text-gray-500">
10+
<div>Name</div>
11+
<div># of runs</div>
12+
<div>Last run</div>
13+
</div>
14+
{[...Array(3)].map((_, index) => (
15+
<div key={index} className="mb-4 grid grid-cols-3 gap-4">
16+
<div className="h-6 animate-pulse rounded bg-gray-200"></div>
17+
<div className="h-6 animate-pulse rounded bg-gray-200"></div>
18+
<div className="h-6 animate-pulse rounded bg-gray-200"></div>
19+
</div>
20+
))}
21+
</div>
22+
</div>
23+
);
24+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
export default function FlowRunsListSkeleton() {
2+
return (
3+
<div className="mx-auto max-w-4xl p-4">
4+
<div className="rounded-lg bg-white p-4 shadow">
5+
<h2 className="mb-4 text-xl font-semibold">Runs</h2>
6+
<div className="mb-4 grid grid-cols-4 gap-4 text-sm font-medium text-gray-500">
7+
<div>Agent</div>
8+
<div>Started</div>
9+
<div>Status</div>
10+
<div>Duration</div>
11+
</div>
12+
{[...Array(4)].map((_, index) => (
13+
<div key={index} className="mb-4 grid grid-cols-4 gap-4">
14+
<div className="h-5 animate-pulse rounded bg-gray-200"></div>
15+
<div className="h-5 animate-pulse rounded bg-gray-200"></div>
16+
<div className="h-5 animate-pulse rounded bg-gray-200"></div>
17+
<div className="h-5 animate-pulse rounded bg-gray-200"></div>
18+
</div>
19+
))}
20+
</div>
21+
</div>
22+
);
23+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
export default function FlowRunsStatusSkeleton() {
2+
return (
3+
<div className="mx-auto max-w-4xl p-4">
4+
<div className="rounded-lg bg-white p-4 shadow">
5+
<div className="mb-6 flex items-center justify-between">
6+
<h2 className="text-xl font-semibold">Stats</h2>
7+
<div className="flex space-x-2">
8+
{["2h", "8h", "24h", "7d", "Custom", "All"].map((btn) => (
9+
<div
10+
key={btn}
11+
className="h-8 w-16 animate-pulse rounded bg-gray-200"
12+
></div>
13+
))}
14+
</div>
15+
</div>
16+
17+
{/* Placeholder for the line chart */}
18+
<div className="mb-6 h-64 w-full animate-pulse rounded bg-gray-200"></div>
19+
20+
{/* Placeholders for total runs and total run time */}
21+
<div className="space-y-2">
22+
<div className="h-6 w-1/3 animate-pulse rounded bg-gray-200"></div>
23+
<div className="h-6 w-1/2 animate-pulse rounded bg-gray-200"></div>
24+
</div>
25+
</div>
26+
</div>
27+
);
28+
}

0 commit comments

Comments
 (0)