import React, { useMemo, useState } from 'react'; import { ExcelRow, COLUMNS } from '../types'; import { ChevronDown, ChevronUp } from 'lucide-react'; import { cn } from '../lib/utils'; interface DataCompletenessProps { data: ExcelRow[]; headers: string[]; } export function DataCompleteness({ data, headers }: DataCompletenessProps) { const [sortCol, setSortCol] = useState('score'); const [sortDesc, setSortDesc] = useState(false); const [page, setPage] = useState(1); const pageSize = 50; const keyColumns = [ COLUMNS.ARTICLE_NO, COLUMNS.ARTICLE_NAME, COLUMNS.BARCODE, COLUMNS.TARIFF_CODE, COLUMNS.COUNTRY_ORIGIN, COLUMNS.RECOMMENDED_AGE, COLUMNS.DETAILS_DE, COLUMNS.DETAILS_EN, COLUMNS.LONG_DE, COLUMNS.LONG_EN, COLUMNS.SHORT_DE, COLUMNS.SHORT_EN, ]; const processedData = useMemo(() => { let result = data.map((row, index) => { let filledKeys = 0; keyColumns.forEach(col => { if (row[col]) filledKeys++; }); const score = Math.round((filledKeys / keyColumns.length) * 100); return { row, index, score }; }); result.sort((a, b) => { if (sortCol === 'score') { return sortDesc ? b.score - a.score : a.score - b.score; } else { const valA = String(a.row[sortCol] || ''); const valB = String(b.row[sortCol] || ''); return sortDesc ? valB.localeCompare(valA) : valA.localeCompare(valB); } }); return result; }, [data, sortCol, sortDesc]); const paginatedData = useMemo(() => { const start = (page - 1) * pageSize; return processedData.slice(start, start + pageSize); }, [processedData, page]); const totalPages = Math.ceil(processedData.length / pageSize); const handleSort = (col: number | 'score') => { if (sortCol === col) { setSortDesc(!sortDesc); } else { setSortCol(col); setSortDesc(col === 'score' ? false : false); // default asc } }; return (

Data Completeness

Evaluating 12 key fields per product.

{keyColumns.slice(2).map(col => ( ))} {paginatedData.map(({ row, index, score }) => ( {keyColumns.slice(2).map(col => ( ))} ))}
handleSort('score')} >
Score {sortCol === 'score' && ( sortDesc ? : )}
handleSort(COLUMNS.ARTICLE_NO)} >
Article No. {sortCol === COLUMNS.ARTICLE_NO && ( sortDesc ? : )}
handleSort(COLUMNS.ARTICLE_NAME)} >
Article Name {sortCol === COLUMNS.ARTICLE_NAME && ( sortDesc ? : )}
{headers[col]}
= 50 ? "bg-yellow-500" : "bg-red-500")} style={{ width: `${score}%` }} />
{score}%
{row[COLUMNS.ARTICLE_NO]} {row[COLUMNS.ARTICLE_NAME]} {row[col] ? ( ) : ( )}
Showing {Math.min((page - 1) * pageSize + 1, processedData.length)} to {Math.min(page * pageSize, processedData.length)} of {processedData.length} entries
Page {page} of {totalPages || 1}
); }