feat(cra): 'Projekt anlegen' aus Datenblatt → IACE mit editierbaren Grenzen
DatasheetExtract: Button legt ein IACE-Projekt an (POST /iace/projects) und speichert die extrahierten Grenzen + Rückfrage-Antworten als metadata.limits_form (PUT), dann Navigation ins Interview. Das Interview-Formular bleibt voll editierbar (jedes vorbefuellte Feld aenderbar, Auto-Save). Manuelles Anlegen ueber /sdk/iace bleibt unveraendert. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
@@ -1,6 +1,7 @@
|
|||||||
'use client'
|
'use client'
|
||||||
|
|
||||||
import { useState } from 'react'
|
import { useState } from 'react'
|
||||||
|
import { useRouter } from 'next/navigation'
|
||||||
import { DATASHEET_EXAMPLES } from './readiness-presets'
|
import { DATASHEET_EXAMPLES } from './readiness-presets'
|
||||||
|
|
||||||
interface Followup { key: string; label: string; question: string }
|
interface Followup { key: string; label: string; question: string }
|
||||||
@@ -27,9 +28,11 @@ const FIELD_LABEL: Record<string, string> = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export function DatasheetExtract() {
|
export function DatasheetExtract() {
|
||||||
|
const router = useRouter()
|
||||||
const [text, setText] = useState('')
|
const [text, setText] = useState('')
|
||||||
const [res, setRes] = useState<ExtractResult | null>(null)
|
const [res, setRes] = useState<ExtractResult | null>(null)
|
||||||
const [loading, setLoading] = useState(false)
|
const [loading, setLoading] = useState(false)
|
||||||
|
const [creating, setCreating] = useState(false)
|
||||||
const [answers, setAnswers] = useState<Record<string, string>>({})
|
const [answers, setAnswers] = useState<Record<string, string>>({})
|
||||||
|
|
||||||
const run = async () => {
|
const run = async () => {
|
||||||
@@ -44,6 +47,39 @@ export function DatasheetExtract() {
|
|||||||
} finally { setLoading(false) }
|
} finally { setLoading(false) }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Create an IACE project from the extracted limits + follow-up answers. The
|
||||||
|
// limits land as the project's editable limits_form; the interview form stays
|
||||||
|
// fully editable (every prefilled field can be changed). Manual creation via
|
||||||
|
// /sdk/iace remains unchanged.
|
||||||
|
const createProject = async () => {
|
||||||
|
if (!res) return
|
||||||
|
setCreating(true)
|
||||||
|
try {
|
||||||
|
const nonEmptyAnswers = Object.fromEntries(
|
||||||
|
Object.entries(answers).filter(([, v]) => (v || '').trim()),
|
||||||
|
)
|
||||||
|
const limits = { ...res.limits, ...nonEmptyAnswers }
|
||||||
|
const machineName = limits.machine_designation || limits.machine_type || 'Neues Produkt'
|
||||||
|
const cr = await fetch('/api/sdk/v1/iace/projects', {
|
||||||
|
method: 'POST', headers: { 'Content-Type': 'application/json' },
|
||||||
|
body: JSON.stringify({
|
||||||
|
machine_name: machineName,
|
||||||
|
machine_type: limits.machine_type || '',
|
||||||
|
manufacturer: limits.manufacturer || '',
|
||||||
|
}),
|
||||||
|
})
|
||||||
|
if (!cr.ok) return
|
||||||
|
const proj = await cr.json()
|
||||||
|
const pid = proj.id || proj.project_id
|
||||||
|
if (!pid) return
|
||||||
|
await fetch(`/api/sdk/v1/iace/projects/${pid}`, {
|
||||||
|
method: 'PUT', headers: { 'Content-Type': 'application/json' },
|
||||||
|
body: JSON.stringify({ metadata: { limits_form: limits } }),
|
||||||
|
})
|
||||||
|
router.push(`/sdk/iace/${pid}/interview`)
|
||||||
|
} finally { setCreating(false) }
|
||||||
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="rounded-xl border border-indigo-200 dark:border-indigo-800 bg-indigo-50/50 dark:bg-indigo-900/20 p-5 mb-6">
|
<div className="rounded-xl border border-indigo-200 dark:border-indigo-800 bg-indigo-50/50 dark:bg-indigo-900/20 p-5 mb-6">
|
||||||
<h2 className="text-lg font-semibold text-gray-900 dark:text-gray-100">Datenblatt-Analyse → Maschinengrenzen</h2>
|
<h2 className="text-lg font-semibold text-gray-900 dark:text-gray-100">Datenblatt-Analyse → Maschinengrenzen</h2>
|
||||||
@@ -129,9 +165,19 @@ export function DatasheetExtract() {
|
|||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
<p className="text-xs text-gray-500 italic">
|
<div className="flex flex-wrap items-center gap-3">
|
||||||
Nächster Schritt: „Projekt anlegen" überträgt diese Grenzen + Antworten in das IACE-Modul; daraus
|
<button onClick={createProject} disabled={creating}
|
||||||
werden Gefährdungen und Maßnahmen abgeleitet (Entwurf — Bestätigung mit Sicherheitsingenieur).
|
className="rounded bg-indigo-600 hover:bg-indigo-700 disabled:opacity-50 text-white text-sm px-4 py-2">
|
||||||
|
{creating ? 'Lege an …' : 'IACE-Projekt anlegen (Grenzen übernehmen)'}
|
||||||
|
</button>
|
||||||
|
<span className="text-xs text-gray-500">
|
||||||
|
Übernimmt Grenzen + Antworten als <span className="font-medium">editierbaren Entwurf</span> ins
|
||||||
|
IACE-Interview — jedes Feld bleibt änderbar. Manuelles Anlegen weiterhin über{' '}
|
||||||
|
<a href="/sdk/iace" className="text-indigo-600 hover:underline">iACE</a>.
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
<p className="text-xs text-gray-400 italic">
|
||||||
|
Aus den Grenzen leitet IACE anschließend Gefährdungen und Maßnahmen ab (Entwurf — Bestätigung mit Sicherheitsingenieur).
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
|
|||||||
Reference in New Issue
Block a user