import { AlertTriangle, CheckCircle2, Loader2 } from 'lucide-react' import { useState } from 'react' import { useParams } from 'common' import { useEdgeFunctionServiceStatusQuery } from 'data/service-status/edge-functions-status-query' import { usePostgresServiceStatusQuery } from 'data/service-status/postgres-service-status-query' import { useProjectServiceStatusQuery } from 'data/service-status/service-status-query' import { useIsFeatureEnabled } from 'hooks/misc/useIsFeatureEnabled' import { useSelectedProject } from 'hooks/misc/useSelectedProject' import { Button, PopoverContent_Shadcn_, PopoverTrigger_Shadcn_, Popover_Shadcn_ } from 'ui' const ServiceStatus = () => { const { ref } = useParams() const project = useSelectedProject() const [open, setOpen] = useState(false) const { projectAuthAll: authEnabled, projectEdgeFunctionAll: edgeFunctionsEnabled, realtimeAll: realtimeEnabled, projectStorageAll: storageEnabled, } = useIsFeatureEnabled([ 'project_auth:all', 'project_edge_function:all', 'realtime:all', 'project_storage:all', ]) const isBranch = project?.parentRef !== project?.ref // [Joshen] Need pooler service check eventually const { data: status, isLoading } = useProjectServiceStatusQuery({ projectRef: ref }) const { data: edgeFunctionsStatus } = useEdgeFunctionServiceStatusQuery({ projectRef: ref }) const { isLoading: isLoadingPostgres, isSuccess: isSuccessPostgres } = usePostgresServiceStatusQuery({ projectRef: ref, connectionString: project?.connectionString, }) const authStatus = status?.find((service) => service.name === 'auth') const restStatus = status?.find((service) => service.name === 'rest') const realtimeStatus = status?.find((service) => service.name === 'realtime') const storageStatus = status?.find((service) => service.name === 'storage') // [Joshen] Need individual troubleshooting docs for each service eventually for users to self serve const services: { name: string error?: string docsUrl?: string isLoading: boolean isSuccess?: boolean }[] = [ { name: 'Database', error: undefined, docsUrl: undefined, isLoading: isLoadingPostgres, isSuccess: isSuccessPostgres, }, { name: 'PostgREST', error: restStatus?.error, docsUrl: undefined, isLoading, isSuccess: restStatus?.healthy, }, ...(authEnabled ? [ { name: 'Auth', error: authStatus?.error, docsUrl: undefined, isLoading, isSuccess: authStatus?.healthy, }, ] : []), ...(realtimeEnabled ? [ { name: 'Realtime', error: realtimeStatus?.error, docsUrl: undefined, isLoading, isSuccess: realtimeStatus?.healthy, }, ] : []), ...(storageEnabled ? [ { name: 'Storage', error: storageStatus?.error, docsUrl: undefined, isLoading, isSuccess: storageStatus?.healthy, }, ] : []), ...(edgeFunctionsEnabled ? [ { name: 'Edge Functions', error: undefined, docsUrl: 'https://supabase.com/docs/guides/functions/troubleshooting', isLoading, isSuccess: edgeFunctionsStatus?.healthy, }, ] : []), ] const isLoadingChecks = services.some((service) => service.isLoading) const allServicesOperational = services.every((service) => service.isSuccess) return ( {services.map((service) => (

{service.name}

{service.isLoading ? 'Checking status' : service.isSuccess ? 'No issues' : 'Unable to connect'}

{service.isLoading ? ( ) : service.isSuccess ? ( ) : ( )}
))}
) } export default ServiceStatus