Skip to content

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

fix: adds timestamp rendering standardization for log selection renderers

TzeYiing184943c79c8d
diff --git a/studio/components/interfaces/Settings/Logs/LogSelectionRenderers/AuthSelectionRenderer.tsx b/studio/components/interfaces/Settings/Logs/LogSelectionRenderers/AuthSelectionRenderer.tsx
index 531b99070cb..aaeaf7518c8 100644
--- a/studio/components/interfaces/Settings/Logs/LogSelectionRenderers/AuthSelectionRenderer.tsx
+++ b/studio/components/interfaces/Settings/Logs/LogSelectionRenderers/AuthSelectionRenderer.tsx
@@ -6,6 +6,7 @@ import {
jsonSyntaxHighlight,
ResponseCodeFormatter,
SelectionDetailedRow,
+ SelectionDetailedTimestampRow,
SeverityFormatter,
} from '../LogsFormatters'
@@ -30,14 +31,7 @@ const AuthSelectionRenderer = ({ log }: { log: PreviewLogData }) => {
</div>
</div>
- <SelectionDetailedRow
- label="ISO Timestamp"
- value={
- isUnixMicro(log.timestamp)
- ? unixMicroToIsoTimestamp(log.timestamp)
- : String(log.timestamp)
- }
- />
+ <SelectionDetailedTimestampRow value={log.timestamp} />
{parsed?.status && (
<SelectionDetailedRow
label="Status"
diff --git a/studio/components/interfaces/Settings/Logs/LogSelectionRenderers/DatabaseApiSelectionRender.tsx b/studio/components/interfaces/Settings/Logs/LogSelectionRenderers/DatabaseApiSelectionRender.tsx
index 1c786f068ae..04e463790e2 100644
--- a/studio/components/interfaces/Settings/Logs/LogSelectionRenderers/DatabaseApiSelectionRender.tsx
+++ b/studio/components/interfaces/Settings/Logs/LogSelectionRenderers/DatabaseApiSelectionRender.tsx
@@ -1,7 +1,12 @@
import React from 'react'
import { LOGS_TAILWIND_CLASSES } from '../Logs.constants'
import LogsDivider from '../Logs.Divider'
-import { jsonSyntaxHighlight, ResponseCodeFormatter, SelectionDetailedRow } from '../LogsFormatters'
+import {
+ jsonSyntaxHighlight,
+ ResponseCodeFormatter,
+ SelectionDetailedRow,
+ SelectionDetailedTimestampRow,
+} from '../LogsFormatters'
const DatabaseApiSelectionRender = ({ log }: any) => {
const request = log?.metadata[0]?.request?.[0]
@@ -16,9 +21,13 @@ const DatabaseApiSelectionRender = ({ log }: any) => {
return (
<>
<div className={`${LOGS_TAILWIND_CLASSES.log_selection_x_padding} space-y-2`}>
- <SelectionDetailedRow label="Status" value={status} valueRender={<ResponseCodeFormatter value={status} />} />
+ <SelectionDetailedRow
+ label="Status"
+ value={status}
+ valueRender={<ResponseCodeFormatter value={status} />}
+ />
<SelectionDetailedRow label="Method" value={method} />
- <SelectionDetailedRow label="Timestamp" value={log.timestamp} />
+ <SelectionDetailedTimestampRow value={log.timestamp} />
<SelectionDetailedRow label="IP Address" value={ipAddress} />
<SelectionDetailedRow label="Origin Country" value={countryOrigin} />
{clientInfo && <SelectionDetailedRow label="Client" value={clientInfo} />}
diff --git a/studio/components/interfaces/Settings/Logs/LogSelectionRenderers/DatabasePostgresSelectionRender.tsx b/studio/components/interfaces/Settings/Logs/LogSelectionRenderers/DatabasePostgresSelectionRender.tsx
index c583f131055..de9ed2e3edd 100644
--- a/studio/components/interfaces/Settings/Logs/LogSelectionRenderers/DatabasePostgresSelectionRender.tsx
+++ b/studio/components/interfaces/Settings/Logs/LogSelectionRenderers/DatabasePostgresSelectionRender.tsx
@@ -2,7 +2,12 @@ import { Alert } from 'ui'
import React from 'react'
import { LOGS_TAILWIND_CLASSES } from '../Logs.constants'
import LogsDivider from '../Logs.Divider'
-import { jsonSyntaxHighlight, SelectionDetailedRow, SeverityFormatter } from '../LogsFormatters'
+import {
+ jsonSyntaxHighlight,
+ SelectionDetailedRow,
+ SelectionDetailedTimestampRow,
+ SeverityFormatter,
+} from '../LogsFormatters'
const DatabasePostgresSelectionRender = ({ log }: any) => {
const postgresUsername = log?.metadata[0]?.parsed[0]?.user_name
@@ -26,6 +31,7 @@ const DatabasePostgresSelectionRender = ({ log }: any) => {
value={errorSeverity}
valueRender={<SeverityFormatter value={errorSeverity} />}
/>
+ <SelectionDetailedTimestampRow value={log.timestamp} />
<SelectionDetailedRow label="Postgres Username" value={postgresUsername} />
<SelectionDetailedRow label="Session ID" value={sessionId} />
</div>
diff --git a/studio/components/interfaces/Settings/Logs/LogSelectionRenderers/DefaultPreviewSelectionRenderer.tsx b/studio/components/interfaces/Settings/Logs/LogSelectionRenderers/DefaultPreviewSelectionRenderer.tsx
index 4f2bfd73b5a..4af80e864b6 100644
--- a/studio/components/interfaces/Settings/Logs/LogSelectionRenderers/DefaultPreviewSelectionRenderer.tsx
+++ b/studio/components/interfaces/Settings/Logs/LogSelectionRenderers/DefaultPreviewSelectionRenderer.tsx
@@ -1,6 +1,6 @@
-import { isUnixMicro, PreviewLogData, unixMicroToIsoTimestamp } from '..'
+import { PreviewLogData } from '..'
import { LOGS_TAILWIND_CLASSES } from '../Logs.constants'
-import { jsonSyntaxHighlight, SelectionDetailedRow } from '../LogsFormatters'
+import { jsonSyntaxHighlight, SelectionDetailedTimestampRow } from '../LogsFormatters'
const DefaultPreviewSelectionRenderer = ({ log }: { log: PreviewLogData }) => (
<div className={`${LOGS_TAILWIND_CLASSES.log_selection_x_padding} space-y-6`}>
@@ -10,11 +10,7 @@ const DefaultPreviewSelectionRenderer = ({ log }: { log: PreviewLogData }) => (
{log.event_message}
</div>
</div>
-
- <SelectionDetailedRow
- label="ISO Timestamp"
- value={isUnixMicro(log.timestamp) ? unixMicroToIsoTimestamp(log.timestamp) : String(log.timestamp)}
- />
+ <SelectionDetailedTimestampRow value={log.timestamp} />
<div className="flex flex-col gap-3">
<h3 className="text-scale-900 text-sm">Metadata</h3>
<pre
diff --git a/studio/components/interfaces/Settings/Logs/LogSelectionRenderers/FunctionInvocationSelectionRender.tsx b/studio/components/interfaces/Settings/Logs/LogSelectionRenderers/FunctionInvocationSelectionRender.tsx
index cb772f6964f..cfd8133b0ae 100644
--- a/studio/components/interfaces/Settings/Logs/LogSelectionRenderers/FunctionInvocationSelectionRender.tsx
+++ b/studio/components/interfaces/Settings/Logs/LogSelectionRenderers/FunctionInvocationSelectionRender.tsx
@@ -2,7 +2,12 @@ import dayjs from 'dayjs'
import { filterFunctionsRequestResponse } from 'lib/logs'
import { PreviewLogData } from '..'
import { LOGS_TAILWIND_CLASSES } from '../Logs.constants'
-import { jsonSyntaxHighlight, ResponseCodeFormatter, SelectionDetailedRow } from '../LogsFormatters'
+import {
+ jsonSyntaxHighlight,
+ ResponseCodeFormatter,
+ SelectionDetailedRow,
+ SelectionDetailedTimestampRow,
+} from '../LogsFormatters'
const FunctionInvocationSelectionRender = ({ log }: { log: PreviewLogData }) => {
const metadata = log.metadata?.[0]
@@ -13,17 +18,17 @@ const FunctionInvocationSelectionRender = ({ log }: { log: PreviewLogData }) =>
const requestUrl = new URL(request?.url)
const executionTimeMs = metadata.execution_time_ms
const deploymentId = metadata.deployment_id
- const timestamp = dayjs(log.timestamp / 1000)
return (
<>
<div className={`${LOGS_TAILWIND_CLASSES.log_selection_x_padding} space-y-2`}>
- <SelectionDetailedRow label="Status" value={status} valueRender={<ResponseCodeFormatter value={status} />} />
- <SelectionDetailedRow label="Method" value={method} />
<SelectionDetailedRow
- label="Timestamp"
- value={dayjs(timestamp).format('DD MMM, YYYY HH:mm')}
+ label="Status"
+ value={status}
+ valueRender={<ResponseCodeFormatter value={status} />}
/>
+ <SelectionDetailedRow label="Method" value={method} />
+ <SelectionDetailedTimestampRow value={log.timestamp} />
<SelectionDetailedRow label="Execution Time" value={`${executionTimeMs}ms`} />
<SelectionDetailedRow label="Deployment ID" value={deploymentId} />
<SelectionDetailedRow label="Log ID" value={log.id} />
diff --git a/studio/components/interfaces/Settings/Logs/LogSelectionRenderers/FunctionLogsSelectionRender.tsx b/studio/components/interfaces/Settings/Logs/LogSelectionRenderers/FunctionLogsSelectionRender.tsx
index fb5a925767b..2f5131fc802 100644
--- a/studio/components/interfaces/Settings/Logs/LogSelectionRenderers/FunctionLogsSelectionRender.tsx
+++ b/studio/components/interfaces/Settings/Logs/LogSelectionRenderers/FunctionLogsSelectionRender.tsx
@@ -1,9 +1,13 @@
import dayjs from 'dayjs'
import { LOGS_TAILWIND_CLASSES } from '../Logs.constants'
-import { jsonSyntaxHighlight, SelectionDetailedRow, SeverityFormatter } from '../LogsFormatters'
+import {
+ jsonSyntaxHighlight,
+ SelectionDetailedRow,
+ SelectionDetailedTimestampRow,
+ SeverityFormatter,
+} from '../LogsFormatters'
const FunctionLogsSelectionRender = ({ log }: any) => {
- const timestamp = dayjs(log.timestamp / 1000)
const metadata = log.metadata[0]
return (
@@ -22,7 +26,7 @@ const FunctionLogsSelectionRender = ({ log }: any) => {
valueRender={<SeverityFormatter value={metadata.level} />}
/>
<SelectionDetailedRow label="Deployment version" value={metadata.version} />
- <SelectionDetailedRow label="Timestamp" value={timestamp.format('DD MMM, YYYY HH:mm')} />
+ <SelectionDetailedTimestampRow value={log.timestamp} />
<SelectionDetailedRow label="Execution ID" value={metadata.execution_id} />
<SelectionDetailedRow label="Deployment ID" value={metadata.deployment_id} />
</div>
diff --git a/studio/components/interfaces/Settings/Logs/LogsFormatters.tsx b/studio/components/interfaces/Settings/Logs/LogsFormatters.tsx
index 87ed2f6f855..e4b22a93cf7 100644
--- a/studio/components/interfaces/Settings/Logs/LogsFormatters.tsx
+++ b/studio/components/interfaces/Settings/Logs/LogsFormatters.tsx
@@ -13,7 +13,16 @@ import CopyButton from 'components/ui/CopyButton'
export const RowLayout: React.FC = ({ children }) => (
<div className="flex h-full w-full items-center gap-4">{children}</div>
)
-
+// renders a timestamp (either unix microsecond or iso timestap)
+export const SelectionDetailedTimestampRow = ({ value }: { value: string | number }) => (
+ <>
+ <SelectionDetailedRow
+ label="Timestamp"
+ value={isUnixMicro(value) ? unixMicroToIsoTimestamp(value) : String(value)}
+ />
+ {console.log(isUnixMicro(value) ? unixMicroToIsoTimestamp(value) : String(value))}
+ </>
+)
export const SelectionDetailedRow = ({
label,
value,
diff --git a/studio/tests/pages/projects/LogsPreviewer.test.js b/studio/tests/pages/projects/LogsPreviewer.test.js
index f7827035e2f..32e1e10c24b 100644
--- a/studio/tests/pages/projects/LogsPreviewer.test.js
+++ b/studio/tests/pages/projects/LogsPreviewer.test.js
@@ -3,18 +3,9 @@ import utc from 'dayjs/plugin/utc'
dayjs.extend(utc)
-// mock the fetch function
-jest.mock('lib/common/fetch')
import { get } from 'lib/common/fetch'
-
-// mock mobx
-jest.mock('mobx-react-lite')
-import { observer } from 'mobx-react-lite'
-observer.mockImplementation((v) => v)
-
-// mock the router
-jest.mock('next/router')
import { useRouter } from 'next/router'
+
const defaultRouterMock = () => {
const router = jest.fn()
router.query = {}
@@ -24,58 +15,15 @@ const defaultRouterMock = () => {
}
useRouter.mockReturnValue(defaultRouterMock())
-// mock monaco editor
-jest.mock('@monaco-editor/react')
-import Editor, { useMonaco } from '@monaco-editor/react'
-Editor = jest.fn()
-Editor.mockImplementation((props) => {
- return (
- <textarea className="monaco-editor" onChange={(e) => props.onChange(e.target.value)}></textarea>
- )
-})
-useMonaco.mockImplementation((v) => v)
-
-// mock usage flags
-jest.mock('components/ui/Flag/Flag')
-import Flag from 'components/ui/Flag/Flag'
-Flag.mockImplementation(({ children }) => <>{children}</>)
-jest.mock('hooks')
-import { useFlag } from 'hooks'
-useFlag.mockReturnValue(true)
-
-import { SWRConfig } from 'swr'
-jest.mock('components/interfaces/Settings/Logs/LogsPreviewer')
import LogsPreviewer from 'components/interfaces/Settings/Logs/LogsPreviewer'
-LogsPreviewer.mockImplementation((props) => {
- const Comp = jest.requireActual('components/interfaces/Settings/Logs/LogsPreviewer').default
- // wrap with SWR to reset the cache each time
- return (
- <SWRConfig
- value={{
- provider: () => new Map(),
- shouldRetryOnError: false,
- }}
- >
- <Comp {...props} />
- </SWRConfig>
- )
-})
-
-jest.mock('hooks')
import { useProjectSubscription } from 'hooks'
-useProjectSubscription = jest.fn((ref) => ({
- subscription: {
- tier: {
- supabase_prod_id: 'tier_free',
- },
- },
-}))
-
-import { render, fireEvent, waitFor, screen, act } from '@testing-library/react'
+import { fireEvent, waitFor, screen, act } from '@testing-library/react'
+import { render } from '../../helpers'
import userEvent from '@testing-library/user-event'
import { wait } from '@testing-library/user-event/dist/utils'
import { logDataFixture } from '../../fixtures'
import { LogsTableName } from 'components/interfaces/Settings/Logs'
+
beforeEach(() => {
// reset mocks between tests
get.mockReset()
@@ -88,48 +36,46 @@ test.each([
queryType: 'api',
tableName: undefined,
tableLog: logDataFixture({
- id: 'some-id',
path: 'some-path',
method: 'POST',
status_code: '400',
metadata: undefined,
}),
- selectionLog: {
- id: 'some-id',
+ selectionLog: logDataFixture({
metadata: [{ request: [{ method: 'POST' }] }],
- },
+ }),
tableTexts: [/POST/, /some\-path/, /400/],
- selectionTexts: [/POST/],
+ selectionTexts: [/POST/, /Timestamp/, RegExp(`${new Date().getFullYear()}.+`, 'g')],
},
// TODO: add more tests for each type of ui
-
{
queryType: 'auth',
tableName: undefined,
tableLog: logDataFixture({
- id: 'some-id',
event_message: JSON.stringify({
msg: 'some message',
path: '/auth-path',
level: 'info',
status: 300,
}),
- timestamp: 1659545029083869,
- id: '4475cf6f-2929-4296-ab44-ce2c17069937',
}),
selectionLog: logDataFixture({
- id: 'some-id',
event_message: JSON.stringify({
msg: 'some message',
path: '/auth-path',
level: 'info',
status: 300,
}),
- timestamp: 1659545029083869,
- id: '4475cf6f-2929-4296-ab44-ce2c17069937',
}),
tableTexts: [/auth\-path/, /some message/, /INFO/],
- selectionTexts: [/auth\-path/, /some message/, /INFO/, /300/],
+ selectionTexts: [
+ /auth\-path/,
+ /some message/,
+ /INFO/,
+ /300/,
+ /Timestamp/,
+ RegExp(`${new Date().getFullYear()}.+`, 'g'),
+ ],
},
])(
'selection $queryType $tableName , can display log data and metadata',