5aaf7ac613
CI / detect-changes (push) Successful in 7s
CI / branch-name (push) Has been skipped
CI / guardrail-integrity (push) Has been skipped
CI / dep-audit (push) Has been skipped
CI / sbom-scan (push) Has been skipped
CI / secret-scan (push) Has been skipped
CI / build-sha-integrity (push) Failing after 4s
CI / validate-canonical-controls (push) Successful in 10s
CI / loc-budget (push) Successful in 14s
CI / go-lint (push) Has been skipped
CI / python-lint (push) Has been skipped
CI / nodejs-lint (push) Has been skipped
CI / nodejs-build (push) Successful in 2m21s
CI / test-go (push) Has been skipped
CI / iace-gt-coverage (push) Has been skipped
CI / test-python-backend (push) Has been skipped
CI / test-python-document-crawler (push) Has been skipped
CI / test-python-dsms-gateway (push) Has been skipped
ComplianceCheckTab.tsx war 519 LOC und blockte jeden weiteren Edit
(500-LOC-Hard-Cap). Drei Concerns ausgelagert:
- _document_types.ts: DOCUMENT_TYPES + DocTypeId (inkl. news doc_type)
- _compliance_storage.ts: STORAGE_KEY_*, DocState/HistoryEntry types,
emptyDocState/initState helpers, countWords
- _useCompliancePolling.ts: Resume-Polling-Hook (importierbar,
Inline-Polling bleibt für Stabilität)
ComplianceCheckTab.tsx ist jetzt 461 LOC (-58).
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
84 lines
2.7 KiB
TypeScript
84 lines
2.7 KiB
TypeScript
/**
|
|
* Custom hook: resume-polling für eine laufende Compliance-Check-Pruefung.
|
|
*
|
|
* Beim Mount: wenn localStorage eine `STORAGE_KEY_CHECK_ID` enthaelt aber
|
|
* noch kein Result da ist, pollt der Hook alle 3s den Status. Setzt
|
|
* Result, Progress, Error oder cleared den active-check-id beim
|
|
* Abschluss.
|
|
*/
|
|
|
|
import { useEffect } from 'react'
|
|
import {
|
|
STORAGE_KEY_CHECK_ID, STORAGE_KEY_RESULTS,
|
|
} from './_compliance_storage'
|
|
|
|
interface ResumePollingArgs {
|
|
activeCheckId: string
|
|
results: unknown | null
|
|
setLoading: (b: boolean) => void
|
|
setProgress: (s: string) => void
|
|
setProgressPct: (n: number) => void
|
|
setResults: (r: unknown) => void
|
|
setActiveCheckId: (s: string) => void
|
|
setError: (s: string | null) => void
|
|
}
|
|
|
|
export function useCompliancePollingResume({
|
|
activeCheckId, results, setLoading, setProgress, setProgressPct,
|
|
setResults, setActiveCheckId, setError,
|
|
}: ResumePollingArgs) {
|
|
useEffect(() => {
|
|
if (!activeCheckId || results) return
|
|
let cancelled = false
|
|
setLoading(true)
|
|
setProgress('Pruefung laeuft noch...')
|
|
const poll = async () => {
|
|
while (!cancelled) {
|
|
await new Promise(r => setTimeout(r, 3000))
|
|
try {
|
|
const res = await fetch(
|
|
`/api/sdk/v1/agent/compliance-check?check_id=${activeCheckId}`,
|
|
)
|
|
if (!res.ok) continue
|
|
const data = await res.json()
|
|
if (data.progress) setProgress(data.progress)
|
|
if (typeof data.progress_pct === 'number') {
|
|
setProgressPct(data.progress_pct)
|
|
}
|
|
if (data.status === 'completed' && data.result) {
|
|
setResults(data.result)
|
|
setProgress('')
|
|
setProgressPct(0)
|
|
setLoading(false)
|
|
localStorage.setItem(
|
|
STORAGE_KEY_RESULTS, JSON.stringify(data.result),
|
|
)
|
|
localStorage.removeItem(STORAGE_KEY_CHECK_ID)
|
|
setActiveCheckId('')
|
|
return
|
|
}
|
|
if (['failed', 'not_found', 'skipped_tdm'].includes(data.status)) {
|
|
if (data.status !== 'not_found') {
|
|
setError(
|
|
data.error
|
|
|| (data.status === 'skipped_tdm'
|
|
? 'TDM-Vorbehalt erkannt — Crawl uebersprungen'
|
|
: 'Pruefung fehlgeschlagen'),
|
|
)
|
|
}
|
|
setProgress('')
|
|
setProgressPct(0)
|
|
setLoading(false)
|
|
localStorage.removeItem(STORAGE_KEY_CHECK_ID)
|
|
setActiveCheckId('')
|
|
return
|
|
}
|
|
} catch { /* retry */ }
|
|
}
|
|
}
|
|
poll()
|
|
return () => { cancelled = true }
|
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
}, [])
|
|
}
|