Files
Ali WaseemandDanny White 712cf7e60b feat(storage): add keyboard shortcuts for storage screens (#45837)
## Summary

Adds keyboard shortcuts to the Storage section, mirroring the
conventions already established for Auth Users and Database pages:

- **Storage navigation chords** (`S, F` / `S, A` / `S, V` / `S, 3`)
active only inside `StorageLayout`.
- **Files (bucket list) page** shortcuts for search, create, refresh,
reset filters, reset sort.
- **Storage Explorer** shortcuts for upload, new folder, view toggle,
refresh, search, multi-select download/move/delete, and an Escape
ladder.
- `ShortcutTooltip` wired into the relevant buttons so users can
discover keybinds on hover.
- Reload spinner is now driven by a shared store flag, so it shows
whether you click the button or fire the shortcut.

## Test plan

### Storage navigation chords
Active anywhere under `/project/<ref>/storage/*`.

| Keybind | Action |
|---------|--------|
| `S` then `F` | Go to Files |
| `S` then `A` | Go to Analytics buckets (platform + feature-flagged) |
| `S` then `V` | Go to Vector buckets (platform + feature-flagged) |
| `S` then `3` | Go to S3 settings (platform only) |

### Files (bucket list) page
At `/project/<ref>/storage/files`.

| Keybind | Action | Notes |
|---------|--------|-------|
| `Shift+F` | Focus search ("Search buckets") | Selects existing text |
| `Shift+N` | Create new bucket | Opens the create-bucket modal |
| `F` then `C` | Reset filters | Clears the search string |
| `Shift+R` | Refresh buckets | Refetches the bucket list |
| `S` then `C` | Reset bucket sort | Only fires when sort ≠ default
(Created at) |

### Storage Explorer (inside a bucket)
At `/project/<ref>/storage/files/buckets/<bucketId>`.

| Keybind | Action | Notes |
|---------|--------|-------|
| `Shift+F` | Focus search ("Search files") | Opens the search input if
hidden, then focuses |
| `Shift+R` | Refresh | Refetches all opened folders; spinner reflects
state |
| `I` then `F` | Upload files | Disabled w/o ` STORAGE_WRITE ` or at
bucket root with no folder |
| `I` then `N` | Create folder | Same permission gates as Upload |
| `V` then `C` | View as columns | |
| `V` then `L` | View as list | |
| `Shift+D` | Download selected | Only fires when ≥1 item selected;
single vs many handled |
| `Shift+M` | Move selected | Only fires when ≥1 item selected AND `
STORAGE_WRITE ` granted |
| `Mod+Backspace` | Delete selected | Only fires when ≥1 item selected
(` Mod ` = ⌘ on macOS / ` Ctrl ` on Win/Linux) |
| `Escape` | Clear selection | If ≥1 item selected |
| `Escape` | Close file preview | If no selection and preview pane open
|
| `Escape` | Close search | If no selection, no preview, and search is
open |

### Tips while testing
- [x] Chords (two-key sequences): press the first key, release, then
press the second key within ~1s
- [x] Hover any wired button (search, Refresh, Upload, Create folder,
View, Download, Move, Delete, the bucket Create button, sidebar items)
to see the keybind in a tooltip
- [x] Most actions also appear under "Shortcuts" in `Cmd+P`
- [x] Chords starting with a plain letter (` S, F ` / ` I, F ` / ` V, C
` / ` F, C ` / ` S, C `) won't fire while typing in an input — click out
first
- [x] `Escape` does fire from inside the search field (closes the
search)
- [x] `Cmd+/` opens the full shortcuts reference

<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit

* **New Features**
* Keyboard shortcuts added across Storage: buckets (refresh, clear sort,
create, search), explorer (upload, create folder, refresh, download,
move, delete, clear search), and navigation shortcuts for
Files/Analytics/Vectors/S3.
* **UI**
* Shortcut keytips/tooltips added to relevant buttons and menu items for
discoverability.
* **Documentation/Tests**
  * Shortcut reference sheet labels updated and covered by a new test.

[![Review Change
Stack](https://storage.googleapis.com/coderabbit_public_assets/review-stack-in-coderabbit-ui.svg)](https://app.coderabbit.ai/change-stack/supabase/supabase/pull/45837)
<!-- end of auto-generated comment: release notes by coderabbit.ai -->

---------

Co-authored-by: Danny White <3104761+dnywh@users.noreply.github.com>
2026-05-13 08:26:04 -06:00

212 lines
8.7 KiB
TypeScript

import { useDebounce } from '@uidotdev/usehooks'
import { useParams } from 'common'
import { ArrowDownNarrowWide, RefreshCw, Search } from 'lucide-react'
import { parseAsBoolean, useQueryState } from 'nuqs'
import { useCallback, useMemo, useRef, useState } from 'react'
import {
Button,
Card,
DropdownMenu,
DropdownMenuContent,
DropdownMenuRadioGroup,
DropdownMenuRadioItem,
DropdownMenuTrigger,
} from 'ui'
import { Admonition } from 'ui-patterns'
import { Input } from 'ui-patterns/DataInputs/Input'
import { PageContainer } from 'ui-patterns/PageContainer'
import { PageSection, PageSectionContent } from 'ui-patterns/PageSection'
import { GenericSkeletonLoader } from 'ui-patterns/ShimmeringLoader'
import { CreateBucketModal } from '../CreateBucketModal'
import { EmptyBucketState } from '../EmptyBucketState'
import { CreateBucketButton } from '../NewBucketButton'
import { STORAGE_BUCKET_SORT } from '../Storage.constants'
import { useStoragePreference } from '../StorageExplorer/useStoragePreference'
import { BucketsTable } from './BucketsTable'
import { useFilesBucketsShortcuts } from './useFilesBucketsShortcuts'
import AlertError from '@/components/ui/AlertError'
import { InlineLink } from '@/components/ui/InlineLink'
import { ShortcutTooltip } from '@/components/ui/ShortcutTooltip'
import { useProjectStorageConfigQuery } from '@/data/config/project-storage-config-query'
import { usePaginatedBucketsQuery } from '@/data/storage/buckets-query'
import { IS_PLATFORM } from '@/lib/constants'
import { formatBytes } from '@/lib/helpers'
import { SHORTCUT_IDS } from '@/state/shortcuts/registry'
import { useStorageExplorerStateSnapshot } from '@/state/storage-explorer'
export const FilesBuckets = () => {
const { ref } = useParams()
const snap = useStorageExplorerStateSnapshot()
const { sortBucket, setSortBucket } = useStoragePreference(snap.projectRef)
const searchInputRef = useRef<HTMLInputElement>(null)
const [filterString, setFilterString] = useState('')
const debouncedFilterString = useDebounce(filterString, 250)
const normalizedSearch = debouncedFilterString.trim()
const sortColumn = sortBucket === STORAGE_BUCKET_SORT.ALPHABETICAL ? 'name' : 'created_at'
const sortOrder = sortBucket === STORAGE_BUCKET_SORT.ALPHABETICAL ? 'asc' : 'desc'
const [visible, setVisible] = useQueryState(
'new',
parseAsBoolean.withDefault(false).withOptions({ history: 'push', clearOnDefault: true })
)
const { data } = useProjectStorageConfigQuery({ projectRef: ref }, { enabled: IS_PLATFORM })
const {
data: bucketsData,
error: bucketsError,
isError: isErrorBuckets,
isPending: isLoadingBuckets,
isSuccess: isSuccessBuckets,
isFetching: isFetchingBuckets,
fetchNextPage,
hasNextPage,
refetch: refetchBuckets,
} = usePaginatedBucketsQuery({
projectRef: ref,
search: normalizedSearch.length > 0 ? normalizedSearch : undefined,
sortColumn,
sortOrder,
})
const buckets = useMemo(() => bucketsData?.pages.flatMap((page) => page) ?? [], [bucketsData])
const fileBuckets = buckets.filter((bucket) => !('type' in bucket) || bucket.type === 'STANDARD')
const hasNoBuckets = fileBuckets.length === 0 && normalizedSearch.length === 0
const formattedGlobalUploadLimit = formatBytes(data?.fileSizeLimit ?? 0)
const hasNoApiKeys =
isErrorBuckets && bucketsError.message.includes('Project has no active API keys')
const handleLoadMoreBuckets = useCallback(() => {
if (hasNextPage && !isFetchingBuckets) {
fetchNextPage()
}
}, [hasNextPage, isFetchingBuckets, fetchNextPage])
const handleRefresh = useCallback(() => {
refetchBuckets()
}, [refetchBuckets])
useFilesBucketsShortcuts({
searchInputRef,
setFilterString,
sortBucket,
setSortBucket,
setCreateVisible: setVisible,
onRefresh: handleRefresh,
})
return (
<>
<PageContainer>
<PageSection>
<PageSectionContent className="h-full gap-y-4">
{isLoadingBuckets && <GenericSkeletonLoader />}
{isErrorBuckets && (
<>
{hasNoApiKeys ? (
<Admonition type="warning" title="Project has no active API keys enabled">
<p className="leading-normal! text-sm">
The Dashboard relies on having active API keys on the project to function. If
you'd like to use Storage through the Dashboard, create a set of API keys{' '}
<InlineLink href={`/project/${ref}/settings/api-keys/new`}>here</InlineLink>.
</p>
</Admonition>
) : (
<AlertError error={bucketsError} subject="Failed to retrieve buckets" />
)}
</>
)}
{isSuccessBuckets && (
<>
{hasNoBuckets ? (
<EmptyBucketState bucketType="files" onCreateBucket={() => setVisible(true)} />
) : (
<>
<div className="flex grow justify-between gap-x-2 items-center mb-4">
<div className="flex items-center gap-x-2">
<ShortcutTooltip
shortcutId={SHORTCUT_IDS.LIST_PAGE_FOCUS_SEARCH}
label="Search buckets"
side="bottom"
>
<Input
ref={searchInputRef}
size="tiny"
className="grow lg:grow-0 w-52"
placeholder="Search for a bucket"
value={filterString}
onChange={(e) => setFilterString(e.target.value)}
icon={<Search />}
/>
</ShortcutTooltip>
<DropdownMenu>
<DropdownMenuTrigger asChild>
<Button type="default" icon={<ArrowDownNarrowWide />}>
Sorted by {sortBucket === 'alphabetical' ? 'name' : 'created at'}
</Button>
</DropdownMenuTrigger>
<DropdownMenuContent align="start" className="w-40">
<DropdownMenuRadioGroup
value={sortBucket}
onValueChange={(value) => setSortBucket(value as STORAGE_BUCKET_SORT)}
>
<DropdownMenuRadioItem value="alphabetical">
Sort by name
</DropdownMenuRadioItem>
<DropdownMenuRadioItem value="created_at">
Sort by created at
</DropdownMenuRadioItem>
</DropdownMenuRadioGroup>
</DropdownMenuContent>
</DropdownMenu>
<ShortcutTooltip
shortcutId={SHORTCUT_IDS.STORAGE_BUCKETS_REFRESH}
side="bottom"
>
<Button
type="default"
icon={<RefreshCw />}
loading={isFetchingBuckets}
onClick={handleRefresh}
>
Refresh
</Button>
</ShortcutTooltip>
</div>
<ShortcutTooltip
shortcutId={SHORTCUT_IDS.LIST_PAGE_NEW_ITEM}
label="Create new bucket"
side="bottom"
>
<CreateBucketButton onClick={() => setVisible(true)} />
</ShortcutTooltip>
</div>
<Card>
<BucketsTable
buckets={fileBuckets}
projectRef={ref ?? '_'}
filterString={filterString}
formattedGlobalUploadLimit={formattedGlobalUploadLimit}
pagination={{
hasMore: hasNextPage,
isLoadingMore: isFetchingBuckets,
onLoadMore: handleLoadMoreBuckets,
}}
/>
</Card>
</>
)}
</>
)}
</PageSectionContent>
</PageSection>
</PageContainer>
<CreateBucketModal open={visible} onOpenChange={setVisible} />
</>
)
}