2025-08-14 05:45:18 +08:00
|
|
|
import React, { useState } from 'react';
|
2025-07-13 22:44:48 +08:00
|
|
|
import { Text } from '@/components/ui/typography';
|
2025-08-14 05:45:18 +08:00
|
|
|
import { Button } from '@/components/ui/buttons';
|
|
|
|
import { Download4 } from '@/components/ui/icons';
|
2025-07-13 22:44:48 +08:00
|
|
|
import { cn } from '@/lib/classMerge';
|
2025-08-14 05:45:18 +08:00
|
|
|
import { downloadMetricFile } from '@/api/buster_rest/metrics/requests';
|
2025-07-13 22:44:48 +08:00
|
|
|
|
|
|
|
interface MetricDataTruncatedWarningProps {
|
|
|
|
className?: string;
|
2025-08-14 05:45:18 +08:00
|
|
|
metricId: string;
|
2025-07-13 22:44:48 +08:00
|
|
|
}
|
|
|
|
|
2025-07-15 01:36:03 +08:00
|
|
|
export const MetricDataTruncatedWarning: React.FC<MetricDataTruncatedWarningProps> = ({
|
2025-08-14 05:45:18 +08:00
|
|
|
className,
|
|
|
|
metricId
|
2025-07-13 22:44:48 +08:00
|
|
|
}) => {
|
2025-08-14 05:45:18 +08:00
|
|
|
const [isDownloading, setIsDownloading] = useState(false);
|
|
|
|
|
|
|
|
const handleDownload = async () => {
|
|
|
|
try {
|
|
|
|
setIsDownloading(true);
|
|
|
|
|
|
|
|
// Call the API to get the download URL
|
|
|
|
const response = await downloadMetricFile(metricId);
|
|
|
|
|
|
|
|
// Simply navigate to the download URL
|
|
|
|
// The response-content-disposition header will force a download
|
|
|
|
window.location.href = response.downloadUrl;
|
|
|
|
|
|
|
|
} catch (error) {
|
|
|
|
console.error('Failed to download metric file:', error);
|
|
|
|
// You might want to show an error toast here
|
|
|
|
} finally {
|
|
|
|
// Add a small delay before removing loading state since download happens async
|
|
|
|
setTimeout(() => {
|
|
|
|
setIsDownloading(false);
|
|
|
|
}, 1000);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2025-07-13 22:44:48 +08:00
|
|
|
return (
|
2025-07-15 01:36:03 +08:00
|
|
|
<div
|
2025-08-14 05:45:18 +08:00
|
|
|
className={cn('bg-background flex items-center justify-between rounded border p-4 shadow', className)}>
|
|
|
|
<div className="flex flex-col space-y-1">
|
|
|
|
<Text className="font-medium">This request returned more than 5,000 records</Text>
|
|
|
|
<Text size="xs" variant="secondary">
|
2025-08-14 05:56:44 +08:00
|
|
|
To see all records, you'll need to download the results.
|
2025-08-14 05:45:18 +08:00
|
|
|
</Text>
|
|
|
|
</div>
|
|
|
|
<Button
|
|
|
|
onClick={handleDownload}
|
|
|
|
loading={isDownloading}
|
|
|
|
variant="default"
|
|
|
|
className="ml-4"
|
|
|
|
prefix={<Download4 />}
|
|
|
|
>
|
|
|
|
Download
|
|
|
|
</Button>
|
2025-07-13 22:44:48 +08:00
|
|
|
</div>
|
|
|
|
);
|
2025-08-14 05:45:18 +08:00
|
|
|
};
|