The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.
TypeScript aialternativeauthdatabasedenoembeddingsexamplefirebasenextjsoauth2pgvectorpostgispostgrespostgresqlpostgrestrealtimesupabasevectorswebsockets
fix(studio): gate health advisor behind feature flag (#50326)
Jordi Enric519a3a5644ed
diff --git a/apps/studio/components/interfaces/ProjectHome/AdvisorSection.tsx b/apps/studio/components/interfaces/ProjectHome/AdvisorSection.tsxindex 7563c64a2f4..3cddb6d126a 100644--- a/apps/studio/components/interfaces/ProjectHome/AdvisorSection.tsx+++ b/apps/studio/components/interfaces/ProjectHome/AdvisorSection.tsx@@ -1,4 +1,4 @@-import { useParams } from 'common'+import { useFlag, useParams } from 'common'import { Shield } from 'lucide-react'import { useCallback, useMemo } from 'react'import { AiIconAnimation, Badge, Button, Card, CardContent, CardHeader, CardTitle, cn } from 'ui'@@ -24,6 +24,7 @@ import { useAdvisorSignals } from '@/components/ui/AdvisorPanel/useAdvisorSignalimport { AiAssistantDropdown } from '@/components/ui/AiAssistantDropdown'import { useProjectHealthLintsQuery } from '@/data/lint/health-lints-query'import { useProjectLintsQuery } from '@/data/lint/lint-query'+import { IS_PLATFORM } from '@/lib/constants'import { useTrack } from '@/lib/telemetry/track'import { useAdvisorStateSnapshot } from '@/state/advisor-state'import { useAiAssistantStateSnapshot } from '@/state/ai-assistant-state'@@ -31,6 +32,7 @@ import { useSidebarManagerSnapshot } from '@/state/sidebar-manager-state'export const AdvisorSection = ({ showEmptyState = false }: { showEmptyState?: boolean }) => {const { ref: projectRef } = useParams()+ const isHealthAdvisorEnabled = useFlag('healthAdvisor') === true && IS_PLATFORMconst track = useTrack()const snap = useAiAssistantStateSnapshot()const { openSidebar } = useSidebarManagerSnapshot()@@ -51,11 +53,11 @@ export const AdvisorSection = ({ showEmptyState = false }: { showEmptyState?: boconst advisorItems = useMemo<AdvisorItem[]>(() => {const criticalLintItems = createAdvisorLintItems([...(lints ?? []),- ...(healthLints ?? []),+ ...(isHealthAdvisorEnabled ? (healthLints ?? []) : []),]).filter((item) => item.source === 'lint' && item.original.level === LINTER_LEVELS.ERROR)return sortAdvisorItems([...criticalLintItems, ...signalItems])- }, [lints, healthLints, signalItems])+ }, [lints, healthLints, signalItems, isHealthAdvisorEnabled])const visibleAdvisorItems = useMemo(() => advisorItems.slice(0, MAX_HOMEPAGE_ADVISOR_ITEMS),@@ -110,7 +112,7 @@ export const AdvisorSection = ({ showEmptyState = false }: { showEmptyState?: bo)if (showEmptyState) {- return <EmptyState />+ return <EmptyState isHealthAdvisorEnabled={isHealthAdvisorEnabled} />}// [Joshen] Note that we're intentionally (for now) not waiting for advisor signals to load@@ -229,19 +231,21 @@ export const AdvisorSection = ({ showEmptyState = false }: { showEmptyState?: bo)}</>) : (- <EmptyState />+ <EmptyState isHealthAdvisorEnabled={isHealthAdvisorEnabled} />)}</div>)}-function EmptyState() {+function EmptyState({ isHealthAdvisorEnabled }: { isHealthAdvisorEnabled: boolean }) {return (<Card className="bg-transparent h-64"><CardContent className="flex flex-col items-center justify-center gap-2 p-16 h-full"><Shield size={20} strokeWidth={1.5} className="text-foreground-muted" /><p className="text-sm text-foreground-light text-center">- No security, performance or health issues found+ {isHealthAdvisorEnabled+ ? 'No security, performance or health issues found'+ : 'No security or performance issues found'}</p></CardContent></Card>diff --git a/apps/studio/components/layouts/AdvisorsLayout/Advisors.Commands.tsx b/apps/studio/components/layouts/AdvisorsLayout/Advisors.Commands.tsxindex 1c25557ecf6..9865874f32d 100644--- a/apps/studio/components/layouts/AdvisorsLayout/Advisors.Commands.tsx+++ b/apps/studio/components/layouts/AdvisorsLayout/Advisors.Commands.tsx@@ -1,4 +1,4 @@-import { useParams } from 'common'+import { useFlag, useParams } from 'common'import type { CommandOptions } from 'ui-patterns/CommandMenu'import { useRegisterCommands } from 'ui-patterns/CommandMenu'import type { IRouteCommand } from 'ui-patterns/CommandMenu/internal/types'@@ -9,11 +9,12 @@ import { IS_PLATFORM } from '@/lib/constants'export function useAdvisorsGoToCommands(options?: CommandOptions) {let { ref } = useParams()ref ||= '_'+ const isHealthAdvisorEnabled = useFlag('healthAdvisor') === trueuseRegisterCommands(COMMAND_MENU_SECTIONS.NAVIGATE,[- ...(IS_PLATFORM+ ...(IS_PLATFORM && isHealthAdvisorEnabled? [{id: 'nav-advisors-health',@@ -36,6 +37,6 @@ export function useAdvisorsGoToCommands(options?: CommandOptions) {defaultHidden: true,},],- { ...options, deps: [ref] }+ { ...options, deps: [ref, isHealthAdvisorEnabled] })}diff --git a/apps/studio/components/layouts/AdvisorsLayout/AdvisorsMenu.utils.test.ts b/apps/studio/components/layouts/AdvisorsLayout/AdvisorsMenu.utils.test.tsindex de9471bd92e..e792cdbe8ba 100644--- a/apps/studio/components/layouts/AdvisorsLayout/AdvisorsMenu.utils.test.ts+++ b/apps/studio/components/layouts/AdvisorsLayout/AdvisorsMenu.utils.test.ts@@ -7,6 +7,7 @@ describe('generateAdvisorsMenu', () => {const [advisors] = generateAdvisorsMenu({ref: 'abc',isAdvisorRulesEnabled: false,+ isHealthAdvisorEnabled: true,isPlatform: true,})@@ -23,6 +24,7 @@ describe('generateAdvisorsMenu', () => {const [advisors] = generateAdvisorsMenu({ref: 'abc',isAdvisorRulesEnabled: false,+ isHealthAdvisorEnabled: true,isPlatform: false,})diff --git a/apps/studio/components/layouts/AdvisorsLayout/AdvisorsMenu.utils.tsx b/apps/studio/components/layouts/AdvisorsLayout/AdvisorsMenu.utils.tsxindex 1c37b9f47b6..3347a4c1da2 100644--- a/apps/studio/components/layouts/AdvisorsLayout/AdvisorsMenu.utils.tsx+++ b/apps/studio/components/layouts/AdvisorsLayout/AdvisorsMenu.utils.tsx@@ -1,4 +1,4 @@-import { useParams } from 'common'+import { useFlag, useParams } from 'common'import { ArrowUpRight } from 'lucide-react'import { useIsAdvisorRulesEnabled } from '@/components/interfaces/App/FeaturePreview/FeaturePreviewContext'@@ -12,14 +12,16 @@ import { SHORTCUT_IDS } from '@/state/shortcuts/registry'export const generateAdvisorsMenu = ({ref,isAdvisorRulesEnabled,+ isHealthAdvisorEnabled,isPlatform,}: {ref: string | undefinedisAdvisorRulesEnabled: boolean+ isHealthAdvisorEnabled: booleanisPlatform: boolean}): ProductMenuGroup[] => {const advisorItems: ProductMenuGroupItem[] = [- ...(isPlatform+ ...(isPlatform && isHealthAdvisorEnabled? [{name: 'Health Advisor',@@ -80,10 +82,12 @@ export const generateAdvisorsMenu = ({export const useGenerateAdvisorsMenu = (): ProductMenuGroup[] => {const { ref } = useParams()const isAdvisorRulesEnabled = useIsAdvisorRulesEnabled()+ const isHealthAdvisorEnabled = useFlag('healthAdvisor') === truereturn generateAdvisorsMenu({ref,isAdvisorRulesEnabled,+ isHealthAdvisorEnabled,isPlatform: IS_PLATFORM,})}diff --git a/apps/studio/components/ui/AdvisorPanel/AdvisorFilters.tsx b/apps/studio/components/ui/AdvisorPanel/AdvisorFilters.tsxindex 3c919aaad5f..c52b3e36d21 100644--- a/apps/studio/components/ui/AdvisorPanel/AdvisorFilters.tsx+++ b/apps/studio/components/ui/AdvisorPanel/AdvisorFilters.tsx@@ -1,3 +1,4 @@+import { useFlag } from 'common'import { X } from 'lucide-react'import { z } from 'zod'@@ -58,9 +59,10 @@ export const AdvisorFilters = ({onClose,isPlatform = false,}: AdvisorFiltersProps) => {- const categoryOptions = (isPlatform ? platformCategories : selfHostedCategories).map(- (category) => ({ label: advisorCategoryLabels[category], value: category })- )+ const isHealthAdvisorEnabled = useFlag('healthAdvisor') === true+ const categoryOptions = (isPlatform ? platformCategories : selfHostedCategories)+ .filter((category) => category !== 'health' || isHealthAdvisorEnabled)+ .map((category) => ({ label: advisorCategoryLabels[category], value: category }))return (<div className="border-b overflow-x-auto">diff --git a/apps/studio/components/ui/AdvisorPanel/AdvisorPanel.tsx b/apps/studio/components/ui/AdvisorPanel/AdvisorPanel.tsxindex 1ea6e46cdfc..5cbf365beb8 100644--- a/apps/studio/components/ui/AdvisorPanel/AdvisorPanel.tsx+++ b/apps/studio/components/ui/AdvisorPanel/AdvisorPanel.tsx@@ -1,3 +1,4 @@+import { useFlag } from 'common'import { useMemo, useRef } from 'react'import { AdvisorDetail } from './AdvisorDetail'@@ -26,8 +27,9 @@ import { useSidebarManagerSnapshot } from '@/state/sidebar-manager-state'export const AdvisorPanel = () => {const track = useTrack()+ const isHealthAdvisorEnabled = useFlag('healthAdvisor') === true && IS_PLATFORMconst {- categoryFilters,+ categoryFilters: savedCategoryFilters,severityFilters,selectedItemId,selectedItemSource,@@ -40,6 +42,11 @@ export const AdvisorPanel = () => {clearFilters,clearNarrowingFilters,} = useAdvisorStateSnapshot()+ const categoryFilters = useMemo(+ () =>+ savedCategoryFilters.filter((category) => category !== 'health' || isHealthAdvisorEnabled),+ [savedCategoryFilters, isHealthAdvisorEnabled]+ )const { data: project } = useSelectedProjectQuery()const { activeSidebar, closeSidebar } = useSidebarManagerSnapshot()@@ -54,7 +61,8 @@ export const AdvisorPanel = () => {const canLoadProjectData = isSidebarOpen && hasProjectRefconst shouldLoadLints =canLoadProjectData && (isCategorySelected('security') || isCategorySelected('performance'))- const shouldLoadHealthLints = canLoadProjectData && isCategorySelected('health')+ const shouldLoadHealthLints =+ isHealthAdvisorEnabled && canLoadProjectData && isCategorySelected('health')const shouldLoadSignals = canLoadProjectData && isCategorySelected('security')const {@@ -132,8 +140,11 @@ export const AdvisorPanel = () => {}const lintItems = useMemo<AdvisorItem[]>(() => {- return createAdvisorLintItems([...(lintData ?? []), ...(healthLintData ?? [])])- }, [lintData, healthLintData])+ return createAdvisorLintItems([+ ...(lintData ?? []),+ ...(isHealthAdvisorEnabled ? (healthLintData ?? []) : []),+ ])+ }, [lintData, healthLintData, isHealthAdvisorEnabled])const notificationItems = useMemo<AdvisorItem[]>(() => {if (!IS_PLATFORM) return []@@ -179,7 +190,9 @@ export const AdvisorPanel = () => {const isLoading =isLintsActuallyLoading || isNotificationsActuallyLoading || isHealthLintsActuallyLoadingconst isError =- isLintsError || isNotificationsError || (isHealthLintsError && isShowingHealthOnly)+ isLintsError ||+ isNotificationsError ||+ (shouldLoadHealthLints && isHealthLintsError && isShowingHealthOnly)const handleBackToList = () => {setSelectedItem(undefined)diff --git a/apps/studio/components/ui/AdvisorPanel/AdvisorPanelBody.tsx b/apps/studio/components/ui/AdvisorPanel/AdvisorPanelBody.tsxindex 78015273dec..3b26e1c7c22 100644--- a/apps/studio/components/ui/AdvisorPanel/AdvisorPanelBody.tsx+++ b/apps/studio/components/ui/AdvisorPanel/AdvisorPanelBody.tsx@@ -1,3 +1,4 @@+import { useFlag } from 'common'import { AlertTriangle, ChevronRight, Inbox } from 'lucide-react'import { Badge, Button, cn } from 'ui'import { GenericSkeletonLoader } from 'ui-patterns/ShimmeringLoader'@@ -14,16 +15,20 @@ import {} from './AdvisorPanel.utils'import { EmptyAdvisor } from './EmptyAdvisor'import type { Notification } from '@/data/notifications/notifications-v2-query'+import { IS_PLATFORM } from '@/lib/constants'import type { AdvisorCategory, AdvisorSeverity } from '@/state/advisor-state'const NoProjectNotice = () => {+ const isHealthAdvisorEnabled = useFlag('healthAdvisor') === true && IS_PLATFORMreturn (<div className="absolute top-28 px-6 flex flex-col items-center justify-center w-full gap-y-2"><Inbox className="text-foreground-muted" strokeWidth={1} /><div className="text-center"><p className="heading-default">Project required</p><p className="text-foreground-light text-sm">- Select a project to view its security, performance and health advisories+ {isHealthAdvisorEnabled+ ? 'Select a project to view its security, performance and health advisories'+ : 'Select a project to view its security and performance advisories'}</p></div></div>diff --git a/apps/studio/data/lint/health-lints-query.ts b/apps/studio/data/lint/health-lints-query.tsindex 2008da4d68c..4cf74907cb9 100644--- a/apps/studio/data/lint/health-lints-query.ts+++ b/apps/studio/data/lint/health-lints-query.ts@@ -1,5 +1,6 @@import { useQuery } from '@tanstack/react-query'import type { components } from 'api-types'+import { useFlag } from 'common'import { lintKeys } from './keys'import type { Lint } from './lint-query'@@ -75,12 +76,18 @@ export const useProjectHealthLintsQuery = <TData = ProjectHealthLintsData>(}: UseCustomQueryOptions<ProjectHealthLintsData, ProjectHealthLintsError, TData> = {}) => {const { data: project } = useSelectedProjectQuery()+ const isHealthAdvisorEnabled = useFlag('healthAdvisor') === trueconst isActive = project?.status === PROJECT_STATUS.ACTIVE_HEALTHYreturn useQuery<ProjectHealthLintsData, ProjectHealthLintsError, TData>({queryKey: lintKeys.healthLints(projectRef),queryFn: ({ signal }) => getProjectHealthLints({ projectRef }, signal),- enabled: enabled && IS_PLATFORM && typeof projectRef !== 'undefined' && isActive,+ enabled:+ enabled &&+ isHealthAdvisorEnabled &&+ IS_PLATFORM &&+ typeof projectRef !== 'undefined' &&+ isActive,// Every run costs a live database connection plus a metrics and a logs query, so keep// repeat mounts (homepage row, advisor panel) on one result and don't retry failures.staleTime: 60_000,diff --git a/apps/studio/pages/project/[ref]/advisors/health.tsx b/apps/studio/pages/project/[ref]/advisors/health.tsxindex 6fbd58d8972..7cb4ecca77f 100644--- a/apps/studio/pages/project/[ref]/advisors/health.tsx+++ b/apps/studio/pages/project/[ref]/advisors/health.tsx@@ -1,6 +1,7 @@-import { useParams } from 'common'+import { useFlag, useParams } from 'common'import { useMemo, useState } from 'react'import { LoadingLine } from 'ui'+import { Admonition } from 'ui-patterns/Admonition'import { LINTER_LEVELS } from '@/components/interfaces/Linter/Linter.constants'import { lintInfoMap, parseLinterLevel } from '@/components/interfaces/Linter/Linter.utils'@@ -18,6 +19,20 @@ import { IS_PLATFORM } from '@/lib/constants'import type { NextPageWithLayout } from '@/types'const ProjectHealthLints: NextPageWithLayout = () => {+ const isHealthAdvisorEnabled = useFlag('healthAdvisor') === true++ if (!IS_PLATFORM || !isHealthAdvisorEnabled) {+ return (+ <div className="flex items-center justify-center w-full h-full">+ <Admonition type="default" title="Health Advisor is not available for this project" />+ </div>+ )+ }++ return <ProjectHealthLintsContent />+}++const ProjectHealthLintsContent = () => {const { preset, id } = useParams()const { data: project } = useSelectedProjectQuery()@@ -33,9 +48,7 @@ const ProjectHealthLints: NextPageWithLayout = () => {projectRef: project?.ref,})- // Health checks are platform-only. If this page is opened self-hosted the query stays- // disabled, and `isPending` would otherwise spin forever.- const isLoading = IS_PLATFORM && isPending+ const isLoading = isPendingconst activeLints = (data ?? []).filter((lint) => lint.categories.includes('HEALTH'))const currentTabFilters = filters.find((filter) => filter.level === currentTab)?.filters ?? []