Update .gitignore to exclude user-uploaded CSV files and remove the group-dev-ad.csv file. Refactor page.tsx to handle CSV file uploads, localStorage management, and enhance user interface for data management. Remove API route for fetching people data from CSV.
This commit is contained in:
71
lib/csv-parser-client.ts
Normal file
71
lib/csv-parser-client.ts
Normal file
@@ -0,0 +1,71 @@
|
||||
export interface Person {
|
||||
nom: string;
|
||||
description: string;
|
||||
type: string;
|
||||
}
|
||||
|
||||
export function parseCSVFromText(content: string): Person[] {
|
||||
const lines = content.split('\n');
|
||||
|
||||
// Skip header line
|
||||
const dataLines = lines.slice(1);
|
||||
|
||||
const people: Person[] = [];
|
||||
|
||||
for (const line of dataLines) {
|
||||
if (!line.trim()) continue;
|
||||
|
||||
// Parse CSV line (handling quoted fields)
|
||||
const fields = parseCSVLine(line);
|
||||
|
||||
if (fields.length >= 7) {
|
||||
const nom = fields[4]?.trim() || '';
|
||||
const description = fields[5]?.trim() || '';
|
||||
const type = fields[6]?.trim() || '';
|
||||
|
||||
// Skip empty names and service accounts
|
||||
if (nom && !nom.startsWith('svc.') && !nom.startsWith('!') && nom !== 'datascience') {
|
||||
people.push({
|
||||
nom,
|
||||
description,
|
||||
type,
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return people;
|
||||
}
|
||||
|
||||
function parseCSVLine(line: string): string[] {
|
||||
const fields: string[] = [];
|
||||
let currentField = '';
|
||||
let inQuotes = false;
|
||||
|
||||
for (let i = 0; i < line.length; i++) {
|
||||
const char = line[i];
|
||||
|
||||
if (char === '"') {
|
||||
if (inQuotes && line[i + 1] === '"') {
|
||||
// Escaped quote
|
||||
currentField += '"';
|
||||
i++;
|
||||
} else {
|
||||
// Toggle quote state
|
||||
inQuotes = !inQuotes;
|
||||
}
|
||||
} else if (char === ',' && !inQuotes) {
|
||||
// Field separator
|
||||
fields.push(currentField);
|
||||
currentField = '';
|
||||
} else {
|
||||
currentField += char;
|
||||
}
|
||||
}
|
||||
|
||||
// Add last field
|
||||
fields.push(currentField);
|
||||
|
||||
return fields.map(field => field.trim());
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user