diff --git a/.env.development b/.env.development index 61c5514..cc1f103 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.629 +NEXT_PUBLIC_APP_VERSION=1.6.630 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 0220728..5bb9f4e 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.629 +NEXT_PUBLIC_APP_VERSION=1.6.630 NEXT_PUBLIC_CPL_MODE=production \ No newline at end of file diff --git a/CHANGELOG.md b/CHANGELOG.md index 7b8b694..c7a9a1f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,12 @@ +## [1.6.630] – 2025-07-22 + +- Fix: Preserve chart state during zoom, pan, and date changes + +- Added React.useMemo to memoize chartData and chartOptions to prevent unnecessary re-renders. +- Ensured chart zoom and pan states are maintained during interactions. +- Improved performance and user experience by avoiding chart + +--- ## [1.6.629] – 2025-07-22 - Fix: Preserve chart state during zoom, pan, and date changes diff --git a/components/main/analogInputs/AnalogInputsChart.tsx b/components/main/analogInputs/AnalogInputsChart.tsx index 4d59303..3c5dd26 100644 --- a/components/main/analogInputs/AnalogInputsChart.tsx +++ b/components/main/analogInputs/AnalogInputsChart.tsx @@ -70,15 +70,28 @@ export default function AnalogInputsChart() { (state: RootState) => state.dateRangePicker.bisDatum ); + // Hilfsfunktion für Default-Datum + const getDefaultDate = (type: "from" | "to") => { + const today = new Date(); + if (type === "to") return today.toISOString().slice(0, 10); + const fromDateObj = new Date(today); + fromDateObj.setDate(today.getDate() - 30); + return fromDateObj.toISOString().slice(0, 10); + }; + // ✅ Lokale States für Picker + Zeitraum - const [localVonDatum, setLocalVonDatum] = React.useState(vonDatumRedux || ""); - const [localBisDatum, setLocalBisDatum] = React.useState(bisDatumRedux || ""); + const [localVonDatum, setLocalVonDatum] = React.useState( + vonDatumRedux || getDefaultDate("from") + ); + const [localBisDatum, setLocalBisDatum] = React.useState( + bisDatumRedux || getDefaultDate("to") + ); const [localZeitraum, setLocalZeitraum] = React.useState(zeitraum); // Synchronisiere lokale Werte mit Redux (z.B. nach AutoLoad Reset) useEffect(() => { - setLocalVonDatum(vonDatumRedux || ""); - setLocalBisDatum(bisDatumRedux || ""); + setLocalVonDatum(vonDatumRedux || getDefaultDate("from")); + setLocalBisDatum(bisDatumRedux || getDefaultDate("to")); setLocalZeitraum(zeitraum); }, [vonDatumRedux, bisDatumRedux, zeitraum]); @@ -105,24 +118,41 @@ export default function AnalogInputsChart() { const handleFetchData = () => { if (!selectedAnalogInput?.id) return; + // Fallback auf Redux-Werte, falls lokale Werte leer sind + const from = localVonDatum || vonDatumRedux || ""; + const to = localBisDatum || bisDatumRedux || ""; + // Redux aktualisieren - dispatch(setVonDatum(localVonDatum)); - dispatch(setBisDatum(localBisDatum)); + dispatch(setVonDatum(from)); + dispatch(setBisDatum(to)); dispatch(setZeitraum(localZeitraum)); - // Debug anzeigen - console.log( - "Fetch-URL:", - `/api/cpl/getAnalogInputsHistory?eingang=${selectedAnalogInput.id}&zeitraum=${localZeitraum}&von=${localVonDatum}&bis=${localBisDatum}` - ); + // Umgebung erkennen und URL generieren + const isDev = + window.location.hostname === "localhost" || + window.location.hostname === "127.0.0.1"; + let fetchUrl = ""; + if (isDev) { + fetchUrl = `/api/cpl/getAnalogInputsHistory?eingang=${selectedAnalogInput.id}&zeitraum=${localZeitraum}&von=${from}&bis=${to}`; + } else { + // Produktion: CPL-Webserver direkt abfragen + const [vonJahr, vonMonat, vonTag] = from.split("-"); + const [bisJahr, bisMonat, bisTag] = to.split("-"); + const aeEingang = 100 + (selectedAnalogInput.id - 1); + let diaType = "DIA1"; + if (localZeitraum === "DIA0") diaType = "DIA0"; + if (localZeitraum === "DIA2") diaType = "DIA2"; + fetchUrl = `${window.location.origin}/CPL?seite.ACP&${diaType}=${vonJahr};${vonMonat};${vonTag};${bisJahr};${bisMonat};${bisTag};${aeEingang};1`; + } + console.log("Fetch-URL:", fetchUrl); // Thunk-Fetch mit neuen Werten dispatch( getAnalogInputsHistoryThunk({ eingang: selectedAnalogInput.id, zeitraum: localZeitraum, - vonDatum: localVonDatum, - bisDatum: localBisDatum, + vonDatum: from, + bisDatum: to, }) ); }; diff --git a/package-lock.json b/package-lock.json index 45cbb1c..e57d231 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "cpl-v4", - "version": "1.6.629", + "version": "1.6.630", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "cpl-v4", - "version": "1.6.629", + "version": "1.6.630", "dependencies": { "@fontsource/roboto": "^5.1.0", "@headlessui/react": "^2.2.4", diff --git a/package.json b/package.json index 778b0ca..4b66049 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "cpl-v4", - "version": "1.6.629", + "version": "1.6.630", "private": true, "scripts": { "dev": "next dev",