The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.
TypeScript aialternativeauthdatabasedenoembeddingsexamplefirebasenextjsoauth2pgvectorpostgispostgrespostgresqlpostgrestrealtimesupabasevectorswebsockets
added basic chart event rendering for logs data
TzeYiingfaccfc928d94
diff --git a/studio/components/interfaces/Settings/Logs/LogEventChart.tsx b/studio/components/interfaces/Settings/Logs/LogEventChart.tsxnew file mode 100644index 00000000000..e82aebf04ee--- /dev/null+++ b/studio/components/interfaces/Settings/Logs/LogEventChart.tsx@@ -0,0 +1,56 @@+import { BarChart } from 'components/to-be-cleaned/Charts/ChartRenderer'+import dayjs from 'dayjs'+import { LogData } from '.'+import utc from 'dayjs/plugin/utc'+dayjs.extend(utc)+interface Props {+ data: LogData[]+ onBarClick: (timestamp: number) => void+}++type TimestampMap = { [timestamp: number]: number }+const LogEventChart: React.FC<Props> = ({ data, onBarClick }) => {+ if (!data) return null++ const countMap = data+ .map((d) => {+ // truncate to per-minute+ return { ...d, timestamp: Math.round(d.timestamp / 1000 / 1000 / 60) * 60 }+ })+ .reduce((acc, d) => {+ if (acc[d.timestamp]) {+ acc[d.timestamp] = acc[d.timestamp] + 1+ } else {+ acc[d.timestamp] = 1+ }+ return acc+ }, {} as TimestampMap)++ let aggregated = []+ for (const [key, value] of Object.entries(countMap)) {+ const v: number = Number(key)+ aggregated.push({+ period_start: dayjs.unix(v).utc().format(),+ timestamp: key,+ timestampMicro: v * 1000 * 1000,+ count: value,+ })+ }+ aggregated = aggregated.sort((a, b) => a.timestampMicro - b.timestampMicro)++ return (+ <BarChart+ data={aggregated}+ attribute="count"+ label="Events"+ onBarClick={(v: any) => {+ const timestamp = v.activePayload[0].payload.timestamp+ // 60s before+ onBarClick((Number(timestamp) + 60) * 1000 * 1000)+ }}+ customDateFormat="YYYY-MM-DDTHH:mm:ss"+ />+ )+}++export default LogEventChartdiff --git a/studio/components/interfaces/Settings/Logs/Logs.types.ts b/studio/components/interfaces/Settings/Logs/Logs.types.tsindex 73491eab407..f93d5c747fe 100644--- a/studio/components/interfaces/Settings/Logs/Logs.types.ts+++ b/studio/components/interfaces/Settings/Logs/Logs.types.ts@@ -1,7 +1,7 @@interface Metadata {[key: string]: string | number | Object | Object[]}-export type LogSearchCallback = (filters: { query: string; from: string }) => void+export type LogSearchCallback = (filters: { query: string; from?: string, fromMicro?: number }) => voidexport interface LogData {id: stringtimestamp: numberdiff --git a/studio/components/interfaces/Settings/Logs/index.ts b/studio/components/interfaces/Settings/Logs/index.tsindex 1f094158c52..2b7b9268f24 100644--- a/studio/components/interfaces/Settings/Logs/index.ts+++ b/studio/components/interfaces/Settings/Logs/index.ts@@ -1,6 +1,5 @@-import LogPanel from './LogPanel'-import LogTable from './LogTable'-export * from './Logs.types'export * from './Logs.constants'-export { LogPanel, LogTable }+export {default as LogPanel} from "./LogPanel"+export {default as LogTable} from "./LogTable"+export {default as LogEventChart} from "./LogEventChart"diff --git a/studio/pages/project/[ref]/settings/logs/[type].tsx b/studio/pages/project/[ref]/settings/logs/[type].tsxindex 6154a981d2c..6ca4428c51f 100644--- a/studio/pages/project/[ref]/settings/logs/[type].tsx+++ b/studio/pages/project/[ref]/settings/logs/[type].tsx@@ -21,6 +21,7 @@ import CodeEditor from 'components/ui/CodeEditor'import {LogPanel,LogTable,+ LogEventChart,Count,Logs,LogTemplate,@@ -205,12 +206,12 @@ export const LogPage: NextPage = () => {},})}- const handleSearch: LogSearchCallback = ({ query, from }) => {- const unixMicro = dayjs(from).valueOf() * 1000+ const handleSearch: LogSearchCallback = ({ query, from, fromMicro }) => {+ const unixMicro = fromMicro ? fromMicro : dayjs(from).valueOf() * 1000setParams((prev) => ({...prev,search_query: query || '',- timestamp_end: from ? String(unixMicro) : '',+ timestamp_end: unixMicro ? String(unixMicro) : '',where: '',sql: '',}))@@ -287,6 +288,14 @@ export const LogPage: NextPage = () => {</div></React.Fragment>)}+ <div>+ <LogEventChart+ data={logData}+ onBarClick={(timestampMicro) => {+ handleSearch({ query: params.search_query, fromMicro: timestampMicro })+ }}+ />+ </div><div className="flex flex-col flex-grow relative">{isValidating && (<div