Files
CPLv4.0/components/main/kabelueberwachung/kue705FO/Charts/TDRChart/TDRChartActionBar.tsx

77 lines
2.3 KiB
TypeScript
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

// /components/main/kabelueberwachung/kue705FO/Charts/TDRChart/TDRChartActionBar.tsx
import React, { useState } from "react";
import { useDispatch, useSelector } from "react-redux";
import { RootState } from "../../../../../../redux/store";
import { fetchTDRChartDataById } from "../../../../../../services/fetchTDRChartDataById";
import {
setTDRChartDataById,
setSelectedTDRId,
} from "../../../../../../redux/slices/tdrDataByIdSlice";
const TDRChartActionBar: React.FC = () => {
const dispatch = useDispatch();
const tdmChartData = useSelector((state: RootState) => state.tdmChart.data);
const selectedSlot = useSelector(
(state: RootState) => state.kueChartMode.selectedSlot
);
const idsForSlot =
selectedSlot !== null ? tdmChartData[selectedSlot] ?? [] : [];
const [selectedId, setSelectedId] = useState<number | null>(null);
const handleSelectChange = async (
e: React.ChangeEvent<HTMLSelectElement>
) => {
const id = parseInt(e.target.value);
setSelectedId(id);
const data = await fetchTDRChartDataById(id);
if (!data) return;
dispatch(setTDRChartDataById({ id, data }));
dispatch(setSelectedTDRId(id));
};
const handleReset = () => {
setSelectedId(null);
dispatch(setSelectedTDRId(-1)); // z.B. -1 als „Reset“-Kennzeichnung
};
return (
<div className="flex justify-between items-center p-2 bg-gray-100 rounded-lg space-x-4">
{/* 🔵 Linke Seite: Reset-Button */}
<button
className="border border-gray-300 bg-white rounded px-3 py-1 text-sm hover:bg-gray-200"
onClick={handleReset}
>
Letzte Messung
</button>
{/* 🔵 Rechte Seite: Dropdown */}
<div className="flex items-center space-x-2">
<label htmlFor="tdrIdSelect" className="text-sm font-semibold">
Messung ID
</label>
<select
id="tdrIdSelect"
value={selectedId ?? ""}
onChange={handleSelectChange}
className="border rounded px-2 py-1 text-sm"
disabled={idsForSlot.length === 0}
>
<option value="">-- Wähle Messung --</option>
{idsForSlot.map((entry) => (
<option key={entry.id} value={entry.id}>
ID {entry.id} {entry.t}
</option>
))}
</select>
</div>
</div>
);
};
export default TDRChartActionBar;