Skip to content

Commit 8719bb6

Browse files
authored
fix(self-hosted): suppress requests to non-existent apis (supabase#46177)
1 parent 8349ae5 commit 8719bb6

3 files changed

Lines changed: 77 additions & 6 deletions

File tree

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest'
2+
3+
import { AdvisorButton } from '@/components/layouts/AppLayout/AdvisorButton'
4+
import { render } from '@/tests/helpers'
5+
6+
const {
7+
mockUseProjectLintsQuery,
8+
mockUseNotificationsV2Query,
9+
mockUseAdvisorSignals,
10+
mockToggleSidebar,
11+
} = vi.hoisted(() => ({
12+
mockUseProjectLintsQuery: vi.fn(),
13+
mockUseNotificationsV2Query: vi.fn(),
14+
mockUseAdvisorSignals: vi.fn(),
15+
mockToggleSidebar: vi.fn(),
16+
}))
17+
18+
vi.mock('@/data/lint/lint-query', () => ({
19+
useProjectLintsQuery: mockUseProjectLintsQuery,
20+
}))
21+
22+
vi.mock('@/data/notifications/notifications-v2-query', () => ({
23+
useNotificationsV2Query: mockUseNotificationsV2Query,
24+
}))
25+
26+
vi.mock('@/components/ui/AdvisorPanel/useAdvisorSignals', () => ({
27+
useAdvisorSignals: mockUseAdvisorSignals,
28+
}))
29+
30+
vi.mock('@/lib/constants', async (importOriginal) => ({
31+
...(await importOriginal<typeof import('@/lib/constants')>()),
32+
IS_PLATFORM: false,
33+
}))
34+
35+
vi.mock('@/state/sidebar-manager-state', () => ({
36+
useSidebarManagerSnapshot: () => ({
37+
toggleSidebar: mockToggleSidebar,
38+
activeSidebar: undefined,
39+
}),
40+
}))
41+
42+
describe('AdvisorButton on self-hosted', () => {
43+
beforeEach(() => {
44+
mockUseProjectLintsQuery.mockReturnValue({ data: [], isPending: false, isError: false })
45+
mockUseNotificationsV2Query.mockReturnValue({
46+
data: { pages: [[]] },
47+
isPending: false,
48+
isError: false,
49+
})
50+
mockUseAdvisorSignals.mockReturnValue({
51+
data: [],
52+
isPending: false,
53+
isError: false,
54+
dismissSignal: vi.fn(),
55+
})
56+
})
57+
58+
afterEach(() => {
59+
vi.clearAllMocks()
60+
})
61+
62+
it('disables the notifications query so no request is made to the platform endpoint', () => {
63+
render(<AdvisorButton projectRef="project-ref" />)
64+
65+
expect(mockUseNotificationsV2Query).toHaveBeenCalledWith(
66+
{ filters: {}, limit: 20 },
67+
{ enabled: false }
68+
)
69+
})
70+
})

apps/studio/components/layouts/AppLayout/AdvisorButton.tsx

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { useAdvisorSignals } from '@/components/ui/AdvisorPanel/useAdvisorSignal
77
import { ButtonTooltip } from '@/components/ui/ButtonTooltip'
88
import { useProjectLintsQuery } from '@/data/lint/lint-query'
99
import { useNotificationsV2Query } from '@/data/notifications/notifications-v2-query'
10+
import { IS_PLATFORM } from '@/lib/constants'
1011
import { useTrack } from '@/lib/telemetry/track'
1112
import { useSidebarManagerSnapshot } from '@/state/sidebar-manager-state'
1213

@@ -17,10 +18,10 @@ export const AdvisorButton = ({ projectRef }: { projectRef?: string }) => {
1718
const { data: lints } = useProjectLintsQuery({ projectRef })
1819
const { data: signalItems } = useAdvisorSignals({ projectRef })
1920

20-
const { data: notificationsData } = useNotificationsV2Query({
21-
filters: {},
22-
limit: 20,
23-
})
21+
const { data: notificationsData } = useNotificationsV2Query(
22+
{ filters: {}, limit: 20 },
23+
{ enabled: IS_PLATFORM }
24+
)
2425
const notifications = useMemo(() => {
2526
return notificationsData?.pages.flatMap((page) => page) ?? []
2627
}, [notificationsData?.pages])

apps/studio/components/layouts/AppLayout/FlyDeprecationBanner.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { LOCAL_STORAGE_KEYS } from 'common'
1+
import { IS_PLATFORM, LOCAL_STORAGE_KEYS } from 'common'
22
import { useRouter } from 'next/router'
33
import { useEffect, useRef, type ReactNode } from 'react'
44
import {
@@ -44,7 +44,7 @@ export const FlyDeprecationBanner = () => {
4444
const isExpired = Date.now() >= BANNER_EXPIRES_AT.getTime()
4545
const onSignIn = router.pathname.startsWith('/sign-in')
4646

47-
const shouldEvaluate = !isExpired && !onSignIn && isSuccess && !acknowledged
47+
const shouldEvaluate = IS_PLATFORM && !isExpired && !onSignIn && isSuccess && !acknowledged
4848

4949
const { isReady, primaries, branches } = useFlyDeprecationProjects({ enabled: shouldEvaluate })
5050

0 commit comments

Comments
 (0)