Files
supabase/apps/studio/components/interfaces/Reports/ReportWidget.tsx
Danny White 476d4a5851 refactor(ui): drop redundant Button variant="default" props (#50161)
## 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
2026-09-11 17:05:26 +10:00

111 lines
3.9 KiB
TypeScript

import { useParams } from 'common'
import { ExternalLink, HelpCircle } from 'lucide-react'
import { NextRouter, useRouter } from 'next/router'
import { ReactNode } from 'react'
import { Button, cn, Loading, Tooltip, TooltipContent, TooltipTrigger } from 'ui'
import type { LogsEndpointParams } from '../Settings/Logs/Logs.types'
import type { BaseReportParams, ReportQueryType } from './Reports.types'
import Panel from '@/components/ui/Panel'
export interface ReportWidgetProps<T = any> {
data: T[]
title: string
description?: string
error?: string | Object | null
tooltip?: string | ReactNode
className?: string
contentClassName?: string
headerClassName?: string
renderer: (props: ReportWidgetRendererProps) => ReactNode
append?: (props: ReportWidgetRendererProps) => ReactNode
// for overriding props, such as data
appendProps?: Partial<ReportWidgetRendererProps>
// omitting params will hide the "View in logs explorer" button
params?: BaseReportParams | LogsEndpointParams
queryType?: ReportQueryType
isLoading: boolean
resolvedSql?: string
}
export interface ReportWidgetRendererProps<T = any> extends ReportWidgetProps<T> {
router: NextRouter
projectRef: string
}
const ReportWidget = (props: ReportWidgetProps) => {
const router = useRouter()
const { ref } = useParams()
const projectRef = ref as string
return (
<Panel noMargin noHideOverflow className={cn('pb-0', props.className)} wrapWithLoading={false}>
<Panel.Content className={cn('space-y-4', props.contentClassName)}>
<div className={cn('flex flex-row items-start justify-between', props.headerClassName)}>
<div className="gap-2">
<div className="flex flex-row gap-2">
<h3 className="w-full h-6">{props.title}</h3>{' '}
{props?.tooltip && (
<Tooltip>
<TooltipTrigger>
<HelpCircle className="text-foreground-light" size={14} strokeWidth={1.5} />
</TooltipTrigger>
<TooltipContent side="bottom">{props.tooltip}</TooltipContent>
</Tooltip>
)}
</div>
<p className="text-sm text-foreground-light">{props.description}</p>
</div>
{props.params && (
<Tooltip>
<TooltipTrigger asChild>
<Button
icon={<ExternalLink />}
className="px-1"
onClick={() => {
const isDbQueryType = props.queryType === 'db'
const pathname = isDbQueryType
? `/project/${projectRef}/sql/new`
: `/project/${projectRef}/logs/explorer`
const query: Record<string, string | undefined> = {}
if (isDbQueryType) {
query.content = props.resolvedSql
} else {
query.q = props.params?.sql
query.its = props.params?.iso_timestamp_start || ''
query.ite = props.params?.iso_timestamp_end || ''
}
router.push({ pathname, query })
}}
/>
</TooltipTrigger>
<TooltipContent side="left">
{props.queryType === 'db' ? 'Open in SQL Editor' : 'Open in Logs Explorer'}
</TooltipContent>
</Tooltip>
)}
</div>
<Loading active={props.isLoading}>
{props.data === undefined
? null
: props.renderer({ ...props, router, projectRef: projectRef as string })}
</Loading>
</Panel.Content>
{props.append && (
<>
{props.append({
...props,
...(props.appendProps || {}),
router,
projectRef: projectRef as string,
})}
</>
)}
</Panel>
)
}
export default ReportWidget