mirror of
https://github.com/supabase/supabase.git
synced 2026-12-04 07:29:16 +00:00
## Problem Unified Logs had saved views behind a dropdown in the toolbar. The dropdown couldn't show more than a name per row, had no room for grouping, and gave new projects nothing to start from — an empty list until you built and saved a filter combination yourself. ## Solution Moved saved views into the filter sidebar as a second level, following the Explorer notebooks/chats pattern: a Saved views button in the sidebar header swaps the filters out for a Views panel, with a breadcrumb back to Logs. Key choices: - **`FilterSideBar` stays generic.** It takes `section`, `headerAction` and `onReset` slots; all saved-views specifics live in `LogsViewsPanel`. - **Presets are virtual, not seeded.** Three built-in views (Errors, Failed requests, Database health) render from a constant with `preset:` ids. No per-project write, so they work for read-only members and can't be deleted into oblivion. They can be duplicated into a real saved view, but not renamed, edited or deleted. - **One dialog for naming.** `ViewNameDialog` backs create, rename and duplicate. - **Clicking a modified view opens the update prompt** instead of re-applying it, which previously discarded unsaved filter edits with no warning. Also fixed two pre-existing alignment issues in the sidebar: filter options sat 4px left of their section heading, and the User filter — a hand-copied clone of the filter row markup — had drifted from the shared one. ## Review instructions 1. Enable the Unified Logs feature preview and the `logsSavedViews` flag, then open **Logs**. 2. Click the layers button in the sidebar header. The filters swap for the Views panel, with **Preset views** above **Saved views**. 3. Click **Errors**. The filter applies and the row highlights; the layers icon turns green. 4. Change a filter. The row reads **Modified** and the update prompt appears. Go back to Logs and return — the prompt is still available. 5. Open the ⋮ menu on a preset: only **Duplicate** is offered. Duplicate it and confirm it lands under Saved views with rename/delete available. 6. Click **+** in the Views header to save the current filters, then rename and delete it. 7. Hit the reset button in the header and confirm the active view clears along with the filters.
74 lines
2.7 KiB
TypeScript
74 lines
2.7 KiB
TypeScript
import { queryOptions, useMutation, useQueryClient } from '@tanstack/react-query'
|
|
import { toast } from 'sonner'
|
|
|
|
import { deleteContents } from './content-delete-mutation'
|
|
import { contentKeys } from './keys'
|
|
import { isLogsViewContent, logsViewContentSchema } from './log-content-schema'
|
|
import { getAllLogContent } from './logs-view-content'
|
|
import type { LogsView, LogsViewDraft } from '@/components/interfaces/UnifiedLogs/UnifiedLogs.views'
|
|
import { handleError, put } from '@/data/fetchers'
|
|
import { IS_PLATFORM } from '@/lib/constants'
|
|
|
|
export const logsViewsQueryOptions = ({ projectRef }: { projectRef?: string }) =>
|
|
queryOptions({
|
|
queryKey: contentKeys.logsViews(projectRef),
|
|
queryFn: async ({ signal }) => {
|
|
const rows = await getAllLogContent({ projectRef }, signal)
|
|
return [...rows]
|
|
.sort((a, b) => a.inserted_at.localeCompare(b.inserted_at))
|
|
.flatMap((row): LogsView[] => {
|
|
if (!isLogsViewContent(row)) return []
|
|
const result = logsViewContentSchema.safeParse(row.content)
|
|
return result.success ? [{ ...result.data, id: row.id, name: row.name }] : []
|
|
})
|
|
},
|
|
enabled: IS_PLATFORM && !!projectRef,
|
|
})
|
|
|
|
type LogsViewWriteVariables = {
|
|
projectRef: string
|
|
id: string
|
|
input: LogsViewDraft
|
|
}
|
|
|
|
async function saveLogsView({ projectRef, id, input }: LogsViewWriteVariables) {
|
|
const { name, ...content } = input
|
|
const { error } = await put('/platform/projects/{ref}/content', {
|
|
params: { path: { ref: projectRef } },
|
|
body: {
|
|
id,
|
|
name,
|
|
type: 'log_sql',
|
|
visibility: 'project',
|
|
content: { ...content, type: 'logs_view', version: 1 },
|
|
},
|
|
headers: { Version: '2' },
|
|
})
|
|
if (error) handleError(error)
|
|
return id
|
|
}
|
|
|
|
export function useSaveLogsViewMutation() {
|
|
const queryClient = useQueryClient()
|
|
return useMutation({
|
|
mutationFn: saveLogsView,
|
|
onSuccess: async (_, { projectRef }) => {
|
|
await queryClient.invalidateQueries({ queryKey: contentKeys.allContentLists(projectRef) })
|
|
await queryClient.invalidateQueries({ queryKey: contentKeys.infiniteList(projectRef) })
|
|
},
|
|
onError: (error) => toast.error(`Failed to save view: ${error.message}`),
|
|
})
|
|
}
|
|
|
|
export function useDeleteLogsViewMutation() {
|
|
const queryClient = useQueryClient()
|
|
return useMutation({
|
|
mutationFn: (variables: Parameters<typeof deleteContents>[0]) => deleteContents(variables),
|
|
onSuccess: async (_, { projectRef }) => {
|
|
await queryClient.invalidateQueries({ queryKey: contentKeys.allContentLists(projectRef) })
|
|
await queryClient.invalidateQueries({ queryKey: contentKeys.infiniteList(projectRef) })
|
|
},
|
|
onError: (error) => toast.error(`Failed to delete view: ${error.message}`),
|
|
})
|
|
}
|