mirror of
https://github.com/supabase/supabase.git
synced 2026-10-05 17:35:10 +03:00
### Context As per PR title - currently the assistant panel's maximize CTA defaults to opening in explorer, which might be confusing for users who don't have the explorer feature preview enabled <img width="581" height="190" alt="image" src="https://github.com/user-attachments/assets/9a9b6129-164e-4e3e-a14e-66ecafe8e5ff" /> <img width="574" height="157" alt="image" src="https://github.com/user-attachments/assets/ffff0a49-3357-4e5f-8cc0-be2f94263128" /> <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit * **New Features** * Updated the AI assistant’s maximize control with context-sensitive actions. * When Explorer preview is enabled, the control opens the active conversation in Explorer. * When Explorer preview is disabled, the control maximizes or minimizes the assistant panel. * Updated the control’s label, accessibility text, and keyboard shortcut to reflect the available action. * Maximized AI Assistant panels now use the full available width, while other sidebars retain responsive sizing. * **Bug Fixes** * Improved sidebar behavior on mobile and overlay layouts to prevent unwanted resizing or collapsing. <!-- end of auto-generated comment: release notes by coderabbit.ai -->
154 lines
6.2 KiB
TypeScript
154 lines
6.2 KiB
TypeScript
import { useBreakpoint, useFlag, useParams } from 'common'
|
|
import { useRouter } from 'next/router'
|
|
import { PropsWithChildren, useEffect, useState } from 'react'
|
|
import { ResizablePanel, ResizablePanelGroup, SidebarProvider, usePanelRef } from 'ui'
|
|
import { SkipToContent } from 'ui-patterns/SkipToContent'
|
|
|
|
import { BannerStack } from '../ui/BannerStack/BannerStack'
|
|
import { LayoutHeader } from './Navigation/LayoutHeader/LayoutHeader'
|
|
import { MobileNavigationBar } from './Navigation/NavigationBar/MobileNavigationBar'
|
|
import { MobileSheetProvider } from './Navigation/NavigationBar/MobileSheetContext'
|
|
import { StudioMobileSheetNav } from './Navigation/NavigationBar/StudioMobileSheetNav'
|
|
import { LayoutSidebar } from './ProjectLayout/LayoutSidebar'
|
|
import {
|
|
LayoutSidebarProvider,
|
|
SIDEBAR_KEYS,
|
|
} from './ProjectLayout/LayoutSidebar/LayoutSidebarProvider'
|
|
import { ProjectContextProvider } from './ProjectLayout/ProjectContext'
|
|
import { AppBannerWrapper } from '@/components/interfaces/App/AppBannerWrapper'
|
|
import { GitHubConfigDriftBanner } from '@/components/interfaces/App/GitHubConfigDriftBanner'
|
|
import { Sidebar } from '@/components/interfaces/Sidebar'
|
|
import { useSyncScopedIntrospection } from '@/data/scoped-introspection'
|
|
import { useLastVisitedOrganization } from '@/hooks/misc/useLastVisitedOrganization'
|
|
import { useCheckLatestDeploy } from '@/hooks/use-check-latest-deploy'
|
|
import { IS_PLATFORM } from '@/lib/constants'
|
|
import { useAppStateSnapshot } from '@/state/app-state'
|
|
import { useSidebarManagerSnapshot } from '@/state/sidebar-manager-state'
|
|
|
|
export interface DefaultLayoutProps {
|
|
headerTitle?: string
|
|
hideMobileMenu?: boolean
|
|
}
|
|
|
|
/**
|
|
* Base layout for all project pages in the dashboard, rendered as the first child on all page files within a project.
|
|
*
|
|
* A second layout as the child to this is required, and the layout depends on which section of the dashboard the page is on. (e.g Auth - AuthLayout)
|
|
*
|
|
* The base layout handles rendering the following UI components:
|
|
* - App banner (e.g for notices or incidents)
|
|
* - Mobile navigation bar
|
|
* - First level side navigation bar (e.g For navigating to Table Editor, SQL Editor, Database page, etc)
|
|
*/
|
|
export const DefaultLayout = ({
|
|
children,
|
|
headerTitle,
|
|
hideMobileMenu,
|
|
}: PropsWithChildren<DefaultLayoutProps>) => {
|
|
useSyncScopedIntrospection()
|
|
useCheckLatestDeploy()
|
|
|
|
const { ref } = useParams()
|
|
const router = useRouter()
|
|
const panelRef = usePanelRef()
|
|
const isMobile = useBreakpoint('md')
|
|
const isSidebarOverlay = useBreakpoint('xl')
|
|
const appSnap = useAppStateSnapshot()
|
|
const { isMaximised, activeSidebar } = useSidebarManagerSnapshot()
|
|
const { lastVisitedOrganization } = useLastVisitedOrganization()
|
|
const showConfigDrift = useFlag('ConfigDrift') && IS_PLATFORM
|
|
|
|
const [isMounted, setIsMounted] = useState(false)
|
|
|
|
const backToDashboardURL = router.pathname.startsWith('/account')
|
|
? appSnap.lastRouteBeforeVisitingAccountPage.length > 0
|
|
? appSnap.lastRouteBeforeVisitingAccountPage
|
|
: IS_PLATFORM && !!lastVisitedOrganization
|
|
? `/org/${lastVisitedOrganization}`
|
|
: IS_PLATFORM
|
|
? '/organizations'
|
|
: '/project/default'
|
|
: undefined
|
|
|
|
const contentMinSizePercentage = 50
|
|
const contentMaxSizePercentage = 70
|
|
|
|
useEffect(() => {
|
|
setIsMounted(true)
|
|
}, [])
|
|
|
|
useEffect(() => {
|
|
if (!isMounted || !panelRef.current || !activeSidebar || isMobile || isSidebarOverlay) return
|
|
if (isMaximised) {
|
|
panelRef.current.collapse()
|
|
} else {
|
|
panelRef.current.resize(`${contentMaxSizePercentage}%`)
|
|
}
|
|
}, [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).
|
|
if (!isMounted) {
|
|
return null
|
|
}
|
|
|
|
return (
|
|
<SidebarProvider defaultOpen={false}>
|
|
<LayoutSidebarProvider>
|
|
<ProjectContextProvider projectRef={ref}>
|
|
<MobileSheetProvider>
|
|
<div className="flex flex-col h-screen w-screen">
|
|
<SkipToContent href="#main" />
|
|
{/* Top Banner */}
|
|
<AppBannerWrapper />
|
|
<div className="shrink-0">
|
|
{isMobile && (
|
|
<MobileNavigationBar
|
|
hideMobileMenu={hideMobileMenu}
|
|
backToDashboardURL={backToDashboardURL}
|
|
/>
|
|
)}
|
|
<LayoutHeader headerTitle={headerTitle} backToDashboardURL={backToDashboardURL} />
|
|
{showConfigDrift && ref && <GitHubConfigDriftBanner />}
|
|
</div>
|
|
{/* Main Content Area */}
|
|
<div className="flex flex-1 w-full overflow-y-hidden">
|
|
{/* Sidebar - Only show for project pages, not account pages */}
|
|
{!router.pathname.startsWith('/account') && <Sidebar />}
|
|
{/* Main Content with Layout Sidebar */}
|
|
<ResizablePanelGroup
|
|
orientation="horizontal"
|
|
className="h-full w-full overflow-x-hidden flex-1 flex flex-row gap-0"
|
|
autoSaveId="default-layout-content"
|
|
>
|
|
<ResizablePanel
|
|
id="panel-content"
|
|
className="w-full"
|
|
panelRef={panelRef}
|
|
collapsible={activeSidebar?.id === SIDEBAR_KEYS.AI_ASSISTANT}
|
|
minSize={`${contentMinSizePercentage}`}
|
|
maxSize={`${contentMaxSizePercentage}`}
|
|
defaultSize={`${contentMaxSizePercentage}`}
|
|
>
|
|
<main id="main" tabIndex={-1} className="h-full overflow-y-auto outline-hidden">
|
|
{children}
|
|
</main>
|
|
</ResizablePanel>
|
|
<LayoutSidebar
|
|
minSize={`${100 - contentMaxSizePercentage}`}
|
|
maxSize="100"
|
|
defaultSize={`${100 - contentMaxSizePercentage}`}
|
|
/>
|
|
</ResizablePanelGroup>
|
|
</div>
|
|
</div>
|
|
|
|
<BannerStack />
|
|
<StudioMobileSheetNav />
|
|
</MobileSheetProvider>
|
|
</ProjectContextProvider>
|
|
</LayoutSidebarProvider>
|
|
</SidebarProvider>
|
|
)
|
|
}
|