mirror of
https://github.com/supabase/supabase.git
synced 2026-12-03 23:18:57 +00:00
The `edgeFunctionsOverview` flag is fully rolled out, so the edge function Overview page now always renders the new Overview. This removes the legacy Overview and everything only it used. - **Overview page**: renders `EdgeFunctionOverview` directly, like the other function tabs. The flag check and the loader shown while flags load are gone. - **`EdgeFunctionRecentInvocations`** and its utils: only the legacy Overview showed this list. - **`components/ui/Charts/AreaChart`**: the legacy Overview was its last importer. The other `AreaChart` uses are recharts' own. **Self-hosted:** flags never load off-platform, so self-hosted Studio always got the legacy Overview. Its Overview tab is already hidden, and the new Overview sends a direct visit to the Details tab, so nothing reachable from the UI changes. After this ships, the `edgeFunctionsOverview` flag can be deleted in ConfigCat. ### How to test 1. Open an edge function's Overview on platform. It shows the new Overview, with no loader flash while flags load. 2. Self-hosted: open `/project/default/functions/<slug>` directly. It redirects to the Details tab. ### Validation - Studio typecheck, lint, Prettier and knip pass on this layer. Functions and Charts unit tests pass. ### Stack Merge in order: 1. #50953 — reusable logs table building blocks 2. #50954 — function-scoped unified logs queries 3. #50955 — slimmer function detail layout, header on Overview 4. #50957 — Invocations merged into a function-scoped Logs tab 5. #50958 — Overview errors in the shared logs table 6. #52281 — remove the legacy Overview --------- Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com> Co-authored-by: Jordi Enric <jordi.err@gmail.com>
316 lines
11 KiB
TypeScript
316 lines
11 KiB
TypeScript
import { QueryClient, useIsFetching, useQueryClient } from '@tanstack/react-query'
|
|
import { fireEvent, screen, waitFor } from '@testing-library/react'
|
|
import { platformComponents as components } from 'api-types'
|
|
import { mockAnimationsApi } from 'jsdom-testing-mocks'
|
|
import { http, HttpResponse } from 'msw'
|
|
import { useQueryState } from 'nuqs'
|
|
import { useLayoutEffect, useState } from 'react'
|
|
import { beforeEach, describe, expect, it } from 'vitest'
|
|
import { z } from 'zod'
|
|
|
|
import { UnifiedLogs } from './UnifiedLogs'
|
|
import {
|
|
EDGE_FUNCTION_LOGS_VIEW,
|
|
getEdgeFunctionLogsScope,
|
|
} from '@/components/interfaces/Functions/EdgeFunctionOverview/EdgeFunctionOverview.utils'
|
|
import { customRender } from '@/tests/lib/custom-render'
|
|
import { addAPIMock, mswServer, type APIErrorBody } from '@/tests/lib/msw'
|
|
|
|
type AnalyticsResponse = components['schemas']['AnalyticsResponse_Output']
|
|
type ProjectResponse = components['schemas']['ProjectDetailResponse_Output']
|
|
|
|
mockAnimationsApi()
|
|
|
|
const log = (id: string, message: string) => ({
|
|
id,
|
|
timestamp: 1793142000000000,
|
|
event_message: message,
|
|
log_type: 'edge function runtime',
|
|
level: 'success',
|
|
status: null,
|
|
pathname: null,
|
|
method: null,
|
|
log_count: null,
|
|
logs: null,
|
|
})
|
|
|
|
const BookmarkControls = () => {
|
|
const [id, setId] = useQueryState('id')
|
|
return (
|
|
<>
|
|
<output aria-label="Current bookmark">{id ?? 'none'}</output>
|
|
<button tabIndex={0} onClick={() => setId('second-log')}>
|
|
Open second bookmark
|
|
</button>
|
|
<button tabIndex={0} onClick={() => setId(null)}>
|
|
Close bookmark
|
|
</button>
|
|
</>
|
|
)
|
|
}
|
|
|
|
const CloseBookmarkAfterRefresh = () => {
|
|
const [, setId] = useQueryState('id')
|
|
const queryClient = useQueryClient()
|
|
const fetchingQueries = useIsFetching()
|
|
const [shouldClose, setShouldClose] = useState(false)
|
|
useLayoutEffect(() => {
|
|
if (shouldClose && fetchingQueries === 0) setId(null)
|
|
}, [shouldClose, fetchingQueries, setId])
|
|
return (
|
|
<button
|
|
tabIndex={0}
|
|
onClick={() => {
|
|
setShouldClose(true)
|
|
queryClient.invalidateQueries({
|
|
predicate: (query) => query.queryKey.includes('single-log'),
|
|
})
|
|
}}
|
|
>
|
|
Close bookmark after refresh
|
|
</button>
|
|
)
|
|
}
|
|
|
|
describe('function log bookmarks', () => {
|
|
beforeEach(() => {
|
|
mswServer.use(
|
|
http.get('/api/enabled-features-overrides', () =>
|
|
HttpResponse.json<{ disabled_features: string[] }>({ disabled_features: [] })
|
|
)
|
|
)
|
|
addAPIMock({
|
|
method: 'get',
|
|
path: '/platform/projects/:ref',
|
|
response: () =>
|
|
HttpResponse.json<ProjectResponse>({
|
|
id: 1,
|
|
ref: 'default',
|
|
organization_id: 1,
|
|
name: 'Test Project',
|
|
status: 'INACTIVE',
|
|
cloud_provider: 'AWS',
|
|
region: 'us-east-1',
|
|
db_host: 'db.default.supabase.co',
|
|
restUrl: 'https://default.supabase.co/rest/v1/',
|
|
inserted_at: '2024-01-01T00:00:00Z',
|
|
updated_at: '2024-01-01T00:00:00Z',
|
|
subscription_id: 'sub_123',
|
|
is_branch_enabled: false,
|
|
is_physical_backups_enabled: false,
|
|
high_availability: false,
|
|
integration_source: null,
|
|
connectionString: null,
|
|
}),
|
|
})
|
|
})
|
|
|
|
it('opens an older bookmark using the same function scope, filters, and dates', async () => {
|
|
const requests: Array<{ sql: string; iso_timestamp_start: string; iso_timestamp_end: string }> =
|
|
[]
|
|
const queryClient = new QueryClient({ defaultOptions: { queries: { retry: false } } })
|
|
addAPIMock({
|
|
method: 'post',
|
|
path: '/platform/projects/:ref/analytics/endpoints/logs.all.otel',
|
|
response: async ({ request }) => {
|
|
const body = z
|
|
.object({
|
|
sql: z.string(),
|
|
iso_timestamp_start: z.string(),
|
|
iso_timestamp_end: z.string(),
|
|
})
|
|
.parse(await request.json())
|
|
requests.push(body)
|
|
let result: AnalyticsResponse['result'] = []
|
|
if (body.sql.includes('row list')) {
|
|
result = [log('recent-log', 'Recent output')]
|
|
if (body.sql.includes("toString(id) = 'second-log'"))
|
|
result = [log('second-log', 'Second bookmarked output')]
|
|
if (body.sql.includes("toString(id) = 'older-log'"))
|
|
result = [log('older-log', 'Bookmarked function output')]
|
|
}
|
|
return HttpResponse.json<AnalyticsResponse>({ result })
|
|
},
|
|
})
|
|
customRender(
|
|
<>
|
|
<BookmarkControls />
|
|
<UnifiedLogs
|
|
scope={getEdgeFunctionLogsScope('fn-123')}
|
|
hasFilterSideBar={false}
|
|
{...EDGE_FUNCTION_LOGS_VIEW}
|
|
/>
|
|
</>,
|
|
{
|
|
queryClient,
|
|
nuqs: {
|
|
hasMemory: true,
|
|
searchParams: '?id=older-log&filter=level:eq:success&date=1793059200000-1793145600000',
|
|
},
|
|
}
|
|
)
|
|
|
|
expect(
|
|
await screen.findByRole('status', { name: 'Bookmarked function output', hidden: true })
|
|
).toBeInTheDocument()
|
|
expect(screen.getByRole('tab', { name: 'Raw JSON', hidden: true })).toBeInTheDocument()
|
|
await waitFor(() => expect(queryClient.isFetching()).toBe(0))
|
|
const lookup = requests.find(({ sql }) => sql.includes("toString(id) = 'older-log'"))
|
|
expect(lookup).toBeDefined()
|
|
expect(lookup?.sql).toContain("log_attributes['function_id'] IN ('fn-123')")
|
|
expect(lookup?.sql).toContain("source = 'function_logs'")
|
|
expect(lookup?.sql).toContain("'success'")
|
|
expect(lookup?.sql).toContain('LIMIT 1')
|
|
expect(lookup?.iso_timestamp_start).toBe('2026-10-27T00:00:00.000Z')
|
|
expect(lookup?.iso_timestamp_end).toBe('2026-10-28T00:00:00.000Z')
|
|
fireEvent.click(screen.getByText('Open second bookmark', { selector: 'button' }))
|
|
expect(
|
|
await screen.findByRole('status', { name: 'Second bookmarked output', hidden: true })
|
|
).toBeInTheDocument()
|
|
expect(screen.queryByText('Bookmarked function output')).not.toBeInTheDocument()
|
|
fireEvent.click(screen.getByText('Close bookmark', { selector: 'button' }))
|
|
await waitFor(() =>
|
|
expect(
|
|
screen.queryByRole('status', { name: 'Second bookmarked output', hidden: true })
|
|
).not.toBeInTheDocument()
|
|
)
|
|
expect(screen.queryByText('Second bookmarked output')).not.toBeInTheDocument()
|
|
})
|
|
|
|
it('keeps a bookmark closed when its pending lookup updates the selected row', async () => {
|
|
let releaseRefresh = () => {}
|
|
const pendingRefresh = new Promise<void>((resolve) => {
|
|
releaseRefresh = resolve
|
|
})
|
|
let lookupCount = 0
|
|
const queryClient = new QueryClient({ defaultOptions: { queries: { retry: false } } })
|
|
addAPIMock({
|
|
method: 'post',
|
|
path: '/platform/projects/:ref/analytics/endpoints/logs.all.otel',
|
|
response: async ({ request }) => {
|
|
const { sql } = z.object({ sql: z.string() }).parse(await request.json())
|
|
if (sql.includes("toString(id) = 'older-log'")) {
|
|
lookupCount++
|
|
if (lookupCount > 1) await pendingRefresh
|
|
return HttpResponse.json<AnalyticsResponse>({
|
|
result: [log('older-log', `Bookmark version ${lookupCount}`)],
|
|
})
|
|
}
|
|
return HttpResponse.json<AnalyticsResponse>({
|
|
result: sql.includes('row list') ? [log('recent-log', 'Recent output')] : [],
|
|
})
|
|
},
|
|
})
|
|
customRender(
|
|
<>
|
|
<BookmarkControls />
|
|
<CloseBookmarkAfterRefresh />
|
|
<UnifiedLogs
|
|
scope={getEdgeFunctionLogsScope('fn-123')}
|
|
hasFilterSideBar={false}
|
|
{...EDGE_FUNCTION_LOGS_VIEW}
|
|
/>
|
|
</>,
|
|
{ queryClient, nuqs: { hasMemory: true, searchParams: '?id=older-log' } }
|
|
)
|
|
expect(
|
|
await screen.findByRole('status', { name: 'Bookmark version 1', hidden: true })
|
|
).toBeInTheDocument()
|
|
await waitFor(() => expect(queryClient.isFetching()).toBe(0))
|
|
try {
|
|
fireEvent.click(screen.getByText('Close bookmark after refresh', { selector: 'button' }))
|
|
await waitFor(() => expect(lookupCount).toBe(2))
|
|
} finally {
|
|
releaseRefresh()
|
|
}
|
|
await waitFor(() => expect(screen.getByLabelText('Current bookmark')).toHaveTextContent('none'))
|
|
expect(
|
|
screen.queryByRole('status', { name: /Bookmark version/, hidden: true })
|
|
).not.toBeInTheDocument()
|
|
})
|
|
|
|
it('updates the bookmark for selected rows without fetching logs already in the table', async () => {
|
|
const queries: string[] = []
|
|
addAPIMock({
|
|
method: 'post',
|
|
path: '/platform/projects/:ref/analytics/endpoints/logs.all.otel',
|
|
response: async ({ request }) => {
|
|
const { sql } = z.object({ sql: z.string() }).parse(await request.json())
|
|
queries.push(sql)
|
|
return HttpResponse.json<AnalyticsResponse>({
|
|
result: sql.includes('row list')
|
|
? [log('recent-0', 'Recent output 0'), log('recent-1', 'Recent output 1')]
|
|
: [],
|
|
})
|
|
},
|
|
})
|
|
customRender(
|
|
<>
|
|
<BookmarkControls />
|
|
<UnifiedLogs
|
|
scope={getEdgeFunctionLogsScope('fn-123')}
|
|
hasFilterSideBar={false}
|
|
{...EDGE_FUNCTION_LOGS_VIEW}
|
|
/>
|
|
</>,
|
|
{ nuqs: { hasMemory: true } }
|
|
)
|
|
|
|
fireEvent.click(await screen.findByText('Recent output 0'))
|
|
await waitFor(() =>
|
|
expect(screen.getByLabelText('Current bookmark')).toHaveTextContent('recent-0')
|
|
)
|
|
fireEvent.click(screen.getAllByText('Recent output 1')[0], { ctrlKey: true })
|
|
await waitFor(() =>
|
|
expect(screen.getByLabelText('Current bookmark')).toHaveTextContent('recent-1')
|
|
)
|
|
expect(
|
|
screen.getByRole('status', { name: '2 logs selected', hidden: true })
|
|
).toBeInTheDocument()
|
|
expect(queries.some((sql) => sql.includes("toString(id) = 'recent-"))).toBe(false)
|
|
})
|
|
|
|
it.each([
|
|
{ hasError: false, behavior: 'clears a bookmark when the scoped log no longer exists' },
|
|
{ hasError: true, behavior: 'keeps the bookmarked ID and displays a lookup error' },
|
|
])('$behavior', async ({ hasError }) => {
|
|
const queryClient = new QueryClient({ defaultOptions: { queries: { retry: false } } })
|
|
addAPIMock({
|
|
method: 'post',
|
|
path: '/platform/projects/:ref/analytics/endpoints/logs.all.otel',
|
|
response: async ({ request }) => {
|
|
const { sql } = z.object({ sql: z.string() }).parse(await request.json())
|
|
if (hasError && sql.includes("toString(id) = 'older-log'")) {
|
|
return HttpResponse.json<APIErrorBody>(
|
|
{ message: 'Bookmark lookup unavailable' },
|
|
{ status: 500 }
|
|
)
|
|
}
|
|
return HttpResponse.json<AnalyticsResponse>({
|
|
result: sql.includes('LIMIT 50') ? [log('recent-log', 'Recent output')] : [],
|
|
})
|
|
},
|
|
})
|
|
customRender(
|
|
<>
|
|
<BookmarkControls />
|
|
<UnifiedLogs
|
|
scope={getEdgeFunctionLogsScope('fn-123')}
|
|
hasFilterSideBar={false}
|
|
{...EDGE_FUNCTION_LOGS_VIEW}
|
|
/>
|
|
</>,
|
|
{ queryClient, nuqs: { hasMemory: true, searchParams: '?id=older-log' } }
|
|
)
|
|
if (hasError) {
|
|
expect(await screen.findByText(/Failed to retrieve logs/)).toBeInTheDocument()
|
|
expect(screen.getByLabelText('Current bookmark')).toHaveTextContent('older-log')
|
|
} else {
|
|
await waitFor(() =>
|
|
expect(screen.getByLabelText('Current bookmark')).toHaveTextContent('none')
|
|
)
|
|
}
|
|
await waitFor(() => expect(queryClient.isFetching()).toBe(0))
|
|
})
|
|
})
|