ruvector/studio/hooks/analytics/useSingleLog.tsx
rUv 814f595995 feat(studio): Add complete RuVector Studio application
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>
2025-12-06 23:04:48 +00:00

81 lines
2.1 KiB
TypeScript

import { useQuery } from '@tanstack/react-query'
import { LOGS_TABLES } from 'components/interfaces/Settings/Logs/Logs.constants'
import type {
LogData,
Logs,
LogsEndpointParams,
QueryType,
} from 'components/interfaces/Settings/Logs/Logs.types'
import { genSingleLogQuery } from 'components/interfaces/Settings/Logs/Logs.utils'
import { get } from 'data/fetchers'
import { useIsFeatureEnabled } from 'hooks/misc/useIsFeatureEnabled'
interface SingleLogHook {
data: LogData | undefined
error: string | Object | null
isLoading: boolean
refresh: () => void
}
type SingleLogParams = {
id?: string
projectRef: string
queryType?: QueryType
paramsToMerge?: Partial<LogsEndpointParams>
}
function useSingleLog({
projectRef,
id,
queryType,
paramsToMerge,
}: SingleLogParams): SingleLogHook {
const table = queryType ? LOGS_TABLES[queryType] : undefined
const sql = id && table ? genSingleLogQuery(table, id) : ''
const params: LogsEndpointParams = { ...paramsToMerge, sql }
const enabled = Boolean(id && table)
const { logsMetadata } = useIsFeatureEnabled(['logs:metadata'])
const {
data,
error: rcError,
isLoading,
isRefetching,
refetch,
} = useQuery({
queryKey: ['projects', projectRef, 'single-log', id, queryType],
queryFn: async ({ signal }) => {
const { data, error } = await get(`/platform/projects/{ref}/analytics/endpoints/logs.all`, {
params: {
path: { ref: projectRef },
query: params,
},
signal,
})
if (error) {
throw error
}
return data as unknown as Logs
},
enabled,
refetchOnWindowFocus: false,
refetchOnMount: false,
refetchOnReconnect: false,
})
let error: null | string | object = rcError ? (rcError as any).message : null
const result = data?.result ? data.result[0] : undefined
return {
data: !!result
? { ...result, metadata: logsMetadata ? result?.metadata : undefined }
: undefined,
isLoading: (enabled && isLoading) || isRefetching,
error,
refresh: () => refetch(),
}
}
export default useSingleLog