Files
supabase/apps/studio/components/interfaces/Settings/Infrastructure/ReadReplicas/ReadReplicaDetails.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

186 lines
7.1 KiB
TypeScript

import { useParams } from 'common'
import { BarChart2Icon } from 'lucide-react'
import { useMemo } from 'react'
import { AWS_REGIONS } from 'shared-data'
import { Card, CardContent, CardHeader, CardTitle } from 'ui'
import {
Chart,
ChartCard,
ChartContent,
ChartEmptyState,
ChartHeader,
ChartLine,
ChartLoadingState,
ChartMetric,
} from 'ui-patterns/Chart'
import { Input } from 'ui-patterns/DataInputs/Input'
import { FormItemLayout } from 'ui-patterns/form/FormItemLayout/FormItemLayout'
import { PageContainer } from 'ui-patterns/PageContainer'
import { PageSection } from 'ui-patterns/PageSection'
import { GenericSkeletonLoader } from 'ui-patterns/ShimmeringLoader'
import { REPLICA_STATUS } from './ReadReplicas.constants'
import { REPORT_DATERANGE_HELPER_LABELS } from '@/components/interfaces/Reports/Reports.constants'
import { RegionFlag } from '@/components/ui/RegionFlag'
import { useInfraMonitoringAttributesQuery } from '@/data/analytics/infra-monitoring-query'
import { useLoadBalancersQuery } from '@/data/read-replicas/load-balancers-query'
import { useReplicationLagQuery } from '@/data/read-replicas/replica-lag-query'
import { useReadReplicasQuery } from '@/data/read-replicas/replicas-query'
import { useReadReplicasStatusesQuery } from '@/data/read-replicas/replicas-status-query'
import { useIsFeatureEnabled } from '@/hooks/misc/useIsFeatureEnabled'
import { useReportDateRange } from '@/hooks/misc/useReportDateRange'
import { useSelectedProjectQuery } from '@/hooks/misc/useSelectedProject'
import { getComputeSizeLabel } from '@/lib/compute-labels'
const attribute = 'physical_replication_lag_physical_replication_lag_seconds'
export const ReadReplicaDetails = () => {
const { ref: projectRef, replicaId } = useParams()
const { data = [], isPending: isLoadingDatabases } = useReadReplicasQuery({ projectRef })
const replica = data.find((x) => x.identifier === replicaId)
const { identifier, connectionString, status: baseStatus, restUrl, region } = replica ?? {}
const regionLabel = Object.values(AWS_REGIONS).find((x) => x.code === region)?.displayName
const { data: project } = useSelectedProjectQuery()
const computeSize = getComputeSizeLabel(project?.infra_compute_size)
const { projectHomepageShowInstanceSize } = useIsFeatureEnabled([
'project_homepage:show_instance_size',
])
const { data: statuses = [] } = useReadReplicasStatusesQuery({ projectRef })
const replicaStatus = statuses.find((x) => x.identifier === identifier)
const status = replicaStatus?.status ?? baseStatus
const { data: loadBalancers = [] } = useLoadBalancersQuery({ projectRef })
const loadBalancer = loadBalancers.find((x) =>
x.databases.some((x) => x.identifier === identifier)
)
const { data: lagDuration, isPending: isLoadingLag } = useReplicationLagQuery(
{
id: identifier ?? '',
projectRef,
connectionString,
},
{ enabled: status === REPLICA_STATUS.ACTIVE_HEALTHY }
)
const { selectedDateRange } = useReportDateRange(REPORT_DATERANGE_HELPER_LABELS.LAST_60_MINUTES)
// [Joshen] This is unused but intentional to scaffold the usage for now, refer to comment below
const { data: infraMonitoringData, isPending: isFetchingInfraMonitoring } =
useInfraMonitoringAttributesQuery(
{
projectRef,
attributes: [attribute],
databaseIdentifier: identifier,
startDate: selectedDateRange.period_start.date,
endDate: selectedDateRange.period_end.date,
interval: selectedDateRange.interval,
},
{ enabled: !!replica }
)
const chartData = useMemo(
() =>
infraMonitoringData?.data.map((x) => ({
timestamp: x.period_start,
[attribute]: (x as Record<string, string | number>)[attribute],
})) ?? [],
[infraMonitoringData?.data]
)
return (
<>
<Chart className="mt-6" isLoading={isLoadingLag || isFetchingInfraMonitoring}>
<ChartCard className="rounded-none border-x-0">
<ChartHeader className="px-10">
<ChartMetric
label="Replication lag"
value={lagDuration !== undefined ? `${lagDuration}s` : '-'}
/>
</ChartHeader>
<ChartContent
isEmpty={chartData.length === 0}
emptyState={
<ChartEmptyState
icon={<BarChart2Icon size={16} />}
title="No data to show"
description="It may take up to 24 hours for data to refresh"
/>
}
loadingState={<ChartLoadingState className="h-[228px]" />}
>
<div className="h-56 px-5">
<ChartLine
showGrid
showYAxis
isFullHeight
data={chartData}
dataKey={attribute}
YAxisProps={{
tickFormatter: (value) => `${value}s`,
width: 80,
}}
config={{
[attribute]: { label: 'Replication lag' },
}}
/>
</div>
</ChartContent>
</ChartCard>
</Chart>
<PageContainer>
<PageSection>
<Card>
<CardHeader>
<CardTitle>Replica Information</CardTitle>
</CardHeader>
{isLoadingDatabases ? (
<CardContent>
<GenericSkeletonLoader />
</CardContent>
) : (
<>
<CardContent>
<FormItemLayout
isReactForm={false}
layout="horizontal"
label="Load Balancer URL"
description="RESTful endpoint for querying and managing your databases through your load balancer."
>
<Input readOnly copy className="input-mono" value={loadBalancer?.endpoint} />
</FormItemLayout>
</CardContent>
<CardContent className="flex flex-col gap-y-4">
<FormItemLayout isReactForm={false} layout="horizontal" label="Replica URL">
<Input readOnly copy className="input-mono" value={restUrl} />
</FormItemLayout>
<FormItemLayout isReactForm={false} layout="horizontal" label="Region">
<Input
readOnly
className="input-mono"
value={regionLabel}
icon={<RegionFlag className="w-5" region={region ?? ''} />}
/>
</FormItemLayout>
{projectHomepageShowInstanceSize && (
<FormItemLayout
isReactForm={false}
layout="horizontal"
label="Compute Size"
description="Size of replica will be identical to the primary database."
>
<Input readOnly className="input-mono" value={computeSize} />
</FormItemLayout>
)}
</CardContent>
</>
)}
</Card>
</PageSection>
</PageContainer>
</>
)
}