Files
CPLv4.0/components/main/system/DetailModal.tsx
ISA b1eb3c46a8 feat: Detailansicht auf dynamische Redux-Datenquellen umgestellt
- DetailModal.tsx überarbeitet, um Redux-Daten je nach ausgewähltem Key (+5V, +15V, -15V, -98V, ADC Temp, CPU Temp) anzuzeigen
- Zeitraum-Auswahl (DIA0, DIA1, DIA2) wird berücksichtigt und löst passenden Thunk aus
- Redux-State-Struktur vollständig integriert für Systemspannungen und Temperaturen
- Chart-Anzeige jetzt dynamisch und erweiterbar
2025-07-03 12:24:53 +02:00

117 lines
3.4 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

// components/main/system/DetailModal.tsx
"use client";
import React from "react";
import { Line } from "react-chartjs-2";
import { useSelector } from "react-redux";
import { RootState } from "@/redux/store";
type Props = {
isOpen: boolean;
selectedKey: string | null;
onClose: () => void;
zeitraum: "DIA0" | "DIA1" | "DIA2";
setZeitraum: (typ: "DIA0" | "DIA1" | "DIA2") => void;
};
type ReduxDataEntry = { t: string; i: number };
export const DetailModal = ({
isOpen,
selectedKey,
onClose,
zeitraum,
setZeitraum,
}: Props) => {
const reduxData: ReduxDataEntry[] = useSelector((state: RootState) => {
switch (selectedKey) {
case "+5V":
return state.systemspannung5Vplus[zeitraum] as ReduxDataEntry[];
case "+15V":
return state.systemspannung15Vplus[zeitraum] as ReduxDataEntry[];
case "-15V":
return state.systemspannung15Vminus[zeitraum] as ReduxDataEntry[];
case "-98V":
return state.systemspannung98Vminus[zeitraum] as ReduxDataEntry[];
case "ADC Temp":
return state.temperaturAdWandler[zeitraum] as ReduxDataEntry[];
case "CPU Temp":
return state.temperaturProzessor[zeitraum] as ReduxDataEntry[];
default:
return [] as ReduxDataEntry[];
}
});
const labels = reduxData.map((e: ReduxDataEntry) => e.t);
const values = reduxData.map((e: ReduxDataEntry) => e.i);
const baseOptions = {
responsive: true,
maintainAspectRatio: false,
scales: {
y: {
beginAtZero: false,
grid: { color: "rgba(200,200,200,0.2)" },
title: { display: true, text: "Wert" },
},
x: {
grid: { color: "rgba(200,200,200,0.2)" },
title: { display: true, text: "Zeit" },
},
},
plugins: {
legend: { position: "bottom" as const },
title: { display: true, text: `Verlauf ${selectedKey}` },
},
};
if (!isOpen || !selectedKey) return null;
return (
<div className="fixed inset-0 bg-black bg-opacity-40 flex items-center justify-center z-50">
<div className="bg-white p-6 rounded-xl w-[50%] h-[60%] overflow-auto shadow-2xl">
<div className="flex justify-between items-center mb-4">
<h2 className="text-xl font-semibold">
Detailansicht: {selectedKey}
</h2>
<button onClick={onClose} className="text-red-500 hover:text-red-700">
</button>
</div>
<div className="mb-4">
<label className="mr-2 font-medium">Zeitraum:</label>
<select
className="border px-2 py-1 rounded"
value={zeitraum}
onChange={(e) =>
setZeitraum(e.target.value as "DIA0" | "DIA1" | "DIA2")
}
>
<option value="DIA0">Alle Messwerte</option>
<option value="DIA1">Stündlich</option>
<option value="DIA2">Täglich</option>
</select>
</div>
<div className="h-[85%]">
<Line
data={{
labels,
datasets: [
{
label: selectedKey,
data: values,
borderColor: "rgba(59,130,246,1)",
backgroundColor: "rgba(59,130,246,0.2)",
fill: false,
},
],
}}
options={baseOptions}
/>
</div>
</div>
</div>
);
};