Removed example for edit mode.
parent
7eeca5c3ba
commit
3d6458ffb0
|
|
@ -30,6 +30,7 @@ const emptyKPI: Partial<Kennzahl> = {
|
|||
|
||||
export function KPIForm({ mode, initialData, onSave, onCancel, loading = false, resetTrigger }: KPIFormProps) {
|
||||
const [formData, setFormData] = useState<Partial<Kennzahl>>(emptyKPI);
|
||||
const [originalExamples, setOriginalExamples] = useState<Array<{ sentence: string; value: string }>>([]);
|
||||
const [isSaving, setIsSaving] = useState(false);
|
||||
const [snackbarOpen, setSnackbarOpen] = useState(false);
|
||||
const [snackbarMessage, setSnackbarMessage] = useState("");
|
||||
|
|
@ -38,14 +39,20 @@ export function KPIForm({ mode, initialData, onSave, onCancel, loading = false,
|
|||
|
||||
useEffect(() => {
|
||||
if (mode === 'edit' && initialData) {
|
||||
setFormData(initialData);
|
||||
setOriginalExamples(initialData.examples || []);
|
||||
setFormData({
|
||||
...initialData,
|
||||
examples: [{ sentence: '', value: '' }]
|
||||
});
|
||||
} else if (mode === 'add') {
|
||||
setOriginalExamples([]);
|
||||
setFormData(emptyKPI);
|
||||
}
|
||||
}, [mode, initialData]);
|
||||
|
||||
useEffect(() => {
|
||||
if (mode === 'add') {
|
||||
setOriginalExamples([]);
|
||||
setFormData(emptyKPI);
|
||||
}
|
||||
}, [resetTrigger]);
|
||||
|
|
@ -65,24 +72,30 @@ export function KPIForm({ mode, initialData, onSave, onCancel, loading = false,
|
|||
setSnackbarMessage("Mindestens ein Beispielsatz ist erforderlich");
|
||||
setSnackbarSeverity("error");
|
||||
setSnackbarOpen(true);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
for (const ex of formData.examples) {
|
||||
const newExamples = formData.examples.filter(ex => ex.sentence?.trim() && ex.value?.trim());
|
||||
|
||||
if (newExamples.length === 0) {
|
||||
setSnackbarMessage('Mindestens ein vollständiger Beispielsatz ist erforderlich.');
|
||||
setSnackbarSeverity("error");
|
||||
setSnackbarOpen(true);
|
||||
return;
|
||||
}
|
||||
|
||||
for (const ex of newExamples) {
|
||||
if (!ex.sentence?.trim() || !ex.value?.trim()) {
|
||||
setSnackbarMessage('Alle Beispielsätze müssen vollständig sein.');
|
||||
setSnackbarSeverity("error");
|
||||
setSnackbarOpen(true);
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
setIsSaving(true);
|
||||
try {
|
||||
const spacyEntries = generateSpacyEntries(formData);
|
||||
const spacyEntries = generateSpacyEntries({ ...formData, examples: newExamples });
|
||||
|
||||
// Für jeden einzelnen Beispielsatz:
|
||||
for (const entry of spacyEntries) {
|
||||
|
|
@ -110,6 +123,10 @@ export function KPIForm({ mode, initialData, onSave, onCancel, loading = false,
|
|||
console.log("SpaCy-Eintrag gespeichert:", data);
|
||||
}
|
||||
|
||||
const allExamples = mode === 'edit'
|
||||
? [...originalExamples, ...newExamples]
|
||||
: newExamples;
|
||||
|
||||
// Dann in die DB speichern
|
||||
await onSave({
|
||||
name: formData.name!,
|
||||
|
|
@ -117,11 +134,18 @@ export function KPIForm({ mode, initialData, onSave, onCancel, loading = false,
|
|||
type: formData.type || 'string',
|
||||
position: formData.position ?? 0,
|
||||
active: formData.active ?? true,
|
||||
examples: formData.examples ?? [],
|
||||
is_trained: false,
|
||||
examples: allExamples,
|
||||
is_trained: false,
|
||||
});
|
||||
// Formular zurücksetzen:
|
||||
setFormData(emptyKPI);
|
||||
if (mode === 'add') {
|
||||
setFormData(emptyKPI);
|
||||
} else {
|
||||
setFormData(prev => ({
|
||||
...prev,
|
||||
examples: [{ sentence: '', value: '' }]
|
||||
}));
|
||||
}
|
||||
|
||||
|
||||
setSnackbarMessage("Beispielsätze gespeichert. Jetzt auf -Neu trainieren- klicken oder weitere Kennzahlen hinzufügen.");
|
||||
|
|
@ -292,6 +316,18 @@ export function KPIForm({ mode, initialData, onSave, onCancel, loading = false,
|
|||
|
||||
<Divider sx={{ my: 3 }} />
|
||||
|
||||
{/* Hinweistext wie viele Beispielsätzen vorhanden sind*/}
|
||||
{mode === 'edit' && originalExamples.length > 0 && (
|
||||
<Box mb={2} p={2} sx={{ backgroundColor: '#e3f2fd', border: '1px solid #90caf9', borderRadius: 2 }}>
|
||||
<Typography variant="body1" sx={{ fontWeight: 'bold', mb: 1 }}>
|
||||
Vorhandene Beispielsätze: {originalExamples.length}
|
||||
</Typography>
|
||||
<Typography variant="body2">
|
||||
Diese Kennzahl hat bereits {originalExamples.length} Beispielsätze. Neue Beispielsätze werden zu den vorhandenen hinzugefügt.
|
||||
</Typography>
|
||||
</Box>
|
||||
)}
|
||||
|
||||
{/* Hinweistext vor Beispielsätzen */}
|
||||
<Box mb={2} p={2} sx={{ backgroundColor: '#fff8e1', border: '1px solid #ffe082', borderRadius: 2 }}>
|
||||
<Typography variant="body1" sx={{ fontWeight: 'bold', mb: 1 }}>
|
||||
|
|
|
|||
Loading…
Reference in New Issue