fix: Implement correct rack navigation in Kabelueberwachung

- Added logic to read the 'rack' query parameter from the URL using useRouter and URLSearchParams.
- Set activeRack state based on the selected rack number from the Dashboard.
- Ensured rack selection is correctly handled upon navigation.
- Maintained manual rack switching functionality with buttons.
This commit is contained in:
ISA
2024-10-23 20:55:04 +02:00
parent d32568fdb1
commit e243122bf1
2 changed files with 30 additions and 12 deletions

View File

@@ -1,14 +1,26 @@
"use client"; // app/kabelueberwachung/page.jsx
import React, { useState, useEffect } from "react";
import { useRouter } from "next/navigation";
import Kue705FO from "../../components/modules/Kue705FO";
function Kabelueberwachung() {
const router = useRouter();
const [activeRack, setActiveRack] = useState(1); // Track the active rack
const [kueIso, setKueIso] = useState([]); // State to store isolation values
const [kueID, setKueID] = useState([]); // State to store the KUE names
const [schleifenwiderstand, setSchleifenwiderstand] = useState([]); // State to store the resistance values
const [kueOnline, setKueOnline] = useState([]); // State to store the module status
// Verwende den useRouter Hook, um den Rack-Parameter zu extrahieren
useEffect(() => {
const query = new URLSearchParams(window.location.search);
const rackParam = query.get("rack");
if (rackParam) {
setActiveRack(parseInt(rackParam)); // Setze das aktive Rack basierend auf dem URL-Parameter
}
}, [router.query]);
// Load the external JavaScript file and fetch the isolation values
useEffect(() => {
if (window.kueIso && Array.isArray(window.kueIso)) {