feat: enhance Jira dashboard with export functionality and sprint comparison
- 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.
This commit is contained in:
58
hooks/useJiraExport.ts
Normal file
58
hooks/useJiraExport.ts
Normal file
@@ -0,0 +1,58 @@
|
||||
'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
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user