Skip to content

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

Further simplify FileExplorerHeader

Joshen Limf33bedba2616
diff --git a/studio/components/to-be-cleaned/Storage/StorageExplorer/FileExplorerHeader.tsx b/studio/components/to-be-cleaned/Storage/StorageExplorer/FileExplorerHeader.tsx
index 6140e69c11e..e4ab9f3e40e 100644
--- a/studio/components/to-be-cleaned/Storage/StorageExplorer/FileExplorerHeader.tsx
+++ b/studio/components/to-be-cleaned/Storage/StorageExplorer/FileExplorerHeader.tsx
@@ -92,31 +92,26 @@ const HeaderBreadcrumbs = ({ loading, breadcrumbs, selectBreadcrumb }: any) => {
}
interface Props {
- loading: { isLoading: boolean; message: string }
isSearching: boolean
itemSearchString: string
+ setIsSearching: (value: boolean) => void
setItemSearchString: (value: string) => void
- onSetPathByString: (paths: any[]) => void
- onToggleSearch: (bool: boolean) => void
onFilesUpload: (event: any, columnIndex: number) => void
- onSelectBack: () => void
}
const FileExplorerHeader: FC<Props> = ({
- loading = {},
- isSearching = false,
itemSearchString = '',
setItemSearchString = () => {},
- onToggleSearch = () => {},
- onSetPathByString = () => {},
onFilesUpload = () => {},
- onSelectBack = () => {},
}) => {
const debounceDuration = 300
- const [isEditingPath, setIsEditingPath] = useState(false)
- const [isRefreshing, setIsRefreshing] = useState(false)
const [pathString, setPathString] = useState('')
const [searchString, setSearchString] = useState('')
+ const [loading, setLoading] = useState({ isLoading: false, message: '' })
+
+ const [isEditingPath, setIsEditingPath] = useState(false)
+ const [isRefreshing, setIsRefreshing] = useState(false)
+ const [isSearching, setIsSearching] = useState(false)
const uploadButtonRef: any = useRef(null)
const previousBreadcrumbs: any = useRef(null)
@@ -130,9 +125,14 @@ const FileExplorerHeader: FC<Props> = ({
setSortBy,
sortByOrder,
setSortByOrder,
+ popColumn,
popColumnAtIndex,
+ popOpenedFolders,
+ fetchFoldersByPath,
refetchAllOpenedFolders,
addNewFolderPlaceholder,
+ clearOpenedFolders,
+ closeFilePreview,
} = storageExplorerStore
const breadcrumbs = columns.map((column: any) => column.name)
@@ -158,6 +158,12 @@ const FileExplorerHeader: FC<Props> = ({
searchInputHandler(event.target.value)
}
+ const onSelectBack = () => {
+ popColumn()
+ popOpenedFolders()
+ closeFilePreview()
+ }
+
const onSelectUpload = () => {
if (uploadButtonRef.current) {
uploadButtonRef.current.click()
@@ -184,6 +190,19 @@ const FileExplorerHeader: FC<Props> = ({
onSetPathByString(compact(pathString.split('/')))
}
+ const onSetPathByString = async (paths: any[]) => {
+ if (paths.length === 0) {
+ popColumnAtIndex(0)
+ clearOpenedFolders()
+ closeFilePreview()
+ } else {
+ const pathString = paths.join('/')
+ setLoading({ isLoading: true, message: `Navigating to ${pathString}...` })
+ await fetchFoldersByPath(paths)
+ setLoading({ isLoading: false, message: '' })
+ }
+ }
+
const cancelSetPathString = () => {
setIsEditingPath(false)
}
@@ -193,11 +212,13 @@ const FileExplorerHeader: FC<Props> = ({
// Searching for column view requires much more thinking
const toggleSearch = () => {
setIsEditingPath(false)
- onToggleSearch(true)
+ setIsSearching(true)
}
+
const onCancelSearch = () => {
setSearchString('')
- onToggleSearch(false)
+ setIsSearching(false)
+ setItemSearchString('')
}
/** Methods for breadcrumbs */
diff --git a/studio/components/to-be-cleaned/Storage/StorageExplorer/StorageExplorer.js b/studio/components/to-be-cleaned/Storage/StorageExplorer/StorageExplorer.js
index 95cdec1e7ae..23791f77909 100644
--- a/studio/components/to-be-cleaned/Storage/StorageExplorer/StorageExplorer.js
+++ b/studio/components/to-be-cleaned/Storage/StorageExplorer/StorageExplorer.js
@@ -27,10 +27,7 @@ const StorageExplorer = observer(({ bucket }) => {
clearSelectedItemsToDelete,
openedFolders,
pushOpenedFolderAtIndex,
- clearOpenedFolders,
- popColumn,
popColumnAtIndex,
- popOpenedFolders,
popOpenedFoldersAtIndex,
setSelectedItemToRename,
selectedItemsToMove,
@@ -49,7 +46,6 @@ const StorageExplorer = observer(({ bucket }) => {
addNewFolder,
fetchFolderContents,
fetchMoreFolderContents,
- fetchFoldersByPath,
renameFolder,
deleteFolder,
uploadFiles,
@@ -60,12 +56,10 @@ const StorageExplorer = observer(({ bucket }) => {
} = storageExplorerStore
const storageExplorerRef = useRef(null)
- const [loading, setLoading] = useState({ isLoading: false, message: '' })
// This state exists outside of the header because FileExplorerColumn needs to listen to these as well
// I'm keeping them outside of the mobx store as I feel that the store should contain persistent data
// Things like showing results from a search filter is "temporary", hence we use react state to manage
- const [isSearching, setIsSearching] = useState(false)
const [itemSearchString, setItemSearchString] = useState('')
// Requires a fixed height to ensure that explorer is constrained to the viewport
@@ -122,19 +116,6 @@ const StorageExplorer = observer(({ bucket }) => {
await fetchFolderContents(folder.id, folder.name, columnIndex)
}
- const onSetPathByString = async (paths) => {
- if (paths.length === 0) {
- popColumnAtIndex(0)
- clearOpenedFolders()
- closeFilePreview()
- } else {
- const pathString = paths.join('/')
- setLoading({ isLoading: true, message: `Navigating to ${pathString}...` })
- await fetchFoldersByPath(paths)
- setLoading({ isLoading: false, message: '' })
- }
- }
-
/** Checkbox selection methods */
/** [Joshen] We'll only support checkbox selection for files ONLY */
@@ -234,13 +215,6 @@ const StorageExplorer = observer(({ bucket }) => {
}
/** Misc UI methods */
-
- const onSelectBack = () => {
- popColumn()
- popOpenedFolders()
- closeFilePreview()
- }
-
const onSelectColumnEmptySpace = (columnIndex) => {
popColumnAtIndex(columnIndex)
popOpenedFoldersAtIndex(columnIndex - 1)
@@ -254,13 +228,6 @@ const StorageExplorer = observer(({ bucket }) => {
const onChangeSortByOrder = (sortByOrder) => setSortByOrder(sortByOrder)
- const onToggleSearch = (bool) => {
- setIsSearching(bool)
- if (bool === false) {
- setItemSearchString('')
- }
- }
-
return (
<div
ref={storageExplorerRef}
@@ -271,14 +238,9 @@ const StorageExplorer = observer(({ bucket }) => {
>
{selectedItems.length === 0 ? (
<FileExplorerHeader
- loading={loading}
- isSearching={isSearching}
itemSearchString={itemSearchString}
setItemSearchString={setItemSearchString}
- onToggleSearch={onToggleSearch}
onFilesUpload={onFilesUpload}
- onSelectBack={onSelectBack}
- onSetPathByString={onSetPathByString}
/>
) : (
<FileExplorerHeaderSelection />