Skip to content

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

Chore/address danny friction log (#37659)

Joshen Lim712a6b15e62d
diff --git a/apps/studio/components/interfaces/Reports/Reports.tsx b/apps/studio/components/interfaces/Reports/Reports.tsx
index 044d4e73534..1bd29985dff 100644
--- a/apps/studio/components/interfaces/Reports/Reports.tsx
+++ b/apps/studio/components/interfaces/Reports/Reports.tsx
@@ -3,6 +3,7 @@ import { useQueryClient } from '@tanstack/react-query'
import dayjs from 'dayjs'
import { groupBy, isEqual, isNull } from 'lodash'
import { ArrowRight, Plus, RefreshCw, Save } from 'lucide-react'
+import { useRouter } from 'next/router'
import { DragEvent, useEffect, useState } from 'react'
import { toast } from 'sonner'
@@ -30,6 +31,7 @@ import { useProfile } from 'lib/profile'
import { useDatabaseSelectorStateSnapshot } from 'state/database-selector'
import { Dashboards } from 'types'
import { Button, cn, DropdownMenu, DropdownMenuContent, DropdownMenuTrigger } from 'ui'
+import ConfirmationModal from 'ui-patterns/Dialogs/ConfirmationModal'
import { createSqlSnippetSkeletonV2 } from '../SQLEditor/SQLEditor.utils'
import { ChartConfig } from '../SQLEditor/UtilityPanel/ChartConfig'
import { GridResize } from './GridResize'
@@ -40,6 +42,7 @@ const DEFAULT_CHART_COLUMN_COUNT = 1
const DEFAULT_CHART_ROW_COUNT = 1
const Reports = () => {
+ const router = useRouter()
const { id, ref } = useParams()
const { profile } = useProfile()
const { data: project } = useSelectedProjectQuery()
@@ -54,6 +57,9 @@ const Reports = () => {
const [hasEdits, setHasEdits] = useState<boolean>(false)
const [isRefreshing, setIsRefreshing] = useState<boolean>(false)
+ const [navigateUrl, setNavigateUrl] = useState<string>()
+ const [confirmNavigate, setConfirmNavigate] = useState(false)
+
const {
data: userContents,
isLoading,
@@ -352,6 +358,31 @@ const Reports = () => {
checkEditState()
}, [config])
+ useEffect(() => {
+ const handleBeforeUnload = (e: BeforeUnloadEvent) => {
+ if (hasEdits) {
+ e.preventDefault()
+ e.returnValue = '' // deprecated, but older browsers still require this
+ }
+ }
+
+ const handleBrowseAway = (url: string) => {
+ if (hasEdits && !confirmNavigate) {
+ setNavigateUrl(url)
+ throw 'Route change declined' // Just to prevent the route change
+ } else {
+ setNavigateUrl(undefined)
+ }
+ }
+
+ window.addEventListener('beforeunload', handleBeforeUnload)
+ router.events.on('routeChangeStart', handleBrowseAway)
+ return () => {
+ window.removeEventListener('beforeunload', handleBeforeUnload)
+ router.events.off('routeChangeStart', handleBrowseAway)
+ }
+ }, [hasEdits, confirmNavigate, router])
+
if (isLoading) {
return <Loading />
}
@@ -361,149 +392,167 @@ const Reports = () => {
}
return (
- <div className="flex flex-col space-y-4" style={{ maxHeight: '100%' }}>
- <div className="flex items-center justify-between">
- <div>
- <h1>{currentReport?.name || 'Reports'}</h1>
- <p className="text-foreground-light">{currentReport?.description}</p>
+ <>
+ <div className="flex flex-col space-y-4" style={{ maxHeight: '100%' }}>
+ <div className="flex items-center justify-between">
+ <div>
+ <h1>{currentReport?.name || 'Reports'}</h1>
+ <p className="text-foreground-light">{currentReport?.description}</p>
+ </div>
+ {hasEdits && (
+ <div className="flex items-center gap-x-2">
+ <Button
+ type="default"
+ disabled={isSaving}
+ onClick={() => setConfig(currentReportContent)}
+ >
+ Cancel
+ </Button>
+ <Button
+ type="primary"
+ icon={<Save />}
+ loading={isSaving}
+ onClick={() => onSaveReport()}
+ >
+ Save changes
+ </Button>
+ </div>
+ )}
</div>
- {hasEdits && (
+ <div className={cn('mb-4 flex items-center gap-x-3 justify-between')}>
<div className="flex items-center gap-x-2">
- <Button
+ <ButtonTooltip
type="default"
- disabled={isSaving}
- onClick={() => setConfig(currentReportContent)}
- >
- Cancel
- </Button>
- <Button
- type="primary"
- icon={<Save />}
- loading={isSaving}
- onClick={() => onSaveReport()}
- >
- Save changes
- </Button>
- </div>
- )}
- </div>
- <div className={cn('mb-4 flex items-center gap-x-3 justify-between')}>
- <div className="flex items-center gap-x-2">
- <ButtonTooltip
- type="default"
- icon={<RefreshCw className={isRefreshing ? 'animate-spin' : ''} />}
- className="w-7"
- disabled={isRefreshing}
- tooltip={{ content: { side: 'bottom', text: 'Refresh report' } }}
- onClick={onRefreshReport}
- />
- <div className="flex items-center gap-x-3">
- <DateRangePicker
- value="7d"
- className="w-48"
- onChange={handleDateRangePicker}
- options={TIME_PERIODS_REPORTS}
- loading={isLoading}
- footer={
- <div className="px-2 py-1">
- <p className="text-xs text-foreground-lighter">
- SQL blocks are independent of the selected date range
- </p>
- </div>
- }
+ icon={<RefreshCw className={isRefreshing ? 'animate-spin' : ''} />}
+ className="w-7"
+ disabled={isRefreshing}
+ tooltip={{ content: { side: 'bottom', text: 'Refresh report' } }}
+ onClick={onRefreshReport}
/>
+ <div className="flex items-center gap-x-3">
+ <DateRangePicker
+ value="7d"
+ className="w-48"
+ onChange={handleDateRangePicker}
+ options={TIME_PERIODS_REPORTS}
+ loading={isLoading}
+ footer={
+ <div className="px-2 py-1">
+ <p className="text-xs text-foreground-lighter">
+ SQL blocks are independent of the selected date range
+ </p>
+ </div>
+ }
+ />
+
+ {startDate && endDate && (
+ <div className="hidden items-center space-x-1 lg:flex ">
+ <span className="text-sm text-foreground-light">
+ {dayjs(startDate).format('MMM D, YYYY')}
+ </span>
+ <span className="text-foreground-lighter">
+ <ArrowRight size={12} />
+ </span>
+ <span className="text-sm text-foreground-light">
+ {dayjs(endDate).format('MMM D, YYYY')}
+ </span>
+ </div>
+ )}
+ </div>
+ </div>
- {startDate && endDate && (
- <div className="hidden items-center space-x-1 lg:flex ">
- <span className="text-sm text-foreground-light">
- {dayjs(startDate).format('MMM D, YYYY')}
- </span>
- <span className="text-foreground-lighter">
- <ArrowRight size={12} />
- </span>
- <span className="text-sm text-foreground-light">
- {dayjs(endDate).format('MMM D, YYYY')}
- </span>
- </div>
+ <div className="flex items-center gap-x-2">
+ {canUpdateReport ? (
+ <DropdownMenu>
+ <DropdownMenuTrigger asChild>
+ <Button type="default" icon={<Plus />}>
+ <span>Add block</span>
+ </Button>
+ </DropdownMenuTrigger>
+ <DropdownMenuContent side="bottom" align="center" className="w-44">
+ <MetricOptions config={config} handleChartSelection={handleChartSelection} />
+ </DropdownMenuContent>
+ </DropdownMenu>
+ ) : (
+ <ButtonTooltip
+ disabled
+ type="default"
+ icon={<Plus />}
+ tooltip={{
+ content: {
+ side: 'bottom',
+ className: 'w-56 text-center',
+ text: 'You need additional permissions to update custom reports',
+ },
+ }}
+ >
+ Add block
+ </ButtonTooltip>
)}
+ <DatabaseSelector />
</div>
</div>
- <div className="flex items-center gap-x-2">
- {canUpdateReport ? (
- <DropdownMenu>
- <DropdownMenuTrigger asChild>
- <Button type="default" icon={<Plus />}>
- <span>Add block</span>
- </Button>
- </DropdownMenuTrigger>
- <DropdownMenuContent side="bottom" align="center" className="w-44">
- <MetricOptions config={config} handleChartSelection={handleChartSelection} />
- </DropdownMenuContent>
- </DropdownMenu>
- ) : (
- <ButtonTooltip
- disabled
- type="default"
- icon={<Plus />}
- tooltip={{
- content: {
- side: 'bottom',
- className: 'w-56 text-center',
- text: 'You need additional permissions to update custom reports',
- },
- }}
- >
- Add block
- </ButtonTooltip>
- )}
- <DatabaseSelector />
- </div>
+ {config?.layout !== undefined && config.layout.length === 0 ? (
+ <div
+ className={cn(
+ 'flex min-h-full items-center justify-center rounded border-2 border-dashed p-16 border-default transition duration-100',
+ isDraggedOver ? 'bg-surface-100' : ''
+ )}
+ onDragOver={onDragOverEmptyState}
+ onDragLeave={onDragOverEmptyState}
+ onDrop={onDropSQLBlockEmptyState}
+ >
+ {canUpdateReport ? (
+ <DropdownMenu>
+ <DropdownMenuTrigger asChild>
+ <Button type="default" iconRight={<Plus size={14} />}>
+ Add your first chart
+ </Button>
+ </DropdownMenuTrigger>
+ <DropdownMenuContent side="bottom" align="center">
+ <MetricOptions config={config} handleChartSelection={handleChartSelection} />
+ </DropdownMenuContent>
+ </DropdownMenu>
+ ) : (
+ <p className="text-sm text-foreground-light">No charts set up yet in report</p>
+ )}
+ </div>
+ ) : (
+ <div className="relative mb-16 flex-grow">
+ {config && startDate && endDate && (
+ <GridResize
+ startDate={startDate}
+ endDate={endDate}
+ interval={config.interval as AnalyticsInterval}
+ editableReport={config}
+ disableUpdate={!canUpdateReport}
+ isRefreshing={isRefreshing}
+ onRemoveChart={popChart}
+ onUpdateChart={updateChart}
+ setEditableReport={setConfig}
+ />
+ )}
+ </div>
+ )}
</div>
-
- {config?.layout !== undefined && config.layout.length === 0 ? (
- <div
- className={cn(
- 'flex min-h-full items-center justify-center rounded border-2 border-dashed p-16 border-default transition duration-100',
- isDraggedOver ? 'bg-surface-100' : ''
- )}
- onDragOver={onDragOverEmptyState}
- onDragLeave={onDragOverEmptyState}
- onDrop={onDropSQLBlockEmptyState}
- >
- {canUpdateReport ? (
- <DropdownMenu>
- <DropdownMenuTrigger asChild>
- <Button type="default" iconRight={<Plus size={14} />}>
- Add your first chart
- </Button>
- </DropdownMenuTrigger>
- <DropdownMenuContent side="bottom" align="center">
- <MetricOptions config={config} handleChartSelection={handleChartSelection} />
- </DropdownMenuContent>
- </DropdownMenu>
- ) : (
- <p className="text-sm text-foreground-light">No charts set up yet in report</p>
- )}
- </div>
- ) : (
- <div className="relative mb-16 flex-grow">
- {config && startDate && endDate && (
- <GridResize
- startDate={startDate}
- endDate={endDate}
- interval={config.interval as AnalyticsInterval}
- editableReport={config}
- disableUpdate={!canUpdateReport}
- isRefreshing={isRefreshing}
- onRemoveChart={popChart}
- onUpdateChart={updateChart}
- setEditableReport={setConfig}
- />
- )}
- </div>
- )}
- </div>
+ <ConfirmationModal
+ visible={!!navigateUrl}
+ variant="warning"
+ title="You have unsaved changes in your report"
+ confirmLabel="Confirm"
+ onConfirm={() => {
+ setConfirmNavigate(true)
+ setNavigateUrl(undefined)
+ router.push(navigateUrl ?? '/')
+ }}
+ onCancel={() => setNavigateUrl(undefined)}
+ >
+ <p className="text-sm">
+ Unsaved changes will be lost, are you sure you want to navigate away?
+ </p>
+ </ConfirmationModal>
+ </>
)
}
diff --git a/apps/studio/components/interfaces/SQLEditor/MonacoEditor.tsx b/apps/studio/components/interfaces/SQLEditor/MonacoEditor.tsx
index 59ea6403dc8..97f4fdb668e 100644
--- a/apps/studio/components/interfaces/SQLEditor/MonacoEditor.tsx
+++ b/apps/studio/components/interfaces/SQLEditor/MonacoEditor.tsx
@@ -88,6 +88,17 @@ const MonacoEditor = ({
},
})
+ editor.addAction({
+ id: 'save-query',
+ label: 'Save Query',
+ keybindings: [monaco.KeyMod.CtrlCmd + monaco.KeyCode.KeyS],
+ contextMenuGroupId: 'operation',
+ contextMenuOrder: 0,
+ run: () => {
+ if (snippet) snapV2.addNeedsSaving(snippet.snippet.id)
+ },
+ })
+
editor.addAction({
id: 'explain-code',
label: 'Explain Code',
diff --git a/apps/studio/components/interfaces/SQLEditor/UtilityPanel/RunButton.tsx b/apps/studio/components/interfaces/SQLEditor/UtilityPanel/RunButton.tsx
index 627e73768ab..19403f8278f 100644
--- a/apps/studio/components/interfaces/SQLEditor/UtilityPanel/RunButton.tsx
+++ b/apps/studio/components/interfaces/SQLEditor/UtilityPanel/RunButton.tsx
@@ -1,5 +1,6 @@
-import { detectOS } from 'lib/helpers'
import { Command, CornerDownLeft, Loader2 } from 'lucide-react'
+
+import { detectOS } from 'lib/helpers'
import { Button } from 'ui'
interface SqlRunButtonProps {
diff --git a/apps/studio/components/interfaces/SQLEditor/UtilityPanel/UtilityActions.tsx b/apps/studio/components/interfaces/SQLEditor/UtilityPanel/UtilityActions.tsx
index 29a026d50dd..d7704a00b44 100644
--- a/apps/studio/components/interfaces/SQLEditor/UtilityPanel/UtilityActions.tsx
+++ b/apps/studio/components/interfaces/SQLEditor/UtilityPanel/UtilityActions.tsx
@@ -6,7 +6,6 @@ import { RoleImpersonationPopover } from 'components/interfaces/RoleImpersonatio
import DatabaseSelector from 'components/ui/DatabaseSelector'
import { useLocalStorageQuery } from 'hooks/misc/useLocalStorage'
import { IS_PLATFORM } from 'lib/constants'
-import { detectOS } from 'lib/helpers'
import { useSqlEditorV2StateSnapshot } from 'state/sql-editor-v2'
import {
Button,
@@ -27,7 +26,7 @@ export type UtilityActionsProps = {
id: string
isExecuting?: boolean
isDisabled?: boolean
- hasSelection: boolean
+ hasSelection?: boolean
prettifyQuery: () => void
executeQuery: () => void
}
@@ -36,11 +35,10 @@ const UtilityActions = ({
id,
isExecuting = false,
isDisabled = false,
- hasSelection,
+ hasSelection = false,
prettifyQuery,
executeQuery,
}: UtilityActionsProps) => {
- const os = detectOS()
const { ref } = useParams()
const snapV2 = useSqlEditorV2StateSnapshot()
@@ -189,6 +187,7 @@ const UtilityActions = ({
variant={IS_PLATFORM ? 'connected-on-both' : 'connected-on-right'}
/>
<SqlRunButton
+ hasSelection={hasSelection}
isDisabled={isDisabled || isExecuting}
isExecuting={isExecuting}
className="rounded-l-none min-w-[82px]"
diff --git a/apps/studio/components/interfaces/Storage/StorageExplorer/FileExplorer.tsx b/apps/studio/components/interfaces/Storage/StorageExplorer/FileExplorer.tsx
index f9db7769c7e..0c1442d0cbe 100644
--- a/apps/studio/components/interfaces/Storage/StorageExplorer/FileExplorer.tsx
+++ b/apps/studio/components/interfaces/Storage/StorageExplorer/FileExplorer.tsx
@@ -4,7 +4,7 @@ import { useEffect, useRef } from 'react'
import { useStorageExplorerStateSnapshot } from 'state/storage-explorer'
import { cn } from 'ui'
import { CONTEXT_MENU_KEYS, STORAGE_VIEWS } from '../Storage.constants'
-import type { StorageColumn, StorageItem, StorageItemWithColumn } from '../Storage.types'
+import type { StorageColumn, StorageItemWithColumn } from '../Storage.types'
import ColumnContextMenu from './ColumnContextMenu'
import FileExplorerColumn from './FileExplorerColumn'
import FolderContextMenu from './FolderContextMenu'
@@ -12,7 +12,6 @@ import ItemContextMenu from './ItemContextMenu'
export interface FileExplorerProps {
columns: StorageColumn[]
- openedFolders: StorageItem[]
selectedItems: StorageItemWithColumn[]
itemSearchString: string
onFilesUpload: (event: any, index: number) => void
@@ -23,7 +22,6 @@ export interface FileExplorerProps {
const FileExplorer = ({
columns = [],
- openedFolders = [],
selectedItems = [],
itemSearchString,
onFilesUpload = noop,
@@ -61,7 +59,6 @@ const FileExplorer = ({
key={`column-${index}`}
index={index}
column={column}
- openedFolders={openedFolders}
selectedItems={selectedItems}
itemSearchString={itemSearchString}
onFilesUpload={onFilesUpload}
diff --git a/apps/studio/components/interfaces/Storage/StorageExplorer/FileExplorerColumn.tsx b/apps/studio/components/interfaces/Storage/StorageExplorer/FileExplorerColumn.tsx
index 84167c8d271..5d1ed5f3066 100644
--- a/apps/studio/components/interfaces/Storage/StorageExplorer/FileExplorerColumn.tsx
+++ b/apps/studio/components/interfaces/Storage/StorageExplorer/FileExplorerColumn.tsx
@@ -19,7 +19,7 @@ import {
STORAGE_ROW_TYPES,
STORAGE_VIEWS,
} from '../Storage.constants'
-import type { StorageColumn, StorageItem, StorageItemWithColumn } from '../Storage.types'
+import type { StorageColumn, StorageItemWithColumn } from '../Storage.types'
import FileExplorerRow from './FileExplorerRow'
const DragOverOverlay = ({ isOpen, onDragLeave, onDrop, folderIsEmpty }: any) => {
@@ -60,7 +60,6 @@ export interface FileExplorerColumnProps {
index: number
column: StorageColumn
fullWidth?: boolean
- openedFolders?: StorageItem[]
selectedItems: StorageItemWithColumn[]
itemSearchString: string
onFilesUpload: (event: any, index: number) => void
@@ -73,7 +72,6 @@ const FileExplorerColumn = ({
index = 0,
column,
fullWidth = false,
- openedFolders = [],
selectedItems = [],
itemSearchString,
onFilesUpload = noop,
@@ -221,7 +219,6 @@ const FileExplorerColumn = ({
view: snap.view,
columnIndex: index,
selectedItems,
- openedFolders,
}}
ItemComponent={FileExplorerRow}
getItemSize={(index) => (index !== 0 && index === columnItems.length ? 85 : 37)}
diff --git a/apps/studio/components/interfaces/Storage/StorageExplorer/FileExplorerRow.tsx b/apps/studio/components/interfaces/Storage/StorageExplorer/FileExplorerRow.tsx
index 306eb49098f..8979041793e 100644
--- a/apps/studio/components/interfaces/Storage/StorageExplorer/FileExplorerRow.tsx
+++ b/apps/studio/components/interfaces/Storage/StorageExplorer/FileExplorerRow.tsx
@@ -22,7 +22,6 @@ import type { ItemRenderer } from 'components/ui/InfiniteList'
import { useCheckPermissions } from 'hooks/misc/useCheckPermissions'
import { BASE_PATH } from 'lib/constants'
import { formatBytes } from 'lib/helpers'
-import { toast } from 'sonner'
import { useStorageExplorerStateSnapshot } from 'state/storage-explorer'
import {
Checkbox,
@@ -51,7 +50,6 @@ import { StorageItem, StorageItemWithColumn } from '../Storage.types'
import FileExplorerRowEditing from './FileExplorerRowEditing'
import { copyPathToFolder, downloadFile } from './StorageExplorer.utils'
import { useCopyUrl } from './useCopyUrl'
-import { useSelectedBucket } from './useSelectedBucket'
export const RowIcon = ({
view,
@@ -104,7 +102,6 @@ export interface FileExplorerRowProps {
view: STORAGE_VIEWS
columnIndex: number
selectedItems: StorageItemWithColumn[]
- openedFolders: StorageItem[]
}
const FileExplorerRow: ItemRenderer<StorageItem, FileExplorerRowProps> = ({
@@ -113,16 +110,14 @@ const FileExplorerRow: ItemRenderer<StorageItem, FileExplorerRowProps> = ({
view = STORAGE_VIEWS.COLUMNS,
columnIndex = 0,
selectedItems = [],
- openedFolders = [],
}) => {
const { ref: projectRef, bucketId } = useParams()
- const { bucket } = useSelectedBucket()
const {
selectedBucket,
selectedFilePreview,
+ openedFolders,
popColumnAtIndex,
- pushOpenedFolderAtIndex,
popOpenedFoldersAtIndex,
clearSelectedItems,
setSelectedFilePreview,
@@ -131,22 +126,21 @@ const FileExplorerRow: ItemRenderer<StorageItem, FileExplorerRowProps> = ({
setSelectedItemsToDelete,
setSelectedItemToRename,
setSelectedItemsToMove,
- fetchFolderContents,
+ openFolder,
downloadFolder,
selectRangeItems,
} = useStorageExplorerStateSnapshot()
+ const { show } = useContextMenu()
const { onCopyUrl } = useCopyUrl()
const isPublic = selectedBucket.public
const itemWithColumnIndex = { ...item, columnIndex }
const isSelected = !!selectedItems.find((i) => i.id === item.id)
const isOpened =
- openedFolders.length > columnIndex ? isEqual(openedFolders[columnIndex], item) : false
+ openedFolders.length > columnIndex ? openedFolders[columnIndex].name === item.name : false
const isPreviewed = !isEmpty(selectedFilePreview) && isEqual(selectedFilePreview?.id, item.id)
const canUpdateFiles = useCheckPermissions(PermissionAction.STORAGE_WRITE, '*')
- const { show } = useContextMenu()
-
const onSelectFile = async (columnIndex: number, file: StorageItem) => {
popColumnAtIndex(columnIndex)
popOpenedFoldersAtIndex(columnIndex - 1)
@@ -154,21 +148,6 @@ const FileExplorerRow: ItemRenderer<StorageItem, FileExplorerRowProps> = ({
clearSelectedItems()
}
- const onSelectFolder = async (columnIndex: number, folder: StorageItem) => {
- if (!bucket) return toast.error('Unable to retrieve bucket details')
-
- setSelectedFilePreview(undefined)
- clearSelectedItems(columnIndex + 1)
- popOpenedFoldersAtIndex(columnIndex - 1)
- pushOpenedFolderAtIndex(folder, columnIndex)
- await fetchFolderContents({
- bucketId: bucket.id,
- folderId: folder.id,
- folderName: folder.name,
- index: columnIndex,
- })
- }
-
const onCheckItem = (isShiftKeyHeld: boolean) => {
// Select a range if shift is held down
if (isShiftKeyHeld && selectedItems.length !== 0) {
@@ -346,7 +325,7 @@ const FileExplorerRow: ItemRenderer<StorageItem, FileExplorerRowProps> = ({
event.preventDefault()
if (item.status !== STORAGE_ROW_STATUS.LOADING && !isOpened && !isPreviewed) {
item.type === STORAGE_ROW_TYPES.FOLDER || item.type === STORAGE_ROW_TYPES.BUCKET
- ? onSelectFolder(columnIndex, item)
+ ? openFolder(columnIndex, item)
: onSelectFile(columnIndex, item)
}
}}
diff --git a/apps/studio/components/interfaces/Storage/StorageExplorer/FileExplorerRowEditing.tsx b/apps/studio/components/interfaces/Storage/StorageExplorer/FileExplorerRowEditing.tsx
index 2be0df79f40..cd17e1b1622 100644
--- a/apps/studio/components/interfaces/Storage/StorageExplorer/FileExplorerRowEditing.tsx
+++ b/apps/studio/components/interfaces/Storage/StorageExplorer/FileExplorerRowEditing.tsx
@@ -30,7 +30,17 @@ const FileExplorerRowEditing = ({ item, view, columnIndex }: FileExplorerRowEdit
const itemWithColumnIndex = { ...item, columnIndex }
renameFolder(itemWithColumnIndex, name, columnIndex)
} else {
- addNewFolder(name, columnIndex)
+ addNewFolder({
+ folderName: name,
+ columnIndex,
+ onError: () => {
+ if (event.type === 'blur') {
+ addNewFolder({ folderName: '', columnIndex })
+ } else {
+ inputRef.current.select()
+ }
+ },
+ })
}
}
@@ -47,7 +57,7 @@ const FileExplorerRowEditing = ({ item, view, columnIndex }: FileExplorerRowEdit
const handleEsc = (event: KeyboardEvent) => {
if (event.key === 'Escape') {
if (item?.id !== undefined) onSaveItemName(item.name)
- else addNewFolder('', columnIndex)
+ else addNewFolder({ folderName: '', columnIndex })
}
}
diff --git a/apps/studio/components/interfaces/Storage/StorageExplorer/StorageExplorer.tsx b/apps/studio/components/interfaces/Storage/StorageExplorer/StorageExplorer.tsx
index cfc8ecd5c40..160e8118e4f 100644
--- a/apps/studio/components/interfaces/Storage/StorageExplorer/StorageExplorer.tsx
+++ b/apps/studio/components/interfaces/Storage/StorageExplorer/StorageExplorer.tsx
@@ -181,7 +181,6 @@ const StorageExplorer = ({ bucket }: StorageExplorerProps) => {
<div className="flex h-full" style={{ height: fileExplorerHeight }}>
<FileExplorer
columns={columns}
- openedFolders={openedFolders}
selectedItems={selectedItems}
itemSearchString={itemSearchString}
onFilesUpload={onFilesUpload}
diff --git a/apps/studio/components/interfaces/TableGridEditor/GridHeaderActions.tsx b/apps/studio/components/interfaces/TableGridEditor/GridHeaderActions.tsx
index 4c83d38d6f6..e9bd8a54ec0 100644
--- a/apps/studio/components/interfaces/TableGridEditor/GridHeaderActions.tsx
+++ b/apps/studio/components/interfaces/TableGridEditor/GridHeaderActions.tsx
@@ -251,7 +251,7 @@ const GridHeaderActions = ({ table }: GridHeaderActionsProps) => {
passHref
href={`/project/${projectRef}/auth/policies?search=${table.id}&schema=${table.schema}`}
>
- Auth {policies.length > 1 ? 'policies' : 'policy'}
+ RLS {policies.length > 1 ? 'policies' : 'policy'}
</Link>
</Button>
)}
diff --git a/apps/studio/components/layouts/SQLEditorLayout/SQLEditorNavV2/SQLEditorTreeViewItem.tsx b/apps/studio/components/layouts/SQLEditorLayout/SQLEditorNavV2/SQLEditorTreeViewItem.tsx
index 3633fdf5b74..d2c48404aa2 100644
--- a/apps/studio/components/layouts/SQLEditorLayout/SQLEditorNavV2/SQLEditorTreeViewItem.tsx
+++ b/apps/studio/components/layouts/SQLEditorLayout/SQLEditorNavV2/SQLEditorTreeViewItem.tsx
@@ -6,7 +6,18 @@ import { Snippet } from 'data/content/sql-folders-query'
import { useCheckPermissions } from 'hooks/misc/useCheckPermissions'
import useLatest from 'hooks/misc/useLatest'
import { useProfile } from 'lib/profile'
-import { Copy, Download, Edit, ExternalLink, Lock, Move, Plus, Share, Trash } from 'lucide-react'
+import {
+ Copy,
+ Download,
+ Edit,
+ ExternalLink,
+ Heart,
+ Lock,
+ Move,
+ Plus,
+ Share,
+ Trash,
+} from 'lucide-react'
import Link from 'next/link'
import { useRouter } from 'next/router'
import { ComponentProps, useEffect } from 'react'
@@ -19,6 +30,7 @@ import {
ContextMenuTrigger_Shadcn_,
ContextMenu_Shadcn_,
TreeViewItem,
+ cn,
} from 'ui'
interface SQLEditorTreeViewItemProps
@@ -85,6 +97,7 @@ export const SQLEditorTreeViewItem = ({
const isOwner = profile?.id === element?.metadata.owner_id
const isSharedSnippet = element.metadata.visibility === 'project'
+ const isFavorite = element.metadata.favorite
const isEditing = status === 'editing'
const isSaving = status === 'saving'
@@ -154,6 +167,14 @@ export const SQLEditorTreeViewItem = ({
}
}
+ const onToggleFavorite = () => {
+ const snippetId = element.metadata.id
+ if (snippetId) {
+ if (isFavorite) snapV2.removeFavorite(snippetId)
+ else snapV2.addFavorite(snippetId)
+ }
+ }
+
return (
<>
<ContextMenu_Shadcn_ modal={false}>
@@ -322,6 +343,19 @@ export const SQLEditorTreeViewItem = ({
Duplicate query
</ContextMenuItem_Shadcn_>
)}
+ <ContextMenuItem_Shadcn_
+ className="gap-x-2"
+ onSelect={() => onToggleFavorite()}
+ onFocusCapture={(e) => e.stopPropagation()}
+ >
+ <Heart
+ size={14}
+ className={cn(
+ isFavorite ? 'fill-brand stroke-none' : 'fill-none stroke-foreground-light'
+ )}
+ />
+ {isFavorite ? 'Remove from' : 'Add to'} favorites
+ </ContextMenuItem_Shadcn_>
{onSelectDownload !== undefined && IS_PLATFORM && (
<ContextMenuItem_Shadcn_
className="gap-x-2"
diff --git a/apps/studio/state/storage-explorer.tsx b/apps/studio/state/storage-explorer.tsx
index afa80ef49ad..67e27994112 100644
--- a/apps/studio/state/storage-explorer.tsx
+++ b/apps/studio/state/storage-explorer.tsx
@@ -275,7 +275,15 @@ function createStorageExplorerState({
})
},
- addNewFolder: async (folderName: string, columnIndex: number) => {
+ addNewFolder: async ({
+ folderName,
+ columnIndex,
+ onError,
+ }: {
+ folderName: string
+ columnIndex: number
+ onError?: () => void
+ }) => {
if (!state.supabaseClient) return console.error('Supabase Client is missing')
const autofix = false
@@ -284,10 +292,16 @@ function createStorageExplorerState({
autofix,
columnIndex,
})
- if (formattedName === null) return
+ if (formattedName === null) {
+ onError?.()
+ return
+ }
if (!/^[a-zA-Z0-9_-\s]*$/.test(formattedName)) {
- return toast.error('Folder name contains invalid special characters')
+ onError?.()
+ return toast.error(
+ 'Only alphanumeric characters, hyphens, and underscores are allowed for folder names.'
+ )
}
if (formattedName.length === 0) {
@@ -318,6 +332,9 @@ function createStorageExplorerState({
paths: [`${pathToFolder}/${EMPTY_FOLDER_PLACEHOLDER_FILE_NAME}`],
})
}
+
+ const newFolder = state.columns[columnIndex].items.find((x) => x.name === formattedName)
+ if (newFolder) state.openFolder(columnIndex, newFolder)
},
fetchFolderContents: async ({
@@ -730,6 +747,19 @@ function createStorageExplorerState({
state.columns = updatedColumns
},
+ openFolder: async (columnIndex: number, folder: StorageItem) => {
+ state.setSelectedFilePreview(undefined)
+ state.clearSelectedItems(columnIndex + 1)
+ state.popOpenedFoldersAtIndex(columnIndex - 1)
+ state.pushOpenedFolderAtIndex(folder, columnIndex)
+ await state.fetchFolderContents({
+ bucketId: state.selectedBucket.id,
+ folderId: folder.id,
+ folderName: folder.name,
+ index: columnIndex,
+ })
+ },
+
downloadFolder: async (folder: StorageItemWithColumn) => {
let progress = 0
const toastId = toast.loading('Retrieving files from folder...')