mirror of
https://github.com/supabase/supabase.git
synced 2026-06-15 08:05:21 +08:00
Closes [FE-3378](https://linear.app/supabase/issue/FE-3378/featlogs-keyboard-shortcuts-for-function-logs-invocations-and-logs). ## Summary Adds a shared shortcut registry for every `LogsPreviewer` surface — Function Logs, Function Invocations, and the Logs Explorer — and brings the grid keyboard model in line with the Auth Users / Table Editor patterns. ## Shortcuts | Key | Action | | --- | --- | | `↑` / `↓` | Move single-row selection; opens side panel | | `Shift+Space` | Toggle current row in multi-select | | `Mod+A` | Toggle all visible rows in multi-select | | `Esc` | Staged: clear multi-select → close side panel | | `Shift+R` | Refresh logs | | `Shift+H` | Toggle histogram | | `Shift+L` | Load older logs | | `Shift+P` | Open time range picker | | `Mod+Shift+J / M / C` | Copy selected rows as JSON / Markdown / CSV (existing global handler) | ## Other changes - `ShortcutTooltip` on search, refresh, histogram, load older, and time-picker controls. - `onSearchInputEscape` wired on the logs search bar (clear → blur). - Visual row highlight (`rdg-row--focused`) when a row is keyboard-focused or multi-selected. - Multi-select copy dropdown gains a **Copy as CSV** entry and shows the keybind on each item via `ShortcutBadge`. - Manual arrow-nav (`navigate()`) updates `selectedRow` directly without going through `onRowClick`, so multi-select checkmarks survive keyboard navigation. ## Test plan - [x] Function Logs and Function Invocations: all shortcuts above fire while the page is mounted, no firing in other tabs. - [x] Logs Explorer: same shortcuts work; copy keybinds still copy *all* rows when nothing is multi-selected. - [x] Arrow keys on first load select the first row even when the focus sink is the active element. - [x] Selecting rows via checkbox or `Shift+Space`, then pressing arrow keys, preserves the checkmarks. - [x] Escape on a populated search input clears it; Escape on an empty input blurs it. - [x] Esc with multi-select active clears the selection before closing the side panel. <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **New Features** * CSV export for log selections (adds CSV alongside JSON and Markdown). * New logs-preview keyboard shortcuts: search focus, refresh, chart toggle, date picker, load older, navigation, and selection. * **Improvements** * Shortcut badges and tooltip integration across the logs UI. * Search input focus/ref support and controlled date-picker visibility. * Better no-results/error rendering and expanded copy dropdown sizing. * **Tests** * Added CSV formatting tests covering RFC 4180 edge cases. <!-- review_stack_entry_start --> [](https://app.coderabbit.ai/change-stack/supabase/supabase/pull/45989) <!-- review_stack_entry_end --> <!-- end of auto-generated comment: release notes by coderabbit.ai -->
110 lines
3.7 KiB
TypeScript
110 lines
3.7 KiB
TypeScript
import { Check, ChevronDown, Copy, X as XIcon } from 'lucide-react'
|
|
import {
|
|
Button,
|
|
DropdownMenu,
|
|
DropdownMenuContent,
|
|
DropdownMenuItem,
|
|
DropdownMenuTrigger,
|
|
} from 'ui'
|
|
|
|
import type { LogData, QueryType } from './Logs.types'
|
|
import { buildLogsPrompt } from './Logs.utils'
|
|
import { SIDEBAR_KEYS } from '@/components/layouts/ProjectLayout/LayoutSidebar/LayoutSidebarProvider'
|
|
import { AiAssistantDropdown } from '@/components/ui/AiAssistantDropdown'
|
|
import { ShortcutBadge } from '@/components/ui/ShortcutBadge'
|
|
import { useAiAssistantStateSnapshot } from '@/state/ai-assistant-state'
|
|
import { SHORTCUT_IDS } from '@/state/shortcuts/registry'
|
|
import { useSidebarManagerSnapshot } from '@/state/sidebar-manager-state'
|
|
|
|
export type LogCopyFormat = 'json' | 'markdown' | 'csv'
|
|
|
|
interface MultiSelectActionBarProps {
|
|
selectedRows: Set<string>
|
|
selectedRowsData: LogData[]
|
|
copiedFormat: LogCopyFormat | null
|
|
onCopy: (format: LogCopyFormat) => void
|
|
onClear: () => void
|
|
queryType?: QueryType
|
|
sqlQuery?: string
|
|
}
|
|
|
|
export function MultiSelectActionBar({
|
|
selectedRows,
|
|
selectedRowsData,
|
|
copiedFormat,
|
|
onCopy,
|
|
onClear,
|
|
queryType,
|
|
sqlQuery,
|
|
}: MultiSelectActionBarProps) {
|
|
const { openSidebar } = useSidebarManagerSnapshot()
|
|
const aiSnap = useAiAssistantStateSnapshot()
|
|
|
|
function handleOpenAiAssistant() {
|
|
const prompt = buildLogsPrompt(selectedRowsData, queryType, sqlQuery)
|
|
openSidebar(SIDEBAR_KEYS.AI_ASSISTANT)
|
|
aiSnap.newChat({ initialMessage: prompt })
|
|
}
|
|
const count = selectedRows.size
|
|
if (count === 0) return null
|
|
|
|
return (
|
|
<div
|
|
className="flex items-center gap-2 px-3 py-1.5 border-b bg-surface-200 text-sm sticky top-0 z-10"
|
|
style={{ height: 40 }}
|
|
>
|
|
<span className="text-foreground-light font-mono text-xs">
|
|
{count} row{count !== 1 ? 's' : ''} selected
|
|
</span>
|
|
|
|
<div className="flex items-center gap-1 ml-auto">
|
|
<DropdownMenu>
|
|
<DropdownMenuTrigger asChild>
|
|
<Button
|
|
type="default"
|
|
size="tiny"
|
|
icon={copiedFormat ? <Check size={12} className="text-brand" /> : <Copy size={12} />}
|
|
iconRight={<ChevronDown size={11} />}
|
|
>
|
|
{copiedFormat ? 'Copied!' : 'Copy'}
|
|
</Button>
|
|
</DropdownMenuTrigger>
|
|
<DropdownMenuContent align="end" className="w-60">
|
|
<DropdownMenuItem onClick={() => onCopy('json')} className="gap-x-2">
|
|
<Copy size={13} />
|
|
<p>Copy as JSON</p>
|
|
<ShortcutBadge shortcutId={SHORTCUT_IDS.RESULTS_COPY_JSON} className="ml-auto" />
|
|
</DropdownMenuItem>
|
|
<DropdownMenuItem onClick={() => onCopy('markdown')} className="gap-x-2">
|
|
<Copy size={13} />
|
|
<p>Copy as Markdown</p>
|
|
<ShortcutBadge shortcutId={SHORTCUT_IDS.RESULTS_COPY_MARKDOWN} className="ml-auto" />
|
|
</DropdownMenuItem>
|
|
<DropdownMenuItem onClick={() => onCopy('csv')} className="gap-x-2">
|
|
<Copy size={13} />
|
|
<p>Copy as CSV</p>
|
|
<ShortcutBadge shortcutId={SHORTCUT_IDS.RESULTS_COPY_CSV} className="ml-auto" />
|
|
</DropdownMenuItem>
|
|
</DropdownMenuContent>
|
|
</DropdownMenu>
|
|
|
|
<AiAssistantDropdown
|
|
label="Explain with AI"
|
|
buildPrompt={() => buildLogsPrompt(selectedRowsData, queryType, sqlQuery)}
|
|
onOpenAssistant={handleOpenAiAssistant}
|
|
telemetrySource="log_explorer"
|
|
/>
|
|
|
|
<Button
|
|
type="text"
|
|
size="tiny"
|
|
icon={<XIcon size={12} />}
|
|
onClick={onClear}
|
|
title="Clear selection"
|
|
className="text-foreground-lighter px-1.5 hover:text-foreground"
|
|
/>
|
|
</div>
|
|
</div>
|
|
)
|
|
}
|