mirror of
https://github.com/ruvnet/RuVector.git
synced 2026-05-25 23:24:03 +00:00
Major additions: - Complete Next.js studio application with 1600+ components - Docker support (Dockerfile.combined, docker-compose.yml) - GCP deployment documentation and benchmarks - SQL benchmark scripts for performance testing - Sentry integration for monitoring - Comprehensive test suite and mocks Studio features: - Dashboard and admin interfaces - Data visualization components - Authentication and user management - API integration with RuVector backend - Static data and public assets 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
118 lines
3 KiB
TypeScript
118 lines
3 KiB
TypeScript
import { useQuery } from '@tanstack/react-query'
|
|
import { useMemo } from 'react'
|
|
|
|
import { LogsTableName } from 'components/interfaces/Settings/Logs/Logs.constants'
|
|
import type {
|
|
EventChart,
|
|
EventChartData,
|
|
Filters,
|
|
LogsEndpointParams,
|
|
} from 'components/interfaces/Settings/Logs/Logs.types'
|
|
import { genChartQuery } from 'components/interfaces/Settings/Logs/Logs.utils'
|
|
import { get } from 'data/fetchers'
|
|
import { useFillTimeseriesSorted } from './useFillTimeseriesSorted'
|
|
import useTimeseriesUnixToIso from './useTimeseriesUnixToIso'
|
|
|
|
interface ProjectUsageStatsHookResult {
|
|
error: string | Object | null
|
|
isLoading: boolean
|
|
filters: Filters
|
|
params: LogsEndpointParams
|
|
eventChartData: EventChartData[]
|
|
refresh: () => void
|
|
}
|
|
|
|
function useProjectUsageStats({
|
|
projectRef,
|
|
table,
|
|
timestampStart,
|
|
timestampEnd,
|
|
filterOverride,
|
|
}: {
|
|
projectRef: string
|
|
table: LogsTableName
|
|
timestampStart: string
|
|
timestampEnd: string
|
|
filterOverride?: Filters
|
|
}): ProjectUsageStatsHookResult {
|
|
const filterOverrideString = JSON.stringify(filterOverride)
|
|
const mergedFilters = useMemo(
|
|
() => ({
|
|
...filterOverride,
|
|
}),
|
|
[filterOverrideString]
|
|
)
|
|
|
|
const params: LogsEndpointParams = useMemo(() => {
|
|
return { iso_timestamp_start: timestampStart, iso_timestamp_end: timestampEnd }
|
|
}, [timestampStart, timestampEnd])
|
|
|
|
const chartQuery = useMemo(
|
|
() => genChartQuery(table, params, mergedFilters),
|
|
[table, params, mergedFilters]
|
|
)
|
|
|
|
const chartQueryKey = useMemo(
|
|
() => [
|
|
'projects',
|
|
projectRef,
|
|
'logs-chart',
|
|
table,
|
|
{
|
|
projectRef,
|
|
sql: chartQuery,
|
|
iso_timestamp_start: timestampStart,
|
|
iso_timestamp_end: timestampEnd,
|
|
},
|
|
],
|
|
[projectRef, chartQuery, timestampStart, timestampEnd, table]
|
|
)
|
|
|
|
const { data: eventChartResponse, refetch: refreshEventChart } = useQuery({
|
|
queryKey: chartQueryKey,
|
|
queryFn: async ({ signal }) => {
|
|
const { data, error } = await get(`/platform/projects/{ref}/analytics/endpoints/logs.all`, {
|
|
params: {
|
|
path: { ref: projectRef },
|
|
query: {
|
|
iso_timestamp_start: timestampStart,
|
|
iso_timestamp_end: timestampEnd,
|
|
sql: chartQuery,
|
|
},
|
|
},
|
|
signal,
|
|
})
|
|
if (error) {
|
|
throw error
|
|
}
|
|
|
|
return data as unknown as EventChart
|
|
},
|
|
refetchOnWindowFocus: false,
|
|
enabled: typeof projectRef !== 'undefined',
|
|
})
|
|
|
|
const normalizedEventChartData = useTimeseriesUnixToIso(
|
|
eventChartResponse?.result ?? [],
|
|
'timestamp'
|
|
)
|
|
|
|
const { data: eventChartData, error: eventChartError } = useFillTimeseriesSorted(
|
|
normalizedEventChartData,
|
|
'timestamp',
|
|
'count',
|
|
0,
|
|
timestampStart,
|
|
timestampEnd || new Date().toISOString()
|
|
)
|
|
|
|
return {
|
|
isLoading: !eventChartResponse,
|
|
error: eventChartError,
|
|
filters: mergedFilters,
|
|
params,
|
|
eventChartData,
|
|
refresh: refreshEventChart,
|
|
}
|
|
}
|
|
export default useProjectUsageStats
|