feat: AnalogInputsChart mit DateRangePicker und vollständiger Redux-Integration erweitert
- analogInputsHistorySlice angepasst: zeitraum, vonDatum, bisDatum und data hinzugefügt - Typdefinitionen im Slice und Thunk korrigiert - getAnalogInputsHistoryThunk erweitert, um vonDatum und bisDatum zu akzeptieren - DateRangePicker korrekt in AnalogInputsChart.tsx integriert - Fehler bei Selector-Zugriffen und Dispatch behoben
This commit is contained in:
@@ -2,22 +2,33 @@
|
||||
import { createSlice, PayloadAction } from "@reduxjs/toolkit";
|
||||
import { getAnalogInputsHistoryThunk } from "../thunks/getAnalogInputsHistoryThunk";
|
||||
|
||||
type InputHistoryState = {
|
||||
data: Record<number, any[]>;
|
||||
isLoading: boolean;
|
||||
error: string | null;
|
||||
export type AnalogInputsHistoryEntry = {
|
||||
t: string;
|
||||
m: number;
|
||||
};
|
||||
|
||||
const initialState: InputHistoryState = {
|
||||
interface AnalogInputsHistoryState {
|
||||
data: Record<string, AnalogInputsHistoryEntry[]>;
|
||||
isLoading: boolean;
|
||||
error: string | null;
|
||||
zeitraum: string; // z.B. "DIA0", "DIA1", "DIA2"
|
||||
}
|
||||
|
||||
const initialState: AnalogInputsHistoryState = {
|
||||
data: {},
|
||||
isLoading: false,
|
||||
error: null,
|
||||
zeitraum: "DIA0",
|
||||
};
|
||||
|
||||
const analogInputsHistorySlice = createSlice({
|
||||
name: "analogInputsHistory",
|
||||
initialState,
|
||||
reducers: {},
|
||||
reducers: {
|
||||
setZeitraum: (state, action: PayloadAction<string>) => {
|
||||
state.zeitraum = action.payload;
|
||||
},
|
||||
},
|
||||
extraReducers: (builder) => {
|
||||
builder
|
||||
.addCase(getAnalogInputsHistoryThunk.pending, (state) => {
|
||||
@@ -26,8 +37,17 @@ const analogInputsHistorySlice = createSlice({
|
||||
})
|
||||
.addCase(
|
||||
getAnalogInputsHistoryThunk.fulfilled,
|
||||
(state, action: PayloadAction<Record<number, any[]>>) => {
|
||||
state.data = action.payload;
|
||||
(
|
||||
state,
|
||||
action: PayloadAction<{
|
||||
eingang: number;
|
||||
zeitraum: string;
|
||||
daten: AnalogInputsHistoryEntry[];
|
||||
}>
|
||||
) => {
|
||||
const key = String(action.payload.eingang + 99); // z.B. 100 für AE1
|
||||
state.data[key] = action.payload.daten;
|
||||
state.zeitraum = action.payload.zeitraum;
|
||||
state.isLoading = false;
|
||||
}
|
||||
)
|
||||
@@ -38,4 +58,6 @@ const analogInputsHistorySlice = createSlice({
|
||||
},
|
||||
});
|
||||
|
||||
export const { setZeitraum } = analogInputsHistorySlice.actions;
|
||||
|
||||
export default analogInputsHistorySlice.reducer;
|
||||
|
||||
@@ -1,15 +1,25 @@
|
||||
// /redux/thunks/getAnalogInputsHistoryThunk.ts
|
||||
import { createAsyncThunk } from "@reduxjs/toolkit";
|
||||
import { fetchAnalogInputsHistoryService } from "@/services/fetchAnalogInputsHistoryService";
|
||||
// redux/thunks/getAnalogInputsHistoryThunk.ts
|
||||
|
||||
export const getAnalogInputsHistoryThunk = createAsyncThunk(
|
||||
"analogInputsHistory/fetch",
|
||||
async (_, { rejectWithValue }) => {
|
||||
try {
|
||||
const data = await fetchAnalogInputsHistoryService();
|
||||
return data;
|
||||
} catch (error: any) {
|
||||
return rejectWithValue(error.message || "Unbekannter Fehler");
|
||||
}
|
||||
import { createAsyncThunk } from "@reduxjs/toolkit";
|
||||
import { fetchAnalogInputsHistory } from "@/services/fetchAnalogInputsHistoryService";
|
||||
import { AnalogInputsHistoryEntry } from "../slices/analogInputsHistorySlice";
|
||||
|
||||
export const getAnalogInputsHistoryThunk = createAsyncThunk<
|
||||
{
|
||||
eingang: number;
|
||||
zeitraum: string;
|
||||
daten: AnalogInputsHistoryEntry[];
|
||||
},
|
||||
{ eingang: number; zeitraum: string }
|
||||
>("analogInputsHistory/fetch", async ({ eingang, zeitraum }, thunkAPI) => {
|
||||
try {
|
||||
const response = await fetchAnalogInputsHistory(eingang, zeitraum);
|
||||
return {
|
||||
eingang,
|
||||
zeitraum,
|
||||
daten: response.daten,
|
||||
};
|
||||
} catch (error: any) {
|
||||
return thunkAPI.rejectWithValue(error.message ?? "Fehler beim Laden");
|
||||
}
|
||||
);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user