mirror of
https://github.com/supabase/supabase.git
synced 2026-06-13 10:09:12 +08:00
## Summary Wires Linear-style keyboard shortcuts across all observability pages — refresh, time picker, filters, and sub-page navigation — with hover tooltips surfacing each binding. | Page | Shortcut | Action | | --- | --- | --- | | Overview | `Shift+R` | Refresh report | | Overview | `Shift+P` | Open time picker | | Query Performance | `Shift+R` | Refresh report | | Query Performance | `R` then `C` | Reset report (`pg_stat_statements_reset`) | | Query Performance | `Shift+F` | Search queries | | Query Performance | `F` then `C` | Reset filters | | API Gateway | `Shift+R` | Refresh report | | API Gateway | `Shift+P` | Open time picker | | API Gateway | `Shift+F` | Add filter | | API Gateway | `F` then `C` | Reset filters | | API Gateway | `Shift+S` | Filter requests by service | | Database | `Shift+R` | Refresh report | | Database | `Shift+P` | Open time picker | | Auth | `Shift+R` | Refresh report | | Auth | `Shift+P` | Open time picker | | Data API | `Shift+R` | Refresh report | | Data API | `Shift+P` | Open time picker | | Storage | `Shift+R` | Refresh report | | Storage | `Shift+P` | Open time picker | | Realtime | `Shift+R` | Refresh report | | Realtime | `Shift+P` | Open time picker | | Edge Functions | `Shift+R` | Refresh report | | Edge Functions | `Shift+P` | Open time picker | | All observability pages | `U` then `O/Q/G/D/P/A/F/S/L` | Jump to sub-page | ## Test plan - [ ] Each shortcut fires on its page; tooltip on hover shows the binding - [ ] Picker shortcut toggles the popover open/closed without leaving the tooltip visible - [ ] Reset-report on Query Performance opens the confirm modal - [ ] `Escape` on the query search clears the value, then blurs - [ ] No "Shift+R already registered" / Tooltip controlled-uncontrolled warnings in the console <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **New Features** * Keyboard shortcuts to navigate Observability pages and perform common actions (refresh, toggle date picker/interval, focus search, reset filters, create reports). * Shortcut hints shown on relevant buttons and controls; date pickers and interval dropdowns can be controlled via shortcuts. * Global shortcut groups/registries added for Observability navigation and page actions. <!-- review_stack_entry_start --> [](https://app.coderabbit.ai/change-stack/supabase/supabase/pull/46277?utm_source=github_walkthrough&utm_medium=github&utm_campaign=change_stack) <!-- review_stack_entry_end --> <!-- end of auto-generated comment: release notes by coderabbit.ai -->
284 lines
10 KiB
TypeScript
284 lines
10 KiB
TypeScript
import { PermissionAction } from '@supabase/shared-types/out/constants'
|
|
import { useFlag, useParams } from 'common'
|
|
import { Plus } from 'lucide-react'
|
|
import { useRouter } from 'next/router'
|
|
import { parseAsBoolean, useQueryState } from 'nuqs'
|
|
import { useMemo, useState } from 'react'
|
|
import { toast } from 'sonner'
|
|
import { Menu } from 'ui'
|
|
import { InnerSideBarEmptyPanel } from 'ui-patterns'
|
|
import ConfirmationModal from 'ui-patterns/Dialogs/ConfirmationModal'
|
|
import { ShimmeringLoader } from 'ui-patterns/ShimmeringLoader'
|
|
|
|
import { generateObservabilityMenuItems } from './ObservabilityMenu.utils'
|
|
import { ObservabilityMenuItem } from './ObservabilityMenuItem'
|
|
import { useSupamonitorStatus } from '@/components/interfaces/QueryPerformance/hooks/useSupamonitorStatus'
|
|
import { CreateReportModal } from '@/components/interfaces/Reports/CreateReportModal'
|
|
import { UpdateCustomReportModal } from '@/components/interfaces/Reports/UpdateModal'
|
|
import { ButtonTooltip } from '@/components/ui/ButtonTooltip'
|
|
import { ProductMenu } from '@/components/ui/ProductMenu'
|
|
import { ProductMenuShortcuts } from '@/components/ui/ProductMenu/ProductMenuShortcuts'
|
|
import { useContentDeleteMutation } from '@/data/content/content-delete-mutation'
|
|
import { Content, ContentBase, useContentQuery } from '@/data/content/content-query'
|
|
import { useAsyncCheckPermissions } from '@/hooks/misc/useCheckPermissions'
|
|
import { useIsFeatureEnabled } from '@/hooks/misc/useIsFeatureEnabled'
|
|
import { IS_PLATFORM } from '@/lib/constants'
|
|
import { useProfile } from '@/lib/profile'
|
|
import { SHORTCUT_IDS } from '@/state/shortcuts/registry'
|
|
import { useShortcut } from '@/state/shortcuts/useShortcut'
|
|
import type { Dashboards } from '@/types'
|
|
|
|
const ObservabilityMenu = () => {
|
|
const router = useRouter()
|
|
const { profile } = useProfile()
|
|
const { ref, id } = useParams()
|
|
const pageKey = (id || router.pathname.split('/')[4] || 'observability') as string
|
|
const showOverview = useFlag('observabilityOverview')
|
|
const { isSupamonitorEnabled } = useSupamonitorStatus()
|
|
|
|
const storageSupported = useIsFeatureEnabled('project_storage:all')
|
|
|
|
const { can: canCreateCustomReport } = useAsyncCheckPermissions(
|
|
PermissionAction.CREATE,
|
|
'user_content',
|
|
{
|
|
resource: { type: 'report', owner_id: profile?.id },
|
|
subject: { id: profile?.id },
|
|
}
|
|
)
|
|
|
|
// Preserve date range query parameters when navigating
|
|
const preservedQueryParams = useMemo(() => {
|
|
const { its, ite, isHelper, helperText } = router.query
|
|
const params = new URLSearchParams()
|
|
|
|
if (its && typeof its === 'string') params.set('its', its)
|
|
if (ite && typeof ite === 'string') params.set('ite', ite)
|
|
if (isHelper && typeof isHelper === 'string') params.set('isHelper', isHelper)
|
|
if (helperText && typeof helperText === 'string') params.set('helperText', helperText)
|
|
|
|
const queryString = params.toString()
|
|
return queryString ? `?${queryString}` : ''
|
|
}, [router.query])
|
|
|
|
const { data: content, isPending: isLoading } = useContentQuery({
|
|
projectRef: ref,
|
|
type: 'report',
|
|
})
|
|
const { mutate: deleteReport, isPending: isDeleting } = useContentDeleteMutation({
|
|
onSuccess: () => {
|
|
setDeleteModalOpen(false)
|
|
toast.success('Successfully deleted report')
|
|
router.push(`/project/${ref}/observability`)
|
|
},
|
|
onError: (error) => {
|
|
toast.error(`Failed to delete report: ${error.message}`)
|
|
},
|
|
})
|
|
|
|
const [deleteModalOpen, setDeleteModalOpen] = useState(false)
|
|
const [showNewReportModal, setShowNewReportModal] = useQueryState(
|
|
'newReport',
|
|
parseAsBoolean.withDefault(false).withOptions({ history: 'push', clearOnDefault: true })
|
|
)
|
|
const [selectedReportToDelete, setSelectedReportToDelete] = useState<Content>()
|
|
const [selectedReportToUpdate, setSelectedReportToUpdate] = useState<Content>()
|
|
|
|
const onConfirmDeleteReport = () => {
|
|
if (ref === undefined) return console.error('Project ref is required')
|
|
if (selectedReportToDelete?.id === undefined) return console.error('Report ID is required')
|
|
deleteReport({ projectRef: ref, ids: [selectedReportToDelete.id] })
|
|
}
|
|
|
|
function isReportContent(c: Content): c is ContentBase & {
|
|
type: 'report'
|
|
content: Dashboards.Content
|
|
} {
|
|
return c.type === 'report'
|
|
}
|
|
|
|
function getReportMenuItems() {
|
|
if (!content) return []
|
|
|
|
const reports = content?.content.filter(isReportContent)
|
|
|
|
const sortedReports = reports?.sort((a, b) => {
|
|
if (a.name < b.name) {
|
|
return -1
|
|
}
|
|
if (a.name > b.name) {
|
|
return 1
|
|
}
|
|
return 0
|
|
})
|
|
|
|
const reportMenuItems = sortedReports.map((r, idx) => ({
|
|
id: r.id,
|
|
name: r.name,
|
|
description: r.description || '',
|
|
key: r.id || idx + '-report',
|
|
url: `/project/${ref}/observability/${r.id}${preservedQueryParams}`,
|
|
hasDropdownActions: true,
|
|
report: r,
|
|
}))
|
|
|
|
return reportMenuItems
|
|
}
|
|
|
|
const reportMenuItems = getReportMenuItems()
|
|
|
|
const menuItems = generateObservabilityMenuItems({
|
|
ref,
|
|
preservedQueryParams,
|
|
showOverview,
|
|
isSupamonitorEnabled,
|
|
storageSupported,
|
|
isPlatform: IS_PLATFORM,
|
|
})
|
|
|
|
useShortcut(
|
|
SHORTCUT_IDS.OBSERVABILITY_NEW_REPORT,
|
|
() => {
|
|
setShowNewReportModal(true)
|
|
},
|
|
{ enabled: IS_PLATFORM && canCreateCustomReport }
|
|
)
|
|
|
|
return (
|
|
<div>
|
|
<ProductMenuShortcuts menu={menuItems} />
|
|
{isLoading ? (
|
|
<div className="px-5 my-4 space-y-2">
|
|
<ShimmeringLoader />
|
|
<ShimmeringLoader className="w-3/4" />
|
|
<ShimmeringLoader className="w-1/2" />
|
|
</div>
|
|
) : (
|
|
<div className="flex flex-col gap-y-6">
|
|
<ProductMenu
|
|
page={pageKey}
|
|
menu={menuItems.map((item) => ({
|
|
...item,
|
|
items: item.items.map((subItem) => ({ ...subItem, items: [] })),
|
|
}))}
|
|
/>
|
|
|
|
{IS_PLATFORM && (
|
|
<>
|
|
<div className="h-px w-full bg-border-overlay" />
|
|
<div className="mx-2">
|
|
<Menu type="pills">
|
|
<Menu.Group
|
|
title={
|
|
<span className="flex w-full items-center justify-between relative h-6">
|
|
<span className="uppercase font-mono">Custom Reports</span>
|
|
{reportMenuItems.length > 0 && (
|
|
<ButtonTooltip
|
|
type="default"
|
|
size="tiny"
|
|
icon={<Plus />}
|
|
disabled={!canCreateCustomReport}
|
|
className="flex items-center justify-center h-6 w-6 absolute top-0 -right-1"
|
|
onClick={() => {
|
|
setShowNewReportModal(true)
|
|
}}
|
|
tooltip={{
|
|
content: {
|
|
side: 'bottom',
|
|
text: !canCreateCustomReport
|
|
? 'You need additional permissions to create custom reports'
|
|
: undefined,
|
|
},
|
|
}}
|
|
/>
|
|
)}
|
|
</span>
|
|
}
|
|
/>
|
|
{reportMenuItems.length > 0 &&
|
|
reportMenuItems.map((item) => (
|
|
<ObservabilityMenuItem
|
|
key={item.id}
|
|
item={item}
|
|
pageKey={pageKey}
|
|
onSelectEdit={() => {
|
|
setSelectedReportToUpdate(item.report)
|
|
}}
|
|
onSelectDelete={() => {
|
|
setSelectedReportToDelete(item.report)
|
|
setDeleteModalOpen(true)
|
|
}}
|
|
/>
|
|
))}
|
|
</Menu>
|
|
{reportMenuItems.length === 0 ? (
|
|
<div className="px-2">
|
|
<InnerSideBarEmptyPanel
|
|
title="No custom reports yet"
|
|
description="Create and save custom reports to track your project metrics"
|
|
actions={
|
|
<ButtonTooltip
|
|
type="default"
|
|
icon={<Plus />}
|
|
disabled={!canCreateCustomReport}
|
|
onClick={() => {
|
|
setShowNewReportModal(true)
|
|
}}
|
|
tooltip={{
|
|
content: {
|
|
side: 'bottom',
|
|
text: !canCreateCustomReport
|
|
? 'You need additional permissions to create custom reports'
|
|
: undefined,
|
|
},
|
|
}}
|
|
>
|
|
New custom report
|
|
</ButtonTooltip>
|
|
}
|
|
/>
|
|
</div>
|
|
) : null}
|
|
</div>
|
|
</>
|
|
)}
|
|
|
|
<UpdateCustomReportModal
|
|
onCancel={() => setSelectedReportToUpdate(undefined)}
|
|
selectedReport={selectedReportToUpdate}
|
|
initialValues={{
|
|
name: selectedReportToUpdate?.name || '',
|
|
description: selectedReportToUpdate?.description || '',
|
|
}}
|
|
/>
|
|
|
|
<ConfirmationModal
|
|
title="Delete custom report"
|
|
confirmLabel="Delete report"
|
|
confirmLabelLoading="Deleting report"
|
|
size="medium"
|
|
loading={isDeleting}
|
|
visible={deleteModalOpen}
|
|
onCancel={() => setDeleteModalOpen(false)}
|
|
onConfirm={onConfirmDeleteReport}
|
|
>
|
|
<div className="text-sm text-foreground-light grid gap-4">
|
|
<div className="grid gap-1">
|
|
<p>Are you sure you want to delete '{selectedReportToDelete?.name}'?</p>
|
|
</div>
|
|
</div>
|
|
</ConfirmationModal>
|
|
|
|
<CreateReportModal
|
|
visible={showNewReportModal}
|
|
onCancel={() => setShowNewReportModal(false)}
|
|
afterSubmit={() => setShowNewReportModal(false)}
|
|
/>
|
|
</div>
|
|
)}
|
|
</div>
|
|
)
|
|
}
|
|
|
|
export default ObservabilityMenu
|