fix: DocumentGenerator — 4 Bugs behoben (Suche, Sources, Status-Tiles)
All checks were successful
CI / go-lint (push) Has been skipped
CI / python-lint (push) Has been skipped
CI / nodejs-lint (push) Has been skipped
CI / test-go-ai-compliance (push) Successful in 41s
CI / test-python-backend-compliance (push) Successful in 37s
CI / test-python-document-crawler (push) Successful in 27s
CI / test-python-dsms-gateway (push) Successful in 21s
All checks were successful
CI / go-lint (push) Has been skipped
CI / python-lint (push) Has been skipped
CI / nodejs-lint (push) Has been skipped
CI / test-go-ai-compliance (push) Successful in 41s
CI / test-python-backend-compliance (push) Successful in 37s
CI / test-python-document-crawler (push) Successful in 27s
CI / test-python-dsms-gateway (push) Successful in 21s
- runSearch() extrahiert: löst stale-closure bei Schnellstart-Buttons - Suchbutton nicht mehr disabled bei leerem Query (zeigt alle Vorlagen) - Status-Tiles: status.total / status.by_status statt status.stats.* - getSources(): gibt strukturierte Objekte zurück statt rohe Strings (Verfügbare Quellen-Kacheln zeigen jetzt Inhalt) Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -312,17 +312,15 @@ function DocumentGeneratorPageInner() {
|
||||
}
|
||||
}, [placeholderValues, selectedDataPointsData])
|
||||
|
||||
// Search handler
|
||||
const handleSearch = useCallback(async () => {
|
||||
if (!searchQuery.trim()) return
|
||||
|
||||
// Core search — accepts explicit params to avoid stale closure issues
|
||||
const runSearch = useCallback(async (query: string, type?: string, lang?: string, jurisdiction?: string) => {
|
||||
setIsSearching(true)
|
||||
try {
|
||||
const results = await searchTemplates({
|
||||
query: searchQuery,
|
||||
templateType: selectedType || undefined,
|
||||
language: selectedLanguage || undefined,
|
||||
jurisdiction: selectedJurisdiction || undefined,
|
||||
query: query || '',
|
||||
templateType: type || undefined,
|
||||
language: (lang as 'de' | 'en') || undefined,
|
||||
jurisdiction: jurisdiction || undefined,
|
||||
limit: 20,
|
||||
})
|
||||
setSearchResults(results)
|
||||
@@ -331,7 +329,12 @@ function DocumentGeneratorPageInner() {
|
||||
} finally {
|
||||
setIsSearching(false)
|
||||
}
|
||||
}, [searchQuery, selectedType, selectedLanguage, selectedJurisdiction])
|
||||
}, [])
|
||||
|
||||
// Search handler (uses current state)
|
||||
const handleSearch = useCallback(async () => {
|
||||
runSearch(searchQuery, selectedType, selectedLanguage, selectedJurisdiction)
|
||||
}, [searchQuery, selectedType, selectedLanguage, selectedJurisdiction, runSearch])
|
||||
|
||||
// Toggle template selection
|
||||
const toggleTemplate = (id: string) => {
|
||||
@@ -408,25 +411,25 @@ function DocumentGeneratorPageInner() {
|
||||
{/* Status Overview */}
|
||||
<div className="grid grid-cols-1 md:grid-cols-4 gap-4">
|
||||
<div className="bg-white rounded-xl border border-gray-200 p-6">
|
||||
<div className="text-sm text-gray-500">Collection Status</div>
|
||||
<div className="text-sm text-gray-500">Datenbank</div>
|
||||
<div className="flex items-center gap-2 mt-1">
|
||||
<StatusBadge status={status?.stats?.status || 'unknown'} />
|
||||
<StatusBadge status={status !== null ? 'ready' : serviceMode === 'rag-only' ? 'running' : 'error'} />
|
||||
</div>
|
||||
</div>
|
||||
<div className="bg-white rounded-xl border border-gray-200 p-6">
|
||||
<div className="text-sm text-gray-500">Indexierte Chunks</div>
|
||||
<div className="text-sm text-gray-500">Vorlagen gesamt</div>
|
||||
<div className="text-3xl font-bold text-gray-900">
|
||||
{status?.stats?.points_count || 0}
|
||||
{status?.total ?? 0}
|
||||
</div>
|
||||
</div>
|
||||
<div className="bg-white rounded-xl border border-gray-200 p-6">
|
||||
<div className="text-sm text-gray-500">Aktive Quellen</div>
|
||||
<div className="text-sm text-gray-500">Veröffentlicht</div>
|
||||
<div className="text-3xl font-bold text-purple-600">
|
||||
{sources.filter((s) => s.enabled).length}
|
||||
{status?.by_status?.published ?? sources.length}
|
||||
</div>
|
||||
</div>
|
||||
<div className="bg-white rounded-xl border border-gray-200 p-6">
|
||||
<div className="text-sm text-gray-500">Ausgewaehlt</div>
|
||||
<div className="text-sm text-gray-500">Ausgewählt</div>
|
||||
<div className="text-3xl font-bold text-blue-600">
|
||||
{selectedTemplates.length}
|
||||
</div>
|
||||
@@ -503,10 +506,10 @@ function DocumentGeneratorPageInner() {
|
||||
</div>
|
||||
<button
|
||||
onClick={handleSearch}
|
||||
disabled={isSearching || !searchQuery.trim()}
|
||||
disabled={isSearching}
|
||||
className="px-6 py-2 bg-purple-600 text-white rounded-lg hover:bg-purple-700 transition-colors disabled:opacity-50"
|
||||
>
|
||||
{isSearching ? 'Suche...' : 'Suchen'}
|
||||
{isSearching ? 'Suche...' : 'Alle anzeigen'}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
@@ -570,7 +573,7 @@ function DocumentGeneratorPageInner() {
|
||||
onClick={() => {
|
||||
setSearchQuery(item.query)
|
||||
setSelectedType(item.type as TemplateType)
|
||||
setTimeout(handleSearch, 100)
|
||||
runSearch(item.query, item.type)
|
||||
}}
|
||||
className="p-4 bg-white rounded-lg border border-gray-200 hover:border-purple-300 hover:shadow transition-all text-center"
|
||||
>
|
||||
|
||||
@@ -132,10 +132,21 @@ export async function getTemplatesStatus(): Promise<any> {
|
||||
|
||||
export async function getSources(): Promise<any[]> {
|
||||
try {
|
||||
const res = await fetch(`${TEMPLATES_API}/sources`, { signal: AbortSignal.timeout(5000) })
|
||||
// Fetch status to get type counts for building source objects
|
||||
const res = await fetch(`${TEMPLATES_API}/status`, { signal: AbortSignal.timeout(5000) })
|
||||
if (!res.ok) return []
|
||||
const data = await res.json()
|
||||
return data.sources || []
|
||||
const byType: Record<string, number> = data.by_type || {}
|
||||
const activeTypes = Object.keys(byType).filter(k => byType[k] > 0)
|
||||
return [
|
||||
{
|
||||
name: 'BreakPilot Compliance',
|
||||
enabled: true,
|
||||
license_type: 'mit' as const,
|
||||
description: `${data.total || 0} selbst erstellte Vorlagen (MIT-Lizenz) — DE & EN`,
|
||||
template_types: activeTypes,
|
||||
},
|
||||
]
|
||||
} catch {
|
||||
return []
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user