-
Notifications
You must be signed in to change notification settings - Fork 293
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[OPIK-398] Project statistics - FE implementation (#735)
* [OPIK-398] Project statistics - FE implementation * - invalidate queries in case of annotate
- Loading branch information
1 parent
ec91598
commit d117259
Showing
16 changed files
with
446 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import { QueryFunctionContext, useQuery } from "@tanstack/react-query"; | ||
import api, { QueryConfig, SPANS_REST_ENDPOINT } from "@/api/api"; | ||
import { SPAN_TYPE } from "@/types/traces"; | ||
import { ColumnsStatistic } from "@/types/shared"; | ||
import { Filters } from "@/types/filters"; | ||
import { generateSearchByIDFilters, processFilters } from "@/lib/filters"; | ||
|
||
type UseSpansStatisticParams = { | ||
projectId: string; | ||
traceId?: string; | ||
type?: SPAN_TYPE; | ||
filters?: Filters; | ||
search?: string; | ||
}; | ||
|
||
export type UseSpansStatisticResponse = { | ||
stats: ColumnsStatistic; | ||
}; | ||
|
||
const getSpansStatistic = async ( | ||
{ signal }: QueryFunctionContext, | ||
{ projectId, traceId, type, filters, search }: UseSpansStatisticParams, | ||
) => { | ||
const { data } = await api.get(`${SPANS_REST_ENDPOINT}stats`, { | ||
signal, | ||
params: { | ||
project_id: projectId, | ||
...(traceId && { trace_id: traceId }), | ||
...(type && { type }), | ||
...processFilters(filters, generateSearchByIDFilters(search)), | ||
}, | ||
}); | ||
|
||
return data; | ||
}; | ||
|
||
export default function useSpansStatistic( | ||
params: UseSpansStatisticParams, | ||
options?: QueryConfig<UseSpansStatisticResponse>, | ||
) { | ||
return useQuery({ | ||
queryKey: ["spans-statistic", params], | ||
queryFn: (context) => getSpansStatistic(context, params), | ||
...options, | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import { QueryFunctionContext, useQuery } from "@tanstack/react-query"; | ||
import api, { QueryConfig, TRACES_REST_ENDPOINT } from "@/api/api"; | ||
import { ColumnsStatistic } from "@/types/shared"; | ||
import { Filters } from "@/types/filters"; | ||
import { generateSearchByIDFilters, processFilters } from "@/lib/filters"; | ||
|
||
type UseTracesStatisticParams = { | ||
projectId: string; | ||
filters?: Filters; | ||
search?: string; | ||
}; | ||
|
||
export type UseTracesStatisticResponse = { | ||
stats: ColumnsStatistic; | ||
}; | ||
|
||
const getTracesStatistic = async ( | ||
{ signal }: QueryFunctionContext, | ||
{ projectId, filters, search }: UseTracesStatisticParams, | ||
) => { | ||
const { data } = await api.get<UseTracesStatisticResponse>( | ||
`${TRACES_REST_ENDPOINT}stats`, | ||
{ | ||
signal, | ||
params: { | ||
project_id: projectId, | ||
...processFilters(filters, generateSearchByIDFilters(search)), | ||
}, | ||
}, | ||
); | ||
|
||
return data; | ||
}; | ||
|
||
export default function useTracesStatistic( | ||
params: UseTracesStatisticParams, | ||
options?: QueryConfig<UseTracesStatisticResponse>, | ||
) { | ||
return useQuery({ | ||
queryKey: ["traces-statistic", params], | ||
queryFn: (context) => getTracesStatistic(context, params), | ||
...options, | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.