Skip to content

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

fix: storage explorer column infinite loading loads the wrong column (#44275)

Gildas Garcia753638caf45d
diff --git a/apps/studio/components/interfaces/Storage/Storage.types.ts b/apps/studio/components/interfaces/Storage/Storage.types.ts
index c9943befe01..3b76c8bdabd 100644
--- a/apps/studio/components/interfaces/Storage/Storage.types.ts
+++ b/apps/studio/components/interfaces/Storage/Storage.types.ts
@@ -1,4 +1,5 @@
import type { PolicyFormField } from 'components/interfaces/Auth/Policies/Policies.types'
+
import { STORAGE_ROW_STATUS, STORAGE_ROW_TYPES } from './Storage.constants'
export interface StoragePolicyFormField extends PolicyFormField {
@@ -19,6 +20,7 @@ export interface BucketCreatePayload extends BucketUpdatePayload {
export interface StorageColumn {
id: string | null
name: string
+ path: string
status: string
items: StorageItem[]
hasMoreItems?: boolean
diff --git a/apps/studio/components/interfaces/Storage/StorageExplorer/FileExplorer.tsx b/apps/studio/components/interfaces/Storage/StorageExplorer/FileExplorer.tsx
index 6f1a3e52cb4..1bfcc42d5f9 100644
--- a/apps/studio/components/interfaces/Storage/StorageExplorer/FileExplorer.tsx
+++ b/apps/studio/components/interfaces/Storage/StorageExplorer/FileExplorer.tsx
@@ -1,8 +1,8 @@
import { noop } from 'lodash'
import { useEffect, useRef } from 'react'
-
import { useStorageExplorerStateSnapshot } from 'state/storage-explorer'
import { cn } from 'ui'
+
import { CONTEXT_MENU_KEYS, STORAGE_ROW_STATUS, STORAGE_VIEWS } from '../Storage.constants'
import type { StorageColumn, StorageItemWithColumn } from '../Storage.types'
import { ColumnContextMenu } from './ColumnContextMenu'
@@ -57,7 +57,7 @@ export const FileExplorer = ({
{isLoading ? (
<FileExplorerColumn
- column={{ id: '', name: '', items: [], status: STORAGE_ROW_STATUS.LOADING }}
+ column={{ id: '', name: '', path: '', items: [], status: STORAGE_ROW_STATUS.LOADING }}
/>
) : snap.view === STORAGE_VIEWS.COLUMNS ? (
<div className="flex">
diff --git a/apps/studio/components/interfaces/Storage/StorageExplorer/StorageExplorer.tsx b/apps/studio/components/interfaces/Storage/StorageExplorer/StorageExplorer.tsx
index 9de3e77cfba..9b8515b3f9f 100644
--- a/apps/studio/components/interfaces/Storage/StorageExplorer/StorageExplorer.tsx
+++ b/apps/studio/components/interfaces/Storage/StorageExplorer/StorageExplorer.tsx
@@ -2,7 +2,6 @@ import { useDebounce } from '@uidotdev/usehooks'
import { useParams } from 'common'
import { useProjectStorageConfigQuery } from 'data/config/project-storage-config-query'
import type { Bucket } from 'data/storage/buckets-query'
-import { useLatest } from 'hooks/misc/useLatest'
import { IS_PLATFORM } from 'lib/constants'
import { compact, get, isEmpty, uniqBy } from 'lodash'
import { useEffect, useRef, useState } from 'react'
diff --git a/apps/studio/components/interfaces/Storage/StorageExplorer/StorageExplorer.utils.test.ts b/apps/studio/components/interfaces/Storage/StorageExplorer/StorageExplorer.utils.test.ts
index 478f04475e4..b0baa3aaa1f 100644
--- a/apps/studio/components/interfaces/Storage/StorageExplorer/StorageExplorer.utils.test.ts
+++ b/apps/studio/components/interfaces/Storage/StorageExplorer/StorageExplorer.utils.test.ts
@@ -170,6 +170,7 @@ describe('sanitizeNameForDuplicateInColumn', () => {
columns: columns.map((columnItems, i) => ({
id: null,
name: `col-${i}`,
+ path: `col-${i}`,
status: STORAGE_ROW_STATUS.READY,
items: columnItems.map((overrides) => ({
id: 'file-id',
diff --git a/apps/studio/state/storage-explorer.tsx b/apps/studio/state/storage-explorer.tsx
index 4448c501edf..ea83eb30e19 100644
--- a/apps/studio/state/storage-explorer.tsx
+++ b/apps/studio/state/storage-explorer.tsx
@@ -327,15 +327,21 @@ function createStorageExplorerState({
status: STORAGE_ROW_STATUS.LOADING,
columnIndex: index,
})
- state.pushColumnAtIndex(
- { id: folderId, name: folderName, status: STORAGE_ROW_STATUS.LOADING, items: [] },
- index
- )
-
const prefix = state.openedFolders
.slice(0, index + 1)
.map((folder) => folder.name)
.join('/')
+ state.pushColumnAtIndex(
+ {
+ id: folderId,
+ name: folderName,
+ path: prefix,
+ status: STORAGE_ROW_STATUS.LOADING,
+ items: [],
+ },
+ index
+ )
+
const options = {
limit: LIMIT,
offset: OFFSET,
@@ -364,6 +370,7 @@ function createStorageExplorerState({
{
id: folderId || folderName,
name: folderName,
+ path: prefix,
status: STORAGE_ROW_STATUS.READY,
items: formattedItems,
hasMoreItems: formattedItems.length === LIMIT,
@@ -395,7 +402,6 @@ function createStorageExplorerState({
}) => {
state.setColumnIsLoadingMore(index)
- const prefix = state.openedFolders.map((folder) => folder.name).join('/')
const options = {
limit: LIMIT,
offset: column.items.length,
@@ -408,14 +414,14 @@ function createStorageExplorerState({
{
projectRef: state.projectRef,
bucketId: state.selectedBucket.id,
- path: prefix,
+ path: column.path,
options,
},
abortController?.signal
)
// Add items to column
- const formattedItems = formatFolderItems(data, prefix)
+ const formattedItems = formatFolderItems(data, column.path)
state.columns = state.columns.map((col, idx) => {
if (idx === index) {
return {
@@ -454,7 +460,7 @@ function createStorageExplorerState({
if (showLoading) {
state.columns = [state.selectedBucket.name].concat(paths).map((path) => {
- return { id: path, name: path, status: STORAGE_ROW_STATUS.LOADING, items: [] }
+ return { id: path, name: path, path, status: STORAGE_ROW_STATUS.LOADING, items: [] }
})
}
@@ -490,6 +496,7 @@ function createStorageExplorerState({
id: null,
status: STORAGE_ROW_STATUS.READY,
name: idx === 0 ? state.selectedBucket.name : pathsWithEmptyPrefix[idx],
+ path: prefix,
items: formattedItems,
hasMoreItems: formattedItems.length === LIMIT,
isLoadingMoreItems: false,