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 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238import { useState, useEffect, useMemo } from 'react'; import { loadDataset, type Dataset, getIgnoredIds, toggleIgnoreId, bulkIgnoreIds } from '../services/DataManager'; import Overview from './Overview'; import ChartSection from './ChartSection'; import TableSection from './TableSection'; import { Loader2, AlertCircle, Trash2, Plus } from 'lucide-react'; const Dashboard = () => { // Default URL provided by user const defaultUrl = 'https://api-staging.equalifyapp.com/public/getAuditTable?id=bbdb555b-cf97-43fd-896b-0b2d162c8cf3&page=1&pageSize=100&contentType=all&sortBy=created_at&sortOrder=desc&status=active'; const [inputUrl, setInputUrl] = useState(''); const [datasets, setDatasets] = useState<Dataset[]>([]); const [loading, setLoading] = useState(false); const [ignoredIds, setIgnoredIds] = useState<string[]>([]); const [error, setError] = useState<string | null>(null); // Initial Load useEffect(() => { setIgnoredIds(getIgnoredIds()); // Load default dataset if no datasets are loaded if (datasets.length === 0) { handleLoadUrl(defaultUrl); } }, []); const handleLoadUrl = async (url: string) => { setLoading(true); setError(null); try { const newDataset = await loadDataset(url); setDatasets(prev => [...prev, newDataset]); setInputUrl(''); // Clear input on success } catch (err: any) { console.error("Failed to load data", err); setError(err.message || "Failed to load dataset"); } finally { setLoading(false); } }; const handleLoadClick = () => { if (inputUrl) { const trimmed = inputUrl.trim(); if (trimmed.startsWith('http')) { handleLoadUrl(trimmed); } else { setError("Please enter a valid URL starting with http:// or https://"); } } }; const handleRemoveDataset = (id: string) => { setDatasets(prev => prev.filter(d => d.id !== id)); }; // Derived State const allBlockers = useMemo(() => { return datasets.flatMap(d => d.blockers); }, [datasets]); const activeData = useMemo(() => { return allBlockers.filter(d => !ignoredIds.includes(d.id)); }, [allBlockers, ignoredIds]); const datasetIgnoredCount = useMemo(() => { return allBlockers.filter(d => ignoredIds.includes(d.id)).length; }, [allBlockers, ignoredIds]); const totalUniqueUrls = useMemo(() => { return new Set(allBlockers.map(d => d.url)).size; }, [allBlockers]); const handleToggleIgnore = (id: string) => { const newIds = toggleIgnoreId(id); setIgnoredIds(newIds); }; const handleBulkIgnore = (ids: string[], shouldIgnore: boolean) => { const newIds = bulkIgnoreIds(ids, shouldIgnore); setIgnoredIds(newIds); }; return ( <div className="container" style={{ paddingBottom: '4rem' }}> {/* Header / Selector */} <div style={{ display: 'flex', justifyContent: 'space-between', alignItems: 'center', margin: '2rem 0', flexWrap: 'wrap', gap: '1rem' }}> <div> <h1 style={{ fontSize: '1.5rem', fontWeight: 700, color: 'var(--neutral-900)' }}>Equalify Data Navigator</h1> <p style={{ color: 'var(--neutral-500)', marginTop: '0.25rem' }}>Accessibility Insights Dashboard</p> </div> <div style={{ flex: 1, minWidth: '300px', maxWidth: '800px' }}> <div style={{ display: 'flex', alignItems: 'center', gap: '0.5rem' }}> <input type="text" placeholder="Enter API URL..." value={inputUrl} onChange={(e) => setInputUrl(e.target.value)} onKeyDown={(e) => { if (e.key === 'Enter') handleLoadClick(); }} style={{ padding: '0.625rem', borderRadius: 'var(--radius-md)', border: '1px solid var(--neutral-300)', flex: 1, fontSize: '0.875rem', outline: 'none', transition: 'border-color 0.2s' }} /> <button className="btn btn-primary" onClick={handleLoadClick} disabled={loading} style={{ whiteSpace: 'nowrap', display: 'flex', alignItems: 'center', gap: '0.5rem' }} > {loading ? <Loader2 className="animate-spin" size={16} /> : <Plus size={16} />} Add Dataset </button> </div> </div> </div> {error && ( <div style={{ padding: '1rem', background: '#FEF2F2', border: '1px solid #FECACA', borderRadius: 'var(--radius-md)', color: '#B91C1C', marginBottom: '2rem', display: 'flex', alignItems: 'flex-start', gap: '0.75rem', fontSize: '0.9rem' }}> <AlertCircle size={20} style={{ marginTop: '0.1rem', flexShrink: 0 }} /> <div> <div style={{ fontWeight: 600 }}>Data Loading Issue</div> <div style={{ marginTop: '0.25rem' }}>{error}</div> </div> </div> )} {/* Loaded Datasets List */} {datasets.length > 0 && ( <div style={{ marginBottom: '2rem', display: 'flex', flexWrap: 'wrap', gap: '0.75rem' }}> {datasets.map(ds => ( <div key={ds.id} style={{ display: 'flex', alignItems: 'center', gap: '0.75rem', padding: '0.5rem 0.75rem', background: 'white', border: '1px solid var(--neutral-200)', borderRadius: '2rem', fontSize: '0.875rem', boxShadow: '0 1px 2px rgba(0,0,0,0.05)' }}> <span style={{ fontWeight: 500, color: 'var(--neutral-700)' }}>{ds.name}</span> <span style={{ color: 'var(--neutral-400)', fontSize: '0.75rem' }}>({ds.blockers.length} items)</span> <button type="button" onClick={() => handleRemoveDataset(ds.id)} style={{ display: 'flex', alignItems: 'center', justifyContent: 'center', color: 'var(--neutral-400)', cursor: 'pointer', padding: '0.4rem', borderRadius: '50%', transition: 'all 0.2s', background: 'var(--neutral-100)', border: 'none', marginLeft: '0.25rem' }} onMouseOver={(e) => { e.currentTarget.style.color = '#B91C1C'; e.currentTarget.style.background = '#FEE2E2'; }} onMouseOut={(e) => { e.currentTarget.style.color = 'var(--neutral-400)'; e.currentTarget.style.background = 'var(--neutral-100)'; }} title="Remove dataset" > <Trash2 size={16} /> </button> </div> ))} </div> )} {loading && datasets.length === 0 ? ( <div style={{ height: '400px', display: 'flex', flexDirection: 'column', alignItems: 'center', justifyContent: 'center', color: 'var(--neutral-500)' }}> <Loader2 className="animate-spin" size={48} style={{ animation: 'spin 1s linear infinite' }} /> <p style={{ marginTop: '1rem' }}>Loading dataset...</p> <style>{`@keyframes spin { from { transform: rotate(0deg); } to { transform: rotate(360deg); } } `}</style> </div> ) : ( <> <Overview activeBlockers={activeData.length} uniqueUrls={totalUniqueUrls} ignoredBlockers={datasetIgnoredCount} /> <ChartSection aggregatedData={activeData} datasets={datasets} /> <TableSection data={allBlockers} ignoredIds={ignoredIds} onToggleIgnore={handleToggleIgnore} onBulkIgnore={handleBulkIgnore} /> </> )} </div> ); }; export default Dashboard;