mirror of https://github.com/buster-so/buster.git
ensure data before taking screenshot
This commit is contained in:
parent
d2c6328259
commit
2cd30db319
|
@ -227,6 +227,18 @@ export const prefetchGetMetricDataClient = async (
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export const ensureMetricData = async (
|
||||||
|
queryClient: QueryClient,
|
||||||
|
params: Parameters<typeof getMetricData>[0]
|
||||||
|
) => {
|
||||||
|
const { id, version_number, report_file_id } = params;
|
||||||
|
const options = metricsQueryKeys.metricsGetData(id, version_number || 'LATEST', report_file_id);
|
||||||
|
return await queryClient.ensureQueryData({
|
||||||
|
...options,
|
||||||
|
queryFn: () => getMetricData({ id, version_number, report_file_id }),
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
//used in list version histories
|
//used in list version histories
|
||||||
export const usePrefetchGetMetricDataClient = () => {
|
export const usePrefetchGetMetricDataClient = () => {
|
||||||
const queryClient = useQueryClient();
|
const queryClient = useQueryClient();
|
||||||
|
|
|
@ -13,8 +13,16 @@ export const MetricViewChart: React.FC<{
|
||||||
readOnly?: boolean;
|
readOnly?: boolean;
|
||||||
className?: string;
|
className?: string;
|
||||||
cardClassName?: string;
|
cardClassName?: string;
|
||||||
|
animate?: boolean;
|
||||||
}> = React.memo(
|
}> = React.memo(
|
||||||
({ metricId, versionNumber, readOnly = false, className = '', cardClassName = '' }) => {
|
({
|
||||||
|
metricId,
|
||||||
|
versionNumber,
|
||||||
|
readOnly = false,
|
||||||
|
className = '',
|
||||||
|
cardClassName = '',
|
||||||
|
animate = true,
|
||||||
|
}) => {
|
||||||
const { data: hasMoreRecords } = useGetMetricData(
|
const { data: hasMoreRecords } = useGetMetricData(
|
||||||
{ id: metricId, versionNumber },
|
{ id: metricId, versionNumber },
|
||||||
{ select: stableMetricDataSelect }
|
{ select: stableMetricDataSelect }
|
||||||
|
@ -28,6 +36,7 @@ export const MetricViewChart: React.FC<{
|
||||||
versionNumber={versionNumber}
|
versionNumber={versionNumber}
|
||||||
readOnly={readOnly}
|
readOnly={readOnly}
|
||||||
className={cardClassName}
|
className={cardClassName}
|
||||||
|
animate={animate}
|
||||||
/>
|
/>
|
||||||
{hasMoreRecords && (
|
{hasMoreRecords && (
|
||||||
<MetricDataTruncatedWarning metricId={metricId} metricVersionNumber={versionNumber} />
|
<MetricDataTruncatedWarning metricId={metricId} metricVersionNumber={versionNumber} />
|
||||||
|
|
|
@ -9,6 +9,7 @@ export const ssr = true;
|
||||||
|
|
||||||
export const component = () => {
|
export const component = () => {
|
||||||
const { metricId, metricVersionNumber } = useGetMetricParams();
|
const { metricId, metricVersionNumber } = useGetMetricParams();
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<AppAssetCheckLayout assetType={'metric_file'}>
|
<AppAssetCheckLayout assetType={'metric_file'}>
|
||||||
<MetricViewChartController
|
<MetricViewChartController
|
||||||
|
|
|
@ -9,11 +9,13 @@ export const MetricViewChartController: React.FC<{
|
||||||
readOnly?: boolean;
|
readOnly?: boolean;
|
||||||
className?: string;
|
className?: string;
|
||||||
cardClassName?: string;
|
cardClassName?: string;
|
||||||
|
animate?: boolean;
|
||||||
}> = React.memo(
|
}> = React.memo(
|
||||||
({
|
({
|
||||||
metricId,
|
metricId,
|
||||||
versionNumber,
|
versionNumber,
|
||||||
readOnly: readOnlyProp = false,
|
readOnly: readOnlyProp = false,
|
||||||
|
animate = true,
|
||||||
className = '',
|
className = '',
|
||||||
cardClassName = '',
|
cardClassName = '',
|
||||||
}) => {
|
}) => {
|
||||||
|
@ -30,6 +32,7 @@ export const MetricViewChartController: React.FC<{
|
||||||
readOnly={isReadOnly}
|
readOnly={isReadOnly}
|
||||||
className={className}
|
className={className}
|
||||||
cardClassName={cardClassName}
|
cardClassName={cardClassName}
|
||||||
|
animate={animate}
|
||||||
/>
|
/>
|
||||||
{!isReadOnly && !isVersionHistoryMode && !isViewingOldVersion && (
|
{!isReadOnly && !isVersionHistoryMode && !isViewingOldVersion && (
|
||||||
<MetricSaveFilePopup metricId={metricId} />
|
<MetricSaveFilePopup metricId={metricId} />
|
||||||
|
|
|
@ -1,35 +1,42 @@
|
||||||
import { createFileRoute } from '@tanstack/react-router';
|
import { createFileRoute } from '@tanstack/react-router';
|
||||||
import { prefetchGetMetric } from '@/api/buster_rest/metrics';
|
import { ensureMetricData, prefetchGetMetric } from '@/api/buster_rest/metrics';
|
||||||
import { useGetUserBasicInfo } from '@/api/buster_rest/users/useGetUserInfo';
|
import { useGetMetricParams } from '@/context/Metrics/useGetMetricParams';
|
||||||
|
import { MetricViewChartController } from '@/controllers/MetricController/MetricViewChartController';
|
||||||
import { GetMetricScreenshotQuerySchema } from '../metrics.$metricId.index';
|
import { GetMetricScreenshotQuerySchema } from '../metrics.$metricId.index';
|
||||||
|
|
||||||
export const Route = createFileRoute('/screenshots/_content/metrics/$metricId/content')({
|
export const Route = createFileRoute('/screenshots/_content/metrics/$metricId/content')({
|
||||||
component: RouteComponent,
|
|
||||||
validateSearch: GetMetricScreenshotQuerySchema,
|
validateSearch: GetMetricScreenshotQuerySchema,
|
||||||
ssr: true,
|
ssr: true,
|
||||||
beforeLoad: async ({ context, params, search, matches }) => {
|
beforeLoad: async ({ context, params, search }) => {
|
||||||
const lastMatch = matches[matches.length - 1];
|
const [metric, metricData] = await Promise.all([
|
||||||
const res = await prefetchGetMetric(context.queryClient, {
|
prefetchGetMetric(context.queryClient, {
|
||||||
id: params.metricId,
|
id: params.metricId,
|
||||||
version_number: search.version_number,
|
version_number: search.version_number,
|
||||||
});
|
}),
|
||||||
if (!res) {
|
ensureMetricData(context.queryClient, {
|
||||||
|
id: params.metricId,
|
||||||
|
version_number: search.version_number,
|
||||||
|
}),
|
||||||
|
]);
|
||||||
|
if (!metric || !metricData) {
|
||||||
throw new Error('Metric not found');
|
throw new Error('Metric not found');
|
||||||
}
|
}
|
||||||
return {
|
return {
|
||||||
metric: res,
|
metric,
|
||||||
};
|
};
|
||||||
},
|
},
|
||||||
});
|
|
||||||
|
|
||||||
function RouteComponent() {
|
|
||||||
const { version_number, type, width, height } = Route.useSearch();
|
|
||||||
const x = useGetUserBasicInfo();
|
|
||||||
|
|
||||||
|
component: () => {
|
||||||
|
const { metricId, metricVersionNumber } = useGetMetricParams();
|
||||||
return (
|
return (
|
||||||
<div className="p-10 flex flex-col h-full border-red-500 border-10 items-center justify-center bg-blue-100 text-2xl text-blue-500">
|
<MetricViewChartController
|
||||||
<div> Hello "/screenshot/hello-world"!</div>
|
metricId={metricId}
|
||||||
<div className="truncate max-w-[300px]">{x?.name}</div>
|
versionNumber={metricVersionNumber}
|
||||||
</div>
|
className="h-full w-full p-0 border-0!"
|
||||||
|
cardClassName="max-h-full! border-0!"
|
||||||
|
readOnly
|
||||||
|
animate={false}
|
||||||
|
/>
|
||||||
);
|
);
|
||||||
}
|
},
|
||||||
|
});
|
||||||
|
|
Loading…
Reference in New Issue