feat: Datenquelle auf statische JSON-Dateien in public umgestellt
- Fetch-API in `LoopChartActionBar.tsx` angepasst, um Mock-Daten aus `/public/CPLmockData/kuesChartData/` zu laden. - Mock-Daten als statische JSON-Dateien (`DIA0.json`, `DIA1.json`, `DIA2.json`) hinzugefügt. - `LoopMeasurementChart.tsx` angepasst, um die Daten aus dem Redux-Store zu verwenden. - Debugging-Logs entfernt und Fehlerbehandlung für fehlgeschlagene API-Requests verbessert. Mock-Daten können jetzt ohne API-Server geladen werden.
This commit is contained in:
@@ -30,37 +30,33 @@ const LoopChartActionBar: React.FC = () => {
|
||||
* @param mode - DIA0, DIA1 oder DIA2
|
||||
* @param slotIndex - Slot für die Abfrage
|
||||
*/
|
||||
const getApiUrl = (mode: "DIA0" | "DIA1" | "DIA2", slotIndex: number) => {
|
||||
const baseUrl =
|
||||
process.env.NODE_ENV === "development"
|
||||
? `/api/mockChartData?${mode}=true`
|
||||
: `/CPL?seite.ACP&${mode}=${vonDatum};${bisDatum};${slotIndex}`;
|
||||
|
||||
return baseUrl;
|
||||
const getApiUrl = (mode: "DIA0" | "DIA1" | "DIA2") => {
|
||||
return process.env.NODE_ENV === "development"
|
||||
? `/CPLmockData/kuesChartData/${mode}.json`
|
||||
: `/CPL?seite.ACP&${mode}=${vonDatum};${bisDatum};${slotIndex}`;
|
||||
};
|
||||
|
||||
/**
|
||||
* Funktion zum Laden der Messwerte
|
||||
*/
|
||||
const handleFetchData = async () => {
|
||||
const slotIndex =
|
||||
selectedSlotType === "schleifenwiderstand"
|
||||
? schleifenwiderstand
|
||||
: isolationswiderstand;
|
||||
|
||||
try {
|
||||
const apiUrl = getApiUrl(selectedMode, slotIndex);
|
||||
const response = await fetch(apiUrl);
|
||||
const data = await response.json();
|
||||
const apiUrl = getApiUrl(selectedMode);
|
||||
console.log("Mock JSON laden von:", apiUrl);
|
||||
|
||||
if (Array.isArray(data)) {
|
||||
console.log("Daten geladen:", data);
|
||||
dispatch(setChartData(data));
|
||||
const response = await fetch(apiUrl);
|
||||
if (!response.ok) throw new Error(`Fehler: ${response.status}`);
|
||||
|
||||
const jsonData = await response.json();
|
||||
console.log("Geladene Daten:", jsonData);
|
||||
|
||||
if (Array.isArray(jsonData)) {
|
||||
dispatch(setChartData(jsonData));
|
||||
} else {
|
||||
console.error("Erwartetes Array, aber erhalten:", data);
|
||||
console.error("Erwartetes Array, aber erhalten:", jsonData);
|
||||
}
|
||||
} catch (error) {
|
||||
console.error("Fehler beim Laden der Daten:", error);
|
||||
console.error("Fehler beim Laden der Mock-Daten:", error);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user