feat: Automatisches Laden der Chart-Daten bei Dropdown-Wechsel
- Redux-Slice `kabelueberwachungChartSlice.ts` erweitert um `selectedMode` und `selectedSlotType` - `LoopChartActionBar.tsx` so angepasst, dass Änderungen in den Dropdown-Menüs automatisch `handleFetchData` aufrufen - `useEffect` hinzugefügt, um Daten beim Wechsel von `selectedMode` oder `selectedSlotType` neu zu laden - Manuelles Klicken auf den "Daten Laden"-Button ist nun nicht mehr nötig
This commit is contained in:
@@ -1,34 +0,0 @@
|
||||
import { createSlice, PayloadAction } from "@reduxjs/toolkit";
|
||||
|
||||
interface DateRangeState {
|
||||
vonDatum: string;
|
||||
bisDatum: string;
|
||||
}
|
||||
|
||||
const initialState: DateRangeState = {
|
||||
vonDatum: "2025;01;01",
|
||||
bisDatum: "2025;07;31",
|
||||
};
|
||||
|
||||
const formatDate = (isoDate: string) => {
|
||||
const date = new Date(isoDate);
|
||||
return `${date.getFullYear()};${(date.getMonth() + 1)
|
||||
.toString()
|
||||
.padStart(2, "0")};${date.getDate().toString().padStart(2, "0")}`;
|
||||
};
|
||||
|
||||
const dateRangeKueChartSlice = createSlice({
|
||||
name: "dateRangeKueChart",
|
||||
initialState,
|
||||
reducers: {
|
||||
setVonDatum: (state, action: PayloadAction<string>) => {
|
||||
state.vonDatum = formatDate(action.payload);
|
||||
},
|
||||
setBisDatum: (state, action: PayloadAction<string>) => {
|
||||
state.bisDatum = formatDate(action.payload);
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
export const { setVonDatum, setBisDatum } = dateRangeKueChartSlice.actions;
|
||||
export default dateRangeKueChartSlice.reducer;
|
||||
55
redux/slices/kabelueberwachungChartSlice.ts
Normal file
55
redux/slices/kabelueberwachungChartSlice.ts
Normal file
@@ -0,0 +1,55 @@
|
||||
import { createSlice, PayloadAction } from "@reduxjs/toolkit";
|
||||
|
||||
interface KabelueberwachungChartState {
|
||||
chartData: any[];
|
||||
vonDatum: string;
|
||||
bisDatum: string;
|
||||
selectedMode: "DIA0" | "DIA1" | "DIA2";
|
||||
selectedSlotType: "isolationswiderstand" | "schleifenwiderstand";
|
||||
}
|
||||
|
||||
const initialState: KabelueberwachungChartState = {
|
||||
chartData: [],
|
||||
vonDatum: "2025-02-01",
|
||||
bisDatum: "2025-02-28",
|
||||
selectedMode: "DIA0",
|
||||
selectedSlotType: "schleifenwiderstand",
|
||||
};
|
||||
|
||||
const kabelueberwachungChartSlice = createSlice({
|
||||
name: "kabelueberwachungChart",
|
||||
initialState,
|
||||
reducers: {
|
||||
setChartData: (state, action: PayloadAction<any[]>) => {
|
||||
state.chartData = action.payload;
|
||||
},
|
||||
setVonDatum: (state, action: PayloadAction<string>) => {
|
||||
state.vonDatum = action.payload;
|
||||
},
|
||||
setBisDatum: (state, action: PayloadAction<string>) => {
|
||||
state.bisDatum = action.payload;
|
||||
},
|
||||
setSelectedMode: (
|
||||
state,
|
||||
action: PayloadAction<"DIA0" | "DIA1" | "DIA2">
|
||||
) => {
|
||||
state.selectedMode = action.payload;
|
||||
},
|
||||
setSelectedSlotType: (
|
||||
state,
|
||||
action: PayloadAction<"isolationswiderstand" | "schleifenwiderstand">
|
||||
) => {
|
||||
state.selectedSlotType = action.payload;
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
export const {
|
||||
setChartData,
|
||||
setVonDatum,
|
||||
setBisDatum,
|
||||
setSelectedMode,
|
||||
setSelectedSlotType,
|
||||
} = kabelueberwachungChartSlice.actions;
|
||||
|
||||
export default kabelueberwachungChartSlice.reducer;
|
||||
Reference in New Issue
Block a user