Skip to content

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

chore: moved query page. added logs to /database section

Jonathan Summers-Muir865598547508
diff --git a/studio/components/interfaces/Settings/Logs/LogTable.tsx b/studio/components/interfaces/Settings/Logs/LogTable.tsx
index 115ef30b594..454ec5fbbca 100644
--- a/studio/components/interfaces/Settings/Logs/LogTable.tsx
+++ b/studio/components/interfaces/Settings/Logs/LogTable.tsx
@@ -39,8 +39,10 @@ const LogTable = ({ data = [], queryType }: Props) => {
})
let columns
if (!queryType) {
+ console.log('no query type')
columns = DEFAULT_COLUMNS
} else {
+ console.log('has query type', queryType)
switch (queryType) {
case 'api':
columns = DatabaseApiColumnRender
diff --git a/studio/components/interfaces/Settings/Logs/LogsNavigation.tsx b/studio/components/interfaces/Settings/Logs/LogsNavigation.tsx
index f255c631e2d..90fa8efb03f 100644
--- a/studio/components/interfaces/Settings/Logs/LogsNavigation.tsx
+++ b/studio/components/interfaces/Settings/Logs/LogsNavigation.tsx
@@ -6,7 +6,7 @@ const LogsNavigation = () => {
const activeRoute = router.pathname.split('/')[4]
const { ref } = router.query
- const indexRoute = 'sources'
+ const indexRoute = 'query'
return (
<Tabs
@@ -18,8 +18,8 @@ const LogsNavigation = () => {
router.push(`/project/${ref}/logs-explorer/${e === indexRoute ? '' : e}`)
}
>
- <Tabs.Panel id="sources" label="Sources" />
<Tabs.Panel id="query" label="Query" />
+ <Tabs.Panel id="sources" label="Sources" />
{/* <Tabs.Panel id="recent" label={'Recent'} /> */}
<Tabs.Panel id="saved" label="Saved" />
<Tabs.Panel id="templates" label="Templates" />
diff --git a/studio/components/interfaces/Settings/Logs/LogsPreviewer.tsx b/studio/components/interfaces/Settings/Logs/LogsPreviewer.tsx
index 18c83096b48..caa673097f5 100644
--- a/studio/components/interfaces/Settings/Logs/LogsPreviewer.tsx
+++ b/studio/components/interfaces/Settings/Logs/LogsPreviewer.tsx
@@ -129,6 +129,8 @@ export const LogsPreviewer: React.FC<Props> = ({ projectRef, queryType, override
})
}
+ console.log('queryType in LogsPreviewr', queryType)
+
return (
<div className="h-full flex flex-col flex-grow">
<PreviewFilterPanel
diff --git a/studio/components/layouts/DatabaseLayout/DatabaseMenu.utils.ts b/studio/components/layouts/DatabaseLayout/DatabaseMenu.utils.ts
index 2958897123d..9aea92c3d20 100644
--- a/studio/components/layouts/DatabaseLayout/DatabaseMenu.utils.ts
+++ b/studio/components/layouts/DatabaseLayout/DatabaseMenu.utils.ts
@@ -26,6 +26,18 @@ export const generateDatabaseMenu = (project?: Project): ProductMenuGroup[] => {
url: `/project/${ref}/database/replication`,
items: [],
},
+ {
+ name: 'API logs',
+ key: 'api-logs',
+ url: `/project/${ref}/database/api-logs`,
+ items: [],
+ },
+ {
+ name: 'Postgres logs',
+ key: 'postgres-logs',
+ url: `/project/${ref}/database/postgres-logs`,
+ items: [],
+ },
],
},
...(IS_PLATFORM
diff --git a/studio/pages/project/[ref]/database/api-logs.tsx b/studio/pages/project/[ref]/database/api-logs.tsx
new file mode 100644
index 00000000000..949beeb037e
--- /dev/null
+++ b/studio/pages/project/[ref]/database/api-logs.tsx
@@ -0,0 +1,26 @@
+import React from 'react'
+import { NextPage } from 'next'
+import { useRouter } from 'next/router'
+import { observer } from 'mobx-react-lite'
+import { withAuth } from 'hooks'
+import { DatabaseLayout } from 'components/layouts/'
+import { LogsTableName } from 'components/interfaces/Settings/Logs'
+import LogsPreviewer from 'components/interfaces/Settings/Logs/LogsPreviewer'
+
+export const LogPage: NextPage = () => {
+ const router = useRouter()
+ const { ref } = router.query
+
+ return (
+ <DatabaseLayout>
+ <LogsPreviewer
+ projectRef={ref as string}
+ condensedLayout={true}
+ tableName={'edge_logs'}
+ queryType={'api'}
+ />
+ </DatabaseLayout>
+ )
+}
+
+export default withAuth(observer(LogPage))
diff --git a/studio/pages/project/[ref]/database/postgres-logs.tsx b/studio/pages/project/[ref]/database/postgres-logs.tsx
new file mode 100644
index 00000000000..d97743f8c81
--- /dev/null
+++ b/studio/pages/project/[ref]/database/postgres-logs.tsx
@@ -0,0 +1,26 @@
+import React from 'react'
+import { NextPage } from 'next'
+import { useRouter } from 'next/router'
+import { observer } from 'mobx-react-lite'
+import { withAuth } from 'hooks'
+import { DatabaseLayout } from 'components/layouts/'
+import { LogsTableName } from 'components/interfaces/Settings/Logs'
+import LogsPreviewer from 'components/interfaces/Settings/Logs/LogsPreviewer'
+
+export const LogPage: NextPage = () => {
+ const router = useRouter()
+ const { ref } = router.query
+
+ return (
+ <DatabaseLayout>
+ <LogsPreviewer
+ projectRef={ref as string}
+ condensedLayout={true}
+ tableName={'postgres_logs'}
+ queryType={'database'}
+ />
+ </DatabaseLayout>
+ )
+}
+
+export default withAuth(observer(LogPage))
diff --git a/studio/pages/project/[ref]/logs-explorer/index.tsx b/studio/pages/project/[ref]/logs-explorer/index.tsx
index 914e3eab211..309cd947dc1 100644
--- a/studio/pages/project/[ref]/logs-explorer/index.tsx
+++ b/studio/pages/project/[ref]/logs-explorer/index.tsx
@@ -1,48 +1,120 @@
-import React from 'react'
+import React, { useEffect, useState } from 'react'
import { NextPage } from 'next'
import { useRouter } from 'next/router'
import { observer } from 'mobx-react-lite'
-import { IconCode, Badge, IconDatabase, Icon, IconCloud } from '@supabase/ui'
+import { Typography, IconAlertCircle, Card, Input } from '@supabase/ui'
import { withAuth } from 'hooks'
+import CodeEditor from 'components/ui/CodeEditor'
import {
+ LogsQueryPanel,
LogsTableName,
- LOGS_SOURCE_DESCRIPTION,
+ LogTable,
+ LogTemplate,
+ TEMPLATES,
} from 'components/interfaces/Settings/Logs'
-import LogsExplorerLayout from 'components/layouts/LogsExplorerLayout/LogsExplorerLayout'
-import CardButton from 'components/ui/CardButton'
+import { uuidv4 } from 'lib/helpers'
+import useLogsQuery from 'hooks/analytics/useLogsQuery'
+import { LogsExplorerLayout } from 'components/layouts'
+import ShimmerLine from 'components/ui/ShimmerLine'
+import LoadingOpacity from 'components/ui/LoadingOpacity'
export const LogsExplorerPage: NextPage = () => {
const router = useRouter()
- const { ref } = router.query
- const sources = Object.values(LogsTableName).sort((a, b) => a - b)
+ const { ref, q } = router.query
+ const [editorId, setEditorId] = useState<string>(uuidv4())
+ const [editorValue, setEditorValue] = useState<string>('')
+
+ const [{ logData, error, isLoading }, { changeQuery, runQuery }] = useLogsQuery(ref as string)
+ useEffect(() => {
+ // on mount, set initial values
+ if (q !== undefined && q !== '') {
+ changeQuery(q as string)
+ runQuery()
+ onSelectTemplate({
+ mode: 'custom',
+ searchString: q as string,
+ })
+ }
+ }, [q])
+
+ const onSelectTemplate = (template: LogTemplate) => {
+ setEditorValue(template.searchString)
+ changeQuery(template.searchString)
+ setEditorId(uuidv4())
+ runQuery()
+ }
+
+ const handleRun = () => {
+ changeQuery(editorValue)
+ runQuery()
+ router.push({
+ pathname: router.pathname,
+ query: { ...router.query, q: editorValue },
+ })
+ }
+
+ const handleClear = () => {
+ setEditorValue('')
+ setEditorId(uuidv4())
+ changeQuery('')
+ }
+
+ const handleInsertSource = (source: LogsTableName) => {
+ setEditorValue((prev) => prev + source)
+ setEditorId(uuidv4())
+ }
+
return (
<LogsExplorerLayout>
- <div className="grid grid-cols-3 gap-6">
- {sources.map((source) => (
- <CardButton
- title={source}
- icon={
- <div
- className="h-6 w-6 text-scale-100 flex items-center justify-center rounded
- bg-scale-1200
- transition-colors
- duration-400
- group-hover:bg-brand-900
- group-hover:text-brand-1200
- "
- >
- <div className="scale-100 group-hover:scale-110">
- {source === LogsTableName.POSTGRES && <IconDatabase size={12} strokeWidth={2} />}
- {source === LogsTableName.EDGE && <IconCloud size={12} strokeWidth={2} />}
- {source === LogsTableName.FUNCTIONS && <IconCode size={12} strokeWidth={2} />}
- {source === LogsTableName.FN_EDGE && <IconCode size={12} strokeWidth={2} />}
- </div>
- </div>
- }
- linkHref={`/project/${ref}/logs-explorer/sources/${source}`}
- description={LOGS_SOURCE_DESCRIPTION[source]}
+ <div className="h-full flex flex-col flex-grow gap-4">
+ <div className="border rounded">
+ <LogsQueryPanel
+ onSelectSource={handleInsertSource}
+ onClear={handleClear}
+ onRun={handleRun}
+ hasEditorValue={Boolean(editorValue)}
+ templates={TEMPLATES.filter((template) => template.mode === 'custom')}
+ onSelectTemplate={onSelectTemplate}
/>
- ))}
+
+ <div className="min-h-[7rem] h-48">
+ <ShimmerLine active={isLoading} />
+ <CodeEditor
+ id={editorId}
+ language="pgsql"
+ defaultValue={editorValue}
+ onInputChange={(v) => setEditorValue(v || '')}
+ onInputRun={handleRun}
+ />
+ </div>
+ </div>
+
+ <div className="flex flex-col flex-grow relative pb-8">
+ <LoadingOpacity active={isLoading}>
+ <div className="flex flex-grow h-full">
+ <LogTable data={logData} />
+ </div>
+ </LoadingOpacity>
+
+ {error && (
+ <div className="flex w-full h-full justify-center items-center mx-auto">
+ <Card className="flex flex-col gap-y-2 w-2/5 bg-scale-400">
+ <div className="flex flex-row gap-x-2 py-2">
+ <IconAlertCircle size={16} />
+ <Typography.Text type="secondary">
+ Sorry! An error occured when fetching data.
+ </Typography.Text>
+ </div>
+ <Input.TextArea
+ label="Error Messages"
+ value={JSON.stringify(error, null, 2)}
+ borderless
+ className=" border-t-2 border-scale-800 pt-2 font-mono"
+ />
+ </Card>
+ </div>
+ )}
+ </div>
</div>
</LogsExplorerLayout>
)
diff --git a/studio/pages/project/[ref]/logs-explorer/query.tsx b/studio/pages/project/[ref]/logs-explorer/query.tsx
deleted file mode 100644
index 2b4c8a9880a..00000000000
--- a/studio/pages/project/[ref]/logs-explorer/query.tsx
+++ /dev/null
@@ -1,123 +0,0 @@
-import React, { useEffect, useState } from 'react'
-import { NextPage } from 'next'
-import { useRouter } from 'next/router'
-import { observer } from 'mobx-react-lite'
-import { Typography, IconAlertCircle, Card, Input } from '@supabase/ui'
-import { withAuth } from 'hooks'
-import CodeEditor from 'components/ui/CodeEditor'
-import {
- LogsQueryPanel,
- LogsTableName,
- LogTable,
- LogTemplate,
- TEMPLATES,
-} from 'components/interfaces/Settings/Logs'
-import { uuidv4 } from 'lib/helpers'
-import useLogsQuery from 'hooks/analytics/useLogsQuery'
-import { LogsExplorerLayout } from 'components/layouts'
-import ShimmerLine from 'components/ui/ShimmerLine'
-import LoadingOpacity from 'components/ui/LoadingOpacity'
-
-export const LogsExplorerPage: NextPage = () => {
- const router = useRouter()
- const { ref, q } = router.query
- const [editorId, setEditorId] = useState<string>(uuidv4())
- const [editorValue, setEditorValue] = useState<string>('')
-
- const [{ logData, error, isLoading }, { changeQuery, runQuery }] = useLogsQuery(ref as string)
- useEffect(() => {
- // on mount, set initial values
- if (q !== undefined && q !== '') {
- changeQuery(q as string)
- runQuery()
- onSelectTemplate({
- mode: 'custom',
- searchString: q as string,
- })
- }
- }, [q])
-
- const onSelectTemplate = (template: LogTemplate) => {
- setEditorValue(template.searchString)
- changeQuery(template.searchString)
- setEditorId(uuidv4())
- runQuery()
- }
-
- const handleRun = () => {
- changeQuery(editorValue)
- runQuery()
- router.push({
- pathname: router.pathname,
- query: { ...router.query, q: editorValue },
- })
- }
-
- const handleClear = () => {
- setEditorValue('')
- setEditorId(uuidv4())
- changeQuery('')
- }
-
- const handleInsertSource = (source: LogsTableName) => {
- setEditorValue((prev) => prev + source)
- setEditorId(uuidv4())
- }
-
- return (
- <LogsExplorerLayout>
- <div className="h-full flex flex-col flex-grow gap-4">
- <div className="border rounded">
- <LogsQueryPanel
- onSelectSource={handleInsertSource}
- onClear={handleClear}
- onRun={handleRun}
- hasEditorValue={Boolean(editorValue)}
- templates={TEMPLATES.filter((template) => template.mode === 'custom')}
- onSelectTemplate={onSelectTemplate}
- />
-
- <div className="min-h-[7rem] h-48">
- <ShimmerLine active={isLoading} />
- <CodeEditor
- id={editorId}
- language="pgsql"
- defaultValue={editorValue}
- onInputChange={(v) => setEditorValue(v || '')}
- onInputRun={handleRun}
- />
- </div>
- </div>
-
- <div className="flex flex-col flex-grow relative pb-8">
- <LoadingOpacity active={isLoading}>
- <div className="flex flex-grow h-full">
- <LogTable data={logData} />
- </div>
- </LoadingOpacity>
-
- {error && (
- <div className="flex w-full h-full justify-center items-center mx-auto">
- <Card className="flex flex-col gap-y-2 w-2/5 bg-scale-400">
- <div className="flex flex-row gap-x-2 py-2">
- <IconAlertCircle size={16} />
- <Typography.Text type="secondary">
- Sorry! An error occured when fetching data.
- </Typography.Text>
- </div>
- <Input.TextArea
- label="Error Messages"
- value={JSON.stringify(error, null, 2)}
- borderless
- className=" border-t-2 border-scale-800 pt-2 font-mono"
- />
- </Card>
- </div>
- )}
- </div>
- </div>
- </LogsExplorerLayout>
- )
-}
-
-export default withAuth(observer(LogsExplorerPage))
diff --git a/studio/pages/project/[ref]/logs-explorer/sources.tsx b/studio/pages/project/[ref]/logs-explorer/sources.tsx
new file mode 100644
index 00000000000..fa6fb66cd6b
--- /dev/null
+++ b/studio/pages/project/[ref]/logs-explorer/sources.tsx
@@ -0,0 +1,48 @@
+import React from 'react'
+import { NextPage } from 'next'
+import { useRouter } from 'next/router'
+import { observer } from 'mobx-react-lite'
+import { IconCode, Badge, IconDatabase, Icon, IconCloud } from '@supabase/ui'
+import { withAuth } from 'hooks'
+import { LogsTableName, LOGS_SOURCE_DESCRIPTION } from 'components/interfaces/Settings/Logs'
+import LogsExplorerLayout from 'components/layouts/LogsExplorerLayout/LogsExplorerLayout'
+import CardButton from 'components/ui/CardButton'
+
+export const LogsExplorerPage: NextPage = () => {
+ const router = useRouter()
+ const { ref } = router.query
+ const sources = Object.values(LogsTableName).sort((a, b) => a - b)
+ return (
+ <LogsExplorerLayout>
+ <div className="grid grid-cols-3 gap-6">
+ {sources.map((source) => (
+ <CardButton
+ title={source}
+ icon={
+ <div
+ className="h-6 w-6 text-scale-100 flex items-center justify-center rounded
+ bg-scale-1200
+ transition-colors
+ duration-400
+ group-hover:bg-brand-900
+ group-hover:text-brand-1200
+ "
+ >
+ <div className="scale-100 group-hover:scale-110">
+ {source === LogsTableName.POSTGRES && <IconDatabase size={12} strokeWidth={2} />}
+ {source === LogsTableName.EDGE && <IconCloud size={12} strokeWidth={2} />}
+ {source === LogsTableName.FUNCTIONS && <IconCode size={12} strokeWidth={2} />}
+ {source === LogsTableName.FN_EDGE && <IconCode size={12} strokeWidth={2} />}
+ </div>
+ </div>
+ }
+ linkHref={`/project/${ref}/logs-explorer/sources/${source}`}
+ description={LOGS_SOURCE_DESCRIPTION[source]}
+ />
+ ))}
+ </div>
+ </LogsExplorerLayout>
+ )
+}
+
+export default withAuth(observer(LogsExplorerPage))
diff --git a/studio/pages/project/[ref]/logs-explorer/sources/[source].tsx b/studio/pages/project/[ref]/logs-explorer/sources/[source].tsx
index eba29b85f55..57d74e73a1f 100644
--- a/studio/pages/project/[ref]/logs-explorer/sources/[source].tsx
+++ b/studio/pages/project/[ref]/logs-explorer/sources/[source].tsx
@@ -96,8 +96,10 @@ export const LogPage: NextPage = () => {
<LogsExplorerLayout subtitle={<span className="font-mono">{source}</span>}>
<LogsPreviewer
projectRef={ref as string}
- condensedLayout={true}
+ condensedLayout={false}
tableName={source as LogsTableName}
+ // @ts-ignore
+ queryType={queryType[source]}
/>
</LogsExplorerLayout>
)