mirror of
https://github.com/supabase/supabase.git
synced 2026-09-22 13:37:53 +08:00
476d4a5851
## 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
116 lines
3.0 KiB
TypeScript
116 lines
3.0 KiB
TypeScript
import { SupportCategories } from '@supabase/shared-types/out/constants'
|
|
import { PropsWithChildren, useEffect, useRef } from 'react'
|
|
import { Button } from 'ui'
|
|
import { Admonition } from 'ui-patterns/Admonition'
|
|
|
|
import { SupportLink } from '@/components/interfaces/Support/SupportLink'
|
|
import { isDashboardErrorSampled } from '@/lib/telemetry/error-sampling'
|
|
import { useTrack } from '@/lib/telemetry/track'
|
|
|
|
export interface AlertErrorProps {
|
|
projectRef?: string
|
|
subject?: string
|
|
description?: string
|
|
error?: { message: string } | null
|
|
layout?: 'vertical' | 'horizontal' | 'responsive'
|
|
className?: string
|
|
showIcon?: boolean
|
|
showInstructions?: boolean
|
|
showErrorPrefix?: boolean
|
|
additionalActions?: React.ReactNode
|
|
hideContactSupport?: boolean
|
|
}
|
|
|
|
export const ContactSupportButton = ({
|
|
projectRef,
|
|
subject,
|
|
error,
|
|
}: {
|
|
projectRef?: string
|
|
subject?: string
|
|
error?: { message: string } | null
|
|
}) => {
|
|
return (
|
|
<Button asChild className="w-min">
|
|
<SupportLink
|
|
queryParams={{
|
|
category: SupportCategories.DASHBOARD_BUG,
|
|
projectRef,
|
|
subject,
|
|
error: error?.message,
|
|
}}
|
|
>
|
|
Contact support
|
|
</SupportLink>
|
|
</Button>
|
|
)
|
|
}
|
|
|
|
// [Joshen] To standardize the language for all error UIs
|
|
export const AlertError = ({
|
|
projectRef,
|
|
subject,
|
|
description = 'Try refreshing your browser, but if the issue persists for more than a few minutes, please reach out to us via support.',
|
|
error,
|
|
className,
|
|
showIcon = true,
|
|
layout = 'responsive',
|
|
showInstructions = true,
|
|
showErrorPrefix = true,
|
|
children,
|
|
additionalActions,
|
|
hideContactSupport = false,
|
|
}: PropsWithChildren<AlertErrorProps>) => {
|
|
const track = useTrack()
|
|
const hasTrackedRef = useRef(false)
|
|
|
|
const formattedErrorMessage = error?.message?.includes('503')
|
|
? '503 Service Temporarily Unavailable'
|
|
: error?.message
|
|
|
|
useEffect(() => {
|
|
if (!hasTrackedRef.current) {
|
|
hasTrackedRef.current = true
|
|
if (isDashboardErrorSampled()) {
|
|
track('dashboard_error_created', {
|
|
source: 'admonition',
|
|
})
|
|
}
|
|
}
|
|
}, [track])
|
|
|
|
return (
|
|
<Admonition
|
|
type="warning"
|
|
layout={additionalActions ? 'vertical' : layout}
|
|
showIcon={showIcon}
|
|
title={subject}
|
|
description={
|
|
<>
|
|
{error?.message && (
|
|
<p>
|
|
{showErrorPrefix && 'Error: '}
|
|
{formattedErrorMessage}
|
|
</p>
|
|
)}
|
|
{showInstructions && <p>{description}</p>}
|
|
{children}
|
|
</>
|
|
}
|
|
actions={
|
|
hideContactSupport ? (
|
|
(additionalActions ?? null)
|
|
) : additionalActions ? (
|
|
<>
|
|
{additionalActions}
|
|
<ContactSupportButton projectRef={projectRef} subject={subject} error={error} />
|
|
</>
|
|
) : (
|
|
<ContactSupportButton projectRef={projectRef} subject={subject} error={error} />
|
|
)
|
|
}
|
|
className={className}
|
|
/>
|
|
)
|
|
}
|