Skip to content

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

Advisor sidebar manager (#39889)

Saxon Fletcherd10001b7a74e
diff --git a/apps/studio/components/interfaces/Home/AdvisorWidget.tsx b/apps/studio/components/interfaces/Home/AdvisorWidget.tsx
index 9a7555a3249..3e946b5802f 100644
--- a/apps/studio/components/interfaces/Home/AdvisorWidget.tsx
+++ b/apps/studio/components/interfaces/Home/AdvisorWidget.tsx
@@ -1,14 +1,17 @@
import { Activity, ExternalLink, Shield } from 'lucide-react'
import Link from 'next/link'
-import { useMemo, useState } from 'react'
+import { useCallback, useMemo, useState } from 'react'
import { useParams } from 'common'
import { LINTER_LEVELS } from 'components/interfaces/Linter/Linter.constants'
-import { EntityTypeIcon, lintInfoMap } from 'components/interfaces/Linter/Linter.utils'
+import { EntityTypeIcon, createLintSummaryPrompt } from 'components/interfaces/Linter/Linter.utils'
import { useQueryPerformanceQuery } from 'components/interfaces/Reports/Reports.queries'
import { ButtonTooltip } from 'components/ui/ButtonTooltip'
import { Lint, useProjectLintsQuery } from 'data/lint/lint-query'
+import { SIDEBAR_KEYS } from 'components/layouts/ProjectLayout/LayoutSidebar/LayoutSidebarProvider'
+import { useAdvisorStateSnapshot } from 'state/advisor-state'
import { useAiAssistantStateSnapshot } from 'state/ai-assistant-state'
+import { useSidebarManagerSnapshot } from 'state/sidebar-manager-state'
import {
AiIconAnimation,
Card,
@@ -27,8 +30,6 @@ import {
TabsTrigger_Shadcn_ as TabsTrigger,
} from 'ui'
import ShimmeringLoader from 'ui-patterns/ShimmeringLoader'
-import { SIDEBAR_KEYS } from 'components/layouts/ProjectLayout/LayoutSidebar/LayoutSidebarProvider'
-import { useSidebarManagerSnapshot } from 'state/sidebar-manager-state'
interface SlowQuery {
rolname: string
@@ -48,6 +49,7 @@ export const AdvisorWidget = () => {
)
const snap = useAiAssistantStateSnapshot()
const { openSidebar } = useSidebarManagerSnapshot()
+ const { setSelectedItemId } = useAdvisorStateSnapshot()
const securityLints = useMemo(
() => (lints ?? []).filter((lint: Lint) => lint.categories.includes('SECURITY')),
@@ -76,6 +78,14 @@ export const AdvisorWidget = () => {
[slowestQueriesData]
)
+ const handleLintClick = useCallback(
+ (lint: Lint) => {
+ setSelectedItemId(lint.cache_key)
+ openSidebar(SIDEBAR_KEYS.ADVISOR_PANEL)
+ },
+ [setSelectedItemId, openSidebar]
+ )
+
const totalIssues =
securityErrorCount + securityWarningCount + performanceErrorCount + performanceWarningCount
const hasErrors = securityErrorCount > 0 || performanceErrorCount > 0
@@ -134,15 +144,15 @@ export const AdvisorWidget = () => {
className="text-sm w-full border-b my-0 last:border-b-0 group px-4 "
>
<div className="flex items-center justify-between w-full group">
- <Link
- href={`/project/${projectRef}/advisors/${title.toLowerCase()}?id=${lint.cache_key}&preset=${lint.level}`}
- className="flex items-center gap-2 transition truncate flex-1 min-w-0 py-3"
+ <button
+ onClick={() => handleLintClick(lint)}
+ className="flex items-center gap-2 transition truncate flex-1 min-w-0 py-3 text-left"
>
<EntityTypeIcon type={lint.metadata?.type} />
<p className="flex-1 font-mono text-xs leading-6 text-xs text-foreground-light group-hover:text-foreground truncate">
{lintText.replace(/\\`/g, '`')}
</p>
- </Link>
+ </button>
<ButtonTooltip
type="text"
className="px-1 opacity-0 group-hover:opacity-100 w-7"
@@ -153,16 +163,11 @@ export const AdvisorWidget = () => {
openSidebar(SIDEBAR_KEYS.AI_ASSISTANT)
snap.newChat({
name: 'Summarize lint',
- initialInput: `Summarize the issue and suggest fixes for the following lint item:
- Title: ${lintInfoMap.find((item) => item.name === lint.name)?.title ?? lint.title}
- Entity: ${(lint.metadata && (lint.metadata.entity || (lint.metadata.schema && lint.metadata.name && `${lint.metadata.schema}.${lint.metadata.name}`))) ?? 'N/A'}
- Schema: ${lint.metadata?.schema ?? 'N/A'}
- Issue Details: ${lint.detail ? lint.detail.replace(/\`/g, '`') : 'N/A'}
- Description: ${lint.description ? lint.description.replace(/\`/g, '`') : 'N/A'}`,
+ initialInput: createLintSummaryPrompt(lint),
})
}}
tooltip={{
- content: { side: 'bottom', text: 'What is this issue?' },
+ content: { side: 'bottom', text: 'Help me fix this issue' },
}}
/>
</div>
diff --git a/apps/studio/components/interfaces/HomeNew/AdvisorSection.tsx b/apps/studio/components/interfaces/HomeNew/AdvisorSection.tsx
index 492e484a661..3bccc7f130b 100644
--- a/apps/studio/components/interfaces/HomeNew/AdvisorSection.tsx
+++ b/apps/studio/components/interfaces/HomeNew/AdvisorSection.tsx
@@ -1,34 +1,18 @@
import { BarChart, Shield } from 'lucide-react'
-import { useCallback, useMemo, useState } from 'react'
+import { useCallback, useMemo } from 'react'
import { useParams } from 'common'
-import LintDetail from 'components/interfaces/Linter/LintDetail'
import { LINTER_LEVELS } from 'components/interfaces/Linter/Linter.constants'
-import {
- createLintSummaryPrompt,
- LintCategoryBadge,
- lintInfoMap,
-} from 'components/interfaces/Linter/Linter.utils'
+import { createLintSummaryPrompt } from 'components/interfaces/Linter/Linter.utils'
import { SIDEBAR_KEYS } from 'components/layouts/ProjectLayout/LayoutSidebar/LayoutSidebarProvider'
import { ButtonTooltip } from 'components/ui/ButtonTooltip'
import { Lint, useProjectLintsQuery } from 'data/lint/lint-query'
import { useSendEventMutation } from 'data/telemetry/send-event-mutation'
import { useSelectedOrganizationQuery } from 'hooks/misc/useSelectedOrganization'
+import { useAdvisorStateSnapshot } from 'state/advisor-state'
import { useAiAssistantStateSnapshot } from 'state/ai-assistant-state'
import { useSidebarManagerSnapshot } from 'state/sidebar-manager-state'
-import {
- AiIconAnimation,
- Button,
- Card,
- CardContent,
- CardHeader,
- CardTitle,
- Sheet,
- SheetContent,
- SheetHeader,
- SheetSection,
- SheetTitle,
-} from 'ui'
+import { AiIconAnimation, Button, Card, CardContent, CardHeader, CardTitle } from 'ui'
import { Row } from 'ui-patterns'
import ShimmeringLoader from 'ui-patterns/ShimmeringLoader'
@@ -46,8 +30,7 @@ export const AdvisorSection = ({ showEmptyState = false }: { showEmptyState?: bo
const { mutate: sendEvent } = useSendEventMutation()
const { data: organization } = useSelectedOrganizationQuery()
const { openSidebar } = useSidebarManagerSnapshot()
-
- const [selectedLint, setSelectedLint] = useState<Lint | null>(null)
+ const { setSelectedItemId } = useAdvisorStateSnapshot()
const errorLints: Lint[] = useMemo(() => {
return lints?.filter((lint) => lint.level === LINTER_LEVELS.ERROR) ?? []
@@ -84,7 +67,8 @@ export const AdvisorSection = ({ showEmptyState = false }: { showEmptyState?: bo
const handleCardClick = useCallback(
(lint: Lint) => {
- setSelectedLint(lint)
+ setSelectedItemId(lint.cache_key)
+ openSidebar(SIDEBAR_KEYS.ADVISOR_PANEL)
if (projectRef && organization?.slug) {
sendEvent({
action: 'home_advisor_issue_card_clicked',
@@ -100,7 +84,7 @@ export const AdvisorSection = ({ showEmptyState = false }: { showEmptyState?: bo
})
}
},
- [sendEvent, projectRef, organization]
+ [sendEvent, setSelectedItemId, openSidebar, projectRef, organization, totalErrors]
)
if (showEmptyState) {
@@ -185,32 +169,6 @@ export const AdvisorSection = ({ showEmptyState = false }: { showEmptyState?: bo
)
})}
</Row>
- <Sheet open={selectedLint !== null} onOpenChange={() => setSelectedLint(null)}>
- <SheetContent>
- {selectedLint && (
- <>
- <SheetHeader>
- <div className="flex items-center gap-4">
- <SheetTitle>
- {lintInfoMap.find((item) => item.name === selectedLint.name)?.title ??
- 'Unknown'}
- </SheetTitle>
- <LintCategoryBadge category={selectedLint.categories[0]} />
- </div>
- </SheetHeader>
- <SheetSection>
- {selectedLint && projectRef && (
- <LintDetail
- lint={selectedLint}
- projectRef={projectRef!}
- onAskAssistant={() => setSelectedLint(null)}
- />
- )}
- </SheetSection>
- </>
- )}
- </SheetContent>
- </Sheet>
</>
) : (
<EmptyState />
diff --git a/apps/studio/components/interfaces/Linter/Linter.utils.tsx b/apps/studio/components/interfaces/Linter/Linter.utils.tsx
index 84d512d441e..5f9b61f6578 100644
--- a/apps/studio/components/interfaces/Linter/Linter.utils.tsx
+++ b/apps/studio/components/interfaces/Linter/Linter.utils.tsx
@@ -312,7 +312,7 @@ export const LintCTA = ({
return (
<Button asChild type="default">
- <Link href={link} target="_blank" rel="noreferrer" className="no-underline">
+ <Link href={link} rel="noreferrer" className="no-underline">
{linkText}
</Link>
</Button>
diff --git a/apps/studio/components/layouts/AdvisorsLayout/AdvisorsLayout.tsx b/apps/studio/components/layouts/AdvisorsLayout/AdvisorsLayout.tsx
index 14635287b93..3daa22f996d 100644
--- a/apps/studio/components/layouts/AdvisorsLayout/AdvisorsLayout.tsx
+++ b/apps/studio/components/layouts/AdvisorsLayout/AdvisorsLayout.tsx
@@ -1,21 +1,15 @@
import { useRouter } from 'next/router'
import { PropsWithChildren } from 'react'
-import { useIsAdvisorRulesEnabled } from 'components/interfaces/App/FeaturePreview/FeaturePreviewContext'
-import { ProductMenu } from 'components/ui/ProductMenu'
-import { useSelectedProjectQuery } from 'hooks/misc/useSelectedProject'
import { withAuth } from 'hooks/misc/withAuth'
import { ProjectLayout } from '../ProjectLayout/ProjectLayout'
-import { generateAdvisorsMenu } from './AdvisorsMenu.utils'
+import { AdvisorsSidebarMenu } from './AdvisorsSidebarMenu'
export interface AdvisorsLayoutProps {
title?: string
}
const AdvisorsLayout = ({ children }: PropsWithChildren<AdvisorsLayoutProps>) => {
- const { data: project } = useSelectedProjectQuery()
- const advisorRules = useIsAdvisorRulesEnabled()
-
const router = useRouter()
const page = router.pathname.split('/')[4]
@@ -23,9 +17,7 @@ const AdvisorsLayout = ({ children }: PropsWithChildren<AdvisorsLayoutProps>) =>
<ProjectLayout
isLoading={false}
product="Advisors"
- productMenu={
- <ProductMenu page={page} menu={generateAdvisorsMenu(project, { advisorRules })} />
- }
+ productMenu={<AdvisorsSidebarMenu page={page} />}
>
{children}
</ProjectLayout>
diff --git a/apps/studio/components/layouts/AdvisorsLayout/AdvisorsSidebarMenu.tsx b/apps/studio/components/layouts/AdvisorsLayout/AdvisorsSidebarMenu.tsx
new file mode 100644
index 00000000000..06e6395b4ae
--- /dev/null
+++ b/apps/studio/components/layouts/AdvisorsLayout/AdvisorsSidebarMenu.tsx
@@ -0,0 +1,40 @@
+import { ProductMenu } from 'components/ui/ProductMenu'
+import { useSelectedProjectQuery } from 'hooks/misc/useSelectedProject'
+import { Badge, Button } from 'ui'
+import { FeaturePreviewSidebarPanel } from '../../ui/FeaturePreviewSidebarPanel'
+import { generateAdvisorsMenu } from './AdvisorsMenu.utils'
+import { useIsAdvisorRulesEnabled } from 'components/interfaces/App/FeaturePreview/FeaturePreviewContext'
+import { useSidebarManagerSnapshot } from 'state/sidebar-manager-state'
+import { SIDEBAR_KEYS } from 'components/layouts/ProjectLayout/LayoutSidebar/LayoutSidebarProvider'
+
+interface AdvisorsSidebarMenuProps {
+ page?: string
+}
+
+export function AdvisorsSidebarMenu({ page }: AdvisorsSidebarMenuProps) {
+ const { data: project } = useSelectedProjectQuery()
+ const advisorRules = useIsAdvisorRulesEnabled()
+ const { toggleSidebar } = useSidebarManagerSnapshot()
+
+ const handleOpenAdvisor = () => {
+ toggleSidebar(SIDEBAR_KEYS.ADVISOR_PANEL)
+ }
+
+ return (
+ <div className="pb-12 relative">
+ <FeaturePreviewSidebarPanel
+ className="mx-4 mt-4"
+ title="Moving to the toolbar"
+ description="Advisors are now available in the top toolbar for quicker access across the dashboard"
+ illustration={<Badge variant="brand">New Location</Badge>}
+ actions={
+ <Button size="tiny" type="default" onClick={handleOpenAdvisor}>
+ Try it now
+ </Button>
+ }
+ />
+
+ <ProductMenu page={page} menu={generateAdvisorsMenu(project, { advisorRules })} />
+ </div>
+ )
+}
diff --git a/apps/studio/components/layouts/AppLayout/AdvisorButton.tsx b/apps/studio/components/layouts/AppLayout/AdvisorButton.tsx
new file mode 100644
index 00000000000..6b3c3c3fccc
--- /dev/null
+++ b/apps/studio/components/layouts/AppLayout/AdvisorButton.tsx
@@ -0,0 +1,54 @@
+import { Lightbulb } from 'lucide-react'
+
+import { useParams } from 'common'
+import { ButtonTooltip } from 'components/ui/ButtonTooltip'
+import { useProjectLintsQuery } from 'data/lint/lint-query'
+import { useSidebarManagerSnapshot } from 'state/sidebar-manager-state'
+import { SIDEBAR_KEYS } from 'components/layouts/ProjectLayout/LayoutSidebar/LayoutSidebarProvider'
+import { cn } from 'ui'
+
+export const AdvisorButton = () => {
+ const { ref: projectRef } = useParams()
+ const { toggleSidebar, activeSidebar } = useSidebarManagerSnapshot()
+ const { data: lints } = useProjectLintsQuery({ projectRef })
+
+ const hasCriticalIssues = Array.isArray(lints) && lints.some((lint) => lint.level === 'ERROR')
+
+ const isOpen = activeSidebar?.id === SIDEBAR_KEYS.ADVISOR_PANEL
+
+ const handleClick = () => {
+ toggleSidebar(SIDEBAR_KEYS.ADVISOR_PANEL)
+ }
+
+ return (
+ <div className="relative">
+ <ButtonTooltip
+ type="outline"
+ size="tiny"
+ id="advisor-center-trigger"
+ className={cn(
+ 'rounded-full w-[32px] h-[32px] flex items-center justify-center p-0 group',
+ isOpen && 'bg-foreground text-background'
+ )}
+ onClick={handleClick}
+ tooltip={{
+ content: {
+ text: 'Advisor Center',
+ },
+ }}
+ >
+ <Lightbulb
+ size={16}
+ strokeWidth={1.5}
+ className={cn(
+ 'text-foreground-light group-hover:text-foreground',
+ isOpen && 'text-background group-hover:text-background'
+ )}
+ />
+ </ButtonTooltip>
+ {hasCriticalIssues && (
+ <span className="absolute top-1.5 right-1.5 w-1.5 h-1.5 rounded-full bg-destructive" />
+ )}
+ </div>
+ )
+}
diff --git a/apps/studio/components/layouts/AppLayout/AssistantButton.tsx b/apps/studio/components/layouts/AppLayout/AssistantButton.tsx
index d9e8b835dd9..8f550e23786 100644
--- a/apps/studio/components/layouts/AppLayout/AssistantButton.tsx
+++ b/apps/studio/components/layouts/AppLayout/AssistantButton.tsx
@@ -2,23 +2,28 @@ import { LOCAL_STORAGE_KEYS } from 'common'
import { ButtonTooltip } from 'components/ui/ButtonTooltip'
import { useLocalStorageQuery } from 'hooks/misc/useLocalStorage'
import { useAiAssistantStateSnapshot } from 'state/ai-assistant-state'
-import { AiIconAnimation, KeyboardShortcut } from 'ui'
-import { SIDEBAR_KEYS } from '../ProjectLayout/LayoutSidebar/LayoutSidebarProvider'
import { useSidebarManagerSnapshot } from 'state/sidebar-manager-state'
+import { SIDEBAR_KEYS } from 'components/layouts/ProjectLayout/LayoutSidebar/LayoutSidebarProvider'
+import { AiIconAnimation, cn, KeyboardShortcut } from 'ui'
export const AssistantButton = () => {
- const { toggleSidebar } = useSidebarManagerSnapshot()
+ const { activeSidebar, toggleSidebar } = useSidebarManagerSnapshot()
const [isAIAssistantHotkeyEnabled] = useLocalStorageQuery<boolean>(
LOCAL_STORAGE_KEYS.HOTKEY_SIDEBAR(SIDEBAR_KEYS.AI_ASSISTANT),
true
)
+ const isOpen = activeSidebar?.id === SIDEBAR_KEYS.AI_ASSISTANT
+
return (
<ButtonTooltip
- type="text"
+ type="outline"
size="tiny"
id="assistant-trigger"
- className="rounded-none w-[32px] h-[30px] flex items-center justify-center p-0 hover:bg-brand-400"
+ className={cn(
+ 'rounded-full w-[32px] h-[32px] flex items-center justify-center p-0',
+ isOpen && 'bg-foreground text-background'
+ )}
onClick={() => {
toggleSidebar(SIDEBAR_KEYS.AI_ASSISTANT)
}}
@@ -33,7 +38,11 @@ export const AssistantButton = () => {
},
}}
>
- <AiIconAnimation allowHoverEffect={false} size={16} />
+ <AiIconAnimation
+ allowHoverEffect={false}
+ size={16}
+ className={cn(isOpen && 'text-background')}
+ />
</ButtonTooltip>
)
}
diff --git a/apps/studio/components/layouts/AppLayout/InlineEditorButton.tsx b/apps/studio/components/layouts/AppLayout/InlineEditorButton.tsx
index 57c39df7a54..db0a6d6bffa 100644
--- a/apps/studio/components/layouts/AppLayout/InlineEditorButton.tsx
+++ b/apps/studio/components/layouts/AppLayout/InlineEditorButton.tsx
@@ -1,27 +1,44 @@
+import { LOCAL_STORAGE_KEYS } from 'common'
+import { SIDEBAR_KEYS } from 'components/layouts/ProjectLayout/LayoutSidebar/LayoutSidebarProvider'
import { ButtonTooltip } from 'components/ui/ButtonTooltip'
+import { useLocalStorageQuery } from 'hooks/misc/useLocalStorage'
import { SqlEditor } from 'icons'
-import { KeyboardShortcut } from 'ui'
+import { useSidebarManagerSnapshot } from 'state/sidebar-manager-state'
+import { cn, KeyboardShortcut } from 'ui'
+
+const InlineEditorKeyboardTooltip = () => {
+ const [hotkeyEnabled] = useLocalStorageQuery(
+ LOCAL_STORAGE_KEYS.HOTKEY_SIDEBAR(SIDEBAR_KEYS.EDITOR_PANEL),
+ true
+ )
+
+ return hotkeyEnabled ? <KeyboardShortcut keys={['Meta', 'e']} /> : null
+}
+
+export const InlineEditorButton = () => {
+ const { activeSidebar, toggleSidebar } = useSidebarManagerSnapshot()
+ const isOpen = activeSidebar?.id === SIDEBAR_KEYS.EDITOR_PANEL
+
+ const handleClick = () => {
+ toggleSidebar(SIDEBAR_KEYS.EDITOR_PANEL)
+ }
-export const InlineEditorButton = ({
- onClick,
- showShortcut = true,
-}: {
- onClick: () => void
- showShortcut?: boolean
-}) => {
return (
<ButtonTooltip
- type="text"
+ type="outline"
size="tiny"
id="editor-trigger"
- className="rounded-none w-[32px] h-[30px] flex items-center justify-center p-0 text-foreground-light hover:text-foreground"
- onClick={onClick}
+ className={cn(
+ 'rounded-full w-[32px] h-[32px] flex items-center justify-center p-0 text-foreground-light hover:text-foreground',
+ isOpen && 'bg-foreground text-background hover:text-background'
+ )}
+ onClick={handleClick}
tooltip={{
content: {
text: (
<div className="flex items-center gap-4">
<span>SQL Editor</span>
- {showShortcut && <KeyboardShortcut keys={['Meta', 'e']} />}
+ <InlineEditorKeyboardTooltip />
</div>
),
},
diff --git a/apps/studio/components/layouts/DefaultLayout.tsx b/apps/studio/components/layouts/DefaultLayout.tsx
index b72a61f2152..8763b5e1b00 100644
--- a/apps/studio/components/layouts/DefaultLayout.tsx
+++ b/apps/studio/components/layouts/DefaultLayout.tsx
@@ -12,6 +12,7 @@ import { SidebarProvider } from 'ui'
import { LayoutHeader } from './ProjectLayout/LayoutHeader'
import MobileNavigationBar from './ProjectLayout/NavigationBar/MobileNavigationBar'
import { ProjectContextProvider } from './ProjectLayout/ProjectContext'
+import { LayoutSidebarProvider } from './ProjectLayout/LayoutSidebar/LayoutSidebarProvider'
export interface DefaultLayoutProps {
headerTitle?: string
@@ -55,29 +56,31 @@ const DefaultLayout = ({
return (
<SidebarProvider defaultOpen={false}>
<ProjectContextProvider projectRef={ref}>
- <AppBannerContextProvider>
- <div className="flex flex-col h-screen w-screen">
- {/* Top Banner */}
- <AppBannerWrapper />
- <div className="flex-shrink-0">
- <MobileNavigationBar hideMobileMenu={hideMobileMenu} />
- <LayoutHeader
- showProductMenu={showProductMenu}
- headerTitle={headerTitle}
- backToDashboardURL={
- router.pathname.startsWith('/account') ? backToDashboardURL : undefined
- }
- />
+ <LayoutSidebarProvider>
+ <AppBannerContextProvider>
+ <div className="flex flex-col h-screen w-screen">
+ {/* Top Banner */}
+ <AppBannerWrapper />
+ <div className="flex-shrink-0">
+ <MobileNavigationBar hideMobileMenu={hideMobileMenu} />
+ <LayoutHeader
+ showProductMenu={showProductMenu}
+ headerTitle={headerTitle}
+ backToDashboardURL={
+ router.pathname.startsWith('/account') ? backToDashboardURL : undefined
+ }
+ />
+ </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 */}
+ <div className="flex-grow h-full overflow-y-auto">{children}</div>
+ </div>
</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 */}
- <div className="flex-grow h-full overflow-y-auto">{children}</div>
- </div>
- </div>
- </AppBannerContextProvider>
+ </AppBannerContextProvider>
+ </LayoutSidebarProvider>
</ProjectContextProvider>
</SidebarProvider>
)
diff --git a/apps/studio/components/layouts/ProjectLayout/LayoutHeader/FeedbackDropdown/FeedbackDropdown.tsx b/apps/studio/components/layouts/ProjectLayout/LayoutHeader/FeedbackDropdown/FeedbackDropdown.tsx
index c73d79a0562..824965c256c 100644
--- a/apps/studio/components/layouts/ProjectLayout/LayoutHeader/FeedbackDropdown/FeedbackDropdown.tsx
+++ b/apps/studio/components/layouts/ProjectLayout/LayoutHeader/FeedbackDropdown/FeedbackDropdown.tsx
@@ -25,8 +25,8 @@ export const FeedbackDropdown = ({ className }: { className?: string }) => {
setIsOpen((isOpen) => !isOpen)
setStage('select')
}}
- type="outline"
- className="rounded-full h-[32px] border-border"
+ type="text"
+ className="rounded-full h-[32px] text-foreground-light hover:text-foreground"
>
<span className={className}>Feedback</span>
</Button>
diff --git a/apps/studio/components/layouts/ProjectLayout/LayoutHeader/HelpPopover.tsx b/apps/studio/components/layouts/ProjectLayout/LayoutHeader/HelpPopover.tsx
index 02b69a0b7a1..3b8c00a1687 100644
--- a/apps/studio/components/layouts/ProjectLayout/LayoutHeader/HelpPopover.tsx
+++ b/apps/studio/components/layouts/ProjectLayout/LayoutHeader/HelpPopover.tsx
@@ -1,6 +1,7 @@
import { Activity, BookOpen, HelpCircle, Mail, Wrench } from 'lucide-react'
import Image from 'next/legacy/image'
import { useRouter } from 'next/router'
+import { useState } from 'react'
import SVG from 'react-inlinesvg'
import { IS_PLATFORM } from 'common'
@@ -17,12 +18,13 @@ import {
Button,
ButtonGroup,
ButtonGroupItem,
+ cn,
Popover,
PopoverContent_Shadcn_,
PopoverTrigger_Shadcn_,
Popover_Shadcn_,
} from 'ui'
-import { SIDEBAR_KEYS } from '../LayoutSidebar/LayoutSidebarProvider'
+import { SIDEBAR_KEYS } from 'components/layouts/ProjectLayout/LayoutSidebar/LayoutSidebarProvider'
export const HelpPopover = () => {
const router = useRouter()
@@ -30,33 +32,39 @@ export const HelpPopover = () => {
const { data: org } = useSelectedOrganizationQuery()
const snap = useAiAssistantStateSnapshot()
const { openSidebar } = useSidebarManagerSnapshot()
-
const { mutate: sendEvent } = useSendEventMutation()
+ const [isOpen, setIsOpen] = useState(false)
const projectRef = project?.parent_project_ref ?? (router.query.ref as string | undefined)
return (
- <Popover_Shadcn_>
+ <Popover_Shadcn_ open={isOpen} onOpenChange={setIsOpen}>
<PopoverTrigger_Shadcn_ asChild>
<ButtonTooltip
id="help-popover-button"
- type="text"
- className="rounded-none w-[32px] h-[30px] group"
- icon={
- <HelpCircle
- size={18}
- strokeWidth={1.5}
- className="!h-[18px] !w-[18px] text-foreground-light group-hover:text-foreground"
- />
- }
- tooltip={{ content: { side: 'bottom', text: 'Help' } }}
+ type="outline"
+ size="tiny"
+ className={cn(
+ 'rounded-full w-[32px] h-[32px] flex items-center justify-center p-0 group',
+ isOpen && 'bg-foreground text-background'
+ )}
onClick={() => {
sendEvent({
action: 'help_button_clicked',
groups: { project: project?.ref, organization: org?.slug },
})
}}
- />
+ tooltip={{ content: { side: 'bottom', text: 'Help' } }}
+ >
+ <HelpCircle
+ size={16}
+ strokeWidth={1.5}
+ className={cn(
+ 'text-foreground-light group-hover:text-foreground',
+ isOpen && 'text-background group-hover:text-background'
+ )}
+ />
+ </ButtonTooltip>
</PopoverTrigger_Shadcn_>
<PopoverContent_Shadcn_ className="w-[400px] space-y-5 p-0 py-5" align="end" side="bottom">
<div className="flex flex-col gap-4">
diff --git a/apps/studio/components/layouts/ProjectLayout/LayoutHeader/LayoutHeader.tsx b/apps/studio/components/layouts/ProjectLayout/LayoutHeader/LayoutHeader.tsx
index b7128895db8..f4142e8ae02 100644
--- a/apps/studio/components/layouts/ProjectLayout/LayoutHeader/LayoutHeader.tsx
+++ b/apps/studio/components/layouts/ProjectLayout/LayoutHeader/LayoutHeader.tsx
@@ -3,7 +3,7 @@ import { ChevronLeft } from 'lucide-react'
import Link from 'next/link'
import { ReactNode, useMemo } from 'react'
-import { LOCAL_STORAGE_KEYS, useParams } from 'common'
+import { useParams } from 'common'
import { useIsBranching2Enabled } from 'components/interfaces/App/FeaturePreview/FeaturePreviewContext'
import { Connect } from 'components/interfaces/Connect/Connect'
import { LocalDropdown } from 'components/interfaces/LocalDropdown'
@@ -15,15 +15,12 @@ import { OrganizationDropdown } from 'components/layouts/AppLayout/OrganizationD
import { ProjectDropdown } from 'components/layouts/AppLayout/ProjectDropdown'
import { getResourcesExceededLimitsOrg } from 'components/ui/OveragesBanner/OveragesBanner.utils'
import { useOrgUsageQuery } from 'data/usage/org-usage-query'
-import { useLocalStorageQuery } from 'hooks/misc/useLocalStorage'
import { useSelectedOrganizationQuery } from 'hooks/misc/useSelectedOrganization'
import { useSelectedProjectQuery } from 'hooks/misc/useSelectedProject'
import { IS_PLATFORM } from 'lib/constants'
import { useRouter } from 'next/router'
import { useAppStateSnapshot } from 'state/app-state'
-import { useSidebarManagerSnapshot } from 'state/sidebar-manager-state'
import { Badge, cn } from 'ui'
-import { SIDEBAR_KEYS } from '../LayoutSidebar/LayoutSidebarProvider'
import { BreadcrumbsView } from './BreadcrumbsView'
import { FeedbackDropdown } from './FeedbackDropdown/FeedbackDropdown'
import { HelpPopover } from './HelpPopover'
@@ -31,6 +28,8 @@ import { HomeIcon } from './HomeIcon'
import { LocalVersionPopover } from './LocalVersionPopover'
import MergeRequestButton from './MergeRequestButton'
import { NotificationsPopoverV2 } from './NotificationsPopoverV2/NotificationsPopover'
+import { useSidebarManagerSnapshot } from 'state/sidebar-manager-state'
+import { AdvisorButton } from 'components/layouts/AppLayout/AdvisorButton'
const LayoutHeaderDivider = ({ className, ...props }: React.HTMLProps<HTMLSpanElement>) => (
<span className={cn('text-border-stronger pr-2', className)} {...props}>
@@ -71,13 +70,8 @@ const LayoutHeader = ({
const { data: selectedOrganization } = useSelectedOrganizationQuery()
const { setMobileMenuOpen } = useAppStateSnapshot()
const gitlessBranching = useIsBranching2Enabled()
- const { toggleSidebar } = useSidebarManagerSnapshot()
const isAccountPage = router.pathname.startsWith('/account')
- const [inlineEditorHotkeyEnabled] = useLocalStorageQuery<boolean>(
- LOCAL_STORAGE_KEYS.HOTKEY_SIDEBAR(SIDEBAR_KEYS.EDITOR_PANEL),
- true
- )
// We only want to query the org usage and check for possible over-ages for plans without usage billing enabled (free or pro with spend cap)
const { data: orgUsage } = useOrgUsageQuery(
@@ -216,16 +210,14 @@ const LayoutHeader = ({
<>
<FeedbackDropdown />
- <div className="overflow-hidden flex items-center rounded-full border">
+ <div className="overflow-hidden flex items-center gap-2">
<HelpPopover />
<NotificationsPopoverV2 />
<AnimatePresence initial={false}>
{!!projectRef && (
<>
- <InlineEditorButton
- onClick={() => toggleSidebar(SIDEBAR_KEYS.EDITOR_PANEL)}
- showShortcut={inlineEditorHotkeyEnabled}
- />
+ <AdvisorButton />
+ <InlineEditorButton />
<AssistantButton />
</>
)}
@@ -236,14 +228,12 @@ const LayoutHeader = ({
) : (
<>
<LocalVersionPopover />
- <div className="overflow-hidden flex items-center rounded-full border">
+ <div className="overflow-hidden flex items-center gap-2">
<AnimatePresence initial={false}>
{!!projectRef && (
<>
- <InlineEditorButton
- onClick={() => toggleSidebar(SIDEBAR_KEYS.EDITOR_PANEL)}
- showShortcut={inlineEditorHotkeyEnabled}
- />
+ <AdvisorButton />
+ <InlineEditorButton />
<AssistantButton />
</>
)}
diff --git a/apps/studio/components/layouts/ProjectLayout/LayoutHeader/NotificationsPopoverV2/NotificationsPopover.tsx b/apps/studio/components/layouts/ProjectLayout/LayoutHeader/NotificationsPopoverV2/NotificationsPopover.tsx
index bf3b1dd16a3..17cfdcb8d34 100644
--- a/apps/studio/components/layouts/ProjectLayout/LayoutHeader/NotificationsPopoverV2/NotificationsPopover.tsx
+++ b/apps/studio/components/layouts/ProjectLayout/LayoutHeader/NotificationsPopoverV2/NotificationsPopover.tsx
@@ -99,29 +99,34 @@ export const NotificationsPopoverV2 = () => {
text: 'Notifications',
},
}}
- type="text"
- className={cn('rounded-none h-[30px] w-[32px] group relative')}
+ type="outline"
+ size="tiny"
+ className={cn(
+ 'rounded-full w-[32px] h-[32px] flex items-center justify-center p-0 group',
+ open && 'bg-foreground text-background'
+ )}
icon={
<div className="relative">
<InboxIcon
size={18}
strokeWidth={1.5}
className={cn(
- '!h-[18px] !w-[18px] text-foreground-light group-hover:text-foreground'
+ 'text-foreground-light group-hover:text-foreground',
+ open && 'text-background group-hover:text-background'
)}
/>
{hasCritical && (
- <div className="absolute -top-1 -right-2 w-3.5 h-3.5 z-10 flex items-center justify-center">
+ <div className="absolute -top-1.5 -right-2 w-3.5 h-3.5 z-10 flex items-center justify-center">
<div className="w-0 h-0 border-l-[6px] border-r-[6px] border-b-[10px] border-l-transparent border-r-transparent border-b-destructive" />
</div>
)}
{hasWarning && !hasCritical && (
- <div className="absolute -top-1 -right-2 w-3.5 h-3.5 z-10 flex items-center justify-center">
+ <div className="absolute -top-1.5 -right-2 w-3.5 h-3.5 z-10 flex items-center justify-center">
<div className="w-2 h-2 rounded-full bg-warning" />
</div>
)}
{!!hasNewNotifications && !hasCritical && !hasWarning && (
- <div className="absolute -top-1 -right-2 w-3.5 h-3.5 z-10 flex items-center justify-center">
+ <div className="absolute -top-1.5 -right-2 w-3.5 h-3.5 z-10 flex items-center justify-center">
<div className="w-2 h-2 rounded-full bg-brand" />
</div>
)}
diff --git a/apps/studio/components/layouts/ProjectLayout/LayoutSidebar/LayoutSidebarProvider.tsx b/apps/studio/components/layouts/ProjectLayout/LayoutSidebar/LayoutSidebarProvider.tsx
index bc946ffbabe..85b8d86d5ea 100644
--- a/apps/studio/components/layouts/ProjectLayout/LayoutSidebar/LayoutSidebarProvider.tsx
+++ b/apps/studio/components/layouts/ProjectLayout/LayoutSidebar/LayoutSidebarProvider.tsx
@@ -1,20 +1,49 @@
import { useRouter } from 'next/router'
import { PropsWithChildren, useEffect } from 'react'
-import { useRegisterSidebar, useSidebarManagerSnapshot } from 'state/sidebar-manager-state'
+
+import { AdvisorPanel } from 'components/ui/AdvisorPanel/AdvisorPanel'
import { AIAssistant } from 'components/ui/AIAssistantPanel/AIAssistant'
import { EditorPanel } from 'components/ui/EditorPanel/EditorPanel'
+import { useSendEventMutation } from 'data/telemetry/send-event-mutation'
+import { useSelectedOrganizationQuery } from 'hooks/misc/useSelectedOrganization'
+import { useSelectedProjectQuery } from 'hooks/misc/useSelectedProject'
+import { useRegisterSidebar, useSidebarManagerSnapshot } from 'state/sidebar-manager-state'
export const SIDEBAR_KEYS = {
AI_ASSISTANT: 'ai-assistant',
EDITOR_PANEL: 'editor-panel',
+ ADVISOR_PANEL: 'advisor-panel',
} as const
+// LayoutSidebars are meant to be used within a project, but rendered within DefaultLayout
+// to prevent unnecessary registering / unregistering of sidebars with every route change
export const LayoutSidebarProvider = ({ children }: PropsWithChildren) => {
+ const { data: project } = useSelectedProjectQuery()
+ const { data: org } = useSelectedOrganizationQuery()
+ const { mutate: sendEvent } = useSendEventMutation()
+
useRegisterSidebar(SIDEBAR_KEYS.AI_ASSISTANT, () => <AIAssistant />, {}, 'i')
useRegisterSidebar(SIDEBAR_KEYS.EDITOR_PANEL, () => <EditorPanel />, {}, 'e')
+ useRegisterSidebar(SIDEBAR_KEYS.ADVISOR_PANEL, () => <AdvisorPanel />)
const router = useRouter()
- const { openSidebar } = useSidebarManagerSnapshot()
+ const { openSidebar, activeSidebar } = useSidebarManagerSnapshot()
+
+ useEffect(() => {
+ if (!!project && activeSidebar) {
+ // add event tracking
+ sendEvent({
+ action: 'sidebar_opened',
+ properties: {
+ sidebar: activeSidebar.id as (typeof SIDEBAR_KEYS)[keyof typeof SIDEBAR_KEYS],
+ },
+ groups: {
+ project: project?.ref ?? 'Unknown',
+ organization: org?.slug ?? 'Unknown',
+ },
+ })
+ }
+ }, [activeSidebar])
// Handle sidebar URL parameter
useEffect(() => {
diff --git a/apps/studio/components/layouts/ProjectLayout/ProjectLayout.tsx b/apps/studio/components/layouts/ProjectLayout/ProjectLayout.tsx
index 507121413df..cb259ffca56 100644
--- a/apps/studio/components/layouts/ProjectLayout/ProjectLayout.tsx
+++ b/apps/studio/components/layouts/ProjectLayout/ProjectLayout.tsx
@@ -21,7 +21,6 @@ import { useEditorType } from '../editors/EditorsLayout.hooks'
import BuildingState from './BuildingState'
import ConnectingState from './ConnectingState'
import { LayoutSidebar } from './LayoutSidebar'
-import { LayoutSidebarProvider } from './LayoutSidebar/LayoutSidebarProvider'
import { LoadingState } from './LoadingState'
import { ProjectPausedState } from './PausedState/ProjectPausedState'
import { PauseFailedState } from './PauseFailedState'
@@ -216,9 +215,7 @@ export const ProjectLayout = forwardRef<HTMLDivElement, PropsWithChildren<Projec
)}
</main>
</ResizablePanel>
- <LayoutSidebarProvider>
- <LayoutSidebar />
- </LayoutSidebarProvider>
+ <LayoutSidebar />
</ResizablePanelGroup>
</ResizablePanel>
</ResizablePanelGroup>
diff --git a/apps/studio/components/ui/AIAssistantPanel/AIAssistant.tsx b/apps/studio/components/ui/AIAssistantPanel/AIAssistant.tsx
index b14e1471059..4f4bf8a8bfc 100644
--- a/apps/studio/components/ui/AIAssistantPanel/AIAssistant.tsx
+++ b/apps/studio/components/ui/AIAssistantPanel/AIAssistant.tsx
@@ -61,7 +61,7 @@ export const AIAssistant = ({ className }: AIAssistantProps) => {
const disablePrompts = useFlag('disableAssistantPrompts')
const { snippets } = useSqlEditorV2StateSnapshot()
const snap = useAiAssistantStateSnapshot()
- const { closeSidebar, isSidebarOpen } = useSidebarManagerSnapshot()
+ const { closeSidebar, activeSidebar } = useSidebarManagerSnapshot()
const isPaidPlan = selectedOrganization?.plan?.id !== 'free'
@@ -435,11 +435,12 @@ export const AIAssistant = ({ className }: AIAssistantProps) => {
}, [snap.initialInput])
useEffect(() => {
- if (isSidebarOpen(SIDEBAR_KEYS.AI_ASSISTANT) && isInSQLEditor && !!snippetContent) {
+ const isOpen = activeSidebar?.id === SIDEBAR_KEYS.AI_ASSISTANT
+ if (isOpen && isInSQLEditor && !!snippetContent) {
snap.setSqlSnippets([{ label: 'Current Query', content: snippetContent }])
}
// eslint-disable-next-line react-hooks/exhaustive-deps
- }, [isSidebarOpen, isInSQLEditor, snippetContent])
+ }, [activeSidebar?.id, isInSQLEditor, snippetContent])
return (
<ErrorBoundary
diff --git a/apps/studio/components/ui/AdvisorPanel/AdvisorPanel.tsx b/apps/studio/components/ui/AdvisorPanel/AdvisorPanel.tsx
new file mode 100644
index 00000000000..1a5cdfe2724
--- /dev/null
+++ b/apps/studio/components/ui/AdvisorPanel/AdvisorPanel.tsx
@@ -0,0 +1,335 @@
+import { AlertTriangle, ChevronLeft, ChevronRight, Gauge, Inbox, Shield, X } from 'lucide-react'
+import { useMemo } from 'react'
+
+import LintDetail from 'components/interfaces/Linter/LintDetail'
+import { SIDEBAR_KEYS } from 'components/layouts/ProjectLayout/LayoutSidebar/LayoutSidebarProvider'
+import { ButtonTooltip } from 'components/ui/ButtonTooltip'
+import { FilterPopover } from 'components/ui/FilterPopover'
+import { Lint, useProjectLintsQuery } from 'data/lint/lint-query'
+import { useSelectedProjectQuery } from 'hooks/misc/useSelectedProject'
+import { AdvisorSeverity, AdvisorTab, useAdvisorStateSnapshot } from 'state/advisor-state'
+import { useSidebarManagerSnapshot } from 'state/sidebar-manager-state'
+import { Badge, Button, TabsList_Shadcn_, TabsTrigger_Shadcn_, Tabs_Shadcn_, cn } from 'ui'
+import { GenericSkeletonLoader } from 'ui-patterns'
+import { EmptyAdvisor } from './EmptyAdvisor'
+
+type AdvisorItem = {
+ id: string
+ title: string
+ severity: AdvisorSeverity
+ createdAt?: number
+ tab: Exclude<AdvisorTab, 'all'>
+ source: 'lint'
+ original: Lint
+}
+
+const severityOptions = [
+ { label: 'Critical', value: 'critical' },
+ { label: 'Warning', value: 'warning' },
+ { label: 'Info', value: 'info' },
+]
+
+const severityOrder: Record<AdvisorSeverity, number> = {
+ critical: 0,
+ warning: 1,
+ info: 2,
+}
+
+const severityLabels: Record<AdvisorSeverity, string> = {
+ critical: 'Critical',
+ warning: 'Warning',
+ info: 'Info',
+}
+
+const severityBadgeVariants: Record<AdvisorSeverity, 'destructive' | 'warning' | 'default'> = {
+ critical: 'destructive',
+ warning: 'warning',
+ info: 'default',
+}
+
+const severityColorClasses: Record<AdvisorSeverity, string> = {
+ critical: 'text-destructive',
+ warning: 'text-warning',
+ info: 'text-foreground-light',
+}
+
+const tabIconMap: Record<Exclude<AdvisorTab, 'all'>, React.ElementType> = {
+ security: Shield,
+ performance: Gauge,
+ messages: Inbox,
+}
+
+const lintLevelToSeverity = (level: Lint['level']): AdvisorSeverity => {
+ switch (level) {
+ case 'ERROR':
+ return 'critical'
+ case 'WARN':
+ return 'warning'
+ default:
+ return 'info'
+ }
+}
+
+export const AdvisorPanel = () => {
+ const {
+ activeTab,
+ severityFilters,
+ selectedItemId,
+ setActiveTab,
+ setSeverityFilters,
+ clearSeverityFilters,
+ setSelectedItemId,
+ } = useAdvisorStateSnapshot()
+ const { data: project } = useSelectedProjectQuery()
+ const { activeSidebar, closeSidebar } = useSidebarManagerSnapshot()
+
+ const isSidebarOpen = activeSidebar?.id === SIDEBAR_KEYS.ADVISOR_PANEL
+
+ const {
+ data: lintData,
+ isLoading: isLintsLoading,
+ isError: isLintsError,
+ } = useProjectLintsQuery(
+ { projectRef: project?.ref },
+ { enabled: isSidebarOpen && !!project?.ref }
+ )
+
+ const lintItems = useMemo<AdvisorItem[]>(() => {
+ if (!lintData) return []
+
+ return lintData
+ .map((lint): AdvisorItem | null => {
+ const categories = lint.categories || []
+ const tab = categories.includes('SECURITY')
+ ? ('security' as const)
+ : categories.includes('PERFORMANCE')
+ ? ('performance' as const)
+ : undefined
+
+ if (!tab) return null
+
+ return {
+ id: lint.cache_key,
+ title: lint.detail,
+ severity: lintLevelToSeverity(lint.level),
+ createdAt: undefined,
+ tab,
+ source: 'lint' as const,
+ original: lint,
+ }
+ })
+ .filter((item): item is AdvisorItem => item !== null)
+ }, [lintData])
+
+ const combinedItems = useMemo<AdvisorItem[]>(() => {
+ const all = [...lintItems]
+
+ return all.sort((a, b) => {
+ const severityDiff = severityOrder[a.severity] - severityOrder[b.severity]
+ if (severityDiff !== 0) return severityDiff
+
+ const createdDiff = (b.createdAt ?? 0) - (a.createdAt ?? 0)
+ if (createdDiff !== 0) return createdDiff
+
+ return a.title.localeCompare(b.title)
+ })
+ }, [lintItems])
+
+ const filteredItems = useMemo<AdvisorItem[]>(() => {
+ return combinedItems.filter((item) => {
+ if (severityFilters.length > 0 && !severityFilters.includes(item.severity)) {
+ return false
+ }
+
+ if (activeTab === 'all') return true
+
+ return item.tab === activeTab
+ })
+ }, [combinedItems, severityFilters, activeTab])
+
+ const itemsFilteredByTabOnly = useMemo<AdvisorItem[]>(() => {
+ return combinedItems.filter((item) => {
+ if (activeTab === 'all') return true
+ return item.tab === activeTab
+ })
+ }, [combinedItems, activeTab])
+
+ const hiddenItemsCount = itemsFilteredByTabOnly.length - filteredItems.length
+
+ const selectedItem = combinedItems.find((item) => item.id === selectedItemId)
+ const isDetailView = !!selectedItem
+
+ const isLoading = isLintsLoading
+ const isError = isLintsError
+
+ const handleTabChange = (tab: string) => {
+ setActiveTab(tab as AdvisorTab)
+ }
+
+ const handleBackToList = () => {
+ setSelectedItemId(undefined)
+ }
+
+ const handleClose = () => {
+ closeSidebar(SIDEBAR_KEYS.ADVISOR_PANEL)
+ }
+
+ return (
+ <div className="flex h-full flex-col bg-background">
+ {isDetailView ? (
+ <>
+ <div className="border-b px-4 py-3 flex items-center gap-3">
+ <ButtonTooltip
+ type="text"
+ className="w-7 h-7 p-0 flex justify-center items-center"
+ icon={<ChevronLeft size={16} strokeWidth={1.5} aria-hidden={true} />}
+ onClick={handleBackToList}
+ tooltip={{ content: { side: 'bottom', text: 'Back to list' } }}
+ />
+ <div className="flex items-center gap-2 overflow-hidden flex-1">
+ <div className="flex-1">
+ <span className="heading-default">{selectedItem?.title}</span>
+ </div>
+ {selectedItem && (
+ <Badge variant={severityBadgeVariants[selectedItem.severity]}>
+ {severityLabels[selectedItem.severity]}
+ </Badge>
+ )}
+ </div>
+ <ButtonTooltip
+ type="text"
+ className="w-7 h-7 p-0"
+ icon={<X strokeWidth={1.5} />}
+ onClick={handleClose}
+ tooltip={{ content: { side: 'bottom', text: 'Close Advisor Center' } }}
+ />
+ </div>
+ <div className="flex-1 overflow-y-auto">
+ {selectedItem ? (
+ <AdvisorDetail item={selectedItem} projectRef={project?.ref ?? ''} />
+ ) : (
+ <div className="px-6 py-8">
+ <p className="text-sm text-foreground-light">
+ Select an advisor item to view more details.
+ </p>
+ </div>
+ )}
+ </div>
+ </>
+ ) : (
+ <>
+ <div className="border-b">
+ <div className="flex items-center justify-between gap-3 px-4 h-[46px]">
+ <Tabs_Shadcn_ value={activeTab} onValueChange={handleTabChange} className="h-full">
+ <TabsList_Shadcn_ className="border-b-0 gap-4 h-full">
+ <TabsTrigger_Shadcn_ value="all" className="h-full text-xs">
+ All
+ </TabsTrigger_Shadcn_>
+ <TabsTrigger_Shadcn_ value="security" className="h-full text-xs">
+ Security
+ </TabsTrigger_Shadcn_>
+ <TabsTrigger_Shadcn_ value="performance" className="h-full text-xs">
+ Performance
+ </TabsTrigger_Shadcn_>
+ </TabsList_Shadcn_>
+ </Tabs_Shadcn_>
+ <div className="flex items-center gap-2">
+ <FilterPopover
+ name="Severity"
+ options={severityOptions}
+ activeOptions={[...severityFilters]}
+ valueKey="value"
+ labelKey="label"
+ onSaveFilters={(values) => setSeverityFilters(values as AdvisorSeverity[])}
+ />
+ <ButtonTooltip
+ type="text"
+ className="w-7 h-7 p-0"
+ icon={<X strokeWidth={1.5} />}
+ onClick={handleClose}
+ tooltip={{ content: { side: 'bottom', text: 'Close Advisor Center' } }}
+ />
+ </div>
+ </div>
+ </div>
+ <div className="flex-1 overflow-y-auto">
+ {isLoading ? (
+ <div>
+ <GenericSkeletonLoader className="w-full p-4" />
+ </div>
+ ) : isError ? (
+ <div className="my-8 mx-4 flex flex-col items-center gap-2">
+ <AlertTriangle className="text-destructive" />
+ <h2 className="text-base text-foreground-light">Error loading advisories</h2>
+ <p className="text-sm text-foreground-lighter">Please try again later.</p>
+ </div>
+ ) : filteredItems.length === 0 ? (
+ <EmptyAdvisor
+ activeTab={activeTab}
+ hasFilters={severityFilters.length > 0}
+ onClearFilters={clearSeverityFilters}
+ />
+ ) : (
+ <>
+ <div className="flex flex-col">
+ {filteredItems.map((item) => {
+ const SeverityIcon = tabIconMap[item.tab]
+ const severityClass = severityColorClasses[item.severity]
+ return (
+ <div key={item.id} className="border-b">
+ <Button
+ type="text"
+ className="justify-start w-full block rounded-none h-auto py-3 px-4 text-foreground-light hover:text-foreground"
+ onClick={() => setSelectedItemId(item.id)}
+ >
+ <div className="flex items-center justify-between gap-2">
+ <div className="flex items-center gap-2 overflow-hidden">
+ <SeverityIcon
+ size={16}
+ strokeWidth={1.5}
+ className={cn('flex-shrink-0', severityClass)}
+ />
+ <span className="truncate">{item.title}</span>
+ </div>
+ <ChevronRight
+ size={16}
+ strokeWidth={1.5}
+ className="flex-shrink-0 text-foreground-lighter"
+ />
+ </div>
+ </Button>
+ </div>
+ )
+ })}
+ </div>
+ {severityFilters.length > 0 && hiddenItemsCount > 0 && (
+ <div className="px-4 py-3">
+ <Button type="text" className="w-full" onClick={clearSeverityFilters}>
+ Show {hiddenItemsCount} more issue{hiddenItemsCount !== 1 ? 's' : ''}
+ </Button>
+ </div>
+ )}
+ </>
+ )}
+ </div>
+ </>
+ )}
+ </div>
+ )
+}
+
+interface AdvisorDetailProps {
+ item: AdvisorItem
+ projectRef: string
+}
+
+const AdvisorDetail = ({ item, projectRef }: AdvisorDetailProps) => {
+ if (item.source === 'lint') {
+ const lint = item.original as Lint
+ return (
+ <div className="px-6 py-6">
+ <LintDetail lint={lint} projectRef={projectRef} />
+ </div>
+ )
+ }
+}
diff --git a/apps/studio/components/ui/AdvisorPanel/EmptyAdvisor.tsx b/apps/studio/components/ui/AdvisorPanel/EmptyAdvisor.tsx
new file mode 100644
index 00000000000..3096b0b19a9
--- /dev/null
+++ b/apps/studio/components/ui/AdvisorPanel/EmptyAdvisor.tsx
@@ -0,0 +1,56 @@
+import { TextSearch } from 'lucide-react'
+import { Button } from 'ui'
+import { AdvisorTab } from 'state/advisor-state'
+
+interface EmptyAdvisorProps {
+ activeTab: AdvisorTab
+ hasFilters: boolean
+ onClearFilters: () => void
+}
+
+export const EmptyAdvisor = ({ activeTab, hasFilters, onClearFilters }: EmptyAdvisorProps) => {
+ const getHeading = () => {
+ if (hasFilters) return 'No items found'
+
+ switch (activeTab) {
+ case 'security':
+ return 'No security issues detected'
+ case 'performance':
+ return 'No performance issues detected'
+ case 'messages':
+ return 'No messages'
+ default:
+ return 'No issues detected'
+ }
+ }
+
+ const getMessage = () => {
+ if (hasFilters) return 'No advisor items match your current filters'
+
+ switch (activeTab) {
+ case 'security':
+ return 'Congrats! There are no security issues detected for this project'
+ case 'performance':
+ return 'Congrats! There are no performance issues detected for this project'
+ case 'messages':
+ return 'There are no messages for this project'
+ default:
+ return 'Congrats! There are no issues detected for this project'
+ }
+ }
+
+ return (
+ <div className="absolute top-28 px-6 flex flex-col items-center justify-center w-full gap-y-2">
+ <TextSearch className="text-foreground-muted" strokeWidth={1} />
+ <div className="text-center">
+ <p className="heading-default">{getHeading()}</p>
+ <p className="text-foreground-light text-sm">{getMessage()}</p>
+ </div>
+ {hasFilters && (
+ <Button type="outline" onClick={onClearFilters}>
+ Clear filters
+ </Button>
+ )}
+ </div>
+ )
+}
diff --git a/apps/studio/components/ui/EditorPanel/EditorPanel.tsx b/apps/studio/components/ui/EditorPanel/EditorPanel.tsx
index e18c0b3ebd9..ea19b47c2da 100644
--- a/apps/studio/components/ui/EditorPanel/EditorPanel.tsx
+++ b/apps/studio/components/ui/EditorPanel/EditorPanel.tsx
@@ -147,7 +147,7 @@ export const EditorPanel = () => {
return (
<div className="flex h-full flex-col bg-background">
<div className="border-b border-b-muted flex items-center justify-between gap-x-4 px-4 h-[46px]">
- <div className="text-sm font-medium">{label}</div>
+ <div className="text-xs">{label}</div>
<div className="flex items-center">
{templates.length > 0 && (
<Popover_Shadcn_ open={isTemplatesOpen} onOpenChange={setIsTemplatesOpen}>
diff --git a/apps/studio/components/ui/FilterPopover.tsx b/apps/studio/components/ui/FilterPopover.tsx
index e8260e71faf..4ae0b2365a5 100644
--- a/apps/studio/components/ui/FilterPopover.tsx
+++ b/apps/studio/components/ui/FilterPopover.tsx
@@ -89,7 +89,7 @@ export const FilterPopover = <T extends Record<string, any>>({
})
useEffect(() => {
- if (!open && activeOptions.length > 0) setSelectedOptions(activeOptions)
+ if (!open) setSelectedOptions(activeOptions)
if (!open) setSearch('')
}, [open, activeOptions])
diff --git a/apps/studio/state/advisor-state.ts b/apps/studio/state/advisor-state.ts
new file mode 100644
index 00000000000..a5839330a32
--- /dev/null
+++ b/apps/studio/state/advisor-state.ts
@@ -0,0 +1,40 @@
+import { proxy, snapshot, useSnapshot } from 'valtio'
+
+export type AdvisorTab = 'all' | 'security' | 'performance' | 'messages'
+export type AdvisorSeverity = 'critical' | 'warning' | 'info'
+
+const initialState = {
+ activeTab: 'all' as AdvisorTab,
+ severityFilters: ['critical'] as AdvisorSeverity[],
+ selectedItemId: undefined as string | undefined,
+}
+
+export const advisorState = proxy({
+ ...initialState,
+ setActiveTab(tab: AdvisorTab) {
+ advisorState.activeTab = tab
+ },
+ setSeverityFilters(severities: AdvisorSeverity[]) {
+ advisorState.severityFilters = severities
+ },
+ clearSeverityFilters() {
+ advisorState.severityFilters = []
+ },
+ setSelectedItemId(id: string | undefined) {
+ advisorState.selectedItemId = id
+ },
+ focusItem({ id, tab }: { id: string; tab?: AdvisorTab }) {
+ if (tab) {
+ advisorState.activeTab = tab
+ }
+ advisorState.selectedItemId = id
+ },
+ reset() {
+ Object.assign(advisorState, initialState)
+ },
+})
+
+export const getAdvisorStateSnapshot = () => snapshot(advisorState)
+
+export const useAdvisorStateSnapshot = (options?: Parameters<typeof useSnapshot>[1]) =>
+ useSnapshot(advisorState, options)
diff --git a/apps/studio/state/sidebar-manager-state.tsx b/apps/studio/state/sidebar-manager-state.tsx
index bb455845ec4..e0e48404090 100644
--- a/apps/studio/state/sidebar-manager-state.tsx
+++ b/apps/studio/state/sidebar-manager-state.tsx
@@ -151,12 +151,16 @@ export const useRegisterSidebar = (
)
useEffect(() => {
- const { registerSidebar, unregisterSidebar } = sidebarManagerState
+ const { registerSidebar, unregisterSidebar, sidebars } = sidebarManagerState
- registerSidebar(id, component, handlers)
+ if (!sidebars[id]) {
+ registerSidebar(id, component, handlers)
+ }
return () => {
- unregisterSidebar(id)
+ if (sidebars[id]) {
+ unregisterSidebar(id)
+ }
}
}, [id])
diff --git a/packages/common/telemetry-constants.ts b/packages/common/telemetry-constants.ts
index 9c1e97d46a2..3afd9419f2e 100644
--- a/packages/common/telemetry-constants.ts
+++ b/packages/common/telemetry-constants.ts
@@ -2010,6 +2010,24 @@ export interface CommandMenuCommandClickedEvent {
groups: Partial<TelemetryGroups>
}
+/**
+ * User opened a sidebar panel.
+ *
+ * @group Events
+ * @source studio
+ * @page Various pages with sidebar buttons
+ */
+export interface SidebarOpenedEvent {
+ action: 'sidebar_opened'
+ properties: {
+ /**
+ * The sidebar panel that was opened, e.g. ai-assistant, editor-panel, advisor-panel
+ */
+ sidebar: 'ai-assistant' | 'editor-panel' | 'advisor-panel'
+ }
+ groups: TelemetryGroups
+}
+
/**
* User was exposed to the table quickstart experiment.
*
@@ -2286,3 +2304,4 @@ export type TelemetryEvent =
| CommandMenuOpenedEvent
| CommandMenuSearchSubmittedEvent
| CommandMenuCommandClickedEvent
+ | SidebarOpenedEvent