mirror of
https://github.com/supabase/supabase.git
synced 2026-12-06 08:29:01 +00:00
## Problem Studio relies on repeated classes to style inline code. Bare `<code>` elements can miss those styles. ## Solution Import the shared styles from #51980 and remove the repeated classes. Keep Markdown renderer behaviour and existing size overrides. Use `data-code-style="plain"` for webhook headers, CLI and upgrade commands, configuration comparisons and connected-resource labels that have their own layout. ## Review instructions Dashboard review: this PR changes Studio only. 1. Open [Database > Extensions](https://studio-staging-git-dnywh-depr-707-code-studio-supabase.vercel.app/dashboard/project/_/database/extensions). Search for `pg_trgm` or another disabled extension and turn on its toggle to open the Enable dialog. Check the Extension and Schema values and the help text under “Install in a different schema”. The SQL block should keep its highlighting and copy control. Close without installing. 2. Open [Edge Functions > Secrets](https://studio-staging-git-dnywh-depr-707-code-studio-supabase.vercel.app/dashboard/project/_/functions/secrets). Scroll to “Default secrets” and check `SUPABASE_URL` and `SUPABASE_DB_URL`: both should use the bordered inline-code style. Hover a name to see “Click to copy”, then click it and confirm the name is copied. No custom secret or deployed function is needed. 3. Compare light and dark themes at narrow and desktop widths. | Before | After | | --- | --- | | <img width="812" height="1066" alt="CleanShot 2026-10-19 at 15 35 10@2x" src="https://github.com/user-attachments/assets/e4a21310-1fac-4143-9ee6-d2452ab4f314" /> | <img width="812" height="1068" alt="CleanShot 2026-10-20 at 15 39 20@2x" src="https://github.com/user-attachments/assets/d2c91ef6-7836-4c71-8f15-d0c0df8e969d" /> |
278 lines
9.2 KiB
TypeScript
278 lines
9.2 KiB
TypeScript
import { getScheduleDeleteCronJobRunDetailsSql } from '@supabase/pg-meta'
|
|
import { CheckCircle2Icon, XCircleIcon } from 'lucide-react'
|
|
import {
|
|
Button,
|
|
Dialog,
|
|
DialogContent,
|
|
DialogHeader,
|
|
DialogSection,
|
|
DialogSectionSeparator,
|
|
DialogTitle,
|
|
DialogTrigger,
|
|
Progress,
|
|
Select,
|
|
SelectContent,
|
|
SelectItem,
|
|
SelectTrigger,
|
|
SelectValue,
|
|
Tooltip,
|
|
TooltipContent,
|
|
TooltipTrigger,
|
|
} from 'ui'
|
|
import { Admonition } from 'ui-patterns/Admonition'
|
|
import { CodeBlock } from 'ui-patterns/CodeBlock'
|
|
|
|
import { CLEANUP_INTERVALS } from './CronJobsTab.constants'
|
|
import {
|
|
useCronJobsCleanupActions,
|
|
type BatchDeletionProgress,
|
|
} from './CronJobsTab.useCleanupActions'
|
|
import { InlineLinkClassName } from '@/components/ui/InlineLink'
|
|
import { useSelectedProjectQuery } from '@/hooks/misc/useSelectedProject'
|
|
|
|
interface CronJobRunDetailsOverflowNoticeV2Props {
|
|
queryCost?: number
|
|
refetchJobs: () => void
|
|
}
|
|
|
|
export const CronJobRunDetailsOverflowNotice = (props: CronJobRunDetailsOverflowNoticeV2Props) => {
|
|
return (
|
|
<Admonition
|
|
type="note"
|
|
className="rounded-none border-x-0 border-t-0 py-2 [&>svg]:top-[0.6rem] [&>svg]:left-10 pl-10 pr-10"
|
|
layout="horizontal"
|
|
actions={<CronJobRunDetailsOverflowDialog {...props} />}
|
|
>
|
|
<p className="text-xs">Last run for each cron job omitted due to high query cost</p>
|
|
</Admonition>
|
|
)
|
|
}
|
|
|
|
const CronJobRunDetailsOverflowDialog = ({
|
|
queryCost,
|
|
refetchJobs,
|
|
}: CronJobRunDetailsOverflowNoticeV2Props) => {
|
|
const { data: project } = useSelectedProjectQuery()
|
|
|
|
const {
|
|
cleanupInterval,
|
|
cleanupState,
|
|
isScheduling,
|
|
isScheduleSuccess,
|
|
setCleanupInterval,
|
|
runBatchedDeletion,
|
|
scheduleCleanup,
|
|
cancelDeletion,
|
|
} = useCronJobsCleanupActions({
|
|
projectRef: project?.ref,
|
|
connectionString: project?.connectionString,
|
|
})
|
|
|
|
const isDeleting = cleanupState.status === 'deleting'
|
|
const isDeleteSuccess = cleanupState.status === 'delete-success'
|
|
const isDeleteError = cleanupState.status === 'delete-error'
|
|
const isBusy = isDeleting || isScheduling
|
|
const canSchedule = isDeleteSuccess || isScheduleSuccess
|
|
|
|
return (
|
|
<Dialog>
|
|
<DialogTrigger asChild>
|
|
<Button>Learn more</Button>
|
|
</DialogTrigger>
|
|
<DialogContent
|
|
aria-describedby={undefined}
|
|
onOpenAutoFocus={(event) => event.preventDefault()}
|
|
>
|
|
<DialogHeader>
|
|
<DialogTitle>Last run for cron jobs omitted for overview</DialogTitle>
|
|
</DialogHeader>
|
|
<DialogSectionSeparator />
|
|
<DialogSection className="flex flex-col gap-y-2">
|
|
<p className="text-sm">
|
|
The dashboard fetches data for the cron jobs overview by running a join between the{' '}
|
|
<code>cron.job</code> and <code className="break-keep!">cron.job_run_details</code>{' '}
|
|
tables to show each cron job's latest run.
|
|
</p>
|
|
|
|
<p className="text-sm">
|
|
However, the join was skipped as the{' '}
|
|
<Tooltip>
|
|
<TooltipTrigger className={InlineLinkClassName}>estimated query cost</TooltipTrigger>
|
|
<TooltipContent side="bottom" className="flex flex-col gap-y-1">
|
|
<p>Estimated cost: {queryCost?.toLocaleString()}</p>
|
|
<p className="text-foreground-light">
|
|
Determined via the <code>EXPLAIN</code> command
|
|
</p>
|
|
</TooltipContent>
|
|
</Tooltip>{' '}
|
|
exceeds safety thresholds, likely due to the size of{' '}
|
|
<code className="break-keep!">cron.job_run_details</code> table.
|
|
</p>
|
|
</DialogSection>
|
|
|
|
<DialogSectionSeparator />
|
|
|
|
<DialogSection className="flex flex-col gap-y-4">
|
|
<p className="font-mono text-foreground-lighter uppercase tracking-tight text-sm">
|
|
Suggested steps
|
|
</p>
|
|
|
|
<p className="text-sm">
|
|
We recommend removing the old run history now, then scheduling a cron job that keeps
|
|
trimming the <code>cron.job_run_details</code> table automatically. This also prevents
|
|
unnecessary bloat on the database.
|
|
</p>
|
|
|
|
<div className="flex flex-col gap-y-2 text-sm">
|
|
<p className="text-foreground">Step 1: Delete older entries</p>
|
|
|
|
{isDeleting ? (
|
|
<DeletionProgress progress={cleanupState.progress} onCancel={cancelDeletion} />
|
|
) : isDeleteSuccess ? (
|
|
<DeletionSuccess totalRowsDeleted={cleanupState.totalRowsDeleted} />
|
|
) : isDeleteError ? (
|
|
<DeletionError
|
|
error={cleanupState.error}
|
|
onRetry={() => runBatchedDeletion(cleanupInterval)}
|
|
/>
|
|
) : (
|
|
<div className="flex flex-col gap-2 sm:flex-row sm:items-center">
|
|
<div className="sm:w-64">
|
|
<Select
|
|
disabled={isBusy}
|
|
value={cleanupInterval}
|
|
onValueChange={setCleanupInterval}
|
|
>
|
|
<SelectTrigger className="w-full">
|
|
<SelectValue placeholder="Select an interval" />
|
|
</SelectTrigger>
|
|
<SelectContent>
|
|
{CLEANUP_INTERVALS.map((option) => (
|
|
<SelectItem key={option.value} value={option.value}>
|
|
{option.label}
|
|
</SelectItem>
|
|
))}
|
|
</SelectContent>
|
|
</Select>
|
|
</div>
|
|
<Button disabled={isBusy} onClick={() => runBatchedDeletion(cleanupInterval)}>
|
|
Delete rows now
|
|
</Button>
|
|
</div>
|
|
)}
|
|
</div>
|
|
|
|
<div className="flex flex-col gap-y-2 text-sm">
|
|
<p className="text-foreground">Step 2: Schedule an automated cleanup</p>
|
|
|
|
{!canSchedule ? (
|
|
<p className="text-foreground-lighter text-xs">
|
|
Complete step 1 to enable scheduling a daily cleanup job.
|
|
</p>
|
|
) : isScheduleSuccess ? (
|
|
<ScheduleSuccess />
|
|
) : (
|
|
<>
|
|
<CodeBlock
|
|
hideLineNumbers
|
|
language="sql"
|
|
value={getScheduleDeleteCronJobRunDetailsSql(cleanupInterval)}
|
|
className="py-3 px-4 text-xs"
|
|
wrapperClassName="max-w-full"
|
|
/>
|
|
<Button
|
|
block
|
|
size="small"
|
|
className="mt-1"
|
|
loading={isScheduling}
|
|
disabled={isScheduling}
|
|
onClick={async () => {
|
|
await scheduleCleanup({
|
|
interval: cleanupInterval,
|
|
onSuccess: () => refetchJobs(),
|
|
})
|
|
}}
|
|
>
|
|
Schedule cleanup job
|
|
</Button>
|
|
</>
|
|
)}
|
|
</div>
|
|
</DialogSection>
|
|
</DialogContent>
|
|
</Dialog>
|
|
)
|
|
}
|
|
|
|
interface DeletionProgressProps {
|
|
progress: BatchDeletionProgress
|
|
onCancel: () => void
|
|
}
|
|
|
|
const DeletionProgress = ({ progress, onCancel }: DeletionProgressProps) => {
|
|
const { currentBatch, totalBatches, totalRowsDeleted } = progress
|
|
const percentComplete =
|
|
totalBatches > 0 ? Math.min(Math.round((currentBatch / totalBatches) * 100), 100) : 0
|
|
|
|
return (
|
|
<div className="space-y-2">
|
|
<div className="flex items-center gap-3">
|
|
<Progress value={percentComplete} className="flex-1 h-2" />
|
|
<span className="text-xs text-foreground-light whitespace-nowrap">
|
|
{percentComplete}% ({currentBatch}/{totalBatches} batches)
|
|
</span>
|
|
</div>
|
|
<div className="flex items-center justify-between">
|
|
<span className="text-xs text-foreground-light">
|
|
Deleted {totalRowsDeleted.toLocaleString()} rows so far...
|
|
</span>
|
|
<Button variant="outline" size="tiny" onClick={onCancel}>
|
|
Cancel
|
|
</Button>
|
|
</div>
|
|
</div>
|
|
)
|
|
}
|
|
|
|
interface DeletionSuccessProps {
|
|
totalRowsDeleted: number
|
|
}
|
|
|
|
const DeletionSuccess = ({ totalRowsDeleted }: DeletionSuccessProps) => (
|
|
<div className="flex items-center gap-2 text-primary">
|
|
<CheckCircle2Icon size={16} />
|
|
<span className="text-sm">Successfully deleted {totalRowsDeleted.toLocaleString()} rows.</span>
|
|
</div>
|
|
)
|
|
|
|
interface DeletionErrorProps {
|
|
error: string
|
|
onRetry: () => void
|
|
}
|
|
|
|
const DeletionError = ({ error, onRetry }: DeletionErrorProps) => (
|
|
<div className="space-y-2">
|
|
<div className="flex items-center gap-2 text-destructive">
|
|
<XCircleIcon size={16} />
|
|
<span className="text-sm">Deletion failed: {error}</span>
|
|
</div>
|
|
<Button size="small" onClick={onRetry}>
|
|
Retry
|
|
</Button>
|
|
</div>
|
|
)
|
|
|
|
const ScheduleSuccess = () => (
|
|
<div className="space-y-2">
|
|
<div className="flex items-center gap-2 text-primary">
|
|
<CheckCircle2Icon size={16} />
|
|
<span className="text-sm">Daily cleanup job scheduled successfully.</span>
|
|
</div>
|
|
<div className="flex items-center gap-2">
|
|
<p className="text-foreground-lighter text-xs">
|
|
New cleanup job should now be visible in the cron jobs overview.
|
|
</p>
|
|
</div>
|
|
</div>
|
|
)
|