Skip to content

Commit e40c5f8

Browse files
Merge pull request #172 from hhftechnology/dev-dashboard
Dev dashboard
2 parents 22eeda8 + 91bb002 commit e40c5f8

35 files changed

Lines changed: 1076 additions & 765 deletions
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
'use client';
2+
3+
import { useEffect, useState } from 'react';
4+
import { Loader2 } from 'lucide-react';
5+
import DashboardWithFilters from '@/components/dashboard/DashboardWithFilters';
6+
import { DashboardShell } from '@/components/layout/DashboardShell';
7+
import { generateTimeSeriesLogs } from '@/lib/demo';
8+
import { TraefikLog } from '@/lib/types';
9+
import { ErrorBoundary } from '@/components/ErrorBoundary';
10+
import { Badge } from '@/components/ui/badge';
11+
12+
// Get max logs display from environment variable (default: 1000)
13+
const MAX_LOGS_DISPLAY = parseInt(process.env.NEXT_PUBLIC_MAX_LOGS_DISPLAY || '1000', 10);
14+
15+
export default function DemoDashboardClient() {
16+
const [logs, setLogs] = useState<TraefikLog[]>([]);
17+
const [loading, setLoading] = useState(true);
18+
const [lastUpdate, setLastUpdate] = useState<Date>(new Date());
19+
20+
useEffect(() => {
21+
const initialLogs = generateTimeSeriesLogs(60, 10);
22+
setLogs(initialLogs);
23+
setLoading(false);
24+
25+
const interval = setInterval(() => {
26+
setLogs(prevLogs => {
27+
const newLogs = generateTimeSeriesLogs(1, 10);
28+
const updatedLogs = [...newLogs, ...prevLogs].slice(0, MAX_LOGS_DISPLAY);
29+
setLastUpdate(new Date());
30+
return updatedLogs;
31+
});
32+
}, 5000);
33+
34+
return () => clearInterval(interval);
35+
}, []);
36+
37+
if (loading) {
38+
return (
39+
<DashboardShell title="Demo Mode" showControls={false}>
40+
<div className="flex items-center justify-center h-[60vh]">
41+
<div className="text-center">
42+
<Loader2 className="h-12 w-12 animate-spin text-primary mx-auto mb-4" />
43+
<p className="text-muted-foreground">Loading demo dashboard...</p>
44+
</div>
45+
</div>
46+
</DashboardShell>
47+
);
48+
}
49+
50+
return (
51+
<DashboardShell
52+
title="Demo Mode"
53+
connected={true}
54+
lastUpdate={lastUpdate}
55+
logsCount={logs.length}
56+
showControls={true}
57+
agentName="Demo Agent"
58+
>
59+
<div className="mb-4">
60+
<Badge variant="secondary" className="gap-2">
61+
<span className="w-2 h-2 bg-yellow-500 rounded-full animate-pulse" />
62+
Demo Mode - Using simulated data
63+
</Badge>
64+
</div>
65+
<ErrorBoundary>
66+
<DashboardWithFilters logs={logs} demoMode={true} />
67+
</ErrorBoundary>
68+
</DashboardShell>
69+
);
70+
}
Lines changed: 9 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -1,67 +1,16 @@
1-
'use client';
1+
import { notFound } from 'next/navigation';
2+
import DemoDashboardClient from './DemoDashboardClient';
23

3-
import { useEffect, useState } from 'react';
4-
import { Loader2 } from 'lucide-react';
5-
import DashboardWithFilters from '@/components/dashboard/DashboardWithFilters';
6-
import { DashboardShell } from '@/components/layout/DashboardShell';
7-
import { generateTimeSeriesLogs } from '@/lib/demo';
8-
import { TraefikLog } from '@/lib/types';
9-
import { ErrorBoundary } from '@/components/ErrorBoundary';
10-
import { Badge } from '@/components/ui/badge';
4+
export const dynamic = 'force-dynamic';
115

126
export default function DemoDashboardPage() {
13-
const [logs, setLogs] = useState<TraefikLog[]>([]);
14-
const [loading, setLoading] = useState(true);
15-
const [lastUpdate, setLastUpdate] = useState<Date>(new Date());
7+
const showDemoPage =
8+
(process.env.NEXT_PUBLIC_SHOW_DEMO_PAGE ?? process.env.SHOW_DEMO_PAGE ?? 'true') !== 'false';
169

17-
useEffect(() => {
18-
const initialLogs = generateTimeSeriesLogs(60, 10);
19-
setLogs(initialLogs);
20-
setLoading(false);
21-
22-
const interval = setInterval(() => {
23-
setLogs(prevLogs => {
24-
const newLogs = generateTimeSeriesLogs(1, 10);
25-
const updatedLogs = [...newLogs, ...prevLogs].slice(0, 1000);
26-
setLastUpdate(new Date());
27-
return updatedLogs;
28-
});
29-
}, 5000);
30-
31-
return () => clearInterval(interval);
32-
}, []);
33-
34-
if (loading) {
35-
return (
36-
<DashboardShell title="Demo Mode" showControls={false}>
37-
<div className="flex items-center justify-center h-[60vh]">
38-
<div className="text-center">
39-
<Loader2 className="h-12 w-12 animate-spin text-primary mx-auto mb-4" />
40-
<p className="text-muted-foreground">Loading demo dashboard...</p>
41-
</div>
42-
</div>
43-
</DashboardShell>
44-
);
10+
if (!showDemoPage) {
11+
// Hide demo route completely when disabled
12+
return notFound();
4513
}
4614

47-
return (
48-
<DashboardShell
49-
title="Demo Mode"
50-
connected={true}
51-
lastUpdate={lastUpdate}
52-
logsCount={logs.length}
53-
showControls={true}
54-
agentName="Demo Agent"
55-
>
56-
<div className="mb-4">
57-
<Badge variant="secondary" className="gap-2">
58-
<span className="w-2 h-2 bg-yellow-500 rounded-full animate-pulse" />
59-
Demo Mode - Using simulated data
60-
</Badge>
61-
</div>
62-
<ErrorBoundary>
63-
<DashboardWithFilters logs={logs} demoMode={true} />
64-
</ErrorBoundary>
65-
</DashboardShell>
66-
);
15+
return <DemoDashboardClient />;
6716
}

0 commit comments

Comments
 (0)