feat: Redux-Struktur für LoopChart vereinheitlicht (DIA0–2 + Typ 3/4)
- Alle Schleifen- und Isolationswiderstandsdaten werden zentral in loopChart.data gespeichert - Redux State unterstützt nun strukturierte Speicherung nach mode (DIA0–DIA2) und type (3/4) - Bestehender Thunk fetchLoopChartDataThunk wurde angepasst zur Wiederverwendung - Zugriff aus Komponente via loopData["DIAx"][type] möglich
This commit is contained in:
48
redux/slices/loopChartSlice.ts
Normal file
48
redux/slices/loopChartSlice.ts
Normal file
@@ -0,0 +1,48 @@
|
||||
// /redux/slices/loopChartSlice.ts
|
||||
import { createSlice } from "@reduxjs/toolkit";
|
||||
import { fetchLoopChartDataThunk } from "../thunks/fetchLoopChartDataThunk";
|
||||
|
||||
interface ChartData {
|
||||
[mode: string]: {
|
||||
[type: number]: any;
|
||||
};
|
||||
}
|
||||
|
||||
interface LoopChartState {
|
||||
data: ChartData;
|
||||
loading: boolean;
|
||||
error: string | null;
|
||||
}
|
||||
|
||||
const initialState: LoopChartState = {
|
||||
data: {},
|
||||
loading: false,
|
||||
error: null,
|
||||
};
|
||||
|
||||
const loopChartSlice = createSlice({
|
||||
name: "loopChart",
|
||||
initialState,
|
||||
reducers: {},
|
||||
extraReducers: (builder) => {
|
||||
builder
|
||||
.addCase(fetchLoopChartDataThunk.pending, (state) => {
|
||||
state.loading = true;
|
||||
state.error = null;
|
||||
})
|
||||
.addCase(fetchLoopChartDataThunk.fulfilled, (state, action) => {
|
||||
state.loading = false;
|
||||
const { mode, type } = action.meta.arg;
|
||||
if (!state.data[mode]) {
|
||||
state.data[mode] = {};
|
||||
}
|
||||
state.data[mode][type] = action.payload;
|
||||
})
|
||||
.addCase(fetchLoopChartDataThunk.rejected, (state, action) => {
|
||||
state.loading = false;
|
||||
state.error = action.payload as string;
|
||||
});
|
||||
},
|
||||
});
|
||||
|
||||
export default loopChartSlice.reducer;
|
||||
@@ -15,6 +15,7 @@ import tdrChartReducer from "./slices/tdrChartSlice";
|
||||
import analogeEingaengeReducer from "./slices/analogeEingaengeSlice";
|
||||
import digitalInputsReducer from "./slices/digitalInputsSlice";
|
||||
import tdrReferenceChartReducer from "./slices/tdrReferenceChartSlice";
|
||||
import loopChartReducer from "./slices/loopChartSlice";
|
||||
|
||||
const store = configureStore({
|
||||
reducer: {
|
||||
@@ -32,6 +33,7 @@ const store = configureStore({
|
||||
brush: brushReducer,
|
||||
tdrChart: tdrChartReducer,
|
||||
tdrReferenceChart: tdrReferenceChartReducer,
|
||||
loopChart: loopChartReducer,
|
||||
},
|
||||
});
|
||||
|
||||
|
||||
35
redux/thunks/fetchLoopChartDataThunk.ts
Normal file
35
redux/thunks/fetchLoopChartDataThunk.ts
Normal file
@@ -0,0 +1,35 @@
|
||||
// /redux/thunks/fetchLoopChartDataThunk.ts
|
||||
import { createAsyncThunk } from "@reduxjs/toolkit";
|
||||
import { fetchLoopChartData } from "../../services/fetchLoopChartData";
|
||||
|
||||
interface FetchLoopChartDataParams {
|
||||
mode: "DIA0" | "DIA1" | "DIA2";
|
||||
type: number;
|
||||
slotNumber: number;
|
||||
vonDatum: string;
|
||||
bisDatum: string;
|
||||
}
|
||||
|
||||
export const fetchLoopChartDataThunk = createAsyncThunk(
|
||||
"loopChart/fetchLoopChartData",
|
||||
async (params: FetchLoopChartDataParams, { rejectWithValue }) => {
|
||||
try {
|
||||
const data = await fetchLoopChartData(
|
||||
params.mode,
|
||||
params.type,
|
||||
params.slotNumber,
|
||||
params.vonDatum,
|
||||
params.bisDatum
|
||||
);
|
||||
|
||||
if (!data) {
|
||||
return rejectWithValue("Keine Daten erhalten");
|
||||
}
|
||||
|
||||
return data;
|
||||
} catch (error: any) {
|
||||
console.error("❌ Fehler in fetchLoopChartDataThunk:", error);
|
||||
return rejectWithValue(error.message || "Unbekannter Fehler");
|
||||
}
|
||||
}
|
||||
);
|
||||
Reference in New Issue
Block a user