mirror of
https://github.com/supabase/supabase.git
synced 2026-10-06 01:45:10 +03:00
## What kind of change does this PR introduce? Mechanical cleanup on top of the Button default-variant change (#50160). ## What is the current behavior? Many callsites still pass `variant="default"` even though that is now the component default. ## What is the new behavior? Removes redundant static `variant="default"` from legacy `Button` and `ButtonTooltip` callsites. Keeps explicit defaults where they document the API: - `button-default.tsx` and `button-sizes.tsx` demos - `DocsButton`, which pins neutral styling at the wrapper boundary ## To test Studio: - [Auth → Rate Limits](https://studio-staging-2s957kwc4-supabase.vercel.app/dashboard/project/_/auth/rate-limits): dirty the form so Cancel appears; Cancel stays neutral, Save stays green - [Project Settings → API Keys](https://studio-staging-2s957kwc4-supabase.vercel.app/dashboard/project/_/settings/api-keys): `DocsButton` in the header actions stays neutral Design system: - [Design system → Button](https://design-system-git-dnywh-dc924ac1-supabase.vercel.app/design-system/docs/components/button): `button-default` / `button-sizes` still show explicit default styling; Primary (green) is restricted to the Primary section (and `asChild`) WWW: - [www → Brand assets](https://zone-www-dot-com-git-dnywh-dc924ac1-supabase.vercel.app/brand-assets): Download logo kit / Download button kit stay neutral
106 lines
3.6 KiB
TypeScript
106 lines
3.6 KiB
TypeScript
import { ChevronDown } from 'lucide-react'
|
|
import {
|
|
Button,
|
|
DropdownMenu,
|
|
DropdownMenuContent,
|
|
DropdownMenuRadioGroup,
|
|
DropdownMenuRadioItem,
|
|
DropdownMenuTrigger,
|
|
Tooltip,
|
|
TooltipContent,
|
|
TooltipTrigger,
|
|
} from 'ui'
|
|
|
|
import { CHART_INTERVALS } from './logs.utils'
|
|
import { InlineLink } from '@/components/ui/InlineLink'
|
|
import { useCheckEntitlements } from '@/hooks/misc/useCheckEntitlements'
|
|
|
|
function getDaysRequired(startValue: number, startUnit: string): number {
|
|
if (startUnit === 'day') return startValue
|
|
if (startUnit === 'hour') return startValue / 24
|
|
return 0
|
|
}
|
|
|
|
interface ChartIntervalDropdownProps {
|
|
value: string
|
|
onChange: (value: string) => void
|
|
organizationSlug?: string
|
|
dropdownAlign?: 'start' | 'center' | 'end'
|
|
tooltipSide?: 'left' | 'right' | 'top' | 'bottom'
|
|
open?: boolean
|
|
onOpenChange?: (open: boolean) => void
|
|
}
|
|
|
|
export const ChartIntervalDropdown = ({
|
|
value,
|
|
onChange,
|
|
organizationSlug,
|
|
dropdownAlign = 'start',
|
|
tooltipSide = 'right',
|
|
open,
|
|
onOpenChange,
|
|
}: ChartIntervalDropdownProps) => {
|
|
const selectedInterval = CHART_INTERVALS.find((i) => i.key === value) || CHART_INTERVALS[1]
|
|
|
|
const { getEntitlementMax } = useCheckEntitlements('log.retention_days')
|
|
const retentionDays = getEntitlementMax()
|
|
|
|
return (
|
|
<DropdownMenu open={open} onOpenChange={onOpenChange}>
|
|
<DropdownMenuTrigger asChild>
|
|
<Button iconRight={<ChevronDown size={14} />}>
|
|
<span>{selectedInterval.label}</span>
|
|
</Button>
|
|
</DropdownMenuTrigger>
|
|
<DropdownMenuContent side="bottom" align={dropdownAlign} className="w-40">
|
|
<DropdownMenuRadioGroup value={value} onValueChange={onChange}>
|
|
{CHART_INTERVALS.map((i) => {
|
|
const daysRequired = getDaysRequired(i.startValue, i.startUnit)
|
|
const disabled = retentionDays !== undefined && daysRequired > retentionDays
|
|
|
|
if (disabled) {
|
|
return (
|
|
<Tooltip key={i.key}>
|
|
<TooltipTrigger asChild>
|
|
<DropdownMenuRadioItem disabled value={i.key} className="pointer-events-auto!">
|
|
{i.label}
|
|
</DropdownMenuRadioItem>
|
|
</TooltipTrigger>
|
|
<TooltipContent side={tooltipSide}>
|
|
<p>
|
|
Your plan only includes up to {retentionDays} day
|
|
{retentionDays !== undefined && retentionDays > 1 ? 's' : ''} of log retention
|
|
</p>
|
|
<p className="text-foreground-light">
|
|
{organizationSlug ? (
|
|
<>
|
|
<InlineLink
|
|
className="text-foreground-light hover:text-foreground"
|
|
href={`/org/${organizationSlug}/billing?panel=subscriptionPlan`}
|
|
>
|
|
Upgrade your plan
|
|
</InlineLink>{' '}
|
|
to increase log retention and view statistics for the{' '}
|
|
{i.label.toLowerCase()}
|
|
</>
|
|
) : (
|
|
`Upgrade your plan to increase log retention and view statistics for the ${i.label.toLowerCase()}`
|
|
)}
|
|
</p>
|
|
</TooltipContent>
|
|
</Tooltip>
|
|
)
|
|
} else {
|
|
return (
|
|
<DropdownMenuRadioItem key={i.key} value={i.key}>
|
|
{i.label}
|
|
</DropdownMenuRadioItem>
|
|
)
|
|
}
|
|
})}
|
|
</DropdownMenuRadioGroup>
|
|
</DropdownMenuContent>
|
|
</DropdownMenu>
|
|
)
|
|
}
|