'use client' /** * Source Policy Management Page (SDK Version) * * Whitelist-based data source management for edu-search-service. * For auditors: Full audit trail for all changes. */ import { useState, useEffect } from 'react' import { useSDK } from '@/lib/sdk' import StepHeader from '@/components/sdk/StepHeader/StepHeader' import { SourcesTab } from '@/components/sdk/source-policy/SourcesTab' import { OperationsMatrixTab } from '@/components/sdk/source-policy/OperationsMatrixTab' import { PIIRulesTab } from '@/components/sdk/source-policy/PIIRulesTab' import { AuditTab } from '@/components/sdk/source-policy/AuditTab' // API base URL for edu-search-service const getApiBase = () => { if (typeof window === 'undefined') return 'http://localhost:8088' const hostname = window.location.hostname if (hostname === 'localhost' || hostname === '127.0.0.1') { return 'http://localhost:8088' } return `https://${hostname}:8089` } interface PolicyStats { active_policies: number allowed_sources: number pii_rules: number blocked_today: number blocked_total: number } type TabId = 'dashboard' | 'sources' | 'operations' | 'pii' | 'audit' export default function SourcePolicyPage() { const { state } = useSDK() const [activeTab, setActiveTab] = useState('dashboard') const [stats, setStats] = useState(null) const [loading, setLoading] = useState(true) const [error, setError] = useState(null) const [apiBase, setApiBase] = useState(null) useEffect(() => { const base = getApiBase() setApiBase(base) }, []) useEffect(() => { if (apiBase !== null) { fetchStats() } }, [apiBase]) const fetchStats = async () => { try { setLoading(true) const res = await fetch(`${apiBase}/v1/admin/policy-stats`) if (!res.ok) { throw new Error('Fehler beim Laden der Statistiken') } const data = await res.json() setStats(data) } catch (err) { setError(err instanceof Error ? err.message : 'Unbekannter Fehler') setStats({ active_policies: 0, allowed_sources: 0, pii_rules: 0, blocked_today: 0, blocked_total: 0, }) } finally { setLoading(false) } } const tabs: { id: TabId; name: string; icon: JSX.Element }[] = [ { id: 'dashboard', name: 'Dashboard', icon: ( ), }, { id: 'sources', name: 'Quellen', icon: ( ), }, { id: 'operations', name: 'Operations', icon: ( ), }, { id: 'pii', name: 'PII-Regeln', icon: ( ), }, { id: 'audit', name: 'Audit', icon: ( ), }, ] return (
{/* Error Display */} {error && (
{error}
)} {/* Stats Cards */} {stats && (
{stats.active_policies}
Aktive Policies
{stats.allowed_sources}
Zugelassene Quellen
{stats.blocked_today}
Blockiert (heute)
{stats.pii_rules}
PII-Regeln
)} {/* Tabs */}
{tabs.map((tab) => ( ))}
{/* Tab Content */} {apiBase === null ? (
Initialisiere...
) : ( <> {activeTab === 'dashboard' && (
{loading ? 'Lade Dashboard...' : 'Dashboard-Ansicht - Wechseln Sie zu einem Tab fuer Details.'}
)} {activeTab === 'sources' && } {activeTab === 'operations' && } {activeTab === 'pii' && } {activeTab === 'audit' && } )}
) }