fix: KVZ Button style wie die anderen (ISO, RSL, TDR) und mit eigene Modal

This commit is contained in:
ISA
2025-08-11 11:35:03 +02:00
parent 9b05f21ccc
commit c107738625
7 changed files with 187 additions and 19 deletions

View File

@@ -0,0 +1,146 @@
"use client"; // KVZChartView.tsx
import React, { useEffect } from "react";
import ReactModal from "react-modal";
import { useDispatch, useSelector } from "react-redux";
import { AppDispatch, RootState } from "@/redux/store";
import {
setChartOpen,
setFullScreen,
setSlotNumber,
setVonDatum,
setBisDatum,
setSelectedMode,
setSelectedSlotType,
} from "@/redux/slices/kabelueberwachungChartSlice";
import { resetBrushRange } from "@/redux/slices/brushSlice";
import FallSensors from "../../../../fall-detection-sensors/FallSensors";
import Report from "../IsoMeasurementChart/Report";
interface KVZChartViewProps {
isOpen: boolean;
onClose: () => void;
slotIndex: number;
}
// Modal zur Anzeige der KVz Zustände (Sturzsensoren / Fall Detection LEDs)
// Stil und Verhalten analog zu ISO / RSL / TDR Modals
const KVZChartView: React.FC<KVZChartViewProps> = ({
isOpen,
onClose,
slotIndex,
}) => {
const dispatch = useDispatch<AppDispatch>();
const isFullScreen = useSelector(
(state: RootState) => state.kabelueberwachungChartSlice.isFullScreen
);
// Beim Öffnen Slot setzen (damit konsistent zu anderen Modals)
useEffect(() => {
if (isOpen) {
dispatch(setSlotNumber(slotIndex));
}
}, [isOpen, slotIndex, dispatch]);
const handleClose = () => {
const today = new Date();
const thirtyDaysAgo = new Date();
thirtyDaysAgo.setDate(today.getDate() - 30);
const toISO = (d: Date) => d.toLocaleDateString("sv-SE");
// Zurücksetzen entspricht Verhalten der anderen Modals
dispatch(setVonDatum(toISO(thirtyDaysAgo)));
dispatch(setBisDatum(toISO(today)));
dispatch(setSelectedMode("DIA1"));
dispatch(setSelectedSlotType("isolationswiderstand"));
dispatch(setChartOpen(false));
dispatch(setFullScreen(false));
dispatch(resetBrushRange());
onClose();
};
const toggleFullScreen = () => {
dispatch(setFullScreen(!isFullScreen));
};
return (
<ReactModal
isOpen={isOpen}
onRequestClose={handleClose}
ariaHideApp={false}
style={{
overlay: { backgroundColor: "rgba(0, 0, 0, 0.5)" },
content: {
top: "50%",
left: "50%",
bottom: "auto",
marginRight: "-50%",
transform: "translate(-50%, -50%)",
width: isFullScreen ? "90vw" : "50rem",
height: isFullScreen ? "90vh" : "28rem",
padding: "1rem",
transition: "all 0.3s ease-in-out",
display: "flex",
flexDirection: "column",
},
}}
>
{/* Action Buttons */}
<div
style={{
position: "absolute",
top: "0.625rem",
right: "0.625rem",
display: "flex",
gap: "0.75rem",
}}
>
<button
onClick={toggleFullScreen}
style={{
background: "transparent",
border: "none",
fontSize: "1.5rem",
cursor: "pointer",
}}
>
<i
className={
isFullScreen ? "bi bi-fullscreen-exit" : "bi bi-arrows-fullscreen"
}
></i>
</button>
<button
onClick={handleClose}
style={{
background: "transparent",
border: "none",
fontSize: "1.5rem",
cursor: "pointer",
}}
>
<i className="bi bi-x-circle-fill"></i>
</button>
</div>
{/* Content */}
<div className="flex flex-col h-full">
<h3 className="text-lg font-semibold mb-1">KVz Zustände & Meldungen</h3>
{/* LED Bereich */}
<div className="w-full flex justify-start mb-4">
<div style={{ width: "12rem" }}>
<FallSensors slotIndex={slotIndex} />
</div>
</div>
{/* Meldungen Bereich */}
<div className="flex-1 border rounded bg-white overflow-hidden">
<Report />
</div>
</div>
</ReactModal>
);
};
export default KVZChartView;

View File

@@ -2,13 +2,14 @@
import React, { useState, useMemo } from "react";
import { useSelector } from "react-redux";
import KueModal from "./modals/SettingsModalWrapper";
import FallSensors from "../../fall-detection-sensors/FallSensors";
// import FallSensors from "../../fall-detection-sensors/FallSensors";
import "bootstrap-icons/font/bootstrap-icons.css"; // Import Bootstrap Icons
import { Kue705FOProps } from "../../../../types/Kue705FOProps";
// Import the new specialized ChartView components
import IsoChartView from "./Charts/IsoMeasurementChart/IsoChartView";
import LoopChartView from "./Charts/LoopMeasurementChart/LoopChartView";
import TDRChartView from "./Charts/TDRChart/TDRChartView";
import KVZChartView from "./Charts/KVZChart/KVZChartView";
// Keep ChartSwitcher import for backwards compatibility if needed
// import ChartSwitcher from "./Charts/ChartSwitcher";
// Remove separate chart imports since we use ChartView components
@@ -68,7 +69,7 @@ const Kue705FO: React.FC<Kue705FOProps> = ({
const [showIsoModal, setShowIsoModal] = useState(false);
const [showRslModal, setShowRslModal] = useState(false);
const [showTdrModal, setShowTdrModal] = useState(false);
const [showKvzPanel, setShowKvzPanel] = useState(false);
const [showKvzModal, setShowKvzModal] = useState(false);
// Keep original showChartModal for backwards compatibility if needed
// const [showChartModal, setShowChartModal] = useState(false);
// Removed unused loopMeasurementCurveChartData state
@@ -85,7 +86,7 @@ const Kue705FO: React.FC<Kue705FOProps> = ({
tdrActive, // <- TDR aktiv Status hinzugefügt
kvzPresence, // <- KVz Presence Array hinzugefügt
kvzActive, // <- KVz Active Array hinzugefügt
kvzStatus, // <- KVz LED Status Array hinzugefügt
// kvzStatus, // <- KVz LED Status Array (jetzt nur im KVZ Modal verwendet)
} = useSelector((state: RootState) => state.kueDataSlice);
//---------------------------------------------
@@ -174,8 +175,9 @@ const Kue705FO: React.FC<Kue705FOProps> = ({
};
const openKvzModal = () => {
setShowKvzPanel(!showKvzPanel);
setShowKvzModal(true);
};
const closeKvzModal = () => setShowKvzModal(false);
//----------------------------------
//hooks einbinden
const kueVersion = useKueVersion(slotIndex, reduxKueVersion);
@@ -240,12 +242,6 @@ const Kue705FO: React.FC<Kue705FOProps> = ({
kvzActive?.[slotIndex] === 1 &&
isAdminLoggedIn;
// KVz LED Status abrufen (4 LEDs pro Slot)
const getKvzLedStatus = (ledIndex: number) => {
const arrayIndex = slotIndex * 4 + ledIndex;
return kvzStatus?.[arrayIndex] === 1;
};
// Removed useChartData(loopMeasurementCurveChartData) as the state was unused
//---------------------------------
@@ -431,8 +427,12 @@ const Kue705FO: React.FC<Kue705FOProps> = ({
? "bg-littwin-blue text-white cursor-pointer"
: "bg-gray-400 cursor-default"
} text-[0.625rem] flex items-center justify-center p-2 min-w-[2.5rem]`}
disabled={!isKvzActiveForSlot}
title={
isKvzActiveForSlot ? "KVZ öffnen" : "KVZ nicht verfügbar"
}
>
{isKvzActiveForSlot ? "KVz" : "\u00A0\u00A0\u00A0"}
{isKvzActiveForSlot ? "KVZ" : "\u00A0\u00A0\u00A0"}
</button>
</div>
@@ -467,15 +467,22 @@ const Kue705FO: React.FC<Kue705FOProps> = ({
slotIndex={slotIndex}
/>
)}
{isKvzActiveForSlot && (
<KVZChartView
isOpen={showKvzModal}
onClose={closeKvzModal}
slotIndex={slotIndex}
/>
)}
</>
)}
{/* KVz Panel - Anzeige ganz unten, nur wenn KVz aktiv ist */}
{showKvzPanel && isKvzActiveForSlot && (
{/* Früher inline Panel jetzt eigenes Modal (KVZChartView) */}
{/* {showKvzPanel && isKvzActiveForSlot && (
<div className="flex flex-col items-center ">
<FallSensors slotIndex={slotIndex} />
</div>
)}
)} */}
{/* Offline-View */}
{kueOnline !== 1 && (