Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: suspend load header components #256

Merged
merged 3 commits into from
May 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 3 additions & 5 deletions components/clickhouse-host.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -54,16 +54,14 @@ export async function ClickHouseHost() {

if (hosts.length === 1) {
return (
<div className="mt-2">
<div className="flex flex-row items-center gap-2">
<HostStatus host={hosts[0]} />
</div>
<div className="flex flex-row items-center gap-2">
<HostStatus host={hosts[0]} />
</div>
)
}

return (
<div className="mt-2">
<div>
<Select>
<SelectTrigger>
<SelectValue placeholder={hosts[0]} />
Expand Down
14 changes: 11 additions & 3 deletions components/header.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import Image from 'next/image'
import { ClickHouseHost } from '@/components/clickhouse-host'
import { Menu } from '@/components/menu/menu'
import { ReloadButton } from '@/components/reload-button'
import { Suspense } from 'react'
import { SingleLineSkeleton } from './skeleton'

const TITLE = process.env.NEXT_PUBLIC_TITLE || 'ClickHouse Monitoring'
const TITLE_SHORT = process.env.NEXT_PUBLIC_TITLE_SHORT || 'Monitoring'
Expand All @@ -24,13 +26,19 @@ export function Header() {
<span className="flex sm:hidden">{TITLE_SHORT}</span>
</h2>
<div className="text-muted-foreground">
<ClickHouseHost />
<Suspense>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

issue (bug_risk): Suspense component missing fallback prop

The Suspense component should include a fallback prop to handle the loading state. This ensures that users have a visual indication that content is being loaded.

<ClickHouseHost />
</Suspense>
</div>
</div>
</div>
<div className="flex items-center space-x-2">
<Menu />
<ReloadButton />
<Suspense
fallback={<SingleLineSkeleton className="w-[200px] space-x-0 pt-0" />}
>
<Menu />
<ReloadButton />
</Suspense>
</div>
</div>
)
Expand Down
18 changes: 14 additions & 4 deletions components/skeleton.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Skeleton } from '@/components/ui/skeleton'
import { cn } from '@/lib/utils'

export function ChartSkeleton() {
return (
Expand Down Expand Up @@ -35,11 +36,20 @@ export function TableSkeleton({
)
}

export function SingleLineSkeleton() {
export function SingleLineSkeleton({
className = 'w-[500px]',
}: {
className?: string
}) {
return (
<div className="flex flex-row items-center space-x-4 pt-5">
<Skeleton className="h-6 w-[300px] bg-slate-200" />
<Skeleton className="h-6 w-[200px] bg-slate-200" />
<div
className={cn(
'flex flex-row items-center gap-2 space-x-4 pt-5',
className
)}
>
<Skeleton className="h-6 w-3/5 bg-slate-200" />
<Skeleton className="h-6 w-2/5 bg-slate-200" />
</div>
)
}