The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.
TypeScript aialternativeauthdatabasedenoembeddingsexamplefirebasenextjsoauth2pgvectorpostgispostgrespostgresqlpostgrestrealtimesupabasevectorswebsockets
Assistant panel maximize CTA to open in explorer only if explorer preview is enabled (#50203)
Joshen Lim9a9228a9f8b3
diff --git a/apps/studio/components/layouts/DefaultLayout.tsx b/apps/studio/components/layouts/DefaultLayout.tsxindex 657b39766fb..defd49f45a8 100644--- a/apps/studio/components/layouts/DefaultLayout.tsx+++ b/apps/studio/components/layouts/DefaultLayout.tsx@@ -52,6 +52,7 @@ export const DefaultLayout = ({const router = useRouter()const panelRef = usePanelRef()const isMobile = useBreakpoint('md')+ const isSidebarOverlay = useBreakpoint('xl')const appSnap = useAppStateSnapshot()const { isMaximised, activeSidebar } = useSidebarManagerSnapshot()const { lastVisitedOrganization } = useLastVisitedOrganization()@@ -77,13 +78,13 @@ export const DefaultLayout = ({}, [])useEffect(() => {- if (!isMounted || !panelRef.current || !activeSidebar || isMobile) return+ if (!isMounted || !panelRef.current || !activeSidebar || isMobile || isSidebarOverlay) returnif (isMaximised) {panelRef.current.collapse()} else {panelRef.current.resize(`${contentMaxSizePercentage}%`)}- }, [isMounted, isMaximised, panelRef, activeSidebar, isMobile])+ }, [isMounted, isMaximised, panelRef, activeSidebar, isMobile, isSidebarOverlay])// This is required to prevent layout shift when rendering resizable panels (they initially render at 50%, then shift// to whatever is specified).diff --git a/apps/studio/components/layouts/ProjectLayout/LayoutSidebar/index.tsx b/apps/studio/components/layouts/ProjectLayout/LayoutSidebar/index.tsxindex 4c243020fca..77903b5999e 100644--- a/apps/studio/components/layouts/ProjectLayout/LayoutSidebar/index.tsx+++ b/apps/studio/components/layouts/ProjectLayout/LayoutSidebar/index.tsx@@ -25,7 +25,7 @@ export const LayoutSidebar = ({defaultSize = '30',}: LayoutSidebarProps) => {const isMobile = useBreakpoint('md')- const { activeSidebar } = useSidebarManagerSnapshot()+ const { activeSidebar, isMaximised } = useSidebarManagerSnapshot()const { content: sheetContent, setContent: setMobileSheetContent } = useMobileSheet()useEffect(() => {@@ -43,6 +43,9 @@ export const LayoutSidebar = ({if (!activeSidebar?.component) return nullif (isMobile) return null+ // `isMaximised` only has meaning for the AI Assistant sidebar+ const isMaximisedSidebar = isMaximised && activeSidebar?.id === SIDEBAR_KEYS.AI_ASSISTANT+return (<><ResizableHandle withHandle />@@ -55,8 +58,8 @@ export const LayoutSidebar = ({className={cn('border-l bg fixed z-40 right-0 top-0 bottom-0','h-dvh',- 'md:absolute md:h-auto md:w-1/2',- 'lg:w-2/5',+ isMaximisedSidebar ? 'md:absolute md:h-auto md:w-full' : 'md:absolute md:h-auto md:w-1/2',+ !isMaximisedSidebar && 'lg:w-2/5','xl:relative xl:border-l-0')}>diff --git a/apps/studio/components/ui/AIAssistantPanel/AIAssistantHeader.test.tsx b/apps/studio/components/ui/AIAssistantPanel/AIAssistantHeader.test.tsxindex 415bb8e8d79..be9b541589b 100644--- a/apps/studio/components/ui/AIAssistantPanel/AIAssistantHeader.test.tsx+++ b/apps/studio/components/ui/AIAssistantPanel/AIAssistantHeader.test.tsx@@ -1,10 +1,14 @@import { fireEvent, screen } from '@testing-library/react'-import { describe, expect, it, vi } from 'vitest'+import { afterEach, describe, expect, it, vi } from 'vitest'import { AIAssistantHeader } from './AIAssistantHeader'import { customRender } from '@/tests/lib/custom-render'-const { openChat } = vi.hoisted(() => ({ openChat: vi.fn() }))+const { openChat, toggleMaximise, useIsExplorerEnabled } = vi.hoisted(() => ({+ openChat: vi.fn(),+ toggleMaximise: vi.fn(),+ useIsExplorerEnabled: vi.fn(),+}))vi.mock('@/state/ai-assistant-state', () => ({useAiAssistantStateSnapshot: () => ({@@ -18,6 +22,14 @@ vi.mock('@/components/interfaces/Explorer/hooks', () => ({useCreateChat: () => ({ openChat }),}))+vi.mock('@/components/interfaces/App/FeaturePreview/FeaturePreviewContext', () => ({+ useIsExplorerEnabled,+}))++vi.mock('@/state/sidebar-manager-state', () => ({+ useSidebarManagerSnapshot: () => ({ isMaximised: false, toggleMaximise }),+}))+vi.mock('@/state/shortcuts/useShortcut', () => ({ useShortcut: vi.fn() }))vi.mock('./AIAssistantChatSelector', () => ({@@ -43,7 +55,12 @@ const defaultProps = {}describe('AIAssistantHeader', () => {- it('opens the active chat in Explorer and closes the sidebar', () => {+ afterEach(() => {+ vi.clearAllMocks()+ })++ it('opens the active chat in Explorer and closes the sidebar when Explorer preview is enabled', () => {+ useIsExplorerEnabled.mockReturnValue(true)const onCloseAssistant = vi.fn()customRender(<AIAssistantHeader {...defaultProps} onCloseAssistant={onCloseAssistant} />)@@ -53,4 +70,18 @@ describe('AIAssistantHeader', () => {expect(onCloseAssistant).toHaveBeenCalledOnce()expect(screen.queryByRole('button', { name: 'Minimize' })).not.toBeInTheDocument()})++ it('shows a Maximize CTA that toggles the sidebar when Explorer preview is disabled', () => {+ useIsExplorerEnabled.mockReturnValue(false)+ const onCloseAssistant = vi.fn()+ customRender(<AIAssistantHeader {...defaultProps} onCloseAssistant={onCloseAssistant} />)++ expect(screen.queryByRole('button', { name: 'Open in Explorer' })).not.toBeInTheDocument()++ fireEvent.click(screen.getByRole('button', { name: 'Maximize' }))++ expect(toggleMaximise).toHaveBeenCalledOnce()+ expect(openChat).not.toHaveBeenCalled()+ expect(onCloseAssistant).not.toHaveBeenCalled()+ })})diff --git a/apps/studio/components/ui/AIAssistantPanel/AIAssistantHeader.tsx b/apps/studio/components/ui/AIAssistantPanel/AIAssistantHeader.tsxindex 82546031fa9..91b3873c2bc 100644--- a/apps/studio/components/ui/AIAssistantPanel/AIAssistantHeader.tsx+++ b/apps/studio/components/ui/AIAssistantPanel/AIAssistantHeader.tsx@@ -11,6 +11,7 @@ import { KeyboardEvent, useState } from 'react'import { toast } from 'sonner'import {Button,+ cn,copyToClipboard,DropdownMenu,DropdownMenuContent,@@ -24,10 +25,12 @@ import { ButtonTooltip } from '../ButtonTooltip'import { ShortcutPills, ShortcutTooltip } from '../ShortcutTooltip'import { AIAssistantChatSelector } from './AIAssistantChatSelector'import { AIAssistantMetadataWarning } from './AIAssistantMetadataWarning'+import { useIsExplorerEnabled } from '@/components/interfaces/App/FeaturePreview/FeaturePreviewContext'import { useCreateChat } from '@/components/interfaces/Explorer/hooks'import { useAiAssistantStateSnapshot } from '@/state/ai-assistant-state'import { SHORTCUT_DEFINITIONS, SHORTCUT_IDS } from '@/state/shortcuts/registry'import { useShortcut } from '@/state/shortcuts/useShortcut'+import { useSidebarManagerSnapshot } from '@/state/sidebar-manager-state'interface AIAssistantHeaderProps {isChatLoading: boolean@@ -50,12 +53,26 @@ export const AIAssistantHeader = ({isHipaaProjectDisallowed,aiOptInLevel,}: AIAssistantHeaderProps) => {- const snap = useAiAssistantStateSnapshot()const { openChat } = useCreateChat()+ const snap = useAiAssistantStateSnapshot()+ const { isMaximised, toggleMaximise } = useSidebarManagerSnapshot()+ const isExplorerEnabled = useIsExplorerEnabled()+const [value, setValue] = useState(snap.activeChat?.name)const [isEditingName, setIsEditingName] = useState(false)const [isOptInModalOpen, setIsOptInModalOpen] = useState(false)+ const maximiseLabel = isExplorerEnabled+ ? 'Open in Explorer'+ : isMaximised+ ? 'Minimize'+ : 'Maximize'++ const onSelectMaximise = () => {+ if (isExplorerEnabled) handleOpenInExplorer()+ else toggleMaximise()+ }+const handleOpenInExplorer = () => {if (!snap.activeChatId) returnopenChat(snap.activeChatId)@@ -100,7 +117,7 @@ export const AIAssistantHeader = ({enabled: shortcutsEnabled && !isChatLoading,})- useShortcut(SHORTCUT_IDS.AI_ASSISTANT_MAXIMIZE, handleOpenInExplorer, {+ useShortcut(SHORTCUT_IDS.AI_ASSISTANT_MAXIMIZE, onSelectMaximise, {enabled: shortcutsEnabled && !isChatLoading,})@@ -153,16 +170,16 @@ export const AIAssistantHeader = ({<ShortcutTooltipside="bottom"- label="Open in Explorer"+ label={maximiseLabel}shortcutId={SHORTCUT_IDS.AI_ASSISTANT_MAXIMIZE}><Buttonvariant="text"- aria-label="Open in Explorer"+ aria-label={maximiseLabel}size="tiny"icon={<Maximize />}- onClick={handleOpenInExplorer}- className="h-7 w-7 p-0"+ onClick={onSelectMaximise}+ className={cn('h-7 w-7 p-0', !isExplorerEnabled && 'hidden md:flex')}/></ShortcutTooltip>