fix: Korrektur der Datenquelle für Geräte-Dropdown
- API-Antwort direkt analysiert: `Points` liegt auf oberster Ebene, nicht unter `data` - Anpassung der Zuweisung: `const locationDeviceData = gisStationsStatic?.Points ?? [];` - Dropdown wird nun korrekt mit Gerätenamen befüllt
This commit is contained in:
@@ -4,6 +4,8 @@ import ReactDOM from "react-dom";
|
||||
import { useRecoilValue, useRecoilState, useSetRecoilState } from "recoil";
|
||||
import { readPoiMarkersStore } from "../redux/slices/readPoiMarkersStoreSlice.js";
|
||||
import { poiReadFromDbTriggerAtom } from "../redux/slices/poiReadFromDbTriggerSlice.js";
|
||||
import { useSelector } from "react-redux";
|
||||
import { selectGisStationsStatic } from "../redux/slices/webService/gisStationsStaticSlice";
|
||||
|
||||
const ShowAddStationPopup = ({ onClose, map, latlng }) => {
|
||||
const [poiTypData, setpoiTypData] = useState(); // Recoil State verwenden
|
||||
@@ -14,7 +16,6 @@ const ShowAddStationPopup = ({ onClose, map, latlng }) => {
|
||||
const [longitude] = useState(latlng.lng.toFixed(5));
|
||||
const setLoadData = useSetRecoilState(readPoiMarkersStore);
|
||||
const setTrigger = useSetRecoilState(poiReadFromDbTriggerAtom);
|
||||
const [locationDeviceData, setLocationDeviceData] = useState([]);
|
||||
const [deviceName, setDeviceName] = useState("");
|
||||
|
||||
useEffect(() => {
|
||||
@@ -35,46 +36,18 @@ const ShowAddStationPopup = ({ onClose, map, latlng }) => {
|
||||
|
||||
fetchpoiTypData();
|
||||
}, []);
|
||||
|
||||
//---------------------------------------------------------------------------------------
|
||||
/* useEffect(() => {
|
||||
// Funktion zum Abrufen der Daten von der API -> DB talas_v5.location_device
|
||||
const fetchData = async () => {
|
||||
try {
|
||||
const response = await fetch("/api/talas_v5/location_device"); // Pfad zu Ihrem API-Endpunkt
|
||||
const data = await response.json();
|
||||
setLocationDeviceData(data); // Setzt den Zustand mit den abgerufenen Daten
|
||||
console.log("Abgerufene Standort- und Gerätedaten:", data);
|
||||
} catch (error) {
|
||||
console.error(
|
||||
"Fehler beim Abrufen der Standort- und Gerätedaten:",
|
||||
error
|
||||
);
|
||||
}
|
||||
};
|
||||
|
||||
fetchData();
|
||||
}, []); // Leerarray als Dependency, um den Effekt nur beim Laden der Komponente auszuführen */
|
||||
|
||||
//------------------------------------------------------------------------------------------
|
||||
useEffect(() => {
|
||||
// Funktion zum Abrufen der Daten von der API -> DB talas_v5.location_device
|
||||
const fetchData = async () => {
|
||||
try {
|
||||
const response = await fetch("/api/talas5/location_device");
|
||||
const data = await response.json();
|
||||
setLocationDeviceData(data);
|
||||
if (data.length > 0) {
|
||||
setDeviceName(data[0].name); // Setzen des anfänglichen Gerätenamens
|
||||
}
|
||||
console.log("Abgerufene Standort- und Gerätedaten:", data);
|
||||
} catch (error) {
|
||||
console.error("Fehler beim Abrufen der Standort- und Gerätedaten:", error);
|
||||
}
|
||||
};
|
||||
const gisStationsStatic = useSelector(selectGisStationsStatic);
|
||||
const locationDeviceData = gisStationsStatic?.Points ?? [];
|
||||
|
||||
fetchData();
|
||||
}, []);
|
||||
console.log("gisStationsStatic aus AddPOIModal:", gisStationsStatic);
|
||||
|
||||
useEffect(() => {
|
||||
if (locationDeviceData?.length > 0) {
|
||||
console.log("🎯 Gerätedaten erfolgreich geladen:", locationDeviceData);
|
||||
setDeviceName((prev) => prev || locationDeviceData[0]?.LD_Name || "");
|
||||
}
|
||||
}, [locationDeviceData]);
|
||||
|
||||
//------------------------------------------------------------------------------------------
|
||||
//-----------------handleSubmit-------------------
|
||||
@@ -85,7 +58,7 @@ const ShowAddStationPopup = ({ onClose, map, latlng }) => {
|
||||
poiTypeId,
|
||||
latitude,
|
||||
longitude,
|
||||
idLD: locationDeviceData.find((device) => device.name === deviceName).idLD,
|
||||
idLD: locationDeviceData.find((device) => device.LD_Name === deviceName)?.IdLD,
|
||||
};
|
||||
|
||||
const response = await fetch("/api/talas_v5_DB/pois/addLocation", {
|
||||
@@ -134,11 +107,16 @@ const ShowAddStationPopup = ({ onClose, map, latlng }) => {
|
||||
Gerät:
|
||||
</label>
|
||||
<select id="deviceName" name="deviceName" value={deviceName} onChange={(e) => setDeviceName(e.target.value)} className="block p-2 w-full border-2 border-gray-200 rounded-md text-sm">
|
||||
{locationDeviceData.map((device, index) => (
|
||||
<option key={index} value={device.name}>
|
||||
{device.name}
|
||||
</option>
|
||||
))}
|
||||
<option value="">-- Gerät auswählen --</option>
|
||||
{locationDeviceData?.length > 0 ? (
|
||||
locationDeviceData.map((device, index) => (
|
||||
<option key={device?.IdLD || index} value={device?.LD_Name}>
|
||||
{device?.LD_Name || "Unbekanntes Gerät"}
|
||||
</option>
|
||||
))
|
||||
) : (
|
||||
<option disabled>Keine Geräte gefunden</option>
|
||||
)}
|
||||
</select>
|
||||
</div>
|
||||
|
||||
|
||||
@@ -76,6 +76,7 @@ import { useInitGisStationsMeasurements } from "./hooks/useInitGisStationsMeasur
|
||||
import { useInitGisSystemStatic } from "./hooks/useInitGisSystemStatic";
|
||||
import { selectGisSystemStatic, setGisSystemStatic } from "../../redux/slices/webService/gisSystemStaticSlice";
|
||||
import ShowAddStationPopup from "../AddPOIModal.js";
|
||||
import { useInitGisStationsStatic } from "../mainComponent/hooks/useInitGisStationsStatic";
|
||||
|
||||
const MapComponent = ({ locations, onLocationUpdate, lineCoordinates }) => {
|
||||
const dispatch = useDispatch();
|
||||
@@ -1039,6 +1040,7 @@ const MapComponent = ({ locations, onLocationUpdate, lineCoordinates }) => {
|
||||
useInitGisStationsStatusDistrict();
|
||||
useInitGisStationsMeasurements();
|
||||
useInitGisSystemStatic();
|
||||
useInitGisStationsStatic();
|
||||
|
||||
//--------------------------------------
|
||||
|
||||
|
||||
@@ -71,7 +71,6 @@ const addItemsToMapContextMenu = (
|
||||
if (!menuItemAdded && map && map.contextmenu) {
|
||||
const editMode = localStorage.getItem("editMode") === "true";
|
||||
if (editMode) {
|
||||
console.log("map :", map);
|
||||
console.log("editMode localStorage:", localStorage.getItem("editMode"));
|
||||
console.log("editMode:", editMode);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user