Files
supabase__supabase/apps/studio/components/interfaces/UnifiedLogs/RowSelectionHeader.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

135 lines
4.9 KiB
TypeScript

import { AnimatePresence, motion } from 'framer-motion'
import { Copy, X } from 'lucide-react'
import { toast } from 'sonner'
import {
copyToClipboard,
DropdownMenu,
DropdownMenuContent,
DropdownMenuItem,
DropdownMenuTrigger,
} from 'ui'
import { type LogData } from '../Settings/Logs/Logs.types'
import {
buildLogsPrompt,
formatLogsAsJson,
formatLogsAsMarkdown,
} from '../Settings/Logs/Logs.utils'
import { SIDEBAR_KEYS } from '@/components/layouts/ProjectLayout/LayoutSidebar/LayoutSidebarProvider'
import { AiAssistantDropdown } from '@/components/ui/AiAssistantDropdown'
import { ButtonTooltip } from '@/components/ui/ButtonTooltip'
import { useDataTable } from '@/components/ui/DataTable/providers/DataTableProvider'
import { ShortcutBadge } from '@/components/ui/ShortcutBadge'
import { useAiAssistantStateSnapshot } from '@/state/ai-assistant-state'
import { SHORTCUT_IDS } from '@/state/shortcuts/registry'
import { useShortcut } from '@/state/shortcuts/useShortcut'
import { useSidebarManagerSnapshot } from '@/state/sidebar-manager-state'
// TODO - format Logs as JSON, as markdown, and as prompt
export const RowSelectionHeader = () => {
const { openSidebar } = useSidebarManagerSnapshot()
const aiSnap = useAiAssistantStateSnapshot()
const { table } = useDataTable()
const selectedRows = table.getSelectedRowModel().rows.map((x) => x.original) as LogData[]
const handleOpenAiAssistant = () => {
const prompt = buildLogsPrompt(selectedRows)
openSidebar(SIDEBAR_KEYS.AI_ASSISTANT)
aiSnap.newChat({ initialMessage: prompt })
}
const onCopy = (format: 'json' | 'markdown') => {
const text =
format === 'json' ? formatLogsAsJson(selectedRows) : formatLogsAsMarkdown(selectedRows)
copyToClipboard(text, () => {
toast.success(
`Copied ${selectedRows.length} log${selectedRows.length !== 1 ? 's' : ''} as ${format === 'json' ? format.toUpperCase() : format}`
)
})
}
const hasSelection = selectedRows.length > 0
useShortcut(SHORTCUT_IDS.RESULTS_COPY_JSON, () => onCopy('json'), {
enabled: hasSelection,
registerInCommandMenu: true,
})
useShortcut(SHORTCUT_IDS.RESULTS_COPY_MARKDOWN, () => onCopy('markdown'), {
enabled: hasSelection,
registerInCommandMenu: true,
})
return (
<div className="relative">
<AnimatePresence>
{selectedRows.length > 0 && (
<motion.div
initial={{ height: 0, opacity: 0 }}
animate={{ height: '36px', opacity: 1 }}
exit={{ height: 0, opacity: 0 }}
transition={{
type: 'spring',
stiffness: 420,
damping: 30,
mass: 0.4,
}}
className="pl-4 pr-2 flex items-center justify-between border-t absolute top-0 z-2 bg-surface-75 w-full"
style={{ overflow: 'hidden' }}
>
<p className="text-xs">
{selectedRows.length} row{selectedRows.length > 1 ? 's' : ''} selected
</p>
<div className="flex items-center justify-center gap-x-1.5">
<DropdownMenu>
<DropdownMenuTrigger asChild>
<ButtonTooltip
size="tiny"
icon={<Copy size={12} />}
className="w-7"
tooltip={{ content: { side: 'bottom', text: 'Copy selected logs' } }}
/>
</DropdownMenuTrigger>
<DropdownMenuContent align="end" className="w-44">
<DropdownMenuItem onClick={() => onCopy('json')} className="gap-2 text-xs">
<Copy size={13} />
Copy as JSON
<ShortcutBadge
shortcutId={SHORTCUT_IDS.RESULTS_COPY_JSON}
className="ml-auto"
/>
</DropdownMenuItem>
<DropdownMenuItem onClick={() => onCopy('markdown')} className="gap-2 text-xs">
<Copy size={13} />
Copy as Markdown
<ShortcutBadge
shortcutId={SHORTCUT_IDS.RESULTS_COPY_MARKDOWN}
className="ml-auto"
/>
</DropdownMenuItem>
</DropdownMenuContent>
</DropdownMenu>
<AiAssistantDropdown
label="Explain with AI"
buildPrompt={() => buildLogsPrompt(selectedRows)}
onOpenAssistant={handleOpenAiAssistant}
telemetrySource="log_explorer"
/>
<ButtonTooltip
variant="text"
icon={<X />}
className="px-1"
onClick={() => table.resetRowSelection()}
tooltip={{ content: { side: 'bottom', text: 'Clear selection' } }}
/>
</div>
</motion.div>
)}
</AnimatePresence>
</div>
)
}