Files
supabase/apps/studio/components/interfaces/Settings/Logs/ErrorCodeDialog.tsx
Joshen Lim 7f5865872a Enforce noUnusedLocals and noUnusedParameters in tsconfig.json + fix all related issues (#45264)
## Context

Enforce `noUnusedLocals` and `noUnusedParameters` in tsconfig.json + fix
all related issues
2026-04-27 17:42:34 +08:00

114 lines
2.8 KiB
TypeScript

import { AlertTriangle } from 'lucide-react'
import {
Alert_Shadcn_,
AlertDescription_Shadcn_,
AlertTitle_Shadcn_,
Badge,
Button_Shadcn_,
Dialog,
DialogContent,
DialogDescription,
DialogHeader,
DialogTitle,
} from 'ui'
import { ShimmeringLoader } from 'ui-patterns/ShimmeringLoader'
import { useErrorCodesQuery } from '@/data/content-api/docs-error-codes-query'
import { Service, type ErrorCodeQueryQuery } from '@/data/graphql/graphql'
interface ErrorCodeDialogProps {
open: boolean
onOpenChange: (open: boolean) => void
errorCode: string
service?: Service
}
export const ErrorCodeDialog = ({
open,
onOpenChange,
errorCode,
service,
}: ErrorCodeDialogProps) => {
const {
data,
isPending: isLoading,
isSuccess,
refetch,
} = useErrorCodesQuery({ code: errorCode, service }, { enabled: open })
return (
<Dialog open={open} onOpenChange={onOpenChange}>
<DialogContent>
<DialogHeader>
<DialogTitle className="mb-4">
Help for error code <code>{errorCode}</code>
</DialogTitle>
<DialogDescription>
{isLoading && <LoadingState />}
{isSuccess && <SuccessState data={data} />}
{!isLoading && !isSuccess && <ErrorState refetch={refetch} />}
</DialogDescription>
</DialogHeader>
</DialogContent>
</Dialog>
)
}
const LoadingState = () => (
<>
<ShimmeringLoader className="w-3/4 mb-2" />
<ShimmeringLoader className="w-1/2" />
</>
)
const SuccessState = ({ data }: { data: ErrorCodeQueryQuery | undefined }) => {
const errors = data?.errors?.nodes?.filter((error) => !!error.message)
if (!errors || errors.length === 0) {
return <>No information found for this error code.</>
}
return (
<>
<p className="mb-4">Possible explanations for this error:</p>
<div className="grid gap-2 grid-cols-[max-content_1fr]">
{errors.map((error) => (
<ErrorExplanation key={`${error.service}-${error.code}`} {...error} />
))}
</div>
</>
)
}
const ErrorExplanation = ({
service,
message,
}: {
code: string
service: Service
message?: string | null
}) => {
if (!message) return null
return (
<>
<Badge className="h-fit">{service}</Badge>
<p>{message}</p>
</>
)
}
const ErrorState = ({ refetch }: { refetch?: () => void }) => (
<Alert_Shadcn_ variant="warning">
<AlertTriangle />
<AlertTitle_Shadcn_>Lookup failed</AlertTitle_Shadcn_>
<AlertDescription_Shadcn_>
<p>Failed to look up error code help info</p>
{refetch && (
<Button_Shadcn_ variant="outline" size="sm" className="mt-2" onClick={refetch}>
Try again
</Button_Shadcn_>
)}
</AlertDescription_Shadcn_>
</Alert_Shadcn_>
)