Files
Alaister YoungandAlaister Young ca2b50a0a7 chore(ui-patterns): collapse the admonition shim into ui-patterns/Admonition (#48377)
Follow-up to #48344: collapses the two resolution paths for the
Admonition module into one.

`src/admonition.tsx` was a back-compat shim re-exporting
`src/Admonition/`. Two ways to resolve one module is exactly what
produced the macOS self-import bug fixed in #48344, and the local
typecheck errors that #48374 worked around. This removes the shim and
standardizes on the PascalCase subpath, matching every other export in
the package.

**Changed:**

- Codemodded all 246 `ui-patterns/admonition` imports to
`ui-patterns/Admonition` (240 `.tsx`, 5 `.mdx`, 1 `.ts` across studio,
docs, www, design-system, and lite-studio)
- Pointed the 5 internal `'../admonition'` imports back at the
`'../Admonition'` directory

**Removed:**

- `packages/ui-patterns/src/admonition.tsx`, and its `./admonition`
entry in the exports map (regenerated with `pnpm gen:exports`)

## To test

- `grep -r "ui-patterns/admonition" --include='*.ts*'` → no hits
- `pnpm test:case-hazards` → passes
- `pnpm typecheck` → all 15 tasks green
- `pnpm --filter studio run lint:ratchet` → passes
- `pnpm --filter ui-patterns vitest run src/Admonition` → 11 tests pass

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

## Summary by CodeRabbit

* **Bug Fixes**
* Standardized Admonition component imports across the application and
documentation.
* Improved compatibility with case-sensitive environments by using the
canonical component path.
  * Removed the legacy Admonition import entry point.

<!-- end of auto-generated comment: release notes by coderabbit.ai -->

---------

Co-authored-by: Alaister Young <10985857+alaister@users.noreply.github.com>
2026-07-29 00:48:56 +08: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/Admonition'
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 variant="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
variant="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} />
</>
)
}