The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.
TypeScript aialternativeauthdatabasedenoembeddingsexamplefirebasenextjsoauth2pgvectorpostgispostgrespostgresqlpostgrestrealtimesupabasevectorswebsockets
implement infinite scrolling for search functionality
Joshen Lim180d6d3863eb
diff --git a/studio/components/to-be-cleaned/Storage/README.md b/studio/components/to-be-cleaned/Storage/README.mdnew file mode 100644index 00000000000..a3b03939136--- /dev/null+++ b/studio/components/to-be-cleaned/Storage/README.md@@ -0,0 +1,6 @@+## What to clean for Storage++- Convert files from javascript to typescript+- Not use mobx store for UI related states, these could simply be done via react's useState or useReducer+ - Involves some heavy surgery nonetheless as 90% of the explorer logic is written a mobx store StorageExplorerStore+ - If anyone is able to get to it before I do, please feel free to take this on and perhaps even write it more simply 🙏diff --git a/studio/components/to-be-cleaned/Storage/StorageExplorer/FileExplorer.js b/studio/components/to-be-cleaned/Storage/StorageExplorer/FileExplorer.jsindex 6e2d898a22b..3123b00ef11 100644--- a/studio/components/to-be-cleaned/Storage/StorageExplorer/FileExplorer.js+++ b/studio/components/to-be-cleaned/Storage/StorageExplorer/FileExplorer.js@@ -12,8 +12,6 @@ const FileExplorer = ({openedFolders = [],selectedItems = [],selectedFilePreview = {},- isSearching = false,- itemSearchString = '',onCheckItem = () => {},onSelectItemDelete = () => {},onSelectItemRename = () => {},@@ -108,8 +106,6 @@ const FileExplorer = ({column={columns[columns.length - 1]}selectedItems={selectedItems}selectedFilePreview={selectedFilePreview}- isSearching={isSearching}- itemSearchString={itemSearchString}onCheckItem={onCheckItem}onSelectFile={onSelectFile}onRenameFile={onRenameFile}diff --git a/studio/components/to-be-cleaned/Storage/StorageExplorer/FileExplorerColumn.js b/studio/components/to-be-cleaned/Storage/StorageExplorer/FileExplorerColumn.jsindex d3477176aa9..727e53c17a4 100644--- a/studio/components/to-be-cleaned/Storage/StorageExplorer/FileExplorerColumn.js+++ b/studio/components/to-be-cleaned/Storage/StorageExplorer/FileExplorerColumn.js@@ -56,8 +56,6 @@ const FileExplorerColumn = ({openedFolders = [],selectedItems = [],selectedFilePreview = {},- isSearching = false,- itemSearchString = '',onCheckItem = () => {},onSelectItemDelete = () => {},onSelectItemRename = () => {},@@ -94,12 +92,7 @@ const FileExplorerColumn = ({(item) => item.type === STORAGE_ROW_TYPES.FILE)- const columnItems = isSearching- ? column.items.filter((item) =>- item.name.toLowerCase().includes(itemSearchString.toLowerCase())- )- : column.items-+ const columnItems = column.itemsconst columnItemsSize = sum(columnItems.map((item) => get(item, ['metadata', 'size'], 0)))const { show } = useContextMenu()@@ -208,8 +201,7 @@ const FileExplorerColumn = ({<divclassName={`${fullWidth ? 'w-full' : 'w-64 border-r border-gray-500'}- ${view === STORAGE_VIEWS.COLUMNS ? 'my-1' : 'mb-1'}- flex-shrink-0 overflow-auto flex flex-col space-y-1+ flex-shrink-0 overflow-auto flex flex-col space-y-1 my-1`}><ShimmeringLoader />@@ -246,11 +238,6 @@ const FileExplorerColumn = ({onLoadNextPage={() => onColumnLoadMore(index, column)}/>- {/* Search empty state */}- {isSearching && columnItems.length === 0 && column.items.length > 0 && (- <div className="text-sm mx-3 my-2 opacity-50">No results found based on your search</div>- )}-{/* Drag drop upload CTA for when column is empty */}{column.items.length === 0 && column.status !== STORAGE_ROW_STATUS.LOADING && (<div className="h-full w-full flex flex-col items-center justify-center">diff --git a/studio/components/to-be-cleaned/Storage/StorageExplorer/StorageExplorer.js b/studio/components/to-be-cleaned/Storage/StorageExplorer/StorageExplorer.jsindex 0360e7cdd89..0e5a662ff48 100644--- a/studio/components/to-be-cleaned/Storage/StorageExplorer/StorageExplorer.js+++ b/studio/components/to-be-cleaned/Storage/StorageExplorer/StorageExplorer.js@@ -1,4 +1,4 @@-import { FC, useEffect, useState, useRef } from 'react'+import { useEffect, useState, useRef } from 'react'import { observer } from 'mobx-react-lite'import { compact, find, isEmpty, uniqBy, get } from 'lodash'@@ -67,16 +67,28 @@ const StorageExplorer = observer(({ bucket }) => {// 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 manageconst [isSearching, setIsSearching] = useState(false)-- // [TODO JOSHEN FOR INFINITE SCROLLING]- // Probably need a useEffect for this to use fetchFolderContents and fetchMoreFolderContents in store- // instead of doing a client side filtering in FileExplorerColumn, pending Alaister to update js libraryconst [itemSearchString, setItemSearchString] = useState('')const previewPaneWidth = 450// Requires a fixed height to ensure that explorer is constrained to the viewportconst fileExplorerHeight = window.innerHeight - 122+ useEffect(async () => {+ const currentFolderIdx = openedFolders.length - 1+ const currentFolder = openedFolders[currentFolderIdx]++ if (itemSearchString) {+ await fetchFolderContents(+ currentFolder.id,+ currentFolder.name,+ currentFolderIdx,+ itemSearchString+ )+ } else if (currentFolder) {+ await fetchFolderContents(currentFolder.id, currentFolder.name, currentFolderIdx)+ }+ }, [itemSearchString])+useEffect(() => {// Load user preferences (view and sort)loadExplorerPreferences()@@ -248,7 +260,9 @@ const StorageExplorer = observer(({ bucket }) => {const onToggleSearch = (bool) => {setIsSearching(bool)- if (bool === false) setItemSearchString('')+ if (bool === false) {+ setItemSearchString('')+ }}return (@@ -294,8 +308,6 @@ const StorageExplorer = observer(({ bucket }) => {openedFolders={openedFolders}selectedItems={selectedItems}selectedFilePreview={selectedFilePreview}- isSearching={isSearching}- itemSearchString={itemSearchString}onCheckItem={onCheckItem}onSelectFile={onSelectFile}onRenameFile={onRenameFile}@@ -313,7 +325,9 @@ const StorageExplorer = observer(({ bucket }) => {onSelectCreateFolder={onSelectCreateFolder}onChangeView={onChangeView}onChangeSortBy={onChangeSortBy}- onColumnLoadMore={fetchMoreFolderContents}+ onColumnLoadMore={(index, column) =>+ fetchMoreFolderContents(index, column, itemSearchString)+ }/><PreviewPaneisOpen={!isEmpty(selectedFilePreview)}diff --git a/studio/localStores/storageExplorer/StorageExplorerStore.js b/studio/localStores/storageExplorer/StorageExplorerStore.jsindex 9acb2433b8e..3eb66d6d031 100644--- a/studio/localStores/storageExplorer/StorageExplorerStore.js+++ b/studio/localStores/storageExplorer/StorageExplorerStore.js@@ -924,28 +924,29 @@ class StorageExplorerStore {/* Folders CRUD */- fetchFolderContents = async (folderId, folderName, index, showLoading = true) => {+ fetchFolderContents = async (folderId, folderName, index, searchString = '') => {this.abortApiCalls()- if (showLoading) {- this.updateRowStatus(folderName, STORAGE_ROW_STATUS.LOADING, index)- this.pushColumnAtIndex(- { id: folderId, name: folderName, status: STORAGE_ROW_STATUS.LOADING, items: [] },- index- )- }+ 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 options = { limit: LIMIT, offset: OFFSET, sortBy: { column: this.sortBy, order: 'asc' } }+ const options = {+ limit: LIMIT,+ offset: OFFSET,+ search: searchString,+ sortBy: { column: this.sortBy, order: 'asc' },+ }const parameters = { signal: this.abortController.signal }const { data: items, error } = await this.supabaseClient.storage.from(this.selectedBucket.name).list(prefix, options, parameters)- if (showLoading) {- this.updateRowStatus(folderName, STORAGE_ROW_STATUS.READY, index)- }+ this.updateRowStatus(folderName, STORAGE_ROW_STATUS.READY, index)if (!error) {const formattedItems = this.formatFolderItems(items)@@ -962,15 +963,14 @@ class StorageExplorerStore {}}- fetchMoreFolderContents = async (index, column) => {+ fetchMoreFolderContents = async (index, column, searchString = '') => {this.setColumnIsLoadingMore(index)- // [Joshen] Bug on the backend that sorting will not be respected- // when we fetch more contents, but its okay, not blocking frontendconst prefix = this.openedFolders.map((folder) => folder.name).join('/')const options = {limit: LIMIT,offset: column.items.length,+ search: searchString,sortBy: { column: this.sortBy, order: 'asc' },}const parameters = { signal: this.abortController.signal }