Home / Function/ ServiceList() — supabase Function Reference

ServiceList() — supabase Function Reference

Architecture documentation for the ServiceList() function in ServiceList.tsx from the supabase codebase.

Entity Profile

Relationship Graph

Source Code

apps/studio/components/interfaces/Settings/API/ServiceList.tsx lines 20–123

export const ServiceList = () => {
  const { data: project, isPending: isLoading } = useSelectedProjectQuery()
  const { ref: projectRef } = useParams()
  const state = useDatabaseSelectorStateSnapshot()

  const [querySource, setQuerySource] = useQueryState('source', parseAsString)

  const { data: customDomainData } = useCustomDomainsQuery({ projectRef })
  const {
    data: databases,
    isError,
    isPending: isLoadingDatabases,
  } = useReadReplicasQuery({ projectRef })
  const { data: loadBalancers } = useLoadBalancersQuery({ projectRef })

  useEffect(() => {
    if (querySource && querySource !== state.selectedDatabaseId) {
      state.setSelectedDatabaseId(querySource)
    }
  }, [querySource, state, projectRef])

  // Get the API service
  const isCustomDomainActive = customDomainData?.customDomain?.status === 'active'
  const selectedDatabase = databases?.find((db) => db.identifier === state.selectedDatabaseId)
  const loadBalancerSelected = state.selectedDatabaseId === 'load-balancer'
  const replicaSelected = selectedDatabase?.identifier !== projectRef

  const endpoint =
    isCustomDomainActive && state.selectedDatabaseId === projectRef
      ? `https://${customDomainData.customDomain.hostname}`
      : loadBalancerSelected
        ? loadBalancers?.[0].endpoint ?? ''
        : selectedDatabase?.restUrl

  return (
    <ScaffoldSection isFullWidth id="api-settings" className="gap-6">
      {!isLoading && project?.status !== PROJECT_STATUS.ACTIVE_HEALTHY ? (
        <Alert_Shadcn_ variant="destructive">
          <AlertCircle size={16} />
          <AlertTitle_Shadcn_>
            API settings are unavailable as the project is not active
          </AlertTitle_Shadcn_>
        </Alert_Shadcn_>
      ) : (
        <>
          <Card>
            <CardHeader className="flex flex-row items-center justify-between">
              Project URL
              <DatabaseSelector
                additionalOptions={
                  (loadBalancers ?? []).length > 0
                    ? [{ id: 'load-balancer', name: 'API Load Balancer' }]
                    : []
                }
                onSelectId={() => {
                  setQuerySource(null)
                }}
              />
            </CardHeader>
            <CardContent>
              {isLoading || isLoadingDatabases ? (
                <div className="space-y-2">
                  <ShimmeringLoader className="py-3.5" />
                  <ShimmeringLoader className="py-3.5 w-3/4" delayIndex={1} />
                </div>
              ) : isError ? (
                <Alert_Shadcn_ variant="destructive">
                  <AlertCircle size={16} />
                  <AlertTitle_Shadcn_>Failed to retrieve project URL</AlertTitle_Shadcn_>
                </Alert_Shadcn_>
              ) : (
                <FormLayout
                  layout="flex-row-reverse"
                  label={
                    isCustomDomainActive ? (
                      <div className="flex items-center space-x-2">
                        <p>URL</p>
                        <Badge>Custom domain active</Badge>
                      </div>
                    ) : (
                      'URL'
                    )
                  }
                  description={
                    loadBalancerSelected
                      ? 'RESTful endpoint for querying and managing your databases through your load balancer'
                      : replicaSelected
                        ? 'RESTful endpoint for querying your read replica'
                        : 'RESTful endpoint for querying and managing your database'
                  }
                  className="[&>div]:xl:w-1/2 [&>div>div]:w-full"
                >
                  <Input copy readOnly className="font-mono" value={endpoint} />
                </FormLayout>
              )}
            </CardContent>
          </Card>

          <PostgrestConfig />
        </>
      )}
    </ScaffoldSection>
  )
}

Subdomains

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free