refactor: Code-Struktur verbessert, Handler und Logik modularisiert
- Alle Event-Handler in eigene Dateien ausgelagert: - `handleOpenModal.ts`, `handleCloseModal.ts` - `handleOpenChartModal.ts`, `handleCloseChartModal.ts` - `handleRefreshClick.ts`, `handleSave.ts` - Neue Hooks zur Verwaltung von Redux-Selektoren und UI-Zuständen erstellt - `Kue705FO.tsx` gesäubert, jetzt schlanker und übersichtlicher - Verbesserte Wartbarkeit und Wiederverwendbarkeit der Code-Basis
This commit is contained in:
@@ -1,21 +1,13 @@
|
||||
"use client"; // components/modules/kue705FO/Kue705FO.tsx
|
||||
import React, { useState, useEffect, useRef } from "react";
|
||||
import Chart from "chart.js/auto";
|
||||
import { useSelector } from "react-redux";
|
||||
import KueModal from "./KueModal";
|
||||
import "bootstrap-icons/font/bootstrap-icons.css"; // Import Bootstrap Icons
|
||||
import { RootState } from "../../../../redux/store";
|
||||
import { useDispatch } from "react-redux";
|
||||
import { setSelectedChartData } from "../../../../redux/slices/variablesSlice";
|
||||
import { goLoop } from "../../../../utils/goLoop";
|
||||
import { goTDR } from "../../../../utils/goTDR";
|
||||
import { Kue705FOProps } from "../../../../types/components/Kue705FOProps";
|
||||
import ChartSwitcher from "./Charts/ChartSwitcher";
|
||||
import { setActiveMode } from "../../../../redux/slices/kueChartModeSlice";
|
||||
import handleButtonClick from "./kue705FO-Funktionen/handleButtonClick";
|
||||
import { setChartOpen } from "../../../../redux/slices/kabelueberwachungChartSlice";
|
||||
import { setSlotNumber } from "../../../../redux/slices/kabelueberwachungChartSlice";
|
||||
import { createTDRChart } from "../../../../utils/chartUtils";
|
||||
//-------Redux Toolkit--------
|
||||
import { RootState } from "../../../../redux/store";
|
||||
import { useDispatch } from "react-redux";
|
||||
//-------hooks----------------
|
||||
import useChartPlugin from "./hooks/useChartPlugin";
|
||||
import useAlarmStatus from "./hooks/useAlarmStatus";
|
||||
@@ -25,6 +17,13 @@ import useLoopDisplay from "./hooks/useLoopDisplay";
|
||||
import useModulName from "./hooks/useModulName";
|
||||
import useChartData from "./hooks/useChartData";
|
||||
import useTDRChart from "./hooks/useTDRChart";
|
||||
//--------handlers----------------
|
||||
import handleButtonClick from "./kue705FO-Funktionen/handleButtonClick";
|
||||
import handleOpenModal from "./handlers/handleOpenModal";
|
||||
import handleCloseModal from "./handlers/handleCloseModal";
|
||||
import handleOpenChartModal from "./handlers/handleOpenChartModal";
|
||||
import handleCloseChartModal from "./handlers/handleCloseChartModal";
|
||||
import handleRefreshClick from "./handlers/handleRefreshClick";
|
||||
|
||||
const Kue705FO: React.FC<Kue705FOProps> = ({
|
||||
isolationswert,
|
||||
@@ -33,7 +32,6 @@ const Kue705FO: React.FC<Kue705FOProps> = ({
|
||||
kueOnline,
|
||||
slotIndex,
|
||||
tdrLocation,
|
||||
alarmStatus,
|
||||
}) => {
|
||||
/* console.log(
|
||||
`Rendering Kue705FO - SlotIndex: ${slotIndex}, ModulName: ${modulName}`
|
||||
@@ -68,7 +66,7 @@ const Kue705FO: React.FC<Kue705FOProps> = ({
|
||||
const [loopMeasurementCurveChartData, setLoopMeasurementCurveChartData] =
|
||||
useState(null);
|
||||
|
||||
// Redux-Variablen abrufen
|
||||
//------- Redux-Variablen abrufen--------------------------------
|
||||
const {
|
||||
kuePSTmMinus96V,
|
||||
kueVersion: reduxKueVersion,
|
||||
@@ -92,40 +90,15 @@ const Kue705FO: React.FC<Kue705FOProps> = ({
|
||||
(state: RootState) => state.variables.kueOverflow?.map(Number) ?? []
|
||||
);
|
||||
|
||||
//-------------------------
|
||||
const handleOpenModal = () => setShowModal(true);
|
||||
const handleCloseModal = () => setShowModal(false);
|
||||
|
||||
const handleOpenChartModal = () => {
|
||||
setShowChartModal(true);
|
||||
dispatch(setChartOpen(true));
|
||||
dispatch(setSlotNumber(slotIndex + 1)); // Slot-Nummer speichern
|
||||
|
||||
if (activeButton === "TDR") {
|
||||
dispatch(setActiveMode("TDR"));
|
||||
} else {
|
||||
dispatch(setActiveMode("Schleife"));
|
||||
}
|
||||
};
|
||||
|
||||
// Funktion aufrufen in handleRefreshClick
|
||||
const handleRefreshClick = () => {
|
||||
if (activeButton === "Schleife") {
|
||||
goLoop(slotIndex, setLoading);
|
||||
} else if (activeButton === "TDR") {
|
||||
goTDR(slotIndex, setLoading);
|
||||
}
|
||||
};
|
||||
|
||||
const handleCloseChartModal = () => {
|
||||
if (chartInstance.current) {
|
||||
console.log("Chart wird beim Schließen des Modals zerstört.");
|
||||
chartInstance.current.destroy();
|
||||
chartInstance.current = null;
|
||||
}
|
||||
setShowChartModal(false);
|
||||
};
|
||||
|
||||
//-------------------------handlers-------------------------
|
||||
const openModal = () => handleOpenModal(setShowModal);
|
||||
const closeModal = () => handleCloseModal(setShowModal);
|
||||
const openChartModal = () =>
|
||||
handleOpenChartModal(setShowChartModal, dispatch, slotIndex, activeButton);
|
||||
const refreshClick = () =>
|
||||
handleRefreshClick(activeButton, slotIndex, setLoading);
|
||||
const closeChartModal = () =>
|
||||
handleCloseChartModal(setShowChartModal, chartInstance);
|
||||
//----------------------------------
|
||||
//hooks einbinden
|
||||
const kueVersion = useKueVersion(slotIndex, reduxKueVersion);
|
||||
@@ -189,7 +162,7 @@ const Kue705FO: React.FC<Kue705FOProps> = ({
|
||||
</h3>
|
||||
|
||||
<button
|
||||
onClick={handleOpenModal}
|
||||
onClick={openModal}
|
||||
className="w-[0.938rem] h-[0.938rem] bg-gray-400 flex items-center justify-center"
|
||||
>
|
||||
<span className="text-white text-[1.25rem]">⚙</span>
|
||||
@@ -198,7 +171,7 @@ const Kue705FO: React.FC<Kue705FOProps> = ({
|
||||
{}
|
||||
<KueModal
|
||||
showModal={showModal}
|
||||
onClose={handleCloseModal}
|
||||
onClose={closeModal}
|
||||
slot={slotIndex}
|
||||
onModulNameChange={setCurrentModulName}
|
||||
/>
|
||||
@@ -269,7 +242,7 @@ const Kue705FO: React.FC<Kue705FOProps> = ({
|
||||
|
||||
<div className="relative w-full h-[2.813rem] bg-gray-100 border border-gray-400 flex items-center justify-center mt-4">
|
||||
<button
|
||||
onClick={handleRefreshClick} // Dynamische Funktion basierend auf aktivem Button
|
||||
onClick={refreshClick} // Dynamische Funktion basierend auf aktivem Button
|
||||
className="absolute -top-[0.063rem] -right-[0.063rem] w-[1.25rem] h-[1.25rem] bg-gray-400 flex items-center justify-center"
|
||||
disabled={loading} // Disable button while loading
|
||||
>
|
||||
@@ -343,7 +316,7 @@ const Kue705FO: React.FC<Kue705FOProps> = ({
|
||||
</div>
|
||||
|
||||
<button
|
||||
onClick={handleOpenChartModal} // Öffnet das Chart-Modal
|
||||
onClick={openChartModal} // Öffnet das Chart-Modal
|
||||
className="w-full h-[1.563rem] bg-littwin-blue text-white text-[0.625rem] flex items-center justify-center mt-[0.063rem]"
|
||||
>
|
||||
Messkurve
|
||||
@@ -352,10 +325,7 @@ const Kue705FO: React.FC<Kue705FOProps> = ({
|
||||
|
||||
{/* Modal für Messkurve */}
|
||||
{showChartModal && (
|
||||
<ChartSwitcher
|
||||
isOpen={showChartModal}
|
||||
onClose={handleCloseChartModal}
|
||||
/>
|
||||
<ChartSwitcher isOpen={showChartModal} onClose={closeChartModal} />
|
||||
)}
|
||||
</>
|
||||
) : (
|
||||
|
||||
Reference in New Issue
Block a user