Spaces:
Running
Running
File size: 1,869 Bytes
c7fb8cf | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 | /**
* ExportButton.jsx
* Downloads ranked results as a CSV file.
*/
import { Download } from 'lucide-react';
function toCSV(candidates, jobTitle) {
const headers = [
'Rank', 'Name', 'File', 'Status', 'Final Score', 'Match %',
'Skills Score', 'Experience Score', 'Education Score', 'Certs Score',
'Projects Score', 'Bonus Score', 'TF-IDF Similarity %',
'Matched Skills', 'Missing Skills', 'Experience Years',
'Education', 'Certifications', 'Location', 'Languages'
];
const rows = candidates.map(c => [
c.rank,
`"${c.name}"`,
`"${c.filename}"`,
c.status,
c.final_score,
c.match_percent,
c.skills_score,
c.experience_score,
c.education_score,
c.certs_score,
c.projects_score,
c.bonus_score,
c.tfidf_similarity,
`"${c.matched_skills.join('; ')}"`,
`"${c.missing_skills.join('; ')}"`,
c.experience_years,
`"${c.education_degree} - ${c.education_field}"`,
`"${c.certifications.join('; ')}"`,
`"${c.location}"`,
`"${c.languages.join('; ')}"`,
]);
return [headers.join(','), ...rows.map(r => r.join(','))].join('\n');
}
export default function ExportButton({ candidates, jobTitle }) {
const handleExport = () => {
const csv = toCSV(candidates, jobTitle);
const blob = new Blob([csv], { type: 'text/csv;charset=utf-8;' });
const url = URL.createObjectURL(blob);
const link = document.createElement('a');
link.href = url;
link.download = `HireIQ_${jobTitle.replace(/\s+/g, '_')}_results.csv`;
document.body.appendChild(link);
link.click();
document.body.removeChild(link);
URL.revokeObjectURL(url);
};
return (
<button
id="export-csv-btn"
onClick={handleExport}
className="btn-secondary flex items-center gap-2 text-sm"
>
<Download size={16} />
Export CSV
</button>
);
}
|