Files
supabase/apps/studio/components/layouts/AdvisorsLayout/AdvisorsMenu.utils.tsx
Jordi Enric 38e8f12b1b fix(studio): gate homepage health advisor (#50328)
## Problem

Health Advisor results appear on the project homepage whenever the main
`healthAdvisor` flag is enabled, so the homepage cannot be rolled out
separately. The existing gates also contain redundant boolean and
platform checks.

## Fix

Require both `healthAdvisor` and `healthAdvisorInHomepage` before
fetching or displaying health advisories on the homepage. Simplify all
Health Advisor gates to use the boolean ConfigCat flag directly,
including the cleanup requested in the review of #50326.

## How to test

- Enable only `healthAdvisor` and verify Health Advisor remains
available outside the homepage while health results do not appear or
load on the homepage.
- Enable both flags and verify health results appear on the homepage.
- Disable `healthAdvisor` and verify Health Advisor remains unavailable
everywhere.
- Existing targeted tests pass: 5 tests across Advisor menu and panel
integration suites.
- Prettier and whitespace checks pass.


<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
## Summary by CodeRabbit

* **New Features**
* Health Advisor is now available in non-platform environments when
enabled.
* Navigation, filtering, lint checks, and project pages consistently
follow the Health Advisor feature setting.
  * Self-hosted environments can use the Health Advisor category.
* **Bug Fixes**
* Homepage Health Advisor visibility now follows both the Health Advisor
and homepage-specific settings.
* Updated empty states and health lint results to match the configured
availability.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->
2026-09-14 13:34:24 +00:00

94 lines
2.4 KiB
TypeScript

import { useFlag, useParams } from 'common'
import { ArrowUpRight } from 'lucide-react'
import { useIsAdvisorRulesEnabled } from '@/components/interfaces/App/FeaturePreview/FeaturePreviewContext'
import type {
ProductMenuGroup,
ProductMenuGroupItem,
} from '@/components/ui/ProductMenu/ProductMenu.types'
import { IS_PLATFORM } from '@/lib/constants'
import { SHORTCUT_IDS } from '@/state/shortcuts/registry'
export const generateAdvisorsMenu = ({
ref,
isAdvisorRulesEnabled,
isHealthAdvisorEnabled,
isPlatform,
}: {
ref: string | undefined
isAdvisorRulesEnabled: boolean
isHealthAdvisorEnabled: boolean
isPlatform: boolean
}): ProductMenuGroup[] => {
const advisorItems: ProductMenuGroupItem[] = [
...(isHealthAdvisorEnabled
? [
{
name: 'Health Advisor',
key: 'health',
url: `/project/${ref}/advisors/health`,
items: [],
shortcutId: SHORTCUT_IDS.NAV_ADVISORS_HEALTH,
},
]
: []),
{
name: 'Security Advisor',
key: 'security',
url: `/project/${ref}/advisors/security`,
items: [],
shortcutId: SHORTCUT_IDS.NAV_ADVISORS_SECURITY,
},
{
name: 'Performance Advisor',
key: 'performance',
url: `/project/${ref}/advisors/performance`,
items: [],
shortcutId: SHORTCUT_IDS.NAV_ADVISORS_PERFORMANCE,
},
{
name: 'Query Performance',
key: 'query-performance',
url: `/project/${ref}/observability/query-performance`,
items: [],
rightIcon: <ArrowUpRight size={14} strokeWidth={1.5} className="h-4 w-4" />,
},
]
return [
{
title: 'Advisors',
items: advisorItems,
},
...(isPlatform && isAdvisorRulesEnabled
? [
{
title: 'Configuration',
items: [
{
name: 'Settings',
key: 'rules',
url: `/project/${ref}/advisors/rules/security`,
items: [],
shortcutId: SHORTCUT_IDS.NAV_ADVISORS_RULES,
},
],
},
]
: []),
]
}
export const useGenerateAdvisorsMenu = (): ProductMenuGroup[] => {
const { ref } = useParams()
const isAdvisorRulesEnabled = useIsAdvisorRulesEnabled()
const isHealthAdvisorEnabled = useFlag('healthAdvisor')
return generateAdvisorsMenu({
ref,
isAdvisorRulesEnabled,
isHealthAdvisorEnabled,
isPlatform: IS_PLATFORM,
})
}