mirror of
https://github.com/supabase/supabase.git
synced 2026-10-17 15:19:08 +03:00
Adds the final set of keyboard shortcuts to the Unified Logs page and converts the last hardcoded `keydown` listener (detail-panel prev/next) to the shared shortcut registry. Each action also surfaces its keybind in a registry-driven tooltip. Closes FE-3415. ## Shortcuts | Action | Shortcut | Notes | | --- | --- | --- | | Refresh logs | `Shift+R` | new | | Download logs | `Shift+E` | new — opens export dropdown | | Focus filter bar | `Shift+F` | new | | Clear filters | `F` then `C` | new | | Copy selected as JSON | `Mod+Shift+J` | new — reuses `results.copy-json` | | Copy selected as Markdown | `Mod+Shift+M` | new — reuses `results.copy-markdown` | | Previous / next log (detail panel) | `↑` / `↓` | converted from hardcoded listener | | Close details panel | `Escape` | new | Existing shared `data-table.*` shortcuts kept as-is: toggle sidebar (`Mod+B`), live mode (`Mod+J`), reset filters (`Mod+Esc`), reset columns (`Mod+U`), reset focus (`Mod+.`). <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **New Features** * Added keyboard shortcuts for Unified Logs: copy selected rows as JSON/Markdown, navigate rows, refresh, clear/reset filters, download, and focus filter — shortcuts show in the command menu and display badges/hints in menus and buttons. * **Refactor** * Shortcut handling unified across log controls; shortcuts enable/disable based on context and a new "Logs" group appears in the shortcut reference. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
136 lines
4.9 KiB
TypeScript
136 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
|
|
type="default"
|
|
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
|
|
type="text"
|
|
icon={<X />}
|
|
className="px-1"
|
|
onClick={() => table.resetRowSelection()}
|
|
tooltip={{ content: { side: 'bottom', text: 'Clear selection' } }}
|
|
/>
|
|
</div>
|
|
</motion.div>
|
|
)}
|
|
</AnimatePresence>
|
|
</div>
|
|
)
|
|
}
|