Delete assets/js/dashboard/stats/graph/fetch-main-graph.ts with huggingface_hub
Browse files
assets/js/dashboard/stats/graph/fetch-main-graph.ts
DELETED
|
@@ -1,89 +0,0 @@
|
|
| 1 |
-
import { Metric } from '../metrics'
|
| 2 |
-
import { DashboardPeriod } from '../../dashboard-time-periods'
|
| 3 |
-
import { useSiteContext } from '../../site-context'
|
| 4 |
-
import { createStatsQuery, StatsQuery } from '../../stats-query'
|
| 5 |
-
import { isRealTimeDashboard } from '../../util/filters'
|
| 6 |
-
import { MetricValue } from '../../api'
|
| 7 |
-
import * as api from '../../api'
|
| 8 |
-
import { Interval } from './intervals'
|
| 9 |
-
import { StatsReportQueryKey, useQueryApi } from '../../hooks/use-query-api'
|
| 10 |
-
import { useDashboardStateContext } from '../../dashboard-state-context'
|
| 11 |
-
import { UseQueryResult } from '@tanstack/react-query'
|
| 12 |
-
|
| 13 |
-
export function useMainGraphQuery(
|
| 14 |
-
metric: Metric,
|
| 15 |
-
interval: Interval
|
| 16 |
-
): {
|
| 17 |
-
apiState: UseQueryResult<MainGraphResponse>
|
| 18 |
-
isRealtimeSilentUpdate: boolean
|
| 19 |
-
} {
|
| 20 |
-
const site = useSiteContext()
|
| 21 |
-
const { dashboardState } = useDashboardStateContext()
|
| 22 |
-
|
| 23 |
-
const metricToQuery =
|
| 24 |
-
metric === 'conversion_rate' ? 'group_conversion_rate' : metric
|
| 25 |
-
|
| 26 |
-
const mainGraphQueryKey: StatsReportQueryKey = [
|
| 27 |
-
'main-graph',
|
| 28 |
-
{
|
| 29 |
-
dashboardState,
|
| 30 |
-
reportParams: {
|
| 31 |
-
metrics: [metricToQuery],
|
| 32 |
-
dimensions: [`time:${interval}`],
|
| 33 |
-
include: {
|
| 34 |
-
time_labels: true,
|
| 35 |
-
partial_time_labels: true,
|
| 36 |
-
empty_metrics: true,
|
| 37 |
-
present_index: true
|
| 38 |
-
}
|
| 39 |
-
}
|
| 40 |
-
}
|
| 41 |
-
]
|
| 42 |
-
|
| 43 |
-
const { apiState, isRealtimeSilentUpdate } = useQueryApi<MainGraphResponse>(
|
| 44 |
-
site,
|
| 45 |
-
mainGraphQueryKey,
|
| 46 |
-
{ getStatsQuery: getMainGraphQuery }
|
| 47 |
-
)
|
| 48 |
-
|
| 49 |
-
return { apiState, isRealtimeSilentUpdate }
|
| 50 |
-
}
|
| 51 |
-
|
| 52 |
-
function getMainGraphQuery(queryKey: StatsReportQueryKey): StatsQuery {
|
| 53 |
-
const [_reportId, keyOpts] = queryKey
|
| 54 |
-
const { dashboardState, reportParams } = keyOpts
|
| 55 |
-
const statsQuery = createStatsQuery(dashboardState, reportParams)
|
| 56 |
-
|
| 57 |
-
if (isRealTimeDashboard(dashboardState)) {
|
| 58 |
-
return { ...statsQuery, date_range: DashboardPeriod.realtime_30m }
|
| 59 |
-
}
|
| 60 |
-
|
| 61 |
-
return statsQuery
|
| 62 |
-
}
|
| 63 |
-
|
| 64 |
-
export type ResultItem = {
|
| 65 |
-
dimensions: [string] // one item
|
| 66 |
-
metrics: MetricValues
|
| 67 |
-
}
|
| 68 |
-
|
| 69 |
-
export type MetricValues = [MetricValue] // one item
|
| 70 |
-
|
| 71 |
-
export type MainGraphResponse = Pick<
|
| 72 |
-
api.QueryApiResponse,
|
| 73 |
-
'query' | 'extraContext'
|
| 74 |
-
> & {
|
| 75 |
-
results: Array<ResultItem | null>
|
| 76 |
-
comparison_results: Array<
|
| 77 |
-
(ResultItem & { change: [number | null] | null }) | null
|
| 78 |
-
>
|
| 79 |
-
meta: {
|
| 80 |
-
partial_time_labels: string[] | null
|
| 81 |
-
comparison_partial_time_labels: string[] | null
|
| 82 |
-
time_labels: string[]
|
| 83 |
-
time_label_result_indices: (number | null)[]
|
| 84 |
-
comparison_time_labels?: string[]
|
| 85 |
-
comparison_time_label_result_indices?: (number | null)[]
|
| 86 |
-
empty_metrics: MetricValues
|
| 87 |
-
present_index: number
|
| 88 |
-
}
|
| 89 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|