mirror of https://github.com/buster-so/buster.git
download data query params
This commit is contained in:
parent
d9cde77d0f
commit
6d4f293a2f
|
@ -1,4 +1,4 @@
|
|||
import { MetricDownloadParamsSchema } from '@buster/server-shared';
|
||||
import { MetricDownloadParamsSchema, MetricDownloadQueryParamsSchema } from '@buster/server-shared';
|
||||
import { zValidator } from '@hono/zod-validator';
|
||||
import { Hono } from 'hono';
|
||||
import { standardErrorHandler } from '../../../../../utils/response';
|
||||
|
@ -6,14 +6,20 @@ import { downloadMetricFileHandler } from './download-metric-file';
|
|||
|
||||
const app = new Hono()
|
||||
// GET /metric_files/:id/download - Download metric file data as CSV
|
||||
.get('/', zValidator('param', MetricDownloadParamsSchema), async (c) => {
|
||||
const { id } = c.req.valid('param');
|
||||
const user = c.get('busterUser');
|
||||
.get(
|
||||
'/',
|
||||
zValidator('param', MetricDownloadParamsSchema),
|
||||
zValidator('query', MetricDownloadQueryParamsSchema),
|
||||
async (c) => {
|
||||
const { id } = c.req.valid('param');
|
||||
// const { report_file_id } = c.req.valid('query');
|
||||
const user = c.get('busterUser');
|
||||
|
||||
const response = await downloadMetricFileHandler(id, user);
|
||||
const response = await downloadMetricFileHandler(id, user);
|
||||
|
||||
return c.json(response);
|
||||
})
|
||||
return c.json(response);
|
||||
}
|
||||
)
|
||||
.onError(standardErrorHandler);
|
||||
|
||||
export default app;
|
||||
|
|
|
@ -9,11 +9,13 @@ import { cn } from '@/lib/classMerge';
|
|||
interface MetricDataTruncatedWarningProps {
|
||||
className?: string;
|
||||
metricId: string;
|
||||
metricVersionNumber: number | undefined;
|
||||
}
|
||||
|
||||
export const MetricDataTruncatedWarning: React.FC<MetricDataTruncatedWarningProps> = ({
|
||||
className,
|
||||
metricId,
|
||||
metricVersionNumber,
|
||||
}) => {
|
||||
const {
|
||||
mutateAsync: handleDownload,
|
||||
|
@ -42,7 +44,7 @@ export const MetricDataTruncatedWarning: React.FC<MetricDataTruncatedWarningProp
|
|||
</Text>
|
||||
</div>
|
||||
<Button
|
||||
onClick={() => handleDownload({ id: metricId })}
|
||||
onClick={() => handleDownload({ id: metricId, metric_version_number: metricVersionNumber })}
|
||||
loading={isGettingFile}
|
||||
variant={hasError ? 'danger' : 'default'}
|
||||
className="ml-4"
|
||||
|
|
|
@ -29,7 +29,9 @@ export const MetricViewChart: React.FC<{
|
|||
readOnly={readOnly}
|
||||
className={cardClassName}
|
||||
/>
|
||||
{hasMoreRecords && <MetricDataTruncatedWarning metricId={metricId} />}
|
||||
{hasMoreRecords && (
|
||||
<MetricDataTruncatedWarning metricId={metricId} metricVersionNumber={versionNumber} />
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
|
|
|
@ -164,10 +164,6 @@ export const useDownloadMetricDataCSV = ({
|
|||
metricVersionNumber: number | undefined;
|
||||
cacheDataId?: string;
|
||||
}) => {
|
||||
const { data: metricData } = useGetMetricData(
|
||||
{ id: metricId, versionNumber: metricVersionNumber, cacheDataId },
|
||||
{ enabled: false }
|
||||
);
|
||||
const { mutateAsync: handleDownload, isPending: isDownloading } = useDownloadMetricFile();
|
||||
|
||||
return useMemo(
|
||||
|
@ -176,14 +172,16 @@ export const useDownloadMetricDataCSV = ({
|
|||
value: 'download-csv',
|
||||
icon: <Download4 />,
|
||||
loading: isDownloading,
|
||||
|
||||
onClick: async () => {
|
||||
const data = metricData?.data;
|
||||
if (data) {
|
||||
await handleDownload({ id: metricId, report_file_id: cacheDataId });
|
||||
}
|
||||
await handleDownload({
|
||||
id: metricId,
|
||||
report_file_id: cacheDataId,
|
||||
metric_version_number: metricVersionNumber,
|
||||
});
|
||||
},
|
||||
}),
|
||||
[metricData, isDownloading]
|
||||
[isDownloading]
|
||||
);
|
||||
};
|
||||
|
||||
|
|
|
@ -8,6 +8,7 @@ export const MetricDownloadParamsSchema = z.object({
|
|||
});
|
||||
export const MetricDownloadQueryParamsSchema = z.object({
|
||||
report_file_id: z.string().uuid('Report file ID must be a valid UUID').optional(),
|
||||
metric_version_number: z.number().optional(),
|
||||
});
|
||||
|
||||
export type MetricDownloadParams = z.infer<typeof MetricDownloadParamsSchema>;
|
||||
|
|
Loading…
Reference in New Issue