forked from PinSpace-Org/GistPin
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLocationTable.tsx
More file actions
52 lines (48 loc) · 1.49 KB
/
Copy pathLocationTable.tsx
File metadata and controls
52 lines (48 loc) · 1.49 KB
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
'use client';
import Sparkline from '@/components/charts/Sparkline';
import { useLocationDataQuery } from '@/lib/analytics-queries';
import ExportButton from '@/components/ui/ExportButton';
import { exportRowsToCsv } from '@/lib/export';
import { TableSkeleton } from '@/components/ui/ChartSkeleton';
export default function LocationTable() {
const { data, isLoading, error } = useLocationDataQuery();
if (isLoading || !data) return <TableSkeleton />;
if (error) return <p>Unable to load location trends.</p>;
return (
<div>
<ExportButton
onExport={(onProgress) =>
exportRowsToCsv({
filenamePrefix: 'location-table',
filters: { points_per_location: 7 },
rows: data.map((row) => ({
location: row.location,
...Object.fromEntries(row.values.map((v, i) => [`day_${i + 1}`, v])),
direction: row.values.at(-1)! > row.values[0] ? 'up' : 'down',
})),
onProgress,
})
}
/>
<table>
<thead>
<tr>
<th>Location</th>
<th>Trend</th>
</tr>
</thead>
<tbody>
{data.map((row) => (
<tr key={row.location}>
<td>{row.location}</td>
<td>
<Sparkline data={row.values} />
{row.values.at(-1)! > row.values[0] ? '↑' : '↓'}
</td>
</tr>
))}
</tbody>
</table>
</div>
);
}