mirror of
https://github.com/supabase/supabase.git
synced 2026-12-04 15:39:13 +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" /> |
145 lines
4.7 KiB
TypeScript
145 lines
4.7 KiB
TypeScript
import { CRON_CLEANUP_JOB_NAME, getScheduleDeleteCronJobRunDetailsSql } from '@supabase/pg-meta'
|
|
import { useState } from 'react'
|
|
import { toast } from 'sonner'
|
|
import {
|
|
Button,
|
|
Dialog,
|
|
DialogContent,
|
|
DialogDescription,
|
|
DialogFooter,
|
|
DialogHeader,
|
|
DialogSection,
|
|
DialogSectionSeparator,
|
|
DialogTitle,
|
|
DialogTrigger,
|
|
Select,
|
|
SelectContent,
|
|
SelectItem,
|
|
SelectTrigger,
|
|
SelectValue,
|
|
} from 'ui'
|
|
import { CodeBlock } from 'ui-patterns/CodeBlock'
|
|
|
|
import { CLEANUP_INTERVALS } from './CronJobsTab.constants'
|
|
import { useCronJobQuery } from '@/data/database-cron-jobs/database-cron-job-query'
|
|
import { useScheduleCronJobRunDetailsCleanupMutation } from '@/data/database-cron-jobs/schedule-clean-up-mutation'
|
|
import { useSelectedProjectQuery } from '@/hooks/misc/useSelectedProject'
|
|
import { useTrack } from '@/lib/telemetry/track'
|
|
|
|
const DEFAULT_CLEANUP_INTERVAL =
|
|
CLEANUP_INTERVALS.find((option) => option.value === '7 days')?.value ?? CLEANUP_INTERVALS[0].value
|
|
|
|
interface EnableCleanupButtonProps {
|
|
onScheduled: () => void
|
|
}
|
|
|
|
/**
|
|
* One-click action to schedule the daily cleanup job that trims old rows from
|
|
* cron.job_run_details. Hidden once the cleanup job already exists — the job
|
|
* itself then shows up in the jobs grid.
|
|
*/
|
|
export const EnableCleanupButton = ({ onScheduled }: EnableCleanupButtonProps) => {
|
|
const track = useTrack()
|
|
const { data: project } = useSelectedProjectQuery()
|
|
|
|
const [open, setOpen] = useState(false)
|
|
const [cleanupInterval, setCleanupInterval] = useState(DEFAULT_CLEANUP_INTERVAL)
|
|
|
|
const { data: cleanupJob, isSuccess } = useCronJobQuery({
|
|
projectRef: project?.ref,
|
|
connectionString: project?.connectionString,
|
|
name: CRON_CLEANUP_JOB_NAME,
|
|
})
|
|
|
|
const { mutate: scheduleCleanup, isPending: isScheduling } =
|
|
useScheduleCronJobRunDetailsCleanupMutation({
|
|
onSuccess: () => {
|
|
toast.success('Scheduled daily cleanup job.')
|
|
setOpen(false)
|
|
onScheduled()
|
|
},
|
|
})
|
|
|
|
if (!isSuccess || cleanupJob !== null) return null
|
|
|
|
const onConfirm = () => {
|
|
if (!project?.ref) {
|
|
return toast.error('There was an error scheduling the cleanup. Please try again.')
|
|
}
|
|
track('cron_job_cleanup_enable_button_clicked', {
|
|
retentionInterval: cleanupInterval,
|
|
})
|
|
scheduleCleanup({
|
|
projectRef: project.ref,
|
|
connectionString: project.connectionString,
|
|
interval: cleanupInterval,
|
|
})
|
|
}
|
|
|
|
return (
|
|
<Dialog
|
|
open={open}
|
|
onOpenChange={(isOpen) => {
|
|
setOpen(isOpen)
|
|
if (isOpen) track('cron_job_cleanup_dialog_opened')
|
|
}}
|
|
>
|
|
<DialogTrigger asChild>
|
|
<Button>Enable cleanup</Button>
|
|
</DialogTrigger>
|
|
<DialogContent>
|
|
<DialogHeader>
|
|
<DialogTitle>Enable automatic cleanup</DialogTitle>
|
|
<DialogDescription>
|
|
Schedules a daily job that deletes old cron job run records
|
|
</DialogDescription>
|
|
</DialogHeader>
|
|
<DialogSectionSeparator />
|
|
<DialogSection className="flex flex-col gap-y-4">
|
|
<p className="text-sm">
|
|
Every cron job run is recorded in the{' '}
|
|
<code className="break-keep!">cron.job_run_details</code> table. Without periodic
|
|
cleanup, the table grows indefinitely and bloats the database.
|
|
</p>
|
|
<div className="flex flex-col gap-y-2 text-sm">
|
|
<p className="text-foreground">Delete run history</p>
|
|
<div className="sm:w-64">
|
|
<Select
|
|
disabled={isScheduling}
|
|
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>
|
|
</div>
|
|
<CodeBlock
|
|
hideLineNumbers
|
|
language="sql"
|
|
value={getScheduleDeleteCronJobRunDetailsSql(cleanupInterval)}
|
|
className="py-3 px-4 text-xs"
|
|
wrapperClassName="max-w-full"
|
|
/>
|
|
</DialogSection>
|
|
<DialogFooter>
|
|
<Button disabled={isScheduling} onClick={() => setOpen(false)}>
|
|
Cancel
|
|
</Button>
|
|
<Button variant="primary" loading={isScheduling} onClick={onConfirm}>
|
|
Enable cleanup
|
|
</Button>
|
|
</DialogFooter>
|
|
</DialogContent>
|
|
</Dialog>
|
|
)
|
|
}
|