Skip to content

The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.

Merge branch 'master' into feat/studio-logs-page-query-params

TzeYiinga29f7d030b92
diff --cc studio/pages/project/[ref]/settings/logs/[type].tsx
index 5fc32f7218f,9837bd0917e..31af2a7e715
--- a/studio/pages/project/[ref]/settings/logs/[type].tsx
+++ b/studio/pages/project/[ref]/settings/logs/[type].tsx
@@@ -28,18 -36,13 +36,19 @@@ import { useFlag } from 'hooks
/**
* Acts as a container component for the entire log display
*
+ * ## Query Params Syncing
+ * Query params are synced on query submission.
- *
+ *
+ * params used are:
+ * - `q` for the editor query.
+ * - `s` for search query.
+ * - `ts` for timestamp start value.
*/
export const LogPage: NextPage = () => {
+ const logsQueryParamsSyncing = useFlag('logsQueryParamsSyncing')
+ const logsCustomSql = useFlag('logsCustomSql')
const router = useRouter()
- const { ref, type } = router.query
-
+ const { ref, type, q, s, ts } = router.query
const [editorId, setEditorId] = useState<string>(uuidv4())
const [editorValue, setEditorValue] = useState('')
const [mode, setMode] = useState<'simple' | 'custom'>('simple')
@@@ -161,30 -150,16 +178,32 @@@
}
}
const handleEditorSubmit = () => {
- setParams((prev) => ({ ...prev, where: editorValue }))
+ setParams((prev) => ({
+ ...prev,
+ where: isSelectQuery ? '' : editorValue,
+ sql: isSelectQuery ? editorValue : '',
+ }))
+ if (!logsQueryParamsSyncing) return
+ router.push({
+ pathname: router.pathname,
+ query: {
+ ...router.query,
+ q: editorValue,
+ },
+ })
}
const handleSearch = (v: string) => {
setParams((prev) => ({ ...prev, search_query: v || '' }))
+ if (!logsQueryParamsSyncing) return
+ router.push({
+ pathname: router.pathname,
+ query: {
+ ...router.query,
+ s: v || '',
+ },
+ })
}
-
-
return (
<SettingsLayout title={title}>
<div className="h-full flex flex-col flex-grow">
diff --cc studio/tests/pages/projects/logs.test.js
index 71343433cbb,2352726b3dd..a5ef1f9f42e
--- a/studio/tests/pages/projects/logs.test.js
+++ b/studio/tests/pages/projects/logs.test.js
@@@ -230,46 -211,59 +236,98 @@@ test('where clause will trigger a log r
await waitFor(() => screen.getByText(/happened/))
})
+test('s= query param will populate the search bar', async () => {
+ useRouter.mockReturnValueOnce({
+ query: { ref: '123', type: 'api', s: 'someSearch' },
- push: jest.fn()
++ push: jest.fn(),
+ })
+ render(<LogPage />)
+ // should populate search input with the search param
+ screen.getByDisplayValue('someSearch')
+ await waitFor(() => {
+ expect(get).toHaveBeenCalledWith(expect.stringContaining('search_query=someSearch'))
+ })
+})
+
+test('q= query param will populate the query input', async () => {
+ useRouter.mockReturnValueOnce({
+ query: { ref: '123', type: 'api', q: 'some_query', s: 'someSearch' },
- push: jest.fn()
-
++ push: jest.fn(),
+ })
+ render(<LogPage />)
+ // should populate editor with the query param
+ await waitFor(() => {
+ expect(get).toHaveBeenCalledWith(expect.stringContaining('where=some_query'))
+ })
+
+ // query takes precedence of search queryparam
+ expect(() => !screen.queryByDisplayValue(/someSearch/))
+})
+
+test('ts= query param will set the timestamp_start param', async () => {
+ useRouter.mockReturnValueOnce({
+ query: { ref: '123', type: 'api', ts: 123456 },
- push: jest.fn()
++ push: jest.fn(),
+ })
+ render(<LogPage />)
+
+ await waitFor(() => {
+ expect(get).toHaveBeenCalledWith(expect.stringContaining('timestamp_start=123456'))
+ })
+})
+ test('custom sql querying', async () => {
+ get.mockImplementation((url) => {
+ if (url.includes('sql=') && url.includes('select')) {
+ return {
+ data: [
+ {
+ my_count: 12345,
+ },
+ ],
+ }
+ }
+ return { data: [] }
+ })
+ const { container } = render(<LogPage />)
+ let editor = container.querySelector('.monaco-editor')
+ expect(editor).toBeFalsy()
+ // TODO: abstract this out into a toggle selection helper
+ const toggle = getToggleByText(/via query/)
+ expect(toggle).toBeTruthy()
+ userEvent.click(toggle)
+
+ // type into the query editor
+ await waitFor(() => {
+ editor = container.querySelector('.monaco-editor')
+ expect(editor).toBeTruthy()
+ })
+ editor = container.querySelector('.monaco-editor')
+ userEvent.type(editor, 'select count(*) as my_count from edge_logs')
+ // should show sandbox warning alert
+ await waitFor(() => screen.getByText(/restricted to a 7 day querying window/))
+
+ // should trigger query
+ userEvent.click(screen.getByText('Run'))
+ await waitFor(
+ () => {
+ expect(get).toHaveBeenCalledWith(expect.stringContaining('sql='))
+ expect(get).toHaveBeenCalledWith(expect.stringContaining('select'))
+ expect(get).toHaveBeenCalledWith(expect.stringContaining('edge_logs'))
+ expect(get).not.toHaveBeenCalledWith(expect.stringContaining('where'))
+ },
+ { timeout: 1000 }
+ )
+
+ await waitFor(() => screen.getByText(/my_count/)) //column header
+ await waitFor(() => screen.getByText(/12345/)) // row value
+
+ // clicking on the row value should not show log selection panel
+ userEvent.click(screen.getByText(/12345/))
+ await waitFor(() => expect(() => screen.getByText(/Metadata/)).toThrow())
+
+ // should not see chronological features
+ await waitFor(() => screen.queryByText(/Load older/)) //column header
+ })
test('load older btn will fetch older logs', async () => {
get.mockImplementation((url) => {