Files
supabase/apps/studio/routes/project/$ref/compute/index.tsx
Joshen Lim 434c00cb14 Joshenlim/fe 5196 move off scaffold components for remaining (#53911)
## Context

Final clean up of deprecated Scaffold components, just touches
- Account audit logs
- Project home page
- Database -> Column privileges
- Storage -> Analytics bucket details
- Storage -> Vector bucket details
- Settings -> Infrastructure -> Disk management
- Settings -> Infrastructure -> Read replica details
- Integrations -> Wrappers overview (Only for non supported integration
UI)
- Edge functions -> Empty state
- Auth -> Performance

Also replaces usage of `ScaffoldDivider` with just the `Separator`
component
And also adjusts the page container sizes of database pages from large
to default - these only have visual differences on viewport widths
larger than a laptop

Testing just needs a quick sweep of all these surfaces to make sure
nothing looks weird - will do so on my end too once the builds go
through!

For @supabase/security's review - review requirement was triggered as
`Documents.tsx` was updated in the organization settings page. But it
was just to change the Divider component 🙏
2026-11-26 21:28:17 +07:00

144 lines
5.0 KiB
TypeScript

import { useQuery } from '@tanstack/react-query'
import { createFileRoute } from '@tanstack/react-router'
import { useParams } from 'common'
import { ExternalLinkIcon, RefreshCwIcon } from 'lucide-react'
import { useState } from 'react'
import { Button } from 'ui'
import { Admonition } from 'ui-patterns/Admonition'
import { PageContainer } from 'ui-patterns/PageContainer'
import {
PageHeader,
PageHeaderDescription,
PageHeaderMeta,
PageHeaderSummary,
PageHeaderTitle,
} from 'ui-patterns/PageHeader'
import { PageSection, PageSectionContent } from 'ui-patterns/PageSection'
import { GenericSkeletonLoader } from 'ui-patterns/ShimmeringLoader'
import {
isComputeForbidden,
isComputeUnavailable,
} from '@/components/interfaces/Compute/Compute.utils'
import { ComputeEmptyState } from '@/components/interfaces/Compute/ComputeEmptyState'
import { ComputeList } from '@/components/interfaces/Compute/ComputeList'
import { DeployComputeInstanceDialog } from '@/components/interfaces/Compute/DeployComputeInstanceDialog'
import { AlertError } from '@/components/ui/AlertError'
import { AlphaNotice } from '@/components/ui/AlphaNotice'
import { NoPermission } from '@/components/ui/NoPermission'
import { computeQueryOptions } from '@/data/compute/compute-query'
import { PRODUCT_NAME } from '@/lib/constants/compute'
export const Route = createFileRoute('/project/$ref/compute/')({
component: ComputePage,
staticData: {
computeLayoutTitle: PRODUCT_NAME,
},
})
function ComputePage() {
const { ref } = useParams()
const [isDeployInstructionsOpen, setIsDeployInstructionsOpen] = useState(false)
const [isManuallyRefreshing, setIsManuallyRefreshing] = useState(false)
const {
data: instances,
error,
isPending,
isError,
isSuccess,
refetch,
} = useQuery(computeQueryOptions({ projectRef: ref }))
// Separate from the query's own isFetching so background polling doesn't flash the button
const handleManualRefresh = () => {
setIsManuallyRefreshing(true)
refetch().finally(() => setIsManuallyRefreshing(false))
}
const isNotEnrolled = isError && isComputeUnavailable(error)
const isMissingPermission = isError && isComputeForbidden(error)
const isUnexpectedError = isError && !isNotEnrolled && !isMissingPermission
return (
<div className="w-full min-h-full flex flex-col items-stretch">
<PageHeader size="default">
<PageHeaderMeta>
<PageHeaderSummary>
<PageHeaderTitle>{PRODUCT_NAME}</PageHeaderTitle>
<PageHeaderDescription>
Run fully managed compute in isolation next to your database
</PageHeaderDescription>
</PageHeaderSummary>
</PageHeaderMeta>
</PageHeader>
<PageContainer size="default">
<PageSection>
<PageSectionContent className="flex flex-col gap-y-8">
<AlphaNotice
entity="Compute"
feedbackUrl="https://github.com/orgs/supabase/discussions"
/>
{isPending && <GenericSkeletonLoader />}
{isNotEnrolled && (
<Admonition
type="default"
layout="horizontal"
title={`You don't have access to ${PRODUCT_NAME} yet`}
description="Join the waitlist to get early access."
actions={
<Button asChild icon={<ExternalLinkIcon />}>
<a
href="https://supabase.com/compute"
target="_blank"
rel="noopener noreferrer"
>
Join waitlist
</a>
</Button>
}
/>
)}
{isMissingPermission && (
<NoPermission resourceText="view this project's compute instances" />
)}
{isUnexpectedError && (
<AlertError
error={error}
subject="Failed to retrieve compute instances"
additionalActions={
<Button
icon={<RefreshCwIcon />}
loading={isManuallyRefreshing}
onClick={handleManualRefresh}
>
Refresh
</Button>
}
/>
)}
{isSuccess && instances.length === 0 && (
<ComputeEmptyState onDeploy={() => setIsDeployInstructionsOpen(true)} />
)}
{isSuccess && instances.length > 0 && ref && (
<ComputeList
projectRef={ref}
instances={instances}
onDeploy={() => setIsDeployInstructionsOpen(true)}
onRefresh={handleManualRefresh}
isRefreshing={isManuallyRefreshing}
/>
)}
</PageSectionContent>
</PageSection>
</PageContainer>
<DeployComputeInstanceDialog
open={isDeployInstructionsOpen}
onOpenChange={setIsDeployInstructionsOpen}
/>
</div>
)
}