feat: Remove test scenario functionality and update related components for real MQTT data usage
This commit is contained in:
parent
fd8cacd62b
commit
738ae59c69
5 changed files with 36 additions and 290 deletions
|
@ -1,7 +1,7 @@
|
|||
import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card"
|
||||
import { Button } from "@/components/ui/button"
|
||||
import { Badge } from "@/components/ui/badge"
|
||||
import { AlertTriangle, VolumeX, CheckCircle, Bell, TestTube } from "lucide-react"
|
||||
import { AlertTriangle, VolumeX, CheckCircle, Bell } from "lucide-react"
|
||||
import { useBedPressureStore } from "@/stores/bedPressureStore"
|
||||
import { useEffect, useState } from "react"
|
||||
|
||||
|
@ -12,35 +12,13 @@ export function AlarmDashboard() {
|
|||
acknowledgeAlarm,
|
||||
silenceAllAlarms
|
||||
} = useBedPressureStore()
|
||||
|
||||
const [unsilencedAlarms, setUnsilencedAlarms] = useState(0)
|
||||
const [testScenario, setTestScenario] = useState<string>('')
|
||||
|
||||
// Update alarm counts
|
||||
useEffect(() => {
|
||||
const unsilenced = activeAlarms.filter(alarm => !alarm.silenced).length
|
||||
setUnsilencedAlarms(unsilenced)
|
||||
}, [activeAlarms])
|
||||
|
||||
const handleTestScenario = async (scenario: string) => {
|
||||
try {
|
||||
setTestScenario(scenario)
|
||||
const response = await fetch('/api/test-scenarios', {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ scenario })
|
||||
})
|
||||
|
||||
if (response.ok) {
|
||||
console.log(`Applied ${scenario} test scenario`)
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Failed to apply test scenario:', error)
|
||||
} finally {
|
||||
setTimeout(() => setTestScenario(''), 2000)
|
||||
}
|
||||
}
|
||||
|
||||
const getSystemStatus = () => {
|
||||
const alarmCount = activeAlarms.filter(a => a.type === 'alarm' && !a.silenced).length
|
||||
const warningCount = activeAlarms.filter(a => a.type === 'warning' && !a.silenced).length
|
||||
|
@ -71,9 +49,8 @@ export function AlarmDashboard() {
|
|||
<div>
|
||||
<CardTitle className={`text-lg ${systemStatus.status === 'ALARM' ? 'text-red-700' : systemStatus.status === 'WARNING' ? 'text-yellow-700' : 'text-green-700'}`}>
|
||||
SYSTEM STATUS: {systemStatus.status}
|
||||
</CardTitle>
|
||||
<p className="text-sm text-gray-600">
|
||||
{isConnected ? 'Hardware Connected' : 'Using Mock Data'} •
|
||||
</CardTitle> <p className="text-sm text-gray-600">
|
||||
{isConnected ? 'Hardware Connected' : 'Hardware Offline'} •
|
||||
{activeAlarms.length} Active Alarms •
|
||||
{unsilencedAlarms} Unsilenced
|
||||
</p>
|
||||
|
@ -149,45 +126,9 @@ export function AlarmDashboard() {
|
|||
<p className="text-2xl font-bold text-green-600">
|
||||
{activeAlarms.filter(a => a.acknowledged).length}
|
||||
</p>
|
||||
</CardContent>
|
||||
</Card>
|
||||
</CardContent> </Card>
|
||||
</div>
|
||||
|
||||
{/* Test Scenarios */}
|
||||
<Card>
|
||||
<CardHeader>
|
||||
<CardTitle className="flex items-center gap-2">
|
||||
<TestTube className="w-5 h-5" />
|
||||
Test Scenarios
|
||||
</CardTitle>
|
||||
</CardHeader>
|
||||
<CardContent>
|
||||
<div className="grid grid-cols-2 md:grid-cols-5 gap-2">
|
||||
{[
|
||||
{ name: 'normal', label: 'Normal', color: 'bg-green-100 text-green-700 hover:bg-green-200' },
|
||||
{ name: 'warning', label: 'Warning', color: 'bg-yellow-100 text-yellow-700 hover:bg-yellow-200' },
|
||||
{ name: 'alarm', label: 'Alarm', color: 'bg-red-100 text-red-700 hover:bg-red-200' },
|
||||
{ name: 'escalation', label: 'Escalation', color: 'bg-orange-100 text-orange-700 hover:bg-orange-200' },
|
||||
{ name: 'mixed', label: 'Mixed', color: 'bg-purple-100 text-purple-700 hover:bg-purple-200' }
|
||||
].map(scenario => (
|
||||
<Button
|
||||
key={scenario.name}
|
||||
variant="outline"
|
||||
size="sm"
|
||||
onClick={() => handleTestScenario(scenario.name)}
|
||||
disabled={testScenario === scenario.name}
|
||||
className={`${scenario.color} border-0`}
|
||||
>
|
||||
{testScenario === scenario.name ? 'Applied!' : scenario.label}
|
||||
</Button>
|
||||
))}
|
||||
</div>
|
||||
<p className="text-xs text-gray-500 mt-2">
|
||||
Click to simulate different alarm scenarios for testing
|
||||
</p>
|
||||
</CardContent>
|
||||
</Card>
|
||||
|
||||
{/* Recent Alarm Activity */}
|
||||
<Card>
|
||||
<CardHeader>
|
||||
|
|
|
@ -143,10 +143,9 @@ export function SensorDetailModal() {
|
|||
</SelectContent>
|
||||
</Select>
|
||||
</div>
|
||||
</div>
|
||||
<p className="text-sm text-gray-600">
|
||||
</div> <p className="text-sm text-gray-600">
|
||||
Showing data for the last {getTimespanLabel(selectedTimespan)}
|
||||
{sensor.source === 'hardware' ? ' (Real sensor data)' : ' (Mock data)'}
|
||||
{sensor.source === 'hardware' ? ' (Real sensor data)' : ' (Hardware offline - no data)'}
|
||||
</p>
|
||||
</CardHeader>
|
||||
<CardContent>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue