🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
76 lines
2.4 KiB
TypeScript
76 lines
2.4 KiB
TypeScript
import { DataService } from '../services/dataService';
|
|
|
|
export const exportToJSON = (dataService: DataService): void => {
|
|
const dimensions = dataService.getDimensions();
|
|
const exportData = {
|
|
dimensions: dimensions.map(dimension => ({
|
|
...dimension,
|
|
kpis: dataService.getKPIsByDimension(dimension.id).map(kpi => ({
|
|
...kpi,
|
|
checks: dataService.getChecksByKPI(kpi.id)
|
|
}))
|
|
})),
|
|
exportedAt: new Date().toISOString()
|
|
};
|
|
|
|
const blob = new Blob([JSON.stringify(exportData, null, 2)], {
|
|
type: 'application/json'
|
|
});
|
|
|
|
const url = URL.createObjectURL(blob);
|
|
const link = document.createElement('a');
|
|
link.href = url;
|
|
link.download = `due-diligence-export-${new Date().toISOString().split('T')[0]}.json`;
|
|
document.body.appendChild(link);
|
|
link.click();
|
|
document.body.removeChild(link);
|
|
URL.revokeObjectURL(url);
|
|
};
|
|
|
|
export const exportToCSV = (dataService: DataService): void => {
|
|
const dimensions = dataService.getDimensions();
|
|
const rows: string[] = [
|
|
'Dimension,KPI,Check Question,Check Type,Current Value,Expected Value,Is Completed,Reference URL,Comment,Created At'
|
|
];
|
|
|
|
dimensions.forEach(dimension => {
|
|
const kpis = dataService.getKPIsByDimension(dimension.id);
|
|
kpis.forEach(kpi => {
|
|
const checks = dataService.getChecksByKPI(kpi.id);
|
|
checks.forEach(check => {
|
|
const row = [
|
|
escapeCSV(dimension.name),
|
|
escapeCSV(kpi.name),
|
|
escapeCSV(check.question),
|
|
escapeCSV(check.check_type),
|
|
escapeCSV(check.current_value || ''),
|
|
escapeCSV(check.expected_value || ''),
|
|
check.is_completed ? 'Yes' : 'No',
|
|
escapeCSV(check.reference_url || ''),
|
|
escapeCSV(check.comment || ''),
|
|
escapeCSV(check.created_at || '')
|
|
].join(',');
|
|
rows.push(row);
|
|
});
|
|
});
|
|
});
|
|
|
|
const csvContent = rows.join('\n');
|
|
const blob = new Blob([csvContent], { type: 'text/csv' });
|
|
|
|
const url = URL.createObjectURL(blob);
|
|
const link = document.createElement('a');
|
|
link.href = url;
|
|
link.download = `due-diligence-export-${new Date().toISOString().split('T')[0]}.csv`;
|
|
document.body.appendChild(link);
|
|
link.click();
|
|
document.body.removeChild(link);
|
|
URL.revokeObjectURL(url);
|
|
};
|
|
|
|
const escapeCSV = (value: string): string => {
|
|
if (value.includes(',') || value.includes('"') || value.includes('\n')) {
|
|
return `"${value.replace(/"/g, '""')}"`;
|
|
}
|
|
return value;
|
|
}; |