mirror of
https://github.com/supabase/supabase.git
synced 2026-10-17 23:29:08 +03:00
## Context This is largely just a mechanical change here: Opting to use lucide icons with the `Icon` suffix across all icon imports within `studio` - so that it’s clearer which components are icons + reduces the possibility of name collision with our own components - e.g <User /> vs <UserIcon /> Also added a eslint rule for this: <img width="1069" height="167" alt="image" src="https://github.com/user-attachments/assets/7f36f443-5ca2-4bf6-8d22-86e774513bfc" /> And updated `AGENTS.md` as such: ``` Icons come from `lucide-react`, always imported with the `Icon` suffix (`import { CheckIcon, Trash2Icon } from 'lucide-react'`) — never the bare names (`Check`) or `Check as CheckIcon` aliases (lint-enforced). ```
94 lines
3.6 KiB
TypeScript
94 lines
3.6 KiB
TypeScript
import { LightbulbIcon } from 'lucide-react'
|
|
import { useMemo } from 'react'
|
|
import { cn } from 'ui'
|
|
|
|
import { SIDEBAR_KEYS } from '@/components/layouts/ProjectLayout/LayoutSidebar/LayoutSidebarProvider'
|
|
import { useAdvisorSignals } from '@/components/ui/AdvisorPanel/useAdvisorSignals'
|
|
import { ButtonTooltip } from '@/components/ui/ButtonTooltip'
|
|
import { useProjectLintsQuery } from '@/data/lint/lint-query'
|
|
import { useNotificationsV2Query } from '@/data/notifications/notifications-v2-query'
|
|
import { IS_PLATFORM } from '@/lib/constants'
|
|
import { useTrack } from '@/lib/telemetry/track'
|
|
import { useSidebarManagerSnapshot } from '@/state/sidebar-manager-state'
|
|
|
|
export const AdvisorButton = ({ projectRef }: { projectRef?: string }) => {
|
|
const { toggleSidebar, activeSidebar } = useSidebarManagerSnapshot()
|
|
const track = useTrack()
|
|
|
|
const { data: lints } = useProjectLintsQuery({ projectRef })
|
|
const { data: signalItems } = useAdvisorSignals({ projectRef })
|
|
|
|
const { data: notificationsData } = useNotificationsV2Query(
|
|
{ filters: {}, limit: 20 },
|
|
{ enabled: IS_PLATFORM }
|
|
)
|
|
const notifications = useMemo(() => {
|
|
return notificationsData?.pages.flatMap((page) => page) ?? []
|
|
}, [notificationsData?.pages])
|
|
const hasUnreadNotifications = notifications.some((x) => x?.status === 'new')
|
|
const hasCriticalNotifications = notifications.some((x) => x?.priority === 'Critical')
|
|
const hasSignals = signalItems.length > 0
|
|
const hasCriticalSignals = signalItems.some((item) => item.severity === 'critical')
|
|
|
|
const hasCriticalIssues =
|
|
hasCriticalNotifications ||
|
|
hasCriticalSignals ||
|
|
(Array.isArray(lints) && lints.some((lint) => lint.level === 'ERROR'))
|
|
const hasWarningIssues = hasSignals && !hasCriticalIssues
|
|
|
|
const isOpen = activeSidebar?.id === SIDEBAR_KEYS.ADVISOR_PANEL
|
|
|
|
const handleClick = () => {
|
|
track('header_advisor_button_clicked')
|
|
toggleSidebar(SIDEBAR_KEYS.ADVISOR_PANEL)
|
|
}
|
|
|
|
return (
|
|
<div className="relative">
|
|
<ButtonTooltip
|
|
variant="outline"
|
|
size="tiny"
|
|
id="advisor-center-trigger"
|
|
className={cn(
|
|
'rounded-full w-[32px] h-[32px] flex items-center justify-center p-0 group',
|
|
// Critical fill/border only when idle — selected matches the other
|
|
// header circles (foreground fill, no destructive outline).
|
|
hasCriticalIssues &&
|
|
!isOpen &&
|
|
'bg-destructive-200 border-destructive-500 hover:border-destructive',
|
|
isOpen && 'bg-foreground text-background'
|
|
)}
|
|
onClick={handleClick}
|
|
tooltip={{
|
|
content: {
|
|
text: 'Advisor Center',
|
|
},
|
|
}}
|
|
>
|
|
<LightbulbIcon
|
|
size={16}
|
|
strokeWidth={1.5}
|
|
className={cn(
|
|
'text-foreground-light group-hover:text-foreground',
|
|
isOpen && 'text-background group-hover:text-background'
|
|
)}
|
|
/>
|
|
<span className="sr-only">Advisor Center</span>
|
|
</ButtonTooltip>
|
|
{hasCriticalIssues ? (
|
|
<span
|
|
className={cn(
|
|
'absolute top-1.5 right-1.5 w-1.5 h-1.5 rounded-full',
|
|
// Slightly lighter on the inverted selected fill in light mode only.
|
|
isOpen ? 'bg-destructive-500 dark:bg-destructive' : 'bg-destructive'
|
|
)}
|
|
/>
|
|
) : hasWarningIssues ? (
|
|
<span className="absolute top-1.5 right-1.5 w-1.5 h-1.5 rounded-full bg-warning" />
|
|
) : hasUnreadNotifications ? (
|
|
<span className="absolute top-1.5 right-1.5 w-1.5 h-1.5 rounded-full bg-primary-bright" />
|
|
) : null}
|
|
</div>
|
|
)
|
|
}
|