fix: nur Daten abrufen, wenn 'Daten laden' button geklickt wird

This commit is contained in:
ISA
2025-08-01 12:23:10 +02:00
parent 0b7542488e
commit ba1b0d8e79
6 changed files with 52 additions and 11 deletions

View File

@@ -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.676
NEXT_PUBLIC_APP_VERSION=1.6.677
NEXT_PUBLIC_CPL_MODE=json # json (Entwicklungsumgebung) oder jsSimulatedProd (CPL ->CGI-Interface-Simulator) oder production (CPL-> CGI-Interface Platzhalter)

View File

@@ -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.676
NEXT_PUBLIC_APP_VERSION=1.6.677
NEXT_PUBLIC_CPL_MODE=production

View File

@@ -1,3 +1,8 @@
## [1.6.677] 2025-08-01
- fix: link in console
---
## [1.6.676] 2025-08-01
- fix: richtige Link in system fetch service

View File

@@ -135,6 +135,7 @@ export const DetailModal = ({
datasets: [],
});
const [isLoading, setIsLoading] = useState(false);
const [shouldUpdateChart, setShouldUpdateChart] = useState(false);
const vonDatum = useSelector(
(state: RootState) => state.kabelueberwachungChartSlice.vonDatum
);
@@ -197,6 +198,13 @@ export const DetailModal = ({
// API-Request beim Klick auf "Daten laden"
const handleFetchData = () => {
setIsLoading(true);
// Clear previous chart data
setChartData({ datasets: [] });
// Flag setzen, dass Chart nach Datenempfang aktualisiert werden soll
setShouldUpdateChart(true);
switch (selectedKey) {
case "+5V":
dispatch(getSystemspannung5VplusThunk(zeitraum));
@@ -233,12 +241,6 @@ export const DetailModal = ({
chartRef.current.resetZoom();
}
}, [zeitraum]);
// beim start soll der Chart einmal aufgerufen wird, also einmal der Button "Daten laden" geklickt werden
useEffect(() => {
if (isOpen && selectedKey) {
handleFetchData();
}
}, [isOpen, selectedKey]);
// Chart.js animation complete callback to set isLoading false
useEffect(() => {
@@ -257,6 +259,40 @@ export const DetailModal = ({
}
}, [chartData, isLoading]);
// Update chart data when Redux data changes (only after button click)
useEffect(() => {
if (shouldUpdateChart && reduxData && reduxData.length > 0) {
console.log("Redux data for chart:", reduxData);
// Convert Redux data to Chart.js format
const chartDataPoints = reduxData.map((entry) => ({
x: new Date(entry.t).getTime(),
y: entry.m || entry.a || entry.i || 0, // Use current value, max, min, or 0
}));
const newChartData = {
datasets: [
{
label: selectedKey || "Messwerte",
data: chartDataPoints,
borderColor: "#00AEEF", // littwin-blue
backgroundColor: "rgba(0, 174, 239, 0.2)", // littwin-blue mit Transparenz
tension: 0.1,
fill: false,
},
],
};
console.log("Chart data points:", chartDataPoints);
setChartData(newChartData);
setShouldUpdateChart(false); // Reset flag
} else if (shouldUpdateChart && (!reduxData || reduxData.length === 0)) {
console.log("No Redux data available");
setChartData({ datasets: [] });
setShouldUpdateChart(false); // Reset flag
}
}, [reduxData, selectedKey, shouldUpdateChart]);
if (!isOpen || !selectedKey) return null;
return (

4
package-lock.json generated
View File

@@ -1,12 +1,12 @@
{
"name": "cpl-v4",
"version": "1.6.676",
"version": "1.6.677",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "cpl-v4",
"version": "1.6.676",
"version": "1.6.677",
"dependencies": {
"@fontsource/roboto": "^5.1.0",
"@headlessui/react": "^2.2.4",

View File

@@ -1,6 +1,6 @@
{
"name": "cpl-v4",
"version": "1.6.676",
"version": "1.6.677",
"private": true,
"scripts": {
"dev": "next dev",