Skip to content

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

fix(studio): gate homepage health advisor (#50328)

Jordi Enric38e8f12b1b77
diff --git a/apps/studio/components/interfaces/ProjectHome/AdvisorSection.tsx b/apps/studio/components/interfaces/ProjectHome/AdvisorSection.tsx
index 3cddb6d126a..e1539c9bd02 100644
--- a/apps/studio/components/interfaces/ProjectHome/AdvisorSection.tsx
+++ b/apps/studio/components/interfaces/ProjectHome/AdvisorSection.tsx
@@ -24,7 +24,6 @@ import { useAdvisorSignals } from '@/components/ui/AdvisorPanel/useAdvisorSignal
import { 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'
@@ -32,7 +31,9 @@ import { useSidebarManagerSnapshot } from '@/state/sidebar-manager-state'
export const AdvisorSection = ({ showEmptyState = false }: { showEmptyState?: boolean }) => {
const { ref: projectRef } = useParams()
- const isHealthAdvisorEnabled = useFlag('healthAdvisor') === true && IS_PLATFORM
+ const isHealthAdvisorEnabled = useFlag('healthAdvisor')
+ const isHealthAdvisorInHomepageEnabled = useFlag('healthAdvisorInHomepage')
+ const canShowHealthAdvisor = isHealthAdvisorEnabled && isHealthAdvisorInHomepageEnabled
const track = useTrack()
const snap = useAiAssistantStateSnapshot()
const { openSidebar } = useSidebarManagerSnapshot()
@@ -45,7 +46,7 @@ export const AdvisorSection = ({ showEmptyState = false }: { showEmptyState?: bo
const { data: healthLints } = useProjectHealthLintsQuery(
{ projectRef },
- { enabled: !showEmptyState }
+ { enabled: !showEmptyState && canShowHealthAdvisor }
)
const { data: signalItems } = useAdvisorSignals({ projectRef, enabled: !showEmptyState })
@@ -53,11 +54,11 @@ export const AdvisorSection = ({ showEmptyState = false }: { showEmptyState?: bo
const advisorItems = useMemo<AdvisorItem[]>(() => {
const criticalLintItems = createAdvisorLintItems([
...(lints ?? []),
- ...(isHealthAdvisorEnabled ? (healthLints ?? []) : []),
+ ...(canShowHealthAdvisor ? (healthLints ?? []) : []),
]).filter((item) => item.source === 'lint' && item.original.level === LINTER_LEVELS.ERROR)
return sortAdvisorItems([...criticalLintItems, ...signalItems])
- }, [lints, healthLints, signalItems, isHealthAdvisorEnabled])
+ }, [lints, healthLints, signalItems, canShowHealthAdvisor])
const visibleAdvisorItems = useMemo(
() => advisorItems.slice(0, MAX_HOMEPAGE_ADVISOR_ITEMS),
@@ -112,7 +113,7 @@ export const AdvisorSection = ({ showEmptyState = false }: { showEmptyState?: bo
)
if (showEmptyState) {
- return <EmptyState isHealthAdvisorEnabled={isHealthAdvisorEnabled} />
+ return <EmptyState canShowHealthAdvisor={canShowHealthAdvisor} />
}
// [Joshen] Note that we're intentionally (for now) not waiting for advisor signals to load
@@ -231,19 +232,19 @@ export const AdvisorSection = ({ showEmptyState = false }: { showEmptyState?: bo
)}
</>
) : (
- <EmptyState isHealthAdvisorEnabled={isHealthAdvisorEnabled} />
+ <EmptyState canShowHealthAdvisor={canShowHealthAdvisor} />
)}
</div>
)
}
-function EmptyState({ isHealthAdvisorEnabled }: { isHealthAdvisorEnabled: boolean }) {
+function EmptyState({ canShowHealthAdvisor }: { canShowHealthAdvisor: 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">
- {isHealthAdvisorEnabled
+ {canShowHealthAdvisor
? 'No security, performance or health issues found'
: 'No security or performance issues found'}
</p>
diff --git a/apps/studio/components/layouts/AdvisorsLayout/Advisors.Commands.tsx b/apps/studio/components/layouts/AdvisorsLayout/Advisors.Commands.tsx
index 9865874f32d..4a5ff7eae2d 100644
--- a/apps/studio/components/layouts/AdvisorsLayout/Advisors.Commands.tsx
+++ b/apps/studio/components/layouts/AdvisorsLayout/Advisors.Commands.tsx
@@ -4,17 +4,16 @@ import { useRegisterCommands } from 'ui-patterns/CommandMenu'
import type { IRouteCommand } from 'ui-patterns/CommandMenu/internal/types'
import { COMMAND_MENU_SECTIONS } from '@/components/interfaces/App/CommandMenu/CommandMenu.utils'
-import { IS_PLATFORM } from '@/lib/constants'
export function useAdvisorsGoToCommands(options?: CommandOptions) {
let { ref } = useParams()
ref ||= '_'
- const isHealthAdvisorEnabled = useFlag('healthAdvisor') === true
+ const isHealthAdvisorEnabled = useFlag('healthAdvisor')
useRegisterCommands(
COMMAND_MENU_SECTIONS.NAVIGATE,
[
- ...(IS_PLATFORM && isHealthAdvisorEnabled
+ ...(isHealthAdvisorEnabled
? [
{
id: 'nav-advisors-health',
diff --git a/apps/studio/components/layouts/AdvisorsLayout/AdvisorsMenu.utils.test.ts b/apps/studio/components/layouts/AdvisorsLayout/AdvisorsMenu.utils.test.ts
index e792cdbe8ba..d9f248e29b4 100644
--- a/apps/studio/components/layouts/AdvisorsLayout/AdvisorsMenu.utils.test.ts
+++ b/apps/studio/components/layouts/AdvisorsLayout/AdvisorsMenu.utils.test.ts
@@ -3,7 +3,7 @@ import { describe, expect, it } from 'vitest'
import { generateAdvisorsMenu } from './AdvisorsMenu.utils'
describe('generateAdvisorsMenu', () => {
- it('puts Health Advisor first on platform', () => {
+ it('puts Health Advisor first when enabled', () => {
const [advisors] = generateAdvisorsMenu({
ref: 'abc',
isAdvisorRulesEnabled: false,
@@ -20,12 +20,12 @@ describe('generateAdvisorsMenu', () => {
expect(advisors.items[0].url).toBe('/project/abc/advisors/health')
})
- it('omits Health Advisor when not on platform', () => {
+ it('omits Health Advisor when disabled', () => {
const [advisors] = generateAdvisorsMenu({
ref: 'abc',
isAdvisorRulesEnabled: false,
- isHealthAdvisorEnabled: true,
- isPlatform: false,
+ isHealthAdvisorEnabled: false,
+ isPlatform: true,
})
expect(advisors.items.map((item) => item.key)).toEqual([
diff --git a/apps/studio/components/layouts/AdvisorsLayout/AdvisorsMenu.utils.tsx b/apps/studio/components/layouts/AdvisorsLayout/AdvisorsMenu.utils.tsx
index 3347a4c1da2..5460a912f0e 100644
--- a/apps/studio/components/layouts/AdvisorsLayout/AdvisorsMenu.utils.tsx
+++ b/apps/studio/components/layouts/AdvisorsLayout/AdvisorsMenu.utils.tsx
@@ -21,7 +21,7 @@ export const generateAdvisorsMenu = ({
isPlatform: boolean
}): ProductMenuGroup[] => {
const advisorItems: ProductMenuGroupItem[] = [
- ...(isPlatform && isHealthAdvisorEnabled
+ ...(isHealthAdvisorEnabled
? [
{
name: 'Health Advisor',
@@ -82,7 +82,7 @@ export const generateAdvisorsMenu = ({
export const useGenerateAdvisorsMenu = (): ProductMenuGroup[] => {
const { ref } = useParams()
const isAdvisorRulesEnabled = useIsAdvisorRulesEnabled()
- const isHealthAdvisorEnabled = useFlag('healthAdvisor') === true
+ const isHealthAdvisorEnabled = useFlag('healthAdvisor')
return generateAdvisorsMenu({
ref,
diff --git a/apps/studio/components/ui/AdvisorPanel/AdvisorFilters.tsx b/apps/studio/components/ui/AdvisorPanel/AdvisorFilters.tsx
index c52b3e36d21..e5b2ee284d3 100644
--- a/apps/studio/components/ui/AdvisorPanel/AdvisorFilters.tsx
+++ b/apps/studio/components/ui/AdvisorPanel/AdvisorFilters.tsx
@@ -59,7 +59,7 @@ export const AdvisorFilters = ({
onClose,
isPlatform = false,
}: AdvisorFiltersProps) => {
- const isHealthAdvisorEnabled = useFlag('healthAdvisor') === true
+ const isHealthAdvisorEnabled = useFlag('healthAdvisor')
const categoryOptions = (isPlatform ? platformCategories : selfHostedCategories)
.filter((category) => category !== 'health' || isHealthAdvisorEnabled)
.map((category) => ({ label: advisorCategoryLabels[category], value: category }))
diff --git a/apps/studio/components/ui/AdvisorPanel/AdvisorPanel.tsx b/apps/studio/components/ui/AdvisorPanel/AdvisorPanel.tsx
index 5cbf365beb8..b5a7eeab1f6 100644
--- a/apps/studio/components/ui/AdvisorPanel/AdvisorPanel.tsx
+++ b/apps/studio/components/ui/AdvisorPanel/AdvisorPanel.tsx
@@ -27,7 +27,7 @@ import { useSidebarManagerSnapshot } from '@/state/sidebar-manager-state'
export const AdvisorPanel = () => {
const track = useTrack()
- const isHealthAdvisorEnabled = useFlag('healthAdvisor') === true && IS_PLATFORM
+ const isHealthAdvisorEnabled = useFlag('healthAdvisor')
const {
categoryFilters: savedCategoryFilters,
severityFilters,
diff --git a/apps/studio/components/ui/AdvisorPanel/AdvisorPanelBody.tsx b/apps/studio/components/ui/AdvisorPanel/AdvisorPanelBody.tsx
index 3b26e1c7c22..0e565780390 100644
--- a/apps/studio/components/ui/AdvisorPanel/AdvisorPanelBody.tsx
+++ b/apps/studio/components/ui/AdvisorPanel/AdvisorPanelBody.tsx
@@ -15,11 +15,10 @@ 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_PLATFORM
+ const isHealthAdvisorEnabled = useFlag('healthAdvisor')
return (
<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} />
diff --git a/apps/studio/data/lint/health-lints-query.ts b/apps/studio/data/lint/health-lints-query.ts
index 4cf74907cb9..1f67e9480a7 100644
--- a/apps/studio/data/lint/health-lints-query.ts
+++ b/apps/studio/data/lint/health-lints-query.ts
@@ -6,7 +6,7 @@ import { lintKeys } from './keys'
import type { Lint } from './lint-query'
import { handleError, post } from '@/data/fetchers'
import { useSelectedProjectQuery } from '@/hooks/misc/useSelectedProject'
-import { IS_PLATFORM, PROJECT_STATUS } from '@/lib/constants'
+import { PROJECT_STATUS } from '@/lib/constants'
import { EMPTY_ARR } from '@/lib/void'
import type { ResponseError, UseCustomQueryOptions } from '@/types'
@@ -76,18 +76,13 @@ export const useProjectHealthLintsQuery = <TData = ProjectHealthLintsData>(
}: UseCustomQueryOptions<ProjectHealthLintsData, ProjectHealthLintsError, TData> = {}
) => {
const { data: project } = useSelectedProjectQuery()
- const isHealthAdvisorEnabled = useFlag('healthAdvisor') === true
+ const isHealthAdvisorEnabled = useFlag('healthAdvisor')
const isActive = project?.status === PROJECT_STATUS.ACTIVE_HEALTHY
return useQuery<ProjectHealthLintsData, ProjectHealthLintsError, TData>({
queryKey: lintKeys.healthLints(projectRef),
queryFn: ({ signal }) => getProjectHealthLints({ projectRef }, signal),
- enabled:
- enabled &&
- isHealthAdvisorEnabled &&
- IS_PLATFORM &&
- typeof projectRef !== 'undefined' &&
- isActive,
+ enabled: enabled && isHealthAdvisorEnabled && 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.tsx
index 7cb4ecca77f..923080da4e5 100644
--- a/apps/studio/pages/project/[ref]/advisors/health.tsx
+++ b/apps/studio/pages/project/[ref]/advisors/health.tsx
@@ -15,13 +15,12 @@ import { FormHeader } from '@/components/ui/Forms/FormHeader'
import { useProjectHealthLintsQuery } from '@/data/lint/health-lints-query'
import { Lint } from '@/data/lint/lint-query'
import { useSelectedProjectQuery } from '@/hooks/misc/useSelectedProject'
-import { IS_PLATFORM } from '@/lib/constants'
import type { NextPageWithLayout } from '@/types'
const ProjectHealthLints: NextPageWithLayout = () => {
- const isHealthAdvisorEnabled = useFlag('healthAdvisor') === true
+ const isHealthAdvisorEnabled = useFlag('healthAdvisor')
- if (!IS_PLATFORM || !isHealthAdvisorEnabled) {
+ if (!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" />