Skip to content

The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.

Support search storage in column view

Joshen Lim3bc95f41a69d
diff --git a/studio/components/to-be-cleaned/Storage/StorageExplorer/FileExplorerHeader.tsx b/studio/components/to-be-cleaned/Storage/StorageExplorer/FileExplorerHeader.tsx
index b83f20da943..2a21c297af8 100644
--- a/studio/components/to-be-cleaned/Storage/StorageExplorer/FileExplorerHeader.tsx
+++ b/studio/components/to-be-cleaned/Storage/StorageExplorer/FileExplorerHeader.tsx
@@ -25,7 +25,7 @@ import { useCheckPermissions } from 'hooks'
import { useStorageStore } from 'localStores/storageExplorer/StorageExplorerStore'
import { STORAGE_SORT_BY, STORAGE_SORT_BY_ORDER, STORAGE_VIEWS } from '../Storage.constants'
-const HeaderPathEdit = ({ loading, breadcrumbs, togglePathEdit }: any) => {
+const HeaderPathEdit = ({ loading, isSearching, breadcrumbs, togglePathEdit }: any) => {
return (
<div
className={`group ${!loading ? 'cursor-pointer' : ''}`}
@@ -39,18 +39,20 @@ const HeaderPathEdit = ({ loading, breadcrumbs, togglePathEdit }: any) => {
) : (
<div className="flex cursor-pointer items-center">
<p className="ml-3 text-sm truncate">{breadcrumbs[breadcrumbs.length - 1] || ''}</p>
- <div className="ml-3 flex items-center space-x-2 opacity-0 transition group-hover:opacity-100">
- <Button type="text" icon={<IconEdit2 />}>
- Navigate
- </Button>
- </div>
+ {!isSearching && (
+ <div className="ml-3 flex items-center space-x-2 opacity-0 transition group-hover:opacity-100">
+ <Button type="text" icon={<IconEdit2 />}>
+ Navigate
+ </Button>
+ </div>
+ )}
</div>
)}
</div>
)
}
-const HeaderBreadcrumbs = ({ loading, breadcrumbs, selectBreadcrumb }: any) => {
+const HeaderBreadcrumbs = ({ loading, isSearching, breadcrumbs, selectBreadcrumb }: any) => {
// Max 5 crumbs, otherwise replace middle segment with ellipsis and only
// have the first 2 and last 2 crumbs visible
const ellipsis = '...'
@@ -77,7 +79,7 @@ const HeaderBreadcrumbs = ({ loading, breadcrumbs, selectBreadcrumb }: any) => {
<p className="ml-3 text-sm">{loading.message}</p>
</div>
) : (
- <div className="ml-3 flex items-center">
+ <div className={`ml-3 flex items-center ${isSearching && 'max-w-[140px] overflow-x-auto'}`}>
{formattedBreadcrumbs.map((crumb: any, idx: number) => (
<div className="flex items-center" key={crumb.name}>
{idx !== 0 && <IconChevronRight size={10} strokeWidth={2} className="mx-3" />}
@@ -258,6 +260,7 @@ const FileExplorerHeader = ({
}}
/>
)}
+ {!isSearching && <></>}
{isEditingPath ? (
<form className="ml-2 flex-grow">
<Input
@@ -291,12 +294,14 @@ const FileExplorerHeader = ({
) : view === STORAGE_VIEWS.COLUMNS ? (
<HeaderPathEdit
loading={loading}
+ isSearching={isSearching}
breadcrumbs={breadcrumbs}
togglePathEdit={togglePathEdit}
/>
) : (
<HeaderBreadcrumbs
loading={loading}
+ isSearching={isSearching}
breadcrumbs={breadcrumbs}
selectBreadcrumb={selectBreadcrumb}
/>
@@ -455,42 +460,38 @@ const FileExplorerHeader = ({
</Tooltip.Root>
</div>
- {/* Search: Disabled for now */}
- {view === STORAGE_VIEWS.LIST && (
- <>
- <div className="h-6 border-r border-panel-border-light dark:border-panel-border-dark" />
- <div className="flex items-center">
- {isSearching ? (
- <Input
- size="tiny"
- autoFocus
- className="w-52"
- icon={<IconSearch size={'tiny'} strokeWidth={2} />}
- actions={[
- <IconX
- key="close"
- className="mx-2 cursor-pointer text-scale-1200"
- size="tiny"
- strokeWidth={2}
- onClick={onCancelSearch}
- />,
- ]}
- placeholder="Search for a file or folder"
- type="text"
- value={searchString}
- onChange={onSearchInputUpdate}
- />
- ) : (
- <Button
- icon={<IconSearch size={16} strokeWidth={2} />}
+ <div className="h-6 border-r border-scale-600" />
+ <div className="flex items-center pr-1.5">
+ {isSearching ? (
+ <Input
+ size="tiny"
+ autoFocus
+ className="w-52"
+ icon={<IconSearch size={'tiny'} strokeWidth={2} />}
+ actions={[
+ <IconX
+ key="close"
+ className="mx-2 cursor-pointer text-scale-1200"
size="tiny"
- type="text"
- onClick={toggleSearch}
- />
- )}
- </div>
- </>
- )}
+ strokeWidth={2}
+ onClick={onCancelSearch}
+ />,
+ ]}
+ placeholder="Search for a file or folder"
+ type="text"
+ value={searchString}
+ onChange={onSearchInputUpdate}
+ />
+ ) : (
+ <Button
+ icon={<IconSearch size={16} strokeWidth={2} />}
+ size="tiny"
+ type="text"
+ className="px-1"
+ onClick={toggleSearch}
+ />
+ )}
+ </div>
</div>
</div>
)
diff --git a/studio/components/to-be-cleaned/Storage/StorageExplorer/StorageExplorer.tsx b/studio/components/to-be-cleaned/Storage/StorageExplorer/StorageExplorer.tsx
index 99e343cf459..23a2ea788de 100644
--- a/studio/components/to-be-cleaned/Storage/StorageExplorer/StorageExplorer.tsx
+++ b/studio/components/to-be-cleaned/Storage/StorageExplorer/StorageExplorer.tsx
@@ -10,7 +10,7 @@ import { useStore } from 'hooks'
import { DEFAULT_PROJECT_API_SERVICE_ID, IS_PLATFORM } from 'lib/constants'
import { copyToClipboard } from 'lib/helpers'
import { useStorageStore } from 'localStores/storageExplorer/StorageExplorerStore'
-import { STORAGE_ROW_TYPES } from '../Storage.constants'
+import { STORAGE_ROW_TYPES, STORAGE_VIEWS } from '../Storage.constants'
import ConfirmDeleteModal from './ConfirmDeleteModal'
import CustomExpiryModal from './CustomExpiryModal'
import FileExplorer from './FileExplorer'
@@ -42,10 +42,12 @@ const StorageExplorer = ({ bucket }: StorageExplorerProps) => {
view,
currentBucketName,
openBucket,
+ selectedBucket,
loadExplorerPreferences,
fetchFolderContents,
fetchMoreFolderContents,
+ fetchFoldersByPath,
deleteFolder,
uploadFiles,
deleteFiles,
@@ -78,28 +80,33 @@ const StorageExplorer = ({ bucket }: StorageExplorerProps) => {
// eslint-disable-next-line react-hooks/exhaustive-deps
useEffect(() => {
const fetchContents = async () => {
- const currentFolderIdx = openedFolders.length - 1
- const currentFolder = openedFolders[currentFolderIdx]
+ if (view === STORAGE_VIEWS.LIST) {
+ const currentFolderIdx = openedFolders.length - 1
+ const currentFolder = openedFolders[currentFolderIdx]
- if (itemSearchString) {
- if (!currentFolder) {
- // At root of bucket
- await fetchFolderContents(bucket.id, bucket.name, -1, itemSearchString)
- } else {
- await fetchFolderContents(
- currentFolder.id,
- currentFolder.name,
- currentFolderIdx,
- itemSearchString
- )
- }
- } else {
- if (!currentFolder) {
- // At root of bucket
- await fetchFolderContents(bucket.id, bucket.name, -1)
+ if (itemSearchString) {
+ if (!currentFolder) {
+ // At root of bucket
+ await fetchFolderContents(bucket.id, bucket.name, -1, itemSearchString)
+ } else {
+ await fetchFolderContents(
+ currentFolder.id,
+ currentFolder.name,
+ currentFolderIdx,
+ itemSearchString
+ )
+ }
} else {
- await fetchFolderContents(currentFolder.id, currentFolder.name, currentFolderIdx)
+ if (!currentFolder) {
+ // At root of bucket
+ await fetchFolderContents(bucket.id, bucket.name, -1)
+ } else {
+ await fetchFolderContents(currentFolder.id, currentFolder.name, currentFolderIdx)
+ }
}
+ } else if (view === STORAGE_VIEWS.COLUMNS) {
+ const paths = openedFolders.map((folder: any) => folder.name)
+ fetchFoldersByPath(paths, itemSearchString)
}
}
diff --git a/studio/localStores/storageExplorer/StorageExplorerStore.js b/studio/localStores/storageExplorer/StorageExplorerStore.js
index 68d96640c11..d5d3ddf17e1 100644
--- a/studio/localStores/storageExplorer/StorageExplorerStore.js
+++ b/studio/localStores/storageExplorer/StorageExplorerStore.js
@@ -1088,21 +1088,26 @@ class StorageExplorerStore {
/* Folders CRUD */
fetchFolderContents = async (folderId, folderName, index, searchString = '') => {
- this.abortApiCalls()
+ if (this.selectedBucket.id === undefined) return
+ this.abortApiCalls()
this.updateRowStatus(folderName, STORAGE_ROW_STATUS.LOADING, index)
this.pushColumnAtIndex(
{ id: folderId, name: folderName, status: STORAGE_ROW_STATUS.LOADING, items: [] },
index
)
- const prefix = this.openedFolders.map((folder) => folder.name).join('/')
+ const prefix = this.openedFolders
+ .slice(0, index + 1)
+ .map((folder) => folder.name)
+ .join('/')
const options = {
limit: LIMIT,
offset: OFFSET,
search: searchString,
sortBy: { column: this.sortBy, order: this.sortByOrder },
}
+
const res = await post(
`${this.endpoint}/buckets/${this.selectedBucket.id}/objects/list`,
{ path: prefix, options },
@@ -1177,7 +1182,9 @@ class StorageExplorerStore {
await this.fetchFoldersByPath(paths)
}
- fetchFoldersByPath = async (paths) => {
+ fetchFoldersByPath = async (paths, searchString = '') => {
+ if (this.selectedBucket.id === undefined) return
+
const pathsWithEmptyPrefix = [''].concat(paths)
const foldersItems = await Promise.all(
@@ -1186,6 +1193,7 @@ class StorageExplorerStore {
const options = {
limit: LIMIT,
offset: OFFSET,
+ search: searchString,
sortBy: { column: this.sortBy, order: this.sortByOrder },
}