Files
supabase/apps/studio/components/interfaces/Database/Replication/RestartCostEstimate.tsx
Joshen Lim 6d08d66b7d Add eslint rule for google translate dynamic spans + address all issues (#52949)
## Context

We've been seeing many `NotFoundError: Failed to execute 'removeChild'
on 'Node'` and `NotFoundError: Failed to execute 'insertBefore' on
'Node'` events on Sentry which are historically known to be caused by
Google Translate in the browser.

There's technically no _right way_ to address this unfortunately, but
one of the solutions which should address most of these issues is to
wrap any dynamic text within a span - we've considered that quite a
while back tbh but never took the time to do this until today with the
help of Claude. Although just a heads up that it might not necessarily
completely eradicate those issues.

Also added an eslint rule which should prevent future occurences of this
<img width="1264" height="192" alt="image"
src="https://github.com/user-attachments/assets/b2c32ea0-45a2-4ccd-82fe-1a859905fc29"
/>
2026-11-05 23:28:46 +08:00

95 lines
3.4 KiB
TypeScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import { useMemo } from 'react'
import { GenericSkeletonLoader } from 'ui-patterns/ShimmeringLoader'
import {
summarizeTableCopyEstimate,
type ReplicationTableIdentity,
type TableCopyEstimate,
} from './TableSyncCopy.utils'
import { useReplicationCostEstimateQuery } from '@/data/replication/cost-estimate-query'
import { formatBytes, formatCurrency } from '@/lib/helpers'
interface RestartCostEstimateProps {
open: boolean
projectRef?: string
sourceId?: number
publicationName?: string
tables: Pick<ReplicationTableIdentity, 'schema' | 'name'>[]
}
export const calculateRestartCostEstimate = (
estimates: TableCopyEstimate[],
tables: Pick<ReplicationTableIdentity, 'schema' | 'name'>[]
) => summarizeTableCopyEstimate(estimates, tables)
export const RestartCostEstimate = ({
open,
projectRef,
sourceId,
publicationName,
tables,
}: RestartCostEstimateProps) => {
const { data: estimate, isFetching } = useReplicationCostEstimateQuery(
{ projectRef, sourceId, publicationName },
{ enabled: open && tables.length > 0 }
)
const restartEstimate = useMemo(
() =>
estimate === undefined
? undefined
: calculateRestartCostEstimate(estimate.table_copy.tables, tables),
[estimate, tables]
)
return (
<div className="space-y-2 border-t px-5 py-4">
{tables.length === 0 ? (
<div className="flex items-center justify-between gap-x-6">
<div className="min-w-0">
<p className="text-sm font-medium">No additional initial sync charge</p>
<p className="text-xs text-foreground-lighter">
This reset will skip initial sync based on the pipeline’s settings.
</p>
</div>
<span className="shrink-0 font-mono text-lg font-semibold" translate="no">
{formatCurrency(0)}
</span>
</div>
) : isFetching ? (
<GenericSkeletonLoader className="w-full" />
) : restartEstimate?.isComplete ? (
<div className="flex items-center justify-between gap-x-6">
<div className="min-w-0">
<p className="text-sm font-medium">Estimated additional initial sync cost</p>
<p className="text-xs text-foreground-lighter">
Based on an estimated {formatBytes(restartEstimate.estimatedBytes)} of initial sync
data across {tables.length}{' '}
{tables.length === 1 ? <span>table</span> : <span>tables</span>}
</p>
</div>
<span className="shrink-0 font-mono text-lg font-semibold" translate="no">
{formatCurrency(restartEstimate.estimatedCost)}
{restartEstimate.hasRowFilteredTables ? <span>*</span> : null}
</span>
</div>
) : (
<p className="text-sm text-foreground-light">
A cost estimate is unavailable. You can still reset the{' '}
{tables.length === 1 ? <span>table</span> : <span>tables</span>}
<span>.</span>
</p>
)}
{restartEstimate?.isComplete && restartEstimate.hasRowFilteredTables && (
<p className="text-xs text-foreground-lighter">
*Row filters can reduce the data processed compared with this estimate.
</p>
)}
{restartEstimate?.isComplete && (
<p className="text-xs text-foreground-lighter">
Quick planning estimate; the final charge is based on successfully processed initial sync
data, which is billed again.
</p>
)}
</div>
)
}