Skip to content

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

Chore/fix searching in table editor clearing tabs (#35198)

Joshen Lim58a9db9db543
diff --git a/apps/studio/components/grid/SupabaseGrid.tsx b/apps/studio/components/grid/SupabaseGrid.tsx
index 7074b3e6781..d24332ae8f5 100644
--- a/apps/studio/components/grid/SupabaseGrid.tsx
+++ b/apps/studio/components/grid/SupabaseGrid.tsx
@@ -7,7 +7,7 @@ import { createPortal } from 'react-dom'
import { useParams } from 'common'
import { useProjectContext } from 'components/layouts/ProjectLayout/ProjectContext'
import { useTableRowsQuery } from 'data/table-rows/table-rows-query'
-import { useUrlState } from 'hooks/ui/useUrlState'
+import { useTableEditorFiltersSort } from 'hooks/misc/useTableEditorFiltersSort'
import { RoleImpersonationState } from 'lib/role-impersonation'
import { EMPTY_ARR } from 'lib/void'
import { useRoleImpersonationStateSnapshot } from 'state/role-impersonation-state'
@@ -25,7 +25,6 @@ import { Grid } from './components/grid/Grid'
import Header, { HeaderProps } from './components/header/Header'
import { RowContextMenu } from './components/menu'
import { Filter, GridProps } from './types'
-import { useTableEditorFiltersSort } from 'hooks/misc/useTableEditorFiltersSort'
export const SupabaseGrid = ({
customHeader,
diff --git a/apps/studio/components/interfaces/Organization/TeamSettings/UpdateRolesPanel/UpdateRolesPanel.tsx b/apps/studio/components/interfaces/Organization/TeamSettings/UpdateRolesPanel/UpdateRolesPanel.tsx
index 4782245ccd3..186beb2ea4d 100644
--- a/apps/studio/components/interfaces/Organization/TeamSettings/UpdateRolesPanel/UpdateRolesPanel.tsx
+++ b/apps/studio/components/interfaces/Organization/TeamSettings/UpdateRolesPanel/UpdateRolesPanel.tsx
@@ -142,14 +142,12 @@ export const UpdateRolesPanel = ({ visible, member, onClose }: UpdateRolesPanelP
if (isApplyAllProjects) {
if (originalConfigurationType === 'org-scope') {
- console.log('Reset: Org scoped')
setProjectsRoleConfiguration(originalConfiguration)
} else {
setProjectsRoleConfiguration([{ ref: undefined, roleId: roleIdToApply }])
}
} else {
if (originalConfigurationType === 'project-scope') {
- console.log('Reset: Project scoped')
setProjectsRoleConfiguration(originalConfiguration)
} else {
setProjectsRoleConfiguration(
diff --git a/apps/studio/components/interfaces/TableGridEditor/NotFoundState.tsx b/apps/studio/components/interfaces/TableGridEditor/NotFoundState.tsx
deleted file mode 100644
index 120e6a0354d..00000000000
--- a/apps/studio/components/interfaces/TableGridEditor/NotFoundState.tsx
+++ /dev/null
@@ -1,21 +0,0 @@
-import InformationBox from 'components/ui/InformationBox'
-import { AlertCircle } from 'lucide-react'
-
-interface NotFoundStateProps {
- id: string | number
-}
-
-const NotFoundState = ({ id }: NotFoundStateProps) => {
- return (
- <div className="flex items-center justify-center h-full">
- <div className="w-[400px]">
- <InformationBox
- icon={<AlertCircle strokeWidth={2} />}
- title={`Unable to find your table with ID ${id}`}
- />
- </div>
- </div>
- )
-}
-
-export default NotFoundState
diff --git a/apps/studio/components/interfaces/TableGridEditor/TableGridEditor.tsx b/apps/studio/components/interfaces/TableGridEditor/TableGridEditor.tsx
index 7530dea458d..df3d071c0cb 100644
--- a/apps/studio/components/interfaces/TableGridEditor/TableGridEditor.tsx
+++ b/apps/studio/components/interfaces/TableGridEditor/TableGridEditor.tsx
@@ -6,6 +6,7 @@ import { useCallback } from 'react'
import { useParams } from 'common'
import { SupabaseGrid } from 'components/grid/SupabaseGrid'
import { useLoadTableEditorStateFromLocalStorageIntoUrl } from 'components/grid/SupabaseGrid.utils'
+import { useEditorType } from 'components/layouts/editors/EditorsLayout.hooks'
import {
Entity,
isMaterializedView,
@@ -16,10 +17,12 @@ import { useCheckPermissions } from 'hooks/misc/useCheckPermissions'
import { useSelectedProject } from 'hooks/misc/useSelectedProject'
import { useUrlState } from 'hooks/ui/useUrlState'
import { PROTECTED_SCHEMAS } from 'lib/constants/schemas'
+import { useAppStateSnapshot } from 'state/app-state'
import { TableEditorTableStateContextProvider } from 'state/table-editor-table'
-import { makeActiveTabPermanent } from 'state/tabs'
-import { GenericSkeletonLoader } from 'ui-patterns'
-import NotFoundState from './NotFoundState'
+import { handleTabClose, makeActiveTabPermanent, useTabsStore } from 'state/tabs'
+import { Button } from 'ui'
+import { Admonition, GenericSkeletonLoader } from 'ui-patterns'
+import { useIsTableEditorTabsEnabled } from '../App/FeaturePreview/FeaturePreviewContext'
import SidePanelEditor from './SidePanelEditor/SidePanelEditor'
import TableDefinition from './TableDefinition'
@@ -28,13 +31,17 @@ export interface TableGridEditorProps {
selectedTable?: Entity
}
-const TableGridEditor = ({
+export const TableGridEditor = ({
isLoadingSelectedTable = false,
selectedTable,
}: TableGridEditorProps) => {
const router = useRouter()
+ const editor = useEditorType()
const project = useSelectedProject()
+ const appSnap = useAppStateSnapshot()
const { ref: projectRef, id } = useParams()
+ const tabs = useTabsStore(projectRef)
+ const isTableEditorTabsEnabled = useIsTableEditorTabsEnabled()
useLoadTableEditorStateFromLocalStorageIntoUrl({
projectRef,
@@ -46,6 +53,7 @@ const TableGridEditor = ({
const canEditTables = useCheckPermissions(PermissionAction.TENANT_SQL_ADMIN_WRITE, 'tables')
const canEditColumns = useCheckPermissions(PermissionAction.TENANT_SQL_ADMIN_WRITE, 'columns')
const isReadOnly = !canEditTables && !canEditColumns
+ const tabId = !!id ? tabs.openTabs.find((x) => x.endsWith(id)) : undefined
const onTableCreated = useCallback(
(table: { id: number }) => {
@@ -54,6 +62,12 @@ const TableGridEditor = ({
[projectRef, router]
)
+ const onClearDashboardHistory = () => {
+ if (projectRef && editor) {
+ appSnap.setDashboardHistory(projectRef, editor === 'table' ? 'editor' : editor, undefined)
+ }
+ }
+
// NOTE: DO NOT PUT HOOKS AFTER THIS LINE
if (isLoadingSelectedTable || !projectRef) {
return (
@@ -68,7 +82,37 @@ const TableGridEditor = ({
}
if (isUndefined(selectedTable)) {
- return <NotFoundState id={Number(id)} />
+ return (
+ <div className="flex items-center justify-center h-full">
+ <div className="w-[400px]">
+ <Admonition
+ type="default"
+ title={`Unable to find your table with ID ${id}`}
+ description="This table doesn't exist in your database"
+ >
+ {isTableEditorTabsEnabled && (
+ <Button
+ type="default"
+ className="mt-2"
+ onClick={() => {
+ if (tabId) {
+ handleTabClose({
+ ref: projectRef,
+ id: tabId,
+ router,
+ editor,
+ onClearDashboardHistory,
+ })
+ }
+ }}
+ >
+ Close tab
+ </Button>
+ )}
+ </Admonition>
+ </div>
+ </div>
+ )
}
const isViewSelected = isView(selectedTable) || isMaterializedView(selectedTable)
@@ -121,5 +165,3 @@ const TableGridEditor = ({
</div>
)
}
-
-export default TableGridEditor
diff --git a/apps/studio/components/interfaces/TableGridEditor/index.ts b/apps/studio/components/interfaces/TableGridEditor/index.ts
index 86131e01172..50e1839b986 100644
--- a/apps/studio/components/interfaces/TableGridEditor/index.ts
+++ b/apps/studio/components/interfaces/TableGridEditor/index.ts
@@ -1,3 +1,2 @@
-export { default as TableGridEditor } from './TableGridEditor'
-export { default as SidePanelEditor } from './SidePanelEditor/SidePanelEditor'
export { default as EmptyState } from './EmptyState'
+export { default as SidePanelEditor } from './SidePanelEditor/SidePanelEditor'
diff --git a/apps/studio/components/layouts/TableEditorLayout/TableEditorMenu.tsx b/apps/studio/components/layouts/TableEditorLayout/TableEditorMenu.tsx
index ba2e93a9a29..1474176cd1a 100644
--- a/apps/studio/components/layouts/TableEditorLayout/TableEditorMenu.tsx
+++ b/apps/studio/components/layouts/TableEditorLayout/TableEditorMenu.tsx
@@ -1,7 +1,6 @@
import { PermissionAction } from '@supabase/shared-types/out/constants'
import { partition } from 'lodash'
import { Filter, Plus } from 'lucide-react'
-import { useRouter } from 'next/router'
import { useEffect, useMemo, useState } from 'react'
import { useParams } from 'common'
@@ -41,13 +40,11 @@ import {
InnerSideBarFilters,
} from 'ui-patterns/InnerSideMenu'
import { useProjectContext } from '../ProjectLayout/ProjectContext'
-import { tableEditorTabsCleanUp } from '../Tabs/Tabs.utils'
import EntityListItem from './EntityListItem'
import { TableMenuEmptyState } from './TableMenuEmptyState'
const TableEditorMenu = () => {
const { ref, id: _id } = useParams()
- const router = useRouter()
const id = _id ? Number(_id) : undefined
const snap = useTableEditorStateSnapshot()
const { selectedSchema, setSelectedSchema } = useQuerySchemaState()
@@ -117,13 +114,6 @@ const TableEditorMenu = () => {
}
}, [selectedTable?.schema])
- useEffect(() => {
- // Clean up tabs + recent items for any tables that might have been removed outside of the dashboard session
- if (isTableEditorTabsEnabled && ref && entityTypes) {
- tableEditorTabsCleanUp({ ref, schemas: [selectedSchema], entities: entityTypes })
- }
- }, [entityTypes])
-
return (
<>
<div className="flex flex-col flex-grow gap-5 pt-5 h-full">
@@ -183,12 +173,10 @@ const TableEditorMenu = () => {
<InnerSideBarFilterSearchInput
autoFocus={!isMobile}
name="search-tables"
- aria-labelledby="Search tables"
- onChange={(e) => {
- setSearchText(e.target.value)
- }}
value={searchText}
placeholder="Search tables..."
+ aria-labelledby="Search tables"
+ onChange={(e) => setSearchText(e.target.value)}
>
<InnerSideBarFilterSortDropdown
value={sort}
diff --git a/apps/studio/components/layouts/Tabs/SortableTab.tsx b/apps/studio/components/layouts/Tabs/SortableTab.tsx
new file mode 100644
index 00000000000..473711df254
--- /dev/null
+++ b/apps/studio/components/layouts/Tabs/SortableTab.tsx
@@ -0,0 +1,132 @@
+import { useSortable } from '@dnd-kit/sortable'
+import { CSS } from '@dnd-kit/utilities'
+import { AnimatePresence, motion } from 'framer-motion'
+import { X } from 'lucide-react'
+import { useRouter } from 'next/router'
+import { useMemo } from 'react'
+
+import { useParams } from 'common'
+import { EntityTypeIcon } from 'components/ui/EntityTypeIcon'
+import { makeTabPermanent, type Tab } from 'state/tabs'
+import { cn, TabsTrigger_Shadcn_ } from 'ui'
+
+/**
+ * Individual draggable tab component that handles:
+ * - Drag
+ * - Drop functionality
+ * - Dynamic schema name display
+ * - Tab label animations
+ * - Close button interactions
+ */
+export const SortableTab = ({
+ tab,
+ index,
+ openTabs,
+ onClose,
+}: {
+ tab: Tab
+ index: number
+ openTabs: Tab[]
+ onClose: (id: string) => void
+}) => {
+ const router = useRouter()
+ const { ref } = useParams()
+ const currentSchema = (router.query.schema as string) || 'public'
+
+ const { attributes, listeners, setNodeRef, transform, transition, isDragging } = useSortable({
+ id: tab.id,
+ })
+
+ const style = {
+ transform: CSS.Transform.toString(transform),
+ transition,
+ zIndex: isDragging ? 1 : 0,
+ }
+
+ // Update schema visibility check to include URL param comparison
+ const shouldShowSchema = useMemo(() => {
+ // For both table and schema tabs, show schema if:
+ // Any tab has a different schema than the current schema parameter
+ if (tab.type === 'r') {
+ const anyTabHasDifferentSchema = openTabs
+ .filter((t) => t.type === 'r')
+ .some((t) => t.metadata?.schema !== currentSchema)
+
+ return anyTabHasDifferentSchema
+ }
+
+ return false
+ }, [openTabs, currentSchema, tab.type])
+
+ // Create a motion version of TabsTrigger while preserving all functionality
+ // const MotionTabsTrigger = motion(TabsTrigger_Shadcn_)
+
+ return (
+ <motion.div
+ ref={setNodeRef}
+ style={style}
+ {...attributes}
+ layoutId={tab.id}
+ transition={{ duration: 0.045 }}
+ animate={{ opacity: isDragging ? 0 : 1 }}
+ className={cn('flex items-center h-10 first-of-type:border-l')}
+ >
+ <TabsTrigger_Shadcn_
+ value={tab.id}
+ onDoubleClick={() => makeTabPermanent(ref, tab.id)}
+ className={cn(
+ 'flex items-center gap-2 pl-3 pr-2.5 text-xs',
+ 'bg-dash-sidebar/50 dark:bg-surface-100/50',
+ 'data-[state=active]:bg-dash-sidebar dark:data-[state=active]:bg-surface-100',
+ 'border-b border-default',
+ 'data-[state=active]:border-b-background-dash-sidebar dark:data-[state=active]:border-b-background-surface-100',
+ 'relative group h-full',
+ 'hover:bg-surface-300 dark:hover:bg-surface-100',
+ tab.isPreview && 'italic font-light' // Optional: style preview tabs differently
+ )}
+ {...listeners}
+ >
+ <EntityTypeIcon type={tab.type} />
+ <div className="flex items-center gap-0">
+ <AnimatePresence mode="popLayout" initial>
+ {shouldShowSchema && (
+ <motion.span
+ initial={{ opacity: 0, width: 0 }}
+ animate={{ opacity: 1, width: 'auto' }}
+ exit={{ opacity: 0, width: 0 }}
+ transition={{ duration: 0.15 }}
+ className="text-foreground-muted group-data-[state=active]:text-foreground-lighter"
+ >
+ {tab?.metadata?.schema}.
+ </motion.span>
+ )}
+ </AnimatePresence>
+ <span>{tab.label || 'Untitled'}</span>
+ </div>
+ <span
+ role="button"
+ onClick={(e) => {
+ e.preventDefault()
+ e.stopPropagation()
+ }}
+ className="p-0.5 ml-1 opacity-0 group-hover:opacity-100 hover:bg-200 rounded-sm cursor-pointer"
+ onMouseDown={(e) => {
+ e.preventDefault()
+ e.stopPropagation()
+ }}
+ onPointerDown={(e) => {
+ e.preventDefault()
+ e.stopPropagation()
+ onClose(tab.id)
+ }}
+ >
+ <X size={12} className="text-foreground-light" />
+ </span>
+ <div className="absolute w-full top-0 left-0 right-0 h-px bg-foreground opacity-0 group-data-[state=active]:opacity-100" />
+ </TabsTrigger_Shadcn_>
+ {index < openTabs.length && (
+ <div role="separator" className="h-full w-px bg-border" key={`separator-${tab.id}`} />
+ )}
+ </motion.div>
+ )
+}
diff --git a/apps/studio/components/layouts/Tabs/TabPreview.tsx b/apps/studio/components/layouts/Tabs/TabPreview.tsx
new file mode 100644
index 00000000000..1b271bb3401
--- /dev/null
+++ b/apps/studio/components/layouts/Tabs/TabPreview.tsx
@@ -0,0 +1,29 @@
+import { motion } from 'framer-motion'
+import { useSnapshot } from 'valtio'
+
+import { useParams } from 'common'
+import { EntityTypeIcon } from 'components/ui/EntityTypeIcon'
+import { getTabsStore } from 'state/tabs'
+
+export const TabPreview = ({ tab }: { tab: string }) => {
+ const { ref } = useParams()
+ const store = getTabsStore(ref)
+ const tabs = useSnapshot(store)
+
+ const tabData = tabs.tabsMap[tab]
+
+ if (!tabData) return null
+
+ return (
+ <motion.div
+ layoutId={tab}
+ transition={{ duration: 0.045 }}
+ animate={{ opacity: 0.7 }}
+ className="flex relative items-center gap-2 px-3 text-xs bg-dash-sidebar dark:bg-surface-100 shadow-lg rounded-sm h-10"
+ >
+ <EntityTypeIcon type={tabData.type} />
+ <span>{tabData.label || 'Untitled'}</span>
+ <div className="absolute w-full top-0 left-0 right-0 h-px bg-foreground-muted" />
+ </motion.div>
+ )
+}
diff --git a/apps/studio/components/layouts/Tabs.tsx b/apps/studio/components/layouts/Tabs/Tabs.tsx
similarity index 52%
rename from apps/studio/components/layouts/Tabs.tsx
rename to apps/studio/components/layouts/Tabs/Tabs.tsx
index 760ede2f516..8c9c79b1e87 100644
--- a/apps/studio/components/layouts/Tabs.tsx
+++ b/apps/studio/components/layouts/Tabs/Tabs.tsx
@@ -6,183 +6,34 @@ import {
useSensor,
useSensors,
} from '@dnd-kit/core'
-import { horizontalListSortingStrategy, SortableContext, useSortable } from '@dnd-kit/sortable'
-import { CSS } from '@dnd-kit/utilities'
+import { horizontalListSortingStrategy, SortableContext } from '@dnd-kit/sortable'
import { AnimatePresence, motion } from 'framer-motion'
import { Plus, X } from 'lucide-react'
import { useRouter } from 'next/router'
-import { useMemo } from 'react'
-import { useSnapshot } from 'valtio'
import { useParams } from 'common'
-import { EntityTypeIcon } from 'components/ui/EntityTypeIcon'
import { useAppStateSnapshot } from 'state/app-state'
import {
editorEntityTypes,
- getTabsStore,
handleTabClose,
handleTabDragEnd,
handleTabNavigation,
- makeTabPermanent,
+ useTabsStore,
type Tab,
} from 'state/tabs'
import { cn, Tabs_Shadcn_, TabsList_Shadcn_, TabsTrigger_Shadcn_ } from 'ui'
-import { useEditorType } from './editors/EditorsLayout.hooks'
-import { CollapseButton } from './Tabs/CollapseButton'
+import { useEditorType } from '../editors/EditorsLayout.hooks'
+import { CollapseButton } from './CollapseButton'
+import { SortableTab } from './SortableTab'
+import { TabPreview } from './TabPreview'
-/**
- * Individual draggable tab component that handles:
- * - Drag
- * - Drop functionality
- * - Dynamic schema name display
- * - Tab label animations
- * - Close button interactions
- */
-const SortableTab = ({
- tab,
- index,
- openTabs,
- onClose,
-}: {
- tab: Tab
- index: number
- openTabs: Tab[]
- onClose: (id: string) => void
-}) => {
- const router = useRouter()
- const { ref } = useParams()
- const currentSchema = (router.query.schema as string) || 'public'
-
- const { attributes, listeners, setNodeRef, transform, transition, isDragging } = useSortable({
- id: tab.id,
- })
-
- const style = {
- transform: CSS.Transform.toString(transform),
- transition,
- zIndex: isDragging ? 1 : 0,
- }
-
- // Update schema visibility check to include URL param comparison
- const shouldShowSchema = useMemo(() => {
- // For both table and schema tabs, show schema if:
- // Any tab has a different schema than the current schema parameter
- if (tab.type === 'r') {
- const anyTabHasDifferentSchema = openTabs
- .filter((t) => t.type === 'r')
- .some((t) => t.metadata?.schema !== currentSchema)
-
- return anyTabHasDifferentSchema
- }
-
- return false
- }, [openTabs, currentSchema, tab.type])
-
- // Create a motion version of TabsTrigger while preserving all functionality
- // const MotionTabsTrigger = motion(TabsTrigger_Shadcn_)
-
- return (
- <motion.div
- ref={setNodeRef}
- style={style}
- {...attributes}
- layoutId={tab.id}
- transition={{ duration: 0.045 }}
- animate={{ opacity: isDragging ? 0 : 1 }}
- className={cn('flex items-center h-10 first-of-type:border-l')}
- >
- <TabsTrigger_Shadcn_
- value={tab.id}
- onDoubleClick={() => makeTabPermanent(ref, tab.id)}
- className={cn(
- 'flex items-center gap-2 px-3 text-xs',
- 'bg-dash-sidebar/50 dark:bg-surface-100/50',
- 'data-[state=active]:bg-dash-sidebar dark:data-[state=active]:bg-surface-100',
- 'border-b border-default',
- // bottom border active rule
- 'data-[state=active]:border-b-background-dash-sidebar dark:data-[state=active]:border-b-background-surface-100',
- 'relative group h-full',
- 'hover:bg-surface-300 dark:hover:bg-surface-100',
- tab.isPreview && 'italic font-light' // Optional: style preview tabs differently
- )}
- {...listeners}
- >
- <EntityTypeIcon type={tab.type} />
- <div className="flex items-center gap-0">
- <AnimatePresence mode="popLayout" initial>
- {shouldShowSchema && (
- <motion.span
- initial={{ opacity: 0, width: 0 }}
- animate={{ opacity: 1, width: 'auto' }}
- exit={{ opacity: 0, width: 0 }}
- transition={{ duration: 0.15 }}
- className="text-foreground-muted group-data-[state=active]:text-foreground-lighter"
- >
- {tab?.metadata?.schema}.
- </motion.span>
- )}
- </AnimatePresence>
- <span>{tab.label || 'Untitled'}</span>
- </div>
- <span
- role="button"
- onClick={(e) => {
- e.preventDefault()
- e.stopPropagation()
- }}
- className="ml-1 opacity-0 group-hover:opacity-100 hover:bg-200 rounded-sm cursor-pointer"
- onMouseDown={(e) => {
- e.preventDefault()
- e.stopPropagation()
- }}
- onPointerDown={(e) => {
- e.preventDefault()
- e.stopPropagation()
- onClose(tab.id)
- }}
- >
- <X size={12} className="text-foreground-light" />
- </span>
- <div className="absolute w-full top-0 left-0 right-0 h-px bg-foreground opacity-0 group-data-[state=active]:opacity-100" />
- </TabsTrigger_Shadcn_>
- {index < openTabs.length && (
- <div role="separator" className="h-full w-px bg-border" key={`separator-${tab.id}`} />
- )}
- </motion.div>
- )
-}
-
-const TabPreview = ({ tab }: { tab: string }) => {
- const { ref } = useParams()
- const store = getTabsStore(ref)
- const tabs = useSnapshot(store)
-
- const tabData = tabs.tabsMap[tab]
-
- if (!tabData) return null
-
- return (
- <motion.div
- layoutId={tab}
- transition={{ duration: 0.045 }}
- animate={{ opacity: 0.7 }}
- className="flex relative items-center gap-2 px-3 text-xs bg-dash-sidebar dark:bg-surface-100 shadow-lg rounded-sm h-10"
- >
- <EntityTypeIcon type={tabData.type} />
- <span>{tabData.label || 'Untitled'}</span>
- <div className="absolute w-full top-0 left-0 right-0 h-px bg-foreground-muted" />
- </motion.div>
- )
-}
-
-export function Tabs() {
+export const EditorTabs = () => {
const { ref } = useParams()
const router = useRouter()
const appSnap = useAppStateSnapshot()
const editor = useEditorType()
- const store = getTabsStore(ref)
- const tabs = useSnapshot(store)
+ const tabs = useTabsStore(ref)
const sensors = useSensors(
useSensor(PointerSensor, {
activationConstraint: {
diff --git a/apps/studio/components/layouts/editors/EditorBaseLayout.tsx b/apps/studio/components/layouts/editors/EditorBaseLayout.tsx
index 7bbb23035b0..72fe6c50c0b 100644
--- a/apps/studio/components/layouts/editors/EditorBaseLayout.tsx
+++ b/apps/studio/components/layouts/editors/EditorBaseLayout.tsx
@@ -8,8 +8,8 @@ import {
} from 'components/interfaces/App/FeaturePreview/FeaturePreviewContext'
import { cn } from 'ui'
import { ProjectLayoutWithAuth } from '../ProjectLayout/ProjectLayout'
-import { Tabs } from '../Tabs'
import { CollapseButton } from '../Tabs/CollapseButton'
+import { EditorTabs } from '../Tabs/Tabs'
import { useEditorType } from './EditorsLayout.hooks'
export interface ExplorerLayoutProps extends ComponentProps<typeof ProjectLayoutWithAuth> {
@@ -41,8 +41,7 @@ export const EditorBaseLayout = ({ children, title, product, ...props }: Explore
!hideTabs ? 'bg-surface-200 dark:bg-alternative' : 'bg-surface-100'
)}
>
- {hideTabs && <CollapseButton hideTabs={hideTabs} />}
- {!hideTabs && <Tabs />}
+ {hideTabs ? <CollapseButton hideTabs={hideTabs} /> : <EditorTabs />}
</div>
) : null}
<div className="h-full">{children}</div>
diff --git a/apps/studio/data/table-editor/table-editor-query.ts b/apps/studio/data/table-editor/table-editor-query.ts
index b9fcdc975d9..8346ca7ae01 100644
--- a/apps/studio/data/table-editor/table-editor-query.ts
+++ b/apps/studio/data/table-editor/table-editor-query.ts
@@ -49,6 +49,8 @@ export const useTableEditorQuery = <TData = TableEditorData>(
{
enabled:
enabled && typeof projectRef !== 'undefined' && typeof id !== 'undefined' && !isNaN(id),
+ refetchOnWindowFocus: false,
+ refetchOnMount: false,
staleTime: 5 * 60 * 1000, // 5 minutes
...options,
}
diff --git a/apps/studio/pages/project/[ref]/editor/[id].tsx b/apps/studio/pages/project/[ref]/editor/[id].tsx
index ea6977367ca..c1f16f54964 100644
--- a/apps/studio/pages/project/[ref]/editor/[id].tsx
+++ b/apps/studio/pages/project/[ref]/editor/[id].tsx
@@ -3,8 +3,8 @@ import { useCallback, useEffect } from 'react'
import { useParams } from 'common'
import { useIsTableEditorTabsEnabled } from 'components/interfaces/App/FeaturePreview/FeaturePreviewContext'
-import { TableGridEditor } from 'components/interfaces/TableGridEditor'
import DeleteConfirmationDialogs from 'components/interfaces/TableGridEditor/DeleteConfirmationDialogs'
+import { TableGridEditor } from 'components/interfaces/TableGridEditor/TableGridEditor'
import DefaultLayout from 'components/layouts/DefaultLayout'
import { EditorBaseLayout } from 'components/layouts/editors/EditorBaseLayout'
import { useProjectContext } from 'components/layouts/ProjectLayout/ProjectContext'
diff --git a/apps/studio/state/tabs.ts b/apps/studio/state/tabs.ts
index cae1ed4fa49..7ddd4ea72ce 100644
--- a/apps/studio/state/tabs.ts
+++ b/apps/studio/state/tabs.ts
@@ -1,7 +1,7 @@
import { ENTITY_TYPE } from 'data/entity-types/entity-type-constants'
import { NextRouter } from 'next/router'
import { ReactNode } from 'react'
-import { proxy, subscribe } from 'valtio'
+import { proxy, subscribe, useSnapshot } from 'valtio'
import { addRecentItem } from './recent-items'
/**
@@ -13,9 +13,28 @@ import { addRecentItem } from './recent-items'
* So do not use this as reference for writing new valtio stores - refer to database-selector instead
*/
+// Object mapping editor types to their corresponding tab types
+export const editorEntityTypes = {
+ table: ['r', 'v', 'm', 'f', 'p'],
+ sql: ['sql'],
+}
+
// Define the type of tabs available in the application
export type TabType = ENTITY_TYPE | 'sql'
+type CreateTabIdParams = {
+ r: { id: number }
+ v: { id: number }
+ m: { id: number }
+ f: { id: number }
+ p: { id: number }
+ sql: { id: string }
+ schema: { schema: string }
+ view: never
+ function: never
+ new: never
+}
+
export interface Tab {
id: string // Unique identifier for the tab
type: TabType // Type of the tab, which can be an entity type or specific string values
@@ -60,7 +79,7 @@ const defaultState: TabsState = {
export const tabsStore = proxy<TabsStateMap>({})
// Helper to get/create state for a specific ref
-export const getTabsStore = (ref: string | undefined): TabsState => {
+export const getTabsStore = (ref?: string): TabsState => {
if (!ref) return proxy(defaultState)
if (!tabsStore[ref]) {
const stored = localStorage.getItem(getStorageKey(ref))
@@ -87,6 +106,11 @@ export const getTabsStore = (ref: string | undefined): TabsState => {
return tabsStore[ref]
}
+export const useTabsStore = (ref?: string) => {
+ const store = getTabsStore(ref)
+ return useSnapshot(store)
+}
+
// Subscribe to changes for each ref and save to localStorage
if (typeof window !== 'undefined') {
subscribe(tabsStore, () => {
@@ -349,19 +373,6 @@ export const handleTabDragEnd = (
handleTabNavigation(ref, tabId, router)
}
-type CreateTabIdParams = {
- r: { id: number }
- v: { id: number }
- m: { id: number }
- f: { id: number }
- p: { id: number }
- sql: { id: string }
- schema: { schema: string }
- view: never
- function: never
- new: never
-}
-
// Function to create a unique tab ID based on type and parameters
export function createTabId<T extends TabType>(type: T, params: CreateTabIdParams[T]): string {
switch (type) {
@@ -382,12 +393,6 @@ export function createTabId<T extends TabType>(type: T, params: CreateTabIdParam
}
}
-// Object mapping editor types to their corresponding tab types
-export const editorEntityTypes = {
- table: ['r', 'v', 'm', 'f', 'p'],
- sql: ['sql'],
-}
-
// Function to remove tabs based on their editor type
export function removeTabsByEditor(ref: string | undefined, type: 'table' | 'sql') {
if (!ref) return