The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.
TypeScript aialternativeauthdatabasedenoembeddingsexamplefirebasenextjsoauth2pgvectorpostgispostgrespostgresqlpostgrestrealtimesupabasevectorswebsockets
Fix addTempRow showing stale name, refactor FileExplorerRow to bring out editing state logic
Joshen Lim09ac743a809f
diff --git a/studio/components/to-be-cleaned/Storage/StorageExplorer/FileExplorerRow.tsx b/studio/components/to-be-cleaned/Storage/StorageExplorer/FileExplorerRow.tsxindex e76d3cc9ac1..95fb39f36ca 100644--- a/studio/components/to-be-cleaned/Storage/StorageExplorer/FileExplorerRow.tsx+++ b/studio/components/to-be-cleaned/Storage/StorageExplorer/FileExplorerRow.tsx@@ -1,5 +1,4 @@-import { FC, useState, useRef, useEffect } from 'react'-import { find, has, isEmpty, isEqual } from 'lodash'+import { find, isEmpty, isEqual } from 'lodash'import {Checkbox,Dropdown,@@ -33,8 +32,9 @@ import {import { formatBytes } from 'lib/helpers'import { BASE_PATH } from 'lib/constants'import { useStorageStore } from 'localStores/storageExplorer/StorageExplorerStore'+import FileExplorerRowEditing from './FileExplorerRowEditing'-const RowIcon = ({ view, status, fileType, mimeType }: any) => {+export const RowIcon = ({ view, status, fileType, mimeType }: any) => {if (view === STORAGE_VIEWS.LIST && status === STORAGE_ROW_STATUS.LOADING) {return <IconLoader size={16} strokeWidth={2} className="animate-spin" />}@@ -71,7 +71,7 @@ const RowIcon = ({ view, status, fileType, mimeType }: any) => {return <IconFile size={16} strokeWidth={2} />}-interface Props {+interface FileExplorerRowProps {index: numberitem: anyview: string@@ -81,7 +81,7 @@ interface Props {selectedFilePreview: any}-const FileExplorerRow: FC<Props> = ({+const FileExplorerRow = ({index: itemIndex,item = {},view = STORAGE_VIEWS.COLUMNS,@@ -89,7 +89,7 @@ const FileExplorerRow: FC<Props> = ({selectedItems = [],openedFolders = [],selectedFilePreview = {},-}) => {+}: FileExplorerRowProps) => {const storageExplorerStore = useStorageStore()const {popColumnAtIndex,@@ -98,9 +98,6 @@ const FileExplorerRow: FC<Props> = ({setFilePreview,closeFilePreview,clearSelectedItems,- addNewFolder,- renameFolder,- renameFile,selectedBucket,setSelectedItems,setSelectedItemsToDelete,@@ -155,54 +152,6 @@ const FileExplorerRow: FC<Props> = ({closeFilePreview()}- const inputRef = useRef<any>(null)- const [itemName, setItemName] = useState(item.name)-- useEffect(() => {- if (inputRef.current) inputRef.current.select()- }, [])-- if (item.status === STORAGE_ROW_STATUS.EDITING) {- const onSetItemName = async (event: any) => {- event.preventDefault()- event.stopPropagation()- if (item.type === STORAGE_ROW_TYPES.FILE) {- await renameFile(item, itemName, columnIndex)- } else if (has(item, 'id')) {- renameFolder(itemWithColumnIndex, itemName, columnIndex)- } else {- addNewFolder(itemName, columnIndex)- }- }-- return (- <div className="storage-row flex items-center justify-between rounded bg-gray-500">- <div className="flex h-full flex-grow items-center px-2.5">- <div className="">- <RowIcon- view={view}- status={item.status}- fileType={item.type}- mimeType={item.metadata?.mimetype}- />- </div>- <form className="h-9" onSubmit={onSetItemName}>- <input- autoFocus- ref={inputRef}- className="storage-row-input ml-3 h-full bg-inherit p-0 px-1 text-sm"- type="text"- value={itemName}- onChange={(event) => setItemName(event.target.value)}- onBlur={onSetItemName}- />- <button className="hidden" type="submit" onClick={onSetItemName} />- </form>- </div>- </div>- )- }-const rowOptions =item.type === STORAGE_ROW_TYPES.FOLDER? [@@ -335,6 +284,10 @@ const FileExplorerRow: FC<Props> = ({? `calc(100% - 50px)`: '100%'+ if (item.status === STORAGE_ROW_STATUS.EDITING) {+ return <FileExplorerRowEditing view={view} item={item} columnIndex={columnIndex} />+ }+return (<divclassName="h-full border-b dark:border-dark"diff --git a/studio/components/to-be-cleaned/Storage/StorageExplorer/FileExplorerRowEditing.tsx b/studio/components/to-be-cleaned/Storage/StorageExplorer/FileExplorerRowEditing.tsxnew file mode 100644index 00000000000..84dbdb48dae--- /dev/null+++ b/studio/components/to-be-cleaned/Storage/StorageExplorer/FileExplorerRowEditing.tsx@@ -0,0 +1,65 @@+import { has } from 'lodash'+import { useState, useEffect, useRef } from 'react'+import { useStorageStore } from 'localStores/storageExplorer/StorageExplorerStore'+import { STORAGE_ROW_TYPES } from '../Storage.constants'+import { RowIcon } from './FileExplorerRow'++export interface FileExplorerRowEditingProps {+ item: any+ view: string+ columnIndex: number+}++const FileExplorerRowEditing = ({ item, view, columnIndex }: FileExplorerRowEditingProps) => {+ const storageExplorerStore = useStorageStore()+ const { renameFile, renameFolder, addNewFolder } = storageExplorerStore++ const inputRef = useRef<any>(null)+ const [itemName, setItemName] = useState(item.name)++ const onSetItemName = async (event: any) => {+ event.preventDefault()+ event.stopPropagation()+ if (item.type === STORAGE_ROW_TYPES.FILE) {+ await renameFile(item, itemName, columnIndex)+ } else if (has(item, 'id')) {+ const itemWithColumnIndex = { ...item, columnIndex }+ renameFolder(itemWithColumnIndex, itemName, columnIndex)+ } else {+ addNewFolder(itemName, columnIndex)+ }+ }++ useEffect(() => {+ if (inputRef.current) inputRef.current.select()+ }, [])++ return (+ <div className="storage-row flex items-center justify-between rounded bg-gray-500">+ <div className="flex h-full flex-grow items-center px-2.5">+ <div className="">+ <RowIcon+ view={view}+ status={item.status}+ fileType={item.type}+ mimeType={item.metadata?.mimetype}+ />+ </div>+ <form className="h-9" onSubmit={onSetItemName}>+ <input+ autoFocus+ ref={inputRef}+ className="storage-row-input ml-3 h-full bg-inherit p-0 px-1 text-sm"+ type="text"+ value={itemName}+ onChange={(event) => setItemName(event.target.value)}+ onBlur={onSetItemName}+ />+ <button className="hidden" type="submit" onClick={onSetItemName} />+ </form>+ </div>+ </div>+ )+}++export default FileExplorerRowEditingdiff --git a/studio/localStores/storageExplorer/StorageExplorerStore.js b/studio/localStores/storageExplorer/StorageExplorerStore.jsindex 64863f990a4..3269577e6ed 100644--- a/studio/localStores/storageExplorer/StorageExplorerStore.js+++ b/studio/localStores/storageExplorer/StorageExplorerStore.js@@ -302,7 +302,7 @@ class StorageExplorerStore {const formattedName = this.sanitizeNameForDuplicateInColumn(folderName, autofix, columnIndex)if (formattedName === null) return- if (!/^[a-zA-Z0-9_-]*$/.test(formattedName)) {+ if (!/^[a-zA-Z0-9_-\s]*$/.test(formattedName)) {return this.ui.setNotification({message: 'Folder name contains invalid special characters',category: 'error',@@ -1576,6 +1576,8 @@ class StorageExplorerStore {}addTempRow = (type, name, status, columnIndex, metadata = {}, isPrepend = false) => {+ console.log('addTempRow', { type, name, status })+const updatedColumns = this.columns.map((column, idx) => {if (idx === columnIndex) {const tempRow = { type, name, status, metadata }