- Added export options for CSV and JSON in `JiraDashboardPageClient`, allowing users to download metrics easily. - Integrated `SprintComparison` component to visualize inter-sprint trends and predictions. - Updated TODO.md to reflect completion of export metrics and sprint comparison features.
59 lines
1.8 KiB
TypeScript
59 lines
1.8 KiB
TypeScript
'use client';
|
|
|
|
import { useState, useTransition } from 'react';
|
|
import { exportJiraAnalytics, ExportFormat } from '@/actions/jira-export';
|
|
|
|
export function useJiraExport() {
|
|
const [isExporting, startTransition] = useTransition();
|
|
const [error, setError] = useState<string | null>(null);
|
|
|
|
const exportAnalytics = (format: ExportFormat = 'csv') => {
|
|
startTransition(async () => {
|
|
try {
|
|
setError(null);
|
|
|
|
const result = await exportJiraAnalytics(format);
|
|
|
|
if (result.success && result.data && result.filename) {
|
|
// Créer un blob et déclencher le téléchargement
|
|
const mimeType = format === 'json' ? 'application/json' : 'text/csv';
|
|
const blob = new Blob([result.data], { type: mimeType });
|
|
|
|
// Créer un lien temporaire pour le téléchargement
|
|
const url = window.URL.createObjectURL(blob);
|
|
const link = document.createElement('a');
|
|
link.href = url;
|
|
link.download = result.filename;
|
|
|
|
// Déclencher le téléchargement
|
|
document.body.appendChild(link);
|
|
link.click();
|
|
|
|
// Nettoyer
|
|
document.body.removeChild(link);
|
|
window.URL.revokeObjectURL(url);
|
|
|
|
console.log(`✅ Export ${format.toUpperCase()} réussi: ${result.filename}`);
|
|
} else {
|
|
setError(result.error || 'Erreur lors de l\'export');
|
|
}
|
|
} catch (err) {
|
|
const errorMessage = err instanceof Error ? err.message : 'Erreur lors de l\'export';
|
|
setError(errorMessage);
|
|
console.error('Erreur export analytics:', err);
|
|
}
|
|
});
|
|
};
|
|
|
|
const exportCSV = () => exportAnalytics('csv');
|
|
const exportJSON = () => exportAnalytics('json');
|
|
|
|
return {
|
|
isExporting,
|
|
error,
|
|
exportCSV,
|
|
exportJSON,
|
|
exportAnalytics
|
|
};
|
|
}
|