mirror of https://github.com/buster-so/buster.git
Added more report version number stuff
This commit is contained in:
parent
f1ea82c730
commit
eaaeca332c
|
@ -67,9 +67,9 @@ export const prefetchGetReportsListClient = async (
|
|||
};
|
||||
|
||||
export const prefetchGetReport = async (
|
||||
queryClient: QueryClient,
|
||||
reportId: string,
|
||||
report_version_number: number | undefined,
|
||||
queryClient: QueryClient
|
||||
report_version_number: number | undefined
|
||||
) => {
|
||||
const version_number = report_version_number || 'LATEST';
|
||||
|
||||
|
@ -78,7 +78,11 @@ export const prefetchGetReport = async (
|
|||
if (!existingData) {
|
||||
await queryClient.prefetchQuery({
|
||||
...reportsQueryKeys.reportsGetReport(reportId, version_number || 'LATEST'),
|
||||
queryFn: () => getReportById(reportId),
|
||||
queryFn: () =>
|
||||
getReportById({
|
||||
id: reportId,
|
||||
version_number: typeof version_number === 'number' ? version_number : undefined,
|
||||
}),
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -88,7 +92,7 @@ export const prefetchGetReport = async (
|
|||
export const usePrefetchGetReportClient = () => {
|
||||
const queryClient = useQueryClient();
|
||||
return (reportId: string, versionNumber?: number) => {
|
||||
return prefetchGetReport(reportId, versionNumber, queryClient);
|
||||
return prefetchGetReport(queryClient, reportId, versionNumber);
|
||||
};
|
||||
};
|
||||
|
||||
|
@ -100,7 +104,10 @@ export const useGetReport = <T = GetReportResponse>(
|
|||
options?: Omit<UseQueryOptions<GetReportResponse, RustApiError, T>, 'queryKey' | 'queryFn'>
|
||||
) => {
|
||||
const queryFn = () => {
|
||||
return getReportById(id ?? '');
|
||||
return getReportById({
|
||||
id: id ?? '',
|
||||
version_number: typeof versionNumber === 'number' ? versionNumber : undefined,
|
||||
});
|
||||
};
|
||||
|
||||
return useQuery({
|
||||
|
@ -112,18 +119,6 @@ export const useGetReport = <T = GetReportResponse>(
|
|||
});
|
||||
};
|
||||
|
||||
/**
|
||||
* Prefetch function for individual report (server-side)
|
||||
*/
|
||||
export const prefetchGetReportById = async (queryClient: QueryClient, reportId: string) => {
|
||||
await queryClient.prefetchQuery({
|
||||
...reportsQueryKeys.reportsGetReport(reportId, 'LATEST'),
|
||||
queryFn: () => getReportById(reportId),
|
||||
});
|
||||
|
||||
return queryClient.getQueryData(reportsQueryKeys.reportsGetReport(reportId, 'LATEST').queryKey);
|
||||
};
|
||||
|
||||
export const useUpdateReport = () => {
|
||||
const queryClient = useQueryClient();
|
||||
|
||||
|
|
|
@ -1,4 +1,6 @@
|
|||
import type {
|
||||
GetReportParams,
|
||||
GetReportQuery,
|
||||
GetReportResponse,
|
||||
GetReportsListRequest,
|
||||
GetReportsListResponse,
|
||||
|
@ -21,8 +23,8 @@ export const getReportsList = async (params?: GetReportsListRequest) => {
|
|||
/**
|
||||
* Get an individual report by ID
|
||||
*/
|
||||
export const getReportById = async (reportId: string) => {
|
||||
return mainApiV2.get<GetReportResponse>(`/reports/${reportId}`).then((res) => res.data);
|
||||
export const getReportById = async ({ id, ...params }: GetReportParams & GetReportQuery) => {
|
||||
return mainApiV2.get<GetReportResponse>(`/reports/${id}`, { params }).then((res) => res.data);
|
||||
};
|
||||
|
||||
/**
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
import { createFileRoute } from '@tanstack/react-router';
|
||||
import { z } from 'zod';
|
||||
import { prefetchGetReportById } from '@/api/buster_rest/reports/queryRequests';
|
||||
import { prefetchGetReport } from '@/api/buster_rest/reports/queryRequests';
|
||||
import { ScrollArea } from '@/components/ui/scroll-area';
|
||||
import { ReportPageController } from '@/controllers/ReportPageControllers';
|
||||
|
||||
|
@ -11,8 +11,13 @@ const searchParamsSchema = z.object({
|
|||
export const Route = createFileRoute('/embed/report/$reportId')({
|
||||
component: RouteComponent,
|
||||
validateSearch: searchParamsSchema,
|
||||
loader: async ({ params, context: { queryClient } }) => {
|
||||
const report = await prefetchGetReportById(queryClient, params.reportId);
|
||||
beforeLoad: ({ search }) => {
|
||||
return {
|
||||
report_version_number: search.report_version_number,
|
||||
};
|
||||
},
|
||||
loader: async ({ params, context: { report_version_number, queryClient } }) => {
|
||||
const report = await prefetchGetReport(queryClient, params.reportId, report_version_number);
|
||||
return {
|
||||
title: report?.name,
|
||||
};
|
||||
|
|
|
@ -1,6 +1,15 @@
|
|||
import { z } from 'zod';
|
||||
import { PaginatedRequestSchema } from '../type-utilities/pagination';
|
||||
|
||||
export const GetReportParamsSchema = z.object({
|
||||
id: z.string().uuid('Report ID must be a valid UUID'),
|
||||
});
|
||||
|
||||
export const GetReportQuerySchema = z.object({
|
||||
password: z.string().min(1).optional(),
|
||||
version_number: z.coerce.number().int().min(1).optional(),
|
||||
});
|
||||
|
||||
export const GetReportsListRequestSchema = PaginatedRequestSchema.extend({
|
||||
shared_with_me: z.coerce.boolean().optional(),
|
||||
only_my_reports: z.coerce.boolean().optional(),
|
||||
|
@ -18,3 +27,5 @@ export const UpdateReportRequestSchema = z
|
|||
|
||||
export type UpdateReportRequest = z.infer<typeof UpdateReportRequestSchema>;
|
||||
export type GetReportsListRequest = z.infer<typeof GetReportsListRequestSchema>;
|
||||
export type GetReportParams = z.infer<typeof GetReportParamsSchema>;
|
||||
export type GetReportQuery = z.infer<typeof GetReportQuerySchema>;
|
||||
|
|
Loading…
Reference in New Issue