feat: Referenzkurve-Button sendet API-Aufruf an Backend (KTR)

- handleSetReference um fetch-Aufruf ergänzt
- Unterscheidung von Entwicklungs- und Produktionsumgebung via NEXT_PUBLIC_API_BASE_URL
- Fehlerbehandlung und Alert bei Erfolg/Misserfolg eingebaut
This commit is contained in:
ISA
2025-03-31 10:05:36 +02:00
parent 14ba25bc57
commit 6b6b6cc9b8
4 changed files with 62 additions and 12 deletions

View File

@@ -121,13 +121,13 @@ const TDRChart: React.FC<{ isFullScreen: boolean }> = ({ isFullScreen }) => {
pointRadius: 10,
pointStyle: "triangle", // Hier den korrekten Stil setzen
showLine: false,
clip: true, // Wenn du die Fehlerstelle sichtbar sehen möchtest
clip: false, // Wenn du die Fehlerstelle sichtbar sehen möchtest
parsing: {
xAxisKey: "d",
yAxisKey: "p",
},
order: 9999,
z: 10, // Hier die Reihenfolge der Marker bestimmen
// Hier die Reihenfolge der Marker bestimmen
},
],
},

View File

@@ -37,18 +37,41 @@ const TDRChartActionBar: React.FC = () => {
};
// 📌 Referenz setzen (nutzt Slotnummer + 1 für die API)
const handleSetReference = () => {
if (selectedSlot === null || !currentChartData?.length) return;
const handleSetReference = async () => {
if (
selectedSlot === null ||
selectedId === null ||
!currentChartData?.length
)
return;
localStorage.setItem(
`ref-curve-slot${selectedSlot}`,
JSON.stringify(currentChartData)
);
try {
const slotNumber = selectedSlot + 1; // Slot ist 0-basiert, API will 1-basiert
const url = `/CPL?KTR${slotNumber}=${selectedId}`;
// 🔄 Redux updaten → Chart reagiert sofort!
dispatch(fetchReferenceCurveBySlotThunk(selectedSlot));
const response = await fetch(url, {
method: "GET",
});
alert("Referenzkurve gesetzt!");
if (!response.ok) {
throw new Error(
`Fehler beim Setzen der Referenz: ${response.statusText}`
);
}
// Optional: lokale Speicherung und Redux-Update
localStorage.setItem(
`ref-curve-slot${selectedSlot}`,
JSON.stringify(currentChartData)
);
dispatch(fetchReferenceCurveBySlotThunk(selectedSlot));
alert("Referenzkurve wurde erfolgreich gesetzt!");
} catch (error) {
console.error("Fehler beim Setzen der Referenzkurve:", error);
alert("Fehler beim Setzen der Referenzkurve.");
}
};
// 📥 Beim Slot-Wechsel TDM-Liste + letzte ID laden

View File

@@ -0,0 +1,27 @@
<mxfile host="65bd71144e">
<diagram id="95LLT6B1yb-ZXk_jyexu" name="Page-1">
<mxGraphModel dx="1732" dy="894" grid="1" gridSize="10" guides="1" tooltips="1" connect="1" arrows="1" fold="1" page="1" pageScale="1" pageWidth="850" pageHeight="1100" math="0" shadow="0">
<root>
<mxCell id="0"/>
<mxCell id="1" parent="0"/>
<mxCell id="2" value="&lt;div style=&quot;color: rgb(204, 204, 204); background-color: rgb(31, 31, 31); font-family: Consolas, &amp;quot;Courier New&amp;quot;, monospace; font-size: 14px; line-height: 19px; white-space: pre;&quot;&gt;&lt;span style=&quot;color: #dcdcaa;&quot;&gt;handleSetReference&lt;/span&gt;&lt;/div&gt;" style="rounded=0;whiteSpace=wrap;html=1;" parent="1" vertex="1">
<mxGeometry x="50" y="160" width="120" height="60" as="geometry"/>
</mxCell>
<mxCell id="3" value="" style="endArrow=classic;html=1;exitX=1;exitY=0.5;exitDx=0;exitDy=0;" parent="1" source="2" edge="1">
<mxGeometry width="50" height="50" relative="1" as="geometry">
<mxPoint x="400" y="480" as="sourcePoint"/>
<mxPoint x="310" y="190" as="targetPoint"/>
</mxGeometry>
</mxCell>
<mxCell id="6" value="fetch" style="edgeLabel;html=1;align=center;verticalAlign=middle;resizable=0;points=[];" parent="3" vertex="1" connectable="0">
<mxGeometry x="0.3333" y="-2" relative="1" as="geometry">
<mxPoint x="-20" y="-22" as="offset"/>
</mxGeometry>
</mxCell>
<mxCell id="7" value="&lt;h6 style=&quot;font-family: Consolas, &amp;quot;Courier New&amp;quot;, monospace; line-height: 19px; white-space: pre;&quot;&gt;&lt;font style=&quot;color: rgb(0, 0, 0); background-color: light-dark(#ffffff, var(--ge-dark-color, #121212)); font-size: 10px;&quot;&gt;fetchReferenceCurveBySlotThunk&lt;/font&gt;&lt;/h6&gt;" style="rounded=1;whiteSpace=wrap;html=1;" vertex="1" parent="1">
<mxGeometry x="310" y="152.5" width="190" height="75" as="geometry"/>
</mxCell>
</root>
</mxGraphModel>
</diagram>
</mxfile>

View File

@@ -14,7 +14,7 @@ export const fetchTDRReferenceCurve = async (
const isDev = process.env.NEXT_PUBLIC_NODE_ENV === "development";
const url = isDev
? `/CPLmockData/tdr-reference-curves/slot${slot}.json`
: `${window.location.origin}/CPL?Service/empty.acp&TDRR=${slot}`;
: `${window.location.origin}/CPL?Service/empty.acp&TDR=${slot}`;
try {
const res = await fetch(url);