Skip to content

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

fix: studio circular imports (#36026)

Alaister Youngd75cb8b45c15
diff --git a/apps/studio/components/interfaces/App/FeaturePreview/FeaturePreview.constants.tsx b/apps/studio/components/interfaces/App/FeaturePreview/FeaturePreview.constants.tsx
new file mode 100644
index 00000000000..ceadbd396bf
--- /dev/null
+++ b/apps/studio/components/interfaces/App/FeaturePreview/FeaturePreview.constants.tsx
@@ -0,0 +1,39 @@
+import { LOCAL_STORAGE_KEYS } from 'common'
+
+export const FEATURE_PREVIEWS = [
+ {
+ key: LOCAL_STORAGE_KEYS.UI_PREVIEW_INLINE_EDITOR,
+ name: 'Directly edit database entities',
+ discussionsUrl: 'https://github.com/orgs/supabase/discussions/33690',
+ isNew: true,
+ isPlatformOnly: false,
+ },
+ {
+ key: LOCAL_STORAGE_KEYS.UI_TABLE_EDITOR_TABS,
+ name: 'Table Editor Tabs',
+ discussionsUrl: 'https://github.com/orgs/supabase/discussions/35636',
+ isNew: true,
+ isPlatformOnly: false,
+ },
+ {
+ key: LOCAL_STORAGE_KEYS.UI_SQL_EDITOR_TABS,
+ name: 'SQL Editor Tabs',
+ discussionsUrl: 'https://github.com/orgs/supabase/discussions/35636',
+ isNew: true,
+ isPlatformOnly: true,
+ },
+ {
+ key: LOCAL_STORAGE_KEYS.UI_PREVIEW_API_SIDE_PANEL,
+ name: 'Project API documentation',
+ discussionsUrl: 'https://github.com/orgs/supabase/discussions/18038',
+ isNew: false,
+ isPlatformOnly: false,
+ },
+ {
+ key: LOCAL_STORAGE_KEYS.UI_PREVIEW_CLS,
+ name: 'Column-level privileges',
+ discussionsUrl: 'https://github.com/orgs/supabase/discussions/20295',
+ isNew: false,
+ isPlatformOnly: false,
+ },
+] as const
diff --git a/apps/studio/components/interfaces/App/FeaturePreview/FeaturePreviewContext.tsx b/apps/studio/components/interfaces/App/FeaturePreview/FeaturePreviewContext.tsx
index 28bdcbfaafe..4fa0a7dcf67 100644
--- a/apps/studio/components/interfaces/App/FeaturePreview/FeaturePreviewContext.tsx
+++ b/apps/studio/components/interfaces/App/FeaturePreview/FeaturePreviewContext.tsx
@@ -5,54 +5,7 @@ import { FeatureFlagContext, LOCAL_STORAGE_KEYS } from 'common'
import { useFlag } from 'hooks/ui/useFlag'
import { IS_PLATFORM } from 'lib/constants'
import { EMPTY_OBJ } from 'lib/void'
-import { APISidePanelPreview } from './APISidePanelPreview'
-import { CLSPreview } from './CLSPreview'
-import { InlineEditorPreview } from './InlineEditorPreview'
-import { SqlEditorTabsPreview } from './SqlEditorTabs'
-import { TableEditorTabsPreview } from './TableEditorTabs'
-
-export const FEATURE_PREVIEWS = [
- {
- key: LOCAL_STORAGE_KEYS.UI_PREVIEW_INLINE_EDITOR,
- name: 'Directly edit database entities',
- content: <InlineEditorPreview />,
- discussionsUrl: 'https://github.com/orgs/supabase/discussions/33690',
- isNew: true,
- isPlatformOnly: false,
- },
- {
- key: LOCAL_STORAGE_KEYS.UI_TABLE_EDITOR_TABS,
- name: 'Table Editor Tabs',
- content: <TableEditorTabsPreview />,
- discussionsUrl: 'https://github.com/orgs/supabase/discussions/35636',
- isNew: true,
- isPlatformOnly: false,
- },
- {
- key: LOCAL_STORAGE_KEYS.UI_SQL_EDITOR_TABS,
- name: 'SQL Editor Tabs',
- content: <SqlEditorTabsPreview />,
- discussionsUrl: 'https://github.com/orgs/supabase/discussions/35636',
- isNew: true,
- isPlatformOnly: true,
- },
- {
- key: LOCAL_STORAGE_KEYS.UI_PREVIEW_API_SIDE_PANEL,
- name: 'Project API documentation',
- content: <APISidePanelPreview />,
- discussionsUrl: 'https://github.com/orgs/supabase/discussions/18038',
- isNew: false,
- isPlatformOnly: false,
- },
- {
- key: LOCAL_STORAGE_KEYS.UI_PREVIEW_CLS,
- name: 'Column-level privileges',
- content: <CLSPreview />,
- discussionsUrl: 'https://github.com/orgs/supabase/discussions/20295',
- isNew: false,
- isPlatformOnly: false,
- },
-]
+import { FEATURE_PREVIEWS } from './FeaturePreview.constants'
type FeaturePreviewContextType = {
flags: { [key: string]: boolean }
diff --git a/apps/studio/components/interfaces/App/FeaturePreview/FeaturePreviewModal.tsx b/apps/studio/components/interfaces/App/FeaturePreview/FeaturePreviewModal.tsx
index fdeabb3c52e..94bc324361f 100644
--- a/apps/studio/components/interfaces/App/FeaturePreview/FeaturePreviewModal.tsx
+++ b/apps/studio/components/interfaces/App/FeaturePreview/FeaturePreviewModal.tsx
@@ -1,6 +1,6 @@
import { ExternalLink, Eye, EyeOff, FlaskConical } from 'lucide-react'
import Link from 'next/link'
-import { useEffect } from 'react'
+import { ReactNode, useEffect } from 'react'
import { LOCAL_STORAGE_KEYS, useParams } from 'common'
import { useSendEventMutation } from 'data/telemetry/send-event-mutation'
@@ -9,7 +9,23 @@ import { IS_PLATFORM } from 'lib/constants'
import { useAppStateSnapshot } from 'state/app-state'
import { removeTabsByEditor } from 'state/tabs'
import { Badge, Button, Modal, ScrollArea, cn } from 'ui'
-import { FEATURE_PREVIEWS, useFeaturePreviewContext } from './FeaturePreviewContext'
+import { APISidePanelPreview } from './APISidePanelPreview'
+import { CLSPreview } from './CLSPreview'
+import { FEATURE_PREVIEWS } from './FeaturePreview.constants'
+import { useFeaturePreviewContext } from './FeaturePreviewContext'
+import { InlineEditorPreview } from './InlineEditorPreview'
+import { SqlEditorTabsPreview } from './SqlEditorTabs'
+import { TableEditorTabsPreview } from './TableEditorTabs'
+
+const FEATURE_PREVIEW_KEY_TO_CONTENT: {
+ [key: string]: ReactNode
+} = {
+ [LOCAL_STORAGE_KEYS.UI_PREVIEW_INLINE_EDITOR]: <InlineEditorPreview />,
+ [LOCAL_STORAGE_KEYS.UI_TABLE_EDITOR_TABS]: <TableEditorTabsPreview />,
+ [LOCAL_STORAGE_KEYS.UI_SQL_EDITOR_TABS]: <SqlEditorTabsPreview />,
+ [LOCAL_STORAGE_KEYS.UI_PREVIEW_API_SIDE_PANEL]: <APISidePanelPreview />,
+ [LOCAL_STORAGE_KEYS.UI_PREVIEW_CLS]: <CLSPreview />,
+}
const FeaturePreviewModal = () => {
const { ref } = useParams()
@@ -128,7 +144,7 @@ const FeaturePreviewModal = () => {
</Button>
</div>
</div>
- {selectedFeature?.content}
+ {FEATURE_PREVIEW_KEY_TO_CONTENT[selectedFeatureKey]}
</div>
</div>
) : (
diff --git a/apps/studio/components/interfaces/Auth/Users/UserHeader.tsx b/apps/studio/components/interfaces/Auth/Users/UserHeader.tsx
index 6f89b2fb0cf..0c4cd915b2a 100644
--- a/apps/studio/components/interfaces/Auth/Users/UserHeader.tsx
+++ b/apps/studio/components/interfaces/Auth/Users/UserHeader.tsx
@@ -3,7 +3,7 @@ import { Copy } from 'lucide-react'
import CopyButton from 'components/ui/CopyButton'
import { User } from 'data/auth/users-infinite-query'
import { cn } from 'ui'
-import { PANEL_PADDING } from './UserPanel'
+import { PANEL_PADDING } from './Users.constants'
import { getDisplayName } from './Users.utils'
export const UserHeader = ({ user }: { user: User }) => {
diff --git a/apps/studio/components/interfaces/Auth/Users/UserLogs.tsx b/apps/studio/components/interfaces/Auth/Users/UserLogs.tsx
index dd252116ba2..a0a13a8479c 100644
--- a/apps/studio/components/interfaces/Auth/Users/UserLogs.tsx
+++ b/apps/studio/components/interfaces/Auth/Users/UserLogs.tsx
@@ -1,19 +1,18 @@
-import dayjs from 'dayjs'
import { ExternalLink, RefreshCw } from 'lucide-react'
import Link from 'next/link'
import { useEffect } from 'react'
import { useParams } from 'common'
import { LOGS_TABLES } from 'components/interfaces/Settings/Logs/Logs.constants'
+import { ButtonTooltip } from 'components/ui/ButtonTooltip'
import { GenericSkeletonLoader } from 'components/ui/ShimmeringLoader'
import { User } from 'data/auth/users-infinite-query'
import useLogsPreview from 'hooks/analytics/useLogsPreview'
+import { useLogsUrlState } from 'hooks/analytics/useLogsUrlState'
import { Button, cn, CriticalIcon, Separator } from 'ui'
import { Admonition, TimestampInfo } from 'ui-patterns'
import { UserHeader } from './UserHeader'
-import { PANEL_PADDING } from './UserPanel'
-import { ButtonTooltip } from 'components/ui/ButtonTooltip'
-import { useLogsUrlState } from 'hooks/analytics/useLogsUrlState'
+import { PANEL_PADDING } from './Users.constants'
interface UserLogsProps {
user: User
diff --git a/apps/studio/components/interfaces/Auth/Users/UserOverview.tsx b/apps/studio/components/interfaces/Auth/Users/UserOverview.tsx
index a8ade0baf4b..0cb86332ff9 100644
--- a/apps/studio/components/interfaces/Auth/Users/UserOverview.tsx
+++ b/apps/studio/components/interfaces/Auth/Users/UserOverview.tsx
@@ -25,7 +25,7 @@ import { PROVIDERS_SCHEMAS } from '../AuthProvidersFormValidation'
import { BanUserModal } from './BanUserModal'
import { DeleteUserModal } from './DeleteUserModal'
import { UserHeader } from './UserHeader'
-import { PANEL_PADDING } from './UserPanel'
+import { PANEL_PADDING } from './Users.constants'
import { providerIconMap } from './Users.utils'
const DATE_FORMAT = 'DD MMM, YYYY HH:mm'
diff --git a/apps/studio/components/interfaces/Auth/Users/UserPanel.tsx b/apps/studio/components/interfaces/Auth/Users/UserPanel.tsx
index 70713f54ee5..730ed2d3ccc 100644
--- a/apps/studio/components/interfaces/Auth/Users/UserPanel.tsx
+++ b/apps/studio/components/interfaces/Auth/Users/UserPanel.tsx
@@ -1,4 +1,3 @@
-import { SimpleCodeBlock } from 'ui'
import { User } from 'data/auth/users-infinite-query'
import { X } from 'lucide-react'
import { useState } from 'react'
@@ -8,21 +7,21 @@ import {
Input_Shadcn_,
ResizableHandle,
ResizablePanel,
+ SimpleCodeBlock,
Tabs_Shadcn_,
TabsContent_Shadcn_,
TabsList_Shadcn_,
TabsTrigger_Shadcn_,
} from 'ui'
-import { UserOverview } from './UserOverview'
import { UserLogs } from './UserLogs'
+import { UserOverview } from './UserOverview'
+import { PANEL_PADDING } from './Users.constants'
interface UserPanelProps {
selectedUser?: User
onClose: () => void
}
-export const PANEL_PADDING = 'px-5 py-5'
-
export const UserPanel = ({ selectedUser, onClose }: UserPanelProps) => {
const [view, setView] = useState<'overview' | 'raw' | 'logs'>('overview')
const [searchQuery, setSearchQuery] = useState('')
diff --git a/apps/studio/components/interfaces/Auth/Users/Users.constants.ts b/apps/studio/components/interfaces/Auth/Users/Users.constants.ts
index b4f9c8a7e1f..daa7050d141 100644
--- a/apps/studio/components/interfaces/Auth/Users/Users.constants.ts
+++ b/apps/studio/components/interfaces/Auth/Users/Users.constants.ts
@@ -1,6 +1,8 @@
import { BASE_PATH } from 'lib/constants'
import { PROVIDER_PHONE, PROVIDERS_SCHEMAS } from '../AuthProvidersFormValidation'
+export const PANEL_PADDING = 'px-5 py-5'
+
// [Joshen] Temporary fix as bulk delete will fire n requests since Auth + API do not have a bulk delete endpoint yet
export const MAX_BULK_DELETE = 20
@@ -17,3 +19,23 @@ export const PROVIDER_FILTER_OPTIONS = PROVIDERS_SCHEMAS.map((provider) => ({
iconClass: '',
}))
)
+
+export type UsersTableColumn = {
+ id: string
+ name: string
+ minWidth?: number
+ width?: number
+ resizable?: boolean
+}
+export type ColumnConfiguration = { id: string; width?: number }
+export const USERS_TABLE_COLUMNS: UsersTableColumn[] = [
+ { id: 'img', name: '', minWidth: 95, width: 95, resizable: false },
+ { id: 'id', name: 'UID', width: 280 },
+ { id: 'name', name: 'Display name', minWidth: 0, width: 150 },
+ { id: 'email', name: 'Email', width: 300 },
+ { id: 'phone', name: 'Phone' },
+ { id: 'providers', name: 'Providers', minWidth: 150 },
+ { id: 'provider_type', name: 'Provider type', minWidth: 150 },
+ { id: 'created_at', name: 'Created at', width: 260 },
+ { id: 'last_sign_in_at', name: 'Last sign in at', width: 260 },
+]
diff --git a/apps/studio/components/interfaces/Auth/Users/Users.utils.tsx b/apps/studio/components/interfaces/Auth/Users/Users.utils.tsx
index df4d24415c3..7f5be688a1c 100644
--- a/apps/studio/components/interfaces/Auth/Users/Users.utils.tsx
+++ b/apps/studio/components/interfaces/Auth/Users/Users.utils.tsx
@@ -16,8 +16,8 @@ import {
ContextMenuTrigger_Shadcn_,
} from 'ui'
import { PROVIDERS_SCHEMAS } from '../AuthProvidersFormValidation'
+import { ColumnConfiguration, USERS_TABLE_COLUMNS } from './Users.constants'
import { HeaderCell } from './UsersGridComponents'
-import { ColumnConfiguration, USERS_TABLE_COLUMNS } from './UsersV2'
const GITHUB_AVATAR_URL = 'https://avatars.githubusercontent.com'
const SUPPORTED_CSP_AVATAR_URLS = [GITHUB_AVATAR_URL, 'https://lh3.googleusercontent.com']
diff --git a/apps/studio/components/interfaces/Auth/Users/UsersV2.tsx b/apps/studio/components/interfaces/Auth/Users/UsersV2.tsx
index cf79c68398a..9597cb064c2 100644
--- a/apps/studio/components/interfaces/Auth/Users/UsersV2.tsx
+++ b/apps/studio/components/interfaces/Auth/Users/UsersV2.tsx
@@ -45,29 +45,15 @@ import { GenericSkeletonLoader } from 'ui-patterns/ShimmeringLoader'
import AddUserDropdown from './AddUserDropdown'
import { DeleteUserModal } from './DeleteUserModal'
import { UserPanel } from './UserPanel'
-import { MAX_BULK_DELETE, PROVIDER_FILTER_OPTIONS } from './Users.constants'
+import {
+ ColumnConfiguration,
+ MAX_BULK_DELETE,
+ PROVIDER_FILTER_OPTIONS,
+ USERS_TABLE_COLUMNS,
+} from './Users.constants'
import { formatUserColumns, formatUsersData, isAtBottom } from './Users.utils'
export type Filter = 'all' | 'verified' | 'unverified' | 'anonymous'
-export type UsersTableColumn = {
- id: string
- name: string
- minWidth?: number
- width?: number
- resizable?: boolean
-}
-export type ColumnConfiguration = { id: string; width?: number }
-export const USERS_TABLE_COLUMNS: UsersTableColumn[] = [
- { id: 'img', name: '', minWidth: 95, width: 95, resizable: false },
- { id: 'id', name: 'UID', width: 280 },
- { id: 'name', name: 'Display name', minWidth: 0, width: 150 },
- { id: 'email', name: 'Email', width: 300 },
- { id: 'phone', name: 'Phone' },
- { id: 'providers', name: 'Providers', minWidth: 150 },
- { id: 'provider_type', name: 'Provider type', minWidth: 150 },
- { id: 'created_at', name: 'Created at', width: 260 },
- { id: 'last_sign_in_at', name: 'Last sign in at', width: 260 },
-]
// [Joshen] Just naming it as V2 as its a rewrite of the old one, to make it easier for reviews
// Can change it to remove V2 thereafter
diff --git a/apps/studio/components/interfaces/Integrations/Wrappers/OverviewTab.tsx b/apps/studio/components/interfaces/Integrations/Wrappers/OverviewTab.tsx
index 8408082c045..3dd175b146d 100644
--- a/apps/studio/components/interfaces/Integrations/Wrappers/OverviewTab.tsx
+++ b/apps/studio/components/interfaces/Integrations/Wrappers/OverviewTab.tsx
@@ -18,8 +18,8 @@ import {
WarningIcon,
} from 'ui'
import { IntegrationOverviewTab } from '../Integration/IntegrationOverviewTab'
-import { INTEGRATIONS } from '../Landing/Integrations.constants'
import { CreateWrapperSheet } from './CreateWrapperSheet'
+import { WRAPPERS } from './Wrappers.constants'
import { WrapperTable } from './WrapperTable'
export const WrapperOverviewTab = () => {
@@ -34,13 +34,12 @@ export const WrapperOverviewTab = () => {
connectionString: project?.connectionString,
})
- const integration = INTEGRATIONS.find((i) => i.id === id)
+ const wrapperMeta = WRAPPERS.find((w) => w.name === id)
- if (integration?.type !== 'wrapper') {
+ if (!wrapperMeta) {
return <p className="text-sm text-foreground-light">Unsupported integration type</p>
}
- const wrapperMeta = integration.meta
const wrappersExtension = data?.find((ext) => ext.name === 'wrappers')
const isWrappersExtensionInstalled = !!wrappersExtension?.installed_version
const hasRequiredVersion =
@@ -117,7 +116,7 @@ export const WrapperOverviewTab = () => {
<Sheet open={!!createWrapperShown} onOpenChange={() => setisClosingCreateWrapper(true)}>
<SheetContent size="lg" tabIndex={undefined}>
<CreateWrapperSheet
- wrapperMeta={integration.meta}
+ wrapperMeta={wrapperMeta}
onClose={() => {
setCreateWrapperShown(false)
setisClosingCreateWrapper(false)
diff --git a/apps/studio/components/interfaces/Integrations/Wrappers/WrappersTab.tsx b/apps/studio/components/interfaces/Integrations/Wrappers/WrappersTab.tsx
index f84bf45a2d9..42b2eee1c13 100644
--- a/apps/studio/components/interfaces/Integrations/Wrappers/WrappersTab.tsx
+++ b/apps/studio/components/interfaces/Integrations/Wrappers/WrappersTab.tsx
@@ -7,11 +7,11 @@ import { ButtonTooltip } from 'components/ui/ButtonTooltip'
import { FDW, useFDWsQuery } from 'data/fdw/fdws-query'
import { useCheckPermissions } from 'hooks/misc/useCheckPermissions'
import { Sheet, SheetContent } from 'ui'
-import { INTEGRATIONS } from '../Landing/Integrations.constants'
import { CreateWrapperSheet } from './CreateWrapperSheet'
-import { WrapperTable } from './WrapperTable'
import DeleteWrapperModal from './DeleteWrapperModal'
+import { WRAPPERS } from './Wrappers.constants'
import { wrapperMetaComparator } from './Wrappers.utils'
+import { WrapperTable } from './WrapperTable'
export const WrappersTab = () => {
const { id } = useParams()
@@ -27,13 +27,12 @@ export const WrappersTab = () => {
})
const wrappers = data ?? []
- const integration = INTEGRATIONS.find((i) => i.id === id)
+ const wrapperMeta = WRAPPERS.find((w) => w.name === id)
// this contains a collection of all wrapper instances for the wrapper type
- const createdWrappers =
- integration?.type === 'wrapper'
- ? wrappers.filter((w) => wrapperMetaComparator(integration.meta, w))
- : []
+ const createdWrappers = wrapperMeta
+ ? wrappers.filter((w) => wrapperMetaComparator(wrapperMeta, w))
+ : []
const Container = useCallback(
({ ...props }: { children: ReactNode } & HTMLProps<HTMLDivElement>) => (
@@ -41,9 +40,9 @@ export const WrappersTab = () => {
{props.children}
<Sheet open={!!createWrapperShown} onOpenChange={() => setisClosingCreateWrapper(true)}>
<SheetContent size="lg" tabIndex={undefined}>
- {integration?.type === 'wrapper' && (
+ {wrapperMeta && (
<CreateWrapperSheet
- wrapperMeta={integration.meta}
+ wrapperMeta={wrapperMeta}
onClose={() => {
setCreateWrapperShown(false)
setisClosingCreateWrapper(false)
@@ -56,10 +55,10 @@ export const WrappersTab = () => {
</Sheet>
</div>
),
- [createWrapperShown, integration, isClosingCreateWrapper]
+ [createWrapperShown, wrapperMeta, isClosingCreateWrapper]
)
- if (!integration || integration.type !== 'wrapper') {
+ if (!wrapperMeta) {
return <div>Missing integration.</div>
}
@@ -69,7 +68,7 @@ export const WrappersTab = () => {
<div className=" w-full h-48 max-w-4xl">
<div className="border rounded-lg h-full flex flex-col gap-y-2 items-center justify-center">
<p className="text-sm text-foreground-light">
- No {integration.meta.label} wrappers have been installed
+ No {wrapperMeta.label} wrappers have been installed
</p>
<ButtonTooltip
type="default"
diff --git a/apps/studio/components/layouts/ProjectLayout/ProjectContext.tsx b/apps/studio/components/layouts/ProjectLayout/ProjectContext.tsx
index 5d0ded13105..a3da2c23ed9 100644
--- a/apps/studio/components/layouts/ProjectLayout/ProjectContext.tsx
+++ b/apps/studio/components/layouts/ProjectLayout/ProjectContext.tsx
@@ -43,11 +43,8 @@ export const ProjectContextProvider = ({
return (
<ProjectContext.Provider value={value}>
<TableEditorStateContextProvider key={`table-editor-state-${projectRef}`}>
- <TabsStateContextProvider key={`tabs-state-${projectRef}`} projectRef={projectRef}>
- <AiAssistantStateContextProvider
- key={`ai-assistant-state-${projectRef}`}
- projectRef={projectRef}
- >
+ <TabsStateContextProvider key={`tabs-state-${projectRef}`}>
+ <AiAssistantStateContextProvider key={`ai-assistant-state-${projectRef}`}>
<StorageExplorerStateContextProvider key={`storage-explorer-state-${projectRef}`}>
<DatabaseSelectorStateContextProvider key={`database-selector-state-${projectRef}`}>
<RoleImpersonationStateContextProvider
diff --git a/apps/studio/data/permissions/permissions-query.ts b/apps/studio/data/permissions/permissions-query.ts
index bd0966c9c55..5de290221cc 100644
--- a/apps/studio/data/permissions/permissions-query.ts
+++ b/apps/studio/data/permissions/permissions-query.ts
@@ -1,8 +1,8 @@
import { useQuery, UseQueryOptions } from '@tanstack/react-query'
+import { useIsLoggedIn } from 'common'
import { get, handleError } from 'data/fetchers'
import { IS_PLATFORM } from 'lib/constants'
-import { useProfile } from 'lib/profile'
import type { Permission, ResponseError } from 'types'
import { permissionKeys } from './keys'
@@ -23,14 +23,14 @@ export const usePermissionsQuery = <TData = PermissionsData>({
enabled = true,
...options
}: UseQueryOptions<PermissionsData, PermissionsError, TData> = {}) => {
- const { profile } = useProfile()
+ const isLoggedIn = useIsLoggedIn()
return useQuery<PermissionsData, PermissionsError, TData>(
permissionKeys.list(),
({ signal }) => getPermissions(signal),
{
...options,
- enabled: IS_PLATFORM && enabled && profile !== undefined,
+ enabled: IS_PLATFORM && enabled && isLoggedIn,
staleTime: 30 * 60 * 1000,
}
)
diff --git a/apps/studio/state/ai-assistant-state.tsx b/apps/studio/state/ai-assistant-state.tsx
index d4ddd0d661f..167965d1f59 100644
--- a/apps/studio/state/ai-assistant-state.tsx
+++ b/apps/studio/state/ai-assistant-state.tsx
@@ -1,9 +1,11 @@
-import { openDB, DBSchema, IDBPDatabase } from 'idb'
import type { Message as MessageType } from 'ai/react'
+import { DBSchema, IDBPDatabase, openDB } from 'idb'
+import { debounce } from 'lodash'
import { createContext, PropsWithChildren, useContext, useEffect, useState } from 'react'
import { proxy, snapshot, subscribe, useSnapshot } from 'valtio'
-import { debounce } from 'lodash'
+
import { LOCAL_STORAGE_KEYS } from 'common'
+import { useSelectedProject } from 'hooks/misc/useSelectedProject'
type SuggestionsType = {
title: string
@@ -411,12 +413,8 @@ export type AiAssistantState = AiAssistantData & {
export const AiAssistantStateContext = createContext<AiAssistantState>(createAiAssistantState())
-export const AiAssistantStateContextProvider = ({
- projectRef,
- children,
-}: PropsWithChildren<{
- projectRef: string | undefined
-}>) => {
+export const AiAssistantStateContextProvider = ({ children }: PropsWithChildren) => {
+ const project = useSelectedProject()
// Initialize state. createAiAssistantState now just sets defaults.
const [state] = useState(() => createAiAssistantState())
@@ -425,8 +423,8 @@ export const AiAssistantStateContextProvider = ({
let isMounted = true
async function loadAndInitializeState() {
- if (!projectRef || typeof window === 'undefined') {
- if (projectRef === undefined) {
+ if (!project?.ref || typeof window === 'undefined') {
+ if (project?.ref === undefined) {
state.resetAiAssistantPanel()
}
return // Don't load if no projectRef or not in browser
@@ -435,11 +433,11 @@ export const AiAssistantStateContextProvider = ({
let loadedState: StoredAiAssistantState | null = null
// 1. Try loading from IndexedDB
- loadedState = await loadFromIndexedDB(projectRef)
+ loadedState = await loadFromIndexedDB(project?.ref)
// 2. If not in IndexedDB, try migrating from localStorage
if (!loadedState) {
- loadedState = await tryMigrateFromLocalStorage(projectRef)
+ loadedState = await tryMigrateFromLocalStorage(project?.ref)
}
if (!isMounted) return // Component unmounted during async operations
@@ -458,11 +456,11 @@ export const AiAssistantStateContextProvider = ({
return () => {
isMounted = false
}
- }, [projectRef, state])
+ }, [project?.ref, state])
// Effect to save state to IndexedDB on changes
useEffect(() => {
- if (typeof window !== 'undefined' && projectRef) {
+ if (typeof window !== 'undefined' && project?.ref) {
// Create a debounced version of saveAiState
const debouncedSaveAiState = debounce(saveAiState, 500)
@@ -470,7 +468,7 @@ export const AiAssistantStateContextProvider = ({
const snap = snapshot(state)
// Prepare state for IndexedDB
const stateToSave: StoredAiAssistantState = {
- projectRef: projectRef,
+ projectRef: project?.ref,
open: snap.open,
activeChatId: snap.activeChatId,
chats: snap.chats
@@ -495,7 +493,7 @@ export const AiAssistantStateContextProvider = ({
}
}
return undefined
- }, [state, projectRef])
+ }, [state, project?.ref])
return (
<AiAssistantStateContext.Provider value={state}>{children}</AiAssistantStateContext.Provider>
diff --git a/apps/studio/state/role-impersonation-state.tsx b/apps/studio/state/role-impersonation-state.tsx
index da30b4160f4..2d969f8ed0b 100644
--- a/apps/studio/state/role-impersonation-state.tsx
+++ b/apps/studio/state/role-impersonation-state.tsx
@@ -2,9 +2,9 @@ import { createContext, PropsWithChildren, useCallback, useContext, useEffect }
import { proxy, snapshot, subscribe, useSnapshot } from 'valtio'
import { useConstant } from 'common'
-import { useProjectContext } from 'components/layouts/ProjectLayout/ProjectContext'
import { executeSql } from 'data/sql/execute-sql-query'
import useLatest from 'hooks/misc/useLatest'
+import { useSelectedProject } from 'hooks/misc/useSelectedProject'
import { getPostgrestClaims, ImpersonationRole } from 'lib/role-impersonation'
import { CustomAccessTokenHookDetails } from '../hooks/misc/useCustomAccessTokenHookDetails'
@@ -58,7 +58,7 @@ export const RoleImpersonationStateContext = createContext<RoleImpersonationStat
)
export const RoleImpersonationStateContextProvider = ({ children }: PropsWithChildren) => {
- const { project } = useProjectContext()
+ const project = useSelectedProject()
async function customizeAccessToken({
schema,
functionName,
diff --git a/apps/studio/state/storage-explorer.tsx b/apps/studio/state/storage-explorer.tsx
index 1c21979b077..c02859646f4 100644
--- a/apps/studio/state/storage-explorer.tsx
+++ b/apps/studio/state/storage-explorer.tsx
@@ -8,7 +8,6 @@ import { proxy, snapshot, useSnapshot } from 'valtio'
import { createClient, SupabaseClient } from '@supabase/supabase-js'
import { BlobReader, BlobWriter, ZipWriter } from '@zip.js/zip.js'
import { LOCAL_STORAGE_KEYS } from 'common'
-import { useProjectContext } from 'components/layouts/ProjectLayout/ProjectContext'
import {
STORAGE_ROW_STATUS,
STORAGE_ROW_TYPES,
@@ -35,12 +34,14 @@ import { InlineLink } from 'components/ui/InlineLink'
import { configKeys } from 'data/config/keys'
import { getAPIKeys, useProjectSettingsV2Query } from 'data/config/project-settings-v2-query'
import { ProjectStorageConfigResponse } from 'data/config/project-storage-config-query'
+import type { Project } from 'data/projects/project-detail-query'
import { getQueryClient } from 'data/query-client'
import { deleteBucketObject } from 'data/storage/bucket-object-delete-mutation'
import { downloadBucketObject } from 'data/storage/bucket-object-download-mutation'
import { listBucketObjects, StorageObject } from 'data/storage/bucket-objects-list-mutation'
import { Bucket } from 'data/storage/buckets-query'
import { moveStorageObject } from 'data/storage/object-move-mutation'
+import { useSelectedProject } from 'hooks/misc/useSelectedProject'
import { IS_PLATFORM, PROJECT_STATUS } from 'lib/constants'
import { tryParseJson } from 'lib/helpers'
import { lookupMime } from 'lib/mime'
@@ -1709,7 +1710,7 @@ const StorageExplorerStateContext = createContext<StorageExplorerState>(
)
export const StorageExplorerStateContextProvider = ({ children }: PropsWithChildren) => {
- const { project } = useProjectContext()
+ const project = useSelectedProject()
const isPaused = project?.status === PROJECT_STATUS.INACTIVE
const [state, setState] = useState(() => createStorageExplorerState(DEFAULT_STATE_CONFIG))
diff --git a/apps/studio/state/tabs.tsx b/apps/studio/state/tabs.tsx
index ad5fdcb9749..59f9bdd8c44 100644
--- a/apps/studio/state/tabs.tsx
+++ b/apps/studio/state/tabs.tsx
@@ -1,5 +1,6 @@
import { useConstant } from 'common'
import { ENTITY_TYPE } from 'data/entity-types/entity-type-constants'
+import { useSelectedProject } from 'hooks/misc/useSelectedProject'
import { partition } from 'lodash'
import { NextRouter } from 'next/router'
import { createContext, PropsWithChildren, ReactNode, useContext, useEffect } from 'react'
@@ -397,17 +398,15 @@ export type TabsState = ReturnType<typeof createTabsState>
export const TabsStateContext = createContext<TabsState>(createTabsState(''))
-export const TabsStateContextProvider = ({
- projectRef,
- children,
-}: PropsWithChildren<{ projectRef?: string }>) => {
- const state = useConstant(() => createTabsState(projectRef ?? ''))
+export const TabsStateContextProvider = ({ children }: PropsWithChildren) => {
+ const project = useSelectedProject()
+ const state = useConstant(() => createTabsState(project?.ref ?? ''))
useEffect(() => {
- if (typeof window !== 'undefined' && projectRef) {
+ if (typeof window !== 'undefined' && project?.ref) {
return subscribe(state, () => {
localStorage.setItem(
- getTabsStorageKey(projectRef),
+ getTabsStorageKey(project?.ref),
JSON.stringify({
activeTab: state.activeTab,
openTabs: state.openTabs,
@@ -416,7 +415,7 @@ export const TabsStateContextProvider = ({
})
)
localStorage.setItem(
- getRecentItemsStorageKey(projectRef),
+ getRecentItemsStorageKey(project?.ref),
JSON.stringify({
items: state.recentItems,
})