Update QueryOptions.ts

This commit is contained in:
Jonathan Summers-Muir committed 2025-06-20 17:58:15 +08:00
1 parent dd69049efa
commit c907da5376
1 file changed
+24 -15
@@ -2,7 +2,7 @@ import { useQuery } from '@tanstack/react-query'
import dayjs from 'dayjs'
import { ARRAY_DELIMITER, SORT_DELIMITER } from 'components/ui/DataTable/DataTable.constants'
import { get } from 'data/fetchers'
import { get, post } from 'data/fetchers'
import { getLogsChartQuery, getLogsCountQuery, getUnifiedLogsQuery } from './UnifiedLogs.queries'
import { BaseChartSchema, ColumnSchema, type FacetMetadataSchema } from './UnifiedLogs.schema'
import type { PageParam, SearchParamsType, UnifiedLogsMeta } from './UnifiedLogs.types'
@@ -117,18 +117,23 @@ export const useChartData = (search: SearchParamsType, projectRef: string) => {
// Get SQL query from utility function (with dynamic bucketing)
const sql = getLogsChartQuery(search)
// Use the get function from data/fetchers for chart data
const { data, error } = await get(`/platform/projects/{ref}/analytics/endpoints/logs.all`, {
params: {
path: { ref: projectRef },
query: {
iso_timestamp_start: dateStart,
iso_timestamp_end: dateEnd,
project: projectRef,
// Use the post function from data/fetchers for chart data
const { data, error } = await post(
`/platform/projects/{ref}/analytics/endpoints/logs.all`,
{
params: {
path: { ref: projectRef },
query: {
iso_timestamp_start: dateStart,
iso_timestamp_end: dateEnd,
project: projectRef,
},
},
body: {
sql,
},
},
})
}
)
if (error) {
if (DEBUG_MODE) console.error('API returned error for chart data:', error)
@@ -314,7 +319,7 @@ export const dataOptions = (search: SearchParamsType, projectRef: string) => {
const countsSql = getLogsCountQuery(search)
// First, fetch the counts data
const { data: countsData, error: countsError } = await get(
const { data: countsData, error: countsError } = await post(
`/platform/projects/{ref}/analytics/endpoints/logs.all`,
{
params: {
@@ -323,9 +328,11 @@ export const dataOptions = (search: SearchParamsType, projectRef: string) => {
iso_timestamp_start: isoTimestampStart,
iso_timestamp_end: isoTimestampEnd,
project: projectRef,
sql: countsSql,
},
},
body: {
sql: countsSql,
},
}
)
@@ -412,7 +419,7 @@ export const dataOptions = (search: SearchParamsType, projectRef: string) => {
console.log('🔍 Raw pageParam received:', pageParam)
}
const { data: logsData, error: logsError } = await get(
const { data: logsData, error: logsError } = await post(
`/platform/projects/{ref}/analytics/endpoints/logs.all`,
{
params: {
@@ -421,9 +428,11 @@ export const dataOptions = (search: SearchParamsType, projectRef: string) => {
iso_timestamp_start: timestampStart,
iso_timestamp_end: timestampEnd,
project: projectRef,
sql: logsSql,
},
},
body: {
sql: logsSql,
},
}
)