The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.
TypeScript aialternativeauthdatabasedenoembeddingsexamplefirebasenextjsoauth2pgvectorpostgispostgrespostgresqlpostgrestrealtimesupabasevectorswebsockets
fix: add in timestamp filtering for single log filtering
TzeYiing6780907b4f47
diff --git a/studio/components/interfaces/Settings/Logs/LogSelection.tsx b/studio/components/interfaces/Settings/Logs/LogSelection.tsxindex 2ca573e4e36..ea4388fd99e 100644--- a/studio/components/interfaces/Settings/Logs/LogSelection.tsx+++ b/studio/components/interfaces/Settings/Logs/LogSelection.tsx@@ -13,19 +13,31 @@ import FunctionInvocationSelectionRender, {import FunctionLogsSelectionRender from './LogSelectionRenderers/FunctionLogsSelectionRender'import DefaultExplorerSelectionRenderer from './LogSelectionRenderers/DefaultExplorerSelectionRenderer'import DefaultPreviewSelectionRenderer from './LogSelectionRenderers/DefaultPreviewSelectionRenderer'-import { isDefaultLogPreviewFormat, LogsTableName } from '.'+import { isDefaultLogPreviewFormat, LogsEndpointParams, LogsTableName } from '.'import useSingleLog from 'hooks/analytics/useSingleLog'import Connecting from 'components/ui/Loading/Loading'-interface Props {+export interface LogSelectionProps {log: LogData | nullonClose: () => voidqueryType?: QueryTypeprojectRef: string+ params: Partial<LogsEndpointParams>}-const LogSelection: FC<Props> = ({ projectRef, log: partialLog, onClose, queryType }) => {- const [{ logData: fullLog, isLoading }] = useSingleLog(projectRef, queryType, partialLog?.id)+const LogSelection: FC<LogSelectionProps> = ({+ projectRef,+ log: partialLog,+ onClose,+ queryType,+ params = {},+}) => {+ const [{ logData: fullLog, isLoading }] = useSingleLog(+ projectRef,+ queryType,+ params,+ partialLog?.id+ )const Formatter = () => {switch (queryType) {case 'api':diff --git a/studio/components/interfaces/Settings/Logs/LogTable.stories.tsx b/studio/components/interfaces/Settings/Logs/LogTable.stories.tsxnew file mode 100644index 00000000000..6be4b415564--- /dev/null+++ b/studio/components/interfaces/Settings/Logs/LogTable.stories.tsx@@ -0,0 +1,46 @@+import React from 'react'++import LogTable from './LogTable'++export default {+ title: 'Logs',+}++export const Functions = (args: any) => (+ <div+ // style={{+ // height: '600px',+ // display: 'flex',+ // flexDirection: 'column',+ // flexGrow: 1,+ // position: 'relative',+ // }}+ // className="+ // flex flex-col flex-grow relative pt-4 flex h-full flex-grow transition-opacity+ // "+ >+ <LogTable+ params={{}}+ queryType="functions"+ projectRef="123"+ data={[+ {+ event_message: 'This is a error log\n',+ event_type: 'log',+ function_id: '001b0b08-331c-403e-810c-a2004b03a019',+ level: 'error',+ timestamp: 1659545029083869,+ id: '3475cf6f-2929-4296-ab44-ce2c17069937',+ },+ {+ event_message: 'This is a uncaughtExceptop\n',+ event_type: 'uncaughtException',+ function_id: '001b0b08-331c-403e-810c-a2004b03a019',+ timestamp: 1659545029083869,+ id: '4475cf6f-2929-4296-ab44-ce2c17069937',+ level: null,+ },+ ]}+ />+ </div>+)diff --git a/studio/components/interfaces/Settings/Logs/LogTable.tsx b/studio/components/interfaces/Settings/Logs/LogTable.tsxindex a2fd5a391a1..59b83fb6c87 100644--- a/studio/components/interfaces/Settings/Logs/LogTable.tsx+++ b/studio/components/interfaces/Settings/Logs/LogTable.tsx@@ -3,7 +3,7 @@ import { useEffect, useState, useMemo } from 'react'import { Alert, Button, IconEye, IconEyeOff, Input } from '@supabase/ui'import DataGrid from '@supabase/react-data-grid'-import LogSelection from './LogSelection'+import LogSelection, { LogSelectionProps } from './LogSelection'import { LogData, QueryType } from './Logs.types'import { SeverityFormatter, ResponseCodeFormatter, HeaderFormmater } from './LogsFormatters'import { isDefaultLogPreviewFormat } from './Logs.utils'@@ -15,13 +15,15 @@ import DefaultPreviewColumnRenderer from './LogColumnRenderers/DefaultPreviewColinterface Props {data?: Array<LogData | Object>- queryType?: QueryTypeonHistogramToggle?: () => voidisHistogramShowing?: booleanisLoading?: booleanerror?: anyshowDownload?: boolean+ // TODO: move all common params to a context to avoid prop drilling+ queryType?: QueryTypeprojectRef: string+ params: LogSelectionProps['params']}type LogMap = { [id: string]: LogData }@@ -57,6 +59,7 @@ const LogTable = ({showDownload,error,projectRef,+ params,}: Props) => {const [focusedLog, setFocusedLog] = useState<LogData | null>(null)const firstRow: LogData | undefined = data?.[0] as LogData@@ -396,6 +399,7 @@ const LogTable = ({onClose={() => setFocusedLog(null)}log={focusedLog}queryType={queryType}+ params={params}/></div>) : null}diff --git a/studio/components/interfaces/Settings/Logs/LogsPreviewer.tsx b/studio/components/interfaces/Settings/Logs/LogsPreviewer.tsxindex 95d0761a75b..a972f28d9c1 100644--- a/studio/components/interfaces/Settings/Logs/LogsPreviewer.tsx+++ b/studio/components/interfaces/Settings/Logs/LogsPreviewer.tsx@@ -162,6 +162,7 @@ export const LogsPreviewer: React.FC<Props> = ({queryType={queryType}isHistogramShowing={showChart}onHistogramToggle={() => setShowChart(!showChart)}+ params={params}/></LoadingOpacity>{!error && (diff --git a/studio/hooks/analytics/useSingleLog.tsx b/studio/hooks/analytics/useSingleLog.tsxindex 75c3f009bcd..1d468d18c6c 100644--- a/studio/hooks/analytics/useSingleLog.tsx+++ b/studio/hooks/analytics/useSingleLog.tsx@@ -22,11 +22,12 @@ interface Handlers {function useSingleLog(project: string,queryType?: QueryType,+ paramsToMerge?: Partial<LogsEndpointParams>,id?: string | null): [Data, Handlers] {const table = queryType ? LOGS_TABLES[queryType] : undefinedconst sql = id && table ? genSingleLogQuery(table, id) : ''- const params: LogsEndpointParams = { project, sql }+ const params: LogsEndpointParams = { ...paramsToMerge, project, sql }const endpointUrl = `${API_URL}/projects/${project}/analytics/endpoints/logs.all?${genQueryParams(params as any)}`diff --git a/studio/pages/project/[ref]/logs-explorer/index.tsx b/studio/pages/project/[ref]/logs-explorer/index.tsxindex ee1a2c1d963..6c819ef40ac 100644--- a/studio/pages/project/[ref]/logs-explorer/index.tsx+++ b/studio/pages/project/[ref]/logs-explorer/index.tsx@@ -150,7 +150,7 @@ export const LogsExplorerPage: NextPageWithLayout = () => {<div className="relative flex flex-grow flex-col"><LoadingOpacity active={isLoading}><div className="flex h-full flex-grow">- <LogTable data={logData} error={error} projectRef={ref as string} />+ <LogTable params={params} data={logData} error={error} projectRef={ref as string} /></div></LoadingOpacity><div className="mt-2 flex flex-row justify-end">diff --git a/studio/tests/pages/projects/LogsPreviewer.test.js b/studio/tests/pages/projects/LogsPreviewer.test.jsindex 0a782814390..0eac35647b3 100644--- a/studio/tests/pages/projects/LogsPreviewer.test.js+++ b/studio/tests/pages/projects/LogsPreviewer.test.js@@ -122,6 +122,8 @@ test.each([expect(get).toHaveBeenCalledWith(expect.stringContaining('iso_timestamp_start'))expect(get).not.toHaveBeenCalledWith(expect.stringContaining('iso_timestamp_end'))})+ // reset mock so that we can check for selection call+ get.mockClear()for (const text of tableTexts) {await screen.findByText(text)@@ -129,6 +131,11 @@ test.each([const row = await screen.findByText(tableTexts[0])fireEvent.click(row)+ await waitFor(() => {+ expect(get).toHaveBeenCalledWith(expect.stringContaining('iso_timestamp_start'))+ expect(get).not.toHaveBeenCalledWith(expect.stringContaining('iso_timestamp_end'))+ })+for (const text of selectionTexts) {await screen.findAllByText(text)}