fix: Mock-Datenzugriff über API-Handler in Entwicklungsumgebung integriert

- fetchAnalogInputsHistoryService angepasst: nutzt /api/cpl/fetchAnalogInputsHistory bei NODE_ENV=development
- Produktionsdaten weiterhin direkt vom CPL-Webserver über CGI-Endpunkte geladen
- Chart- und Redux-Datenstrom jetzt vollständig stabil in Entwicklung und Produktion
- Fehler beim direkten Zugriff auf Mock-Dateien in Pages Router Next.js behoben
This commit is contained in:
ISA
2025-04-29 10:55:20 +02:00
parent 40e2b54836
commit e341f43204
6 changed files with 174 additions and 109 deletions

View File

@@ -0,0 +1,41 @@
// /redux/slices/analogInputsHistorySlice.ts
import { createSlice, PayloadAction } from "@reduxjs/toolkit";
import { fetchAnalogInputsHistoryThunk } from "../thunks/fetchAnalogInputsHistoryThunk";
type InputHistoryState = {
data: Record<number, any[]>;
isLoading: boolean;
error: string | null;
};
const initialState: InputHistoryState = {
data: {},
isLoading: false,
error: null,
};
const analogInputsHistorySlice = createSlice({
name: "analogInputsHistory",
initialState,
reducers: {},
extraReducers: (builder) => {
builder
.addCase(fetchAnalogInputsHistoryThunk.pending, (state) => {
state.isLoading = true;
state.error = null;
})
.addCase(
fetchAnalogInputsHistoryThunk.fulfilled,
(state, action: PayloadAction<Record<number, any[]>>) => {
state.data = action.payload;
state.isLoading = false;
}
)
.addCase(fetchAnalogInputsHistoryThunk.rejected, (state, action) => {
state.isLoading = false;
state.error = action.payload as string;
});
},
});
export default analogInputsHistorySlice.reducer;

View File

@@ -23,6 +23,7 @@ import tdmSingleChartReducer from "./slices/tdmSingleChartSlice";
import tdrReferenceChartDataBySlotReducer from "./slices/tdrReferenceChartDataBySlotSlice";
import loopChartTypeSlice from "./slices/loopChartTypeSlice";
import systemVoltTempReducer from "./slices/systemVoltTempSlice";
import analogInputsHistoryReducer from "./slices/analogInputsHistorySlice";
const store = configureStore({
reducer: {
@@ -48,6 +49,7 @@ const store = configureStore({
tdrReferenceChartDataBySlotSlice: tdrReferenceChartDataBySlotReducer,
loopChartType: loopChartTypeSlice,
systemVoltTemp: systemVoltTempReducer,
analogInputsHistory: analogInputsHistoryReducer,
},
});

View File

@@ -0,0 +1,15 @@
// /redux/thunks/fetchAnalogInputsHistoryThunk.ts
import { createAsyncThunk } from "@reduxjs/toolkit";
import { fetchAnalogInputsHistoryService } from "../../services/fetchAnalogInputsHistoryService";
export const fetchAnalogInputsHistoryThunk = createAsyncThunk(
"analogInputsHistory/fetch",
async (_, { rejectWithValue }) => {
try {
const data = await fetchAnalogInputsHistoryService();
return data;
} catch (error: any) {
return rejectWithValue(error.message || "Unbekannter Fehler");
}
}
);