From b9651a53a9a3c56919052084f54a18d725e29076 Mon Sep 17 00:00:00 2001 From: Ismail Ali Date: Thu, 26 Jun 2025 22:56:20 +0200 Subject: [PATCH] esLint --- .env.development | 2 +- .env.production | 2 +- .eslintrc.json | 18 +- .husky/pre-commit | 3 +- CHANGELOG.md | 5 + .../components/modules/Kue705FO.test.tsx | 129 - __tests__/example.test.ts | 7 - components/header/Header.tsx | 10 +- .../header/settingsModal/SettingsModal.tsx | 27 +- components/icons/CogIcon.tsx | 25 +- .../main/analogInputs/AnalogInputsChart.tsx | 6 +- .../AnalogInputsSettingsModal.tsx | 11 +- .../main/analogInputs/AnalogInputsTable.tsx | 2 +- .../main/einausgaenge/DigitalInputs.tsx | 7 +- .../einausgaenge/DigitalOutputsWidget.tsx | 5 +- .../modals/DigitalOutputsModal.tsx | 8 +- .../main/einausgaenge/modals/InputModal.tsx | 47 +- .../kue705FO/Charts/ChartSwitcher.tsx | 52 +- .../LoopMeasurementChart/CustomTooltip.tsx | 9 +- .../LoopMeasurementChart/DateRangePicker.tsx | 5 +- .../LoopChartActionBar.tsx | 21 +- .../LoopMeasurementChart.tsx | 22 +- .../kue705FO/Charts/TDRChart/TDRChart.tsx | 13 +- .../Charts/TDRChart/TDRChartActionBar.tsx | 24 +- .../kabelueberwachung/kue705FO/Kue705FO.tsx | 61 +- .../kue705FO/handlers/handleChange.ts | 4 +- .../handlers/handleCloseChartModal.ts | 4 +- .../kue705FO/handlers/handleRefreshClick.ts | 4 +- .../kue705FO/handlers/handleSave.ts | 8 +- .../kue705FO/hooks/useChartData.ts | 2 +- .../kue705FO/hooks/useChartPlugin.ts | 3 +- .../kue705FO/hooks/useIsoDisplay.ts | 26 +- .../kue705FO/hooks/useKueVersion.ts | 2 +- .../kue705FO/hooks/useTDRChart.ts | 31 +- .../kue705FO-Funktionen/handleButtonClick.ts | 7 +- .../kue705FO/modals/Knotenpunkte.tsx | 2 +- .../kue705FO/modals/KueEinstellung.tsx | 4 +- .../kue705FO/modals/SettingsModalWrapper.tsx | 21 +- .../kue705FO/modals/TdrEinstellung.tsx | 10 +- .../GeneralSettings.tsx | 36 +- .../settingsPageComponents/NTPSettings.tsx | 23 +- .../OPCUAInterfaceSettings.tsx | 40 +- .../handlers/handleAdminLogin.ts | 7 +- .../handlers/handleGeneralSubmit.ts | 2 - .../main/uebersicht/Baugruppentraeger.tsx | 4 +- .../main/uebersicht/Last20MessagesTable.tsx | 2 +- components/main/uebersicht/NetworkInfo.tsx | 93 +- .../Screenshot 2025-06-26 153608.png | Bin 0 -> 78815 bytes mocks/api/SERVICE/digitalInputsMockData.json | 8 +- mocks/api/SERVICE/digitalOutputsMockData.json | 2 +- .../SERVICE/last20MessagesMockData.json | 3560 ++++++++- .../meldungen/messages.json | 6808 ++++++++--------- package-lock.json | 4 +- package.json | 2 +- pages/_app.tsx | 5 +- pages/analogeEingaenge.tsx | 41 +- pages/api/cpl/getAnalogInputsHistory.ts | 9 +- pages/api/cpl/getDigitalOutputsHandler.ts | 4 +- pages/api/cpl/kabelueberwachungAPIHandler.ts | 6 +- pages/api/cpl/last20MessagesAPIHandler.ts | 3 +- pages/api/cpl/messages.ts | 11 +- pages/api/cpl/opcuaAPIHandler.ts | 1 + pages/api/cpl/slotDataAPIHandler.ts | 33 +- pages/api/cpl/systemAPIHandler.ts | 1 + pages/api/cpl/systemVoltTempAPIHandler.ts | 1 + pages/api/cpl/tdmDataAPIHandler.ts | 1 + pages/api/cpl/tdrDataAPIHandler.ts | 1 + pages/api/cpl/tdrReferenceCurveAPIHandler.ts | 1 + pages/api/cpl/updateDigitalInputs.ts | 12 +- .../cpl/updateKueSettingsDataAPIHandler.ts | 2 +- .../cpl/updateTdrReferenceCurveAPIHandler.ts | 1 + .../cpl/updateTdrSettingsDataAPIHandler.ts | 7 +- pages/dashboard.tsx | 1 - pages/digitalInputs.tsx | 41 +- pages/digitalOutputs.tsx | 34 +- pages/kabelueberwachung.tsx | 127 +- pages/meldungen.tsx | 5 +- pages/system.tsx | 3 +- redux/slices/analogInputsSlice.ts | 8 +- redux/slices/selectedAnalogInputSlice.ts | 30 +- types/analogInput.ts | 12 +- types/digitalOutput.ts | 6 + 82 files changed, 7476 insertions(+), 4171 deletions(-) delete mode 100644 __tests__/components/modules/Kue705FO.test.tsx delete mode 100644 __tests__/example.test.ts create mode 100644 docs/TODOsScreenshots/Screenshot 2025-06-26 153608.png create mode 100644 types/digitalOutput.ts diff --git a/.env.development b/.env.development index 52e65b3..c1909f9 100644 --- a/.env.development +++ b/.env.development @@ -6,6 +6,6 @@ NEXT_PUBLIC_USE_MOCK_BACKEND_LOOP_START=false NEXT_PUBLIC_EXPORT_STATIC=false NEXT_PUBLIC_USE_CGI=false # App-Versionsnummer -NEXT_PUBLIC_APP_VERSION=1.6.482 +NEXT_PUBLIC_APP_VERSION=1.6.483 NEXT_PUBLIC_CPL_MODE=json # json (Entwicklungsumgebung) oder jsSimulatedProd (CPL ->CGI-Interface-Simulator) oder production (CPL-> CGI-Interface Platzhalter) diff --git a/.env.production b/.env.production index 654ffc4..3ff32c0 100644 --- a/.env.production +++ b/.env.production @@ -5,5 +5,5 @@ NEXT_PUBLIC_CPL_API_PATH=/CPL NEXT_PUBLIC_EXPORT_STATIC=true NEXT_PUBLIC_USE_CGI=true # App-Versionsnummer -NEXT_PUBLIC_APP_VERSION=1.6.482 +NEXT_PUBLIC_APP_VERSION=1.6.483 NEXT_PUBLIC_CPL_MODE=production \ No newline at end of file diff --git a/.eslintrc.json b/.eslintrc.json index 6b10a5b..727c5d2 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -1,6 +1,20 @@ { "extends": [ + "next", "next/core-web-vitals", - "next/typescript" - ] + "eslint:recommended", + "plugin:@typescript-eslint/recommended" + ], + "plugins": ["@typescript-eslint", "react"], + "parser": "@typescript-eslint/parser", + "parserOptions": { + "ecmaVersion": "latest", + "sourceType": "module", + "ecmaFeatures": { + "jsx": true + } + }, + "rules": { + // deine Regeln hier + } } diff --git a/.husky/pre-commit b/.husky/pre-commit index 0e617d1..1c7b838 100644 --- a/.husky/pre-commit +++ b/.husky/pre-commit @@ -1,7 +1,7 @@ #!/bin/sh echo "🔄 Version wird automatisch erhöht (bumpVersion.ts)..." -npx husky add .husky/pre-commit "npm run check" +npm run check # 1. Version erhöhen npx ts-node scripts/bumpVersion.ts || exit 1 @@ -14,3 +14,4 @@ node ./scripts/updateChangelogFromCommit.js "$COMMIT_MSG" || exit 1 # 4. Dateien zum Commit hinzufügen git add package.json package-lock.json CHANGELOG.md .env.development .env.production +npm run check diff --git a/CHANGELOG.md b/CHANGELOG.md index 8300a33..3842cd4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,8 @@ +## [1.6.483] – 2025-06-26 + +- EsLint + +--- ## [1.6.482] – 2025-06-26 - feat: Tabellenkopf in Berichte-Seite fixiert und Scrollen verbessert diff --git a/__tests__/components/modules/Kue705FO.test.tsx b/__tests__/components/modules/Kue705FO.test.tsx deleted file mode 100644 index 7be6db3..0000000 --- a/__tests__/components/modules/Kue705FO.test.tsx +++ /dev/null @@ -1,129 +0,0 @@ -import React from "react"; -import { render, fireEvent, screen } from "@testing-library/react"; -import configureStore from "redux-mock-store"; -import { Provider } from "react-redux"; -import "@testing-library/jest-dom"; -import Kue705FO from "../../../components/main/kabelueberwachung/kue705FO/Kue705FO"; - -// Mocks für externe Abhängigkeiten -jest.mock("chart.js/auto", () => ({ - default: { - register: jest.fn(), - }, - Chart: jest.fn().mockImplementation(() => ({ - destroy: jest.fn(), - update: jest.fn(), - })), -})); - -jest.mock("chartjs-plugin-zoom", () => ({})); - -// Initialzustand für Redux -const mockStore = configureStore([]); -const initialState = { - variables: { - kuePSTmMinus96V: [0], - kueCableBreak: [0], - kueGroundFault: [0], - kueAlarm1: [0], - kueAlarm2: [0], - kueOverflow: [0], - kueVersion: [419], - tdrActive: [1], - }, - auth: { - isAdminLoggedIn: true, // Füge dies hinzu - }, -}; - -// Standard-Props -const defaultProps = { - isolationswert: 200, - schleifenwiderstand: 5.6, - modulName: "TestModul", - kueOnline: 1, - slotIndex: 0, - tdrLocation: [2.5], -}; - -describe("Kue705FO Integration Tests", () => { - let store: ReturnType; - - beforeEach(() => { - store = mockStore(initialState); - }); - - it("should render correctly with default props", () => { - render( - - - - ); - - // Überprüfen, ob die Basis-Darstellung korrekt ist - expect(screen.getByText("KÜ705-FO")).toBeInTheDocument(); - expect(screen.getByText("TestModul")).toBeInTheDocument(); - }); - - it("should toggle between TDR and Schleife modes", () => { - render( - - - - ); - - // Überprüfen, ob Schleife aktiv ist - expect(screen.getByText("Schleifenwiderstand [kOhm]")).toBeInTheDocument(); - expect(screen.getByText("5.6 KOhm")).toBeInTheDocument(); - - // TDR-Button klicken - fireEvent.click(screen.getByText("TDR")); - - // Überprüfen, ob TDR aktiv ist - expect(screen.getByText("Entfernung [Km]")).toBeInTheDocument(); - expect(screen.getByText("2.5 Km")).toBeInTheDocument(); - - // Zurück zu Schleife wechseln - fireEvent.click(screen.getByText("Schleife")); - expect(screen.getByText("Schleifenwiderstand [kOhm]")).toBeInTheDocument(); - }); - - it("should open and close the settings modal", () => { - render( - - - - ); - - // Modal öffnen - fireEvent.click(screen.getByText("⚙")); - expect(screen.getByText("KUE Einstellung - Slot 1")).toBeInTheDocument(); - - // Modal schließen - fireEvent.click(screen.getByRole("button", { name: /x/i })); - expect( - screen.queryByText("KUE Einstellung - Slot 1") - ).not.toBeInTheDocument(); - }); - - it("should disable TDR button when tdrActive is 0", () => { - // Zustand aktualisieren - store = mockStore({ - ...initialState, - variables: { - ...initialState.variables, - tdrActive: [0], - }, - }); - - render( - - - - ); - - // TDR-Button sollte deaktiviert sein - const tdrButton = screen.getByText("TDR"); - expect(tdrButton).toBeDisabled(); - }); -}); diff --git a/__tests__/example.test.ts b/__tests__/example.test.ts deleted file mode 100644 index 8ffd273..0000000 --- a/__tests__/example.test.ts +++ /dev/null @@ -1,7 +0,0 @@ -// __tests__/example.test.ts -describe('Basic Test', () => { - it('should pass', () => { - expect(true).toBe(true); - }); - }); - \ No newline at end of file diff --git a/components/header/Header.tsx b/components/header/Header.tsx index 6361476..50bb973 100644 --- a/components/header/Header.tsx +++ b/components/header/Header.tsx @@ -7,7 +7,7 @@ import SettingsModal from "@/components/header/settingsModal/SettingsModal"; import { RootState } from "@/redux/store"; import { useSelector, useDispatch } from "react-redux"; import { AppDispatch } from "@/redux/store"; -import decodeToken from "@/utils/decodeToken"; + import { getSystemSettingsThunk } from "@/redux/thunks/getSystemSettingsThunk"; function Header() { @@ -16,7 +16,6 @@ function Header() { const [isAdminLoggedIn, setIsAdminLoggedIn] = useState(false); // Removed duplicate declaration of deviceName - const handleSettingsClick = () => setShowSettingsModal(true); const handleCloseSettingsModal = () => setShowSettingsModal(false); const handleLogout = () => { @@ -26,13 +25,6 @@ function Header() { router.push("/offline.html"); // Weiterleitung }; - const handleLogin = () => { - const token = JSON.stringify({ exp: Date.now() + 5 * 60 * 1000 }); // Beispiel-Token mit 5 Minuten Ablaufzeit - sessionStorage.setItem("token", token); // Token speichern - localStorage.setItem("isAdminLoggedIn", "true"); // Admin-Status setzen - setIsAdminLoggedIn(true); // Zustand sofort aktualisieren - }; - useEffect(() => { // Initialer Check beim Laden der Komponente const isAdmin = localStorage.getItem("isAdminLoggedIn") === "true"; diff --git a/components/header/settingsModal/SettingsModal.tsx b/components/header/settingsModal/SettingsModal.tsx index 1708e9a..5f65d12 100644 --- a/components/header/settingsModal/SettingsModal.tsx +++ b/components/header/settingsModal/SettingsModal.tsx @@ -1,5 +1,5 @@ "use client"; // components/header/settingsModal/SettingsModal.tsx -import React, { useState, useEffect } from "react"; +import React, { useState } from "react"; import ReactModal from "react-modal"; import "bootstrap-icons/font/bootstrap-icons.css"; import { RootState } from "../../../redux/store"; @@ -8,13 +8,7 @@ import handleClearDatabase from "./handlers/handleClearDatabase"; import handleReboot from "./handlers/handleReboot"; import handleSetDateTime from "./handlers/handleSetDateTime"; import handleSubmit from "./handlers/handleSubmit"; -import bcrypt from "bcryptjs"; -import CryptoJS from "crypto-js"; import { useAdminAuth } from "./hooks/useAdminAuth"; -import { useSystemSettings } from "./hooks/useSystemSettings"; -import { generateKeyAndIV, generateToken } from "./utils/cryptoUtils"; -import USERS from "./config/users"; -import handleAdminLogin from "./handlers/handleAdminLogin"; ReactModal.setAppElement("#__next"); @@ -27,13 +21,6 @@ function SettingModal({ }) { const { isAdminLoggedIn, logoutAdmin } = useAdminAuth(showModal); - const { formValues, setFormValues } = useSystemSettings(showModal); - - const [username, setUsername] = useState(""); - const [password, setPassword] = useState(""); - const [error, setError] = useState(""); - const [showLoginForm, setShowLoginForm] = useState(false); - const deviceName_Redux = useSelector( (state: RootState) => state.systemSettingsSlice.deviceName ); @@ -69,11 +56,11 @@ function SettingModal({ ); const [name, setName] = useState(deviceName_Redux || ""); - const [mac1, setMac1] = useState(mac1_Redux || ""); + const [mac1] = useState(mac1_Redux || ""); const [ip, setIp] = useState(ip_Redux || ""); const [subnet, setSubnet] = useState(subnet_Redux || ""); const [gateway, setGateway] = useState(gateway_Redux || ""); - const [systemUhr, setSystemUhr] = useState(datetime_Redux || ""); + const [systemUhr] = useState(datetime_Redux || ""); const [ntp1, setNtp1] = useState(ntp1_Redux || ""); const [ntp2, setNtp2] = useState(ntp2_Redux || ""); const [ntp3, setNtp3] = useState(ntp3_Redux || ""); @@ -82,7 +69,7 @@ function SettingModal({ typeof active_Redux === "boolean" ? active_Redux : active_Redux === "true" ); - const [originalValues, setOriginalValues] = useState({ + const [originalValues] = useState({ name: name, ip: ip, subnet: subnet, @@ -93,6 +80,8 @@ function SettingModal({ ntpTimezone: ntpTimezone, active: active, }); + + // const [showLoginForm, setShowLoginForm] = useState(false); const currentValues = { name, ip, @@ -266,9 +255,7 @@ function SettingModal({ Neustart CPL