import { useState } from 'react' import { Table, Group, Text, TextInput } from '@mantine/core' import { IconPlus, IconPlayerPlay, IconTrash } from '@tabler/icons-react' import { Card, CardHeader, CardTitle, CardContent, SimpleSelect, Button, FnActionIcon } from '@fn_library' import * as WailsApp from '../wailsjs/go/main/App' import type { Entity, Assertion, AssertionResult, AssertionInput } from '../types' interface Props { entities: Entity[] } export function AssertionPanel({ entities }: Props) { const [assertions, setAssertions] = useState([]) const [results, setResults] = useState([]) const [selectedEntity, setSelectedEntity] = useState(entities[0]?.id ?? '') const [showAdd, setShowAdd] = useState(false) const [newName, setNewName] = useState('') const [newKind, setNewKind] = useState('range') const [newRule, setNewRule] = useState('') const [newSeverity, setNewSeverity] = useState('warning') const loadAssertions = async (entityId: string) => { setSelectedEntity(entityId) const list = await WailsApp.ListAssertions(entityId) as unknown as Assertion[] setAssertions(list || []) setResults([]) } const handleAdd = async () => { if (!newName || !newRule) return const input: AssertionInput = { entity_id: selectedEntity, name: newName, kind: newKind, rule: newRule, severity: newSeverity, description: '', } await WailsApp.AddAssertion(input as never) setShowAdd(false) setNewName('') setNewRule('') loadAssertions(selectedEntity) } const handleEval = async () => { const res = await WailsApp.EvalAssertions(selectedEntity) as unknown as AssertionResult[] setResults(res || []) } const handleDelete = async (id: string) => { await WailsApp.DeleteAssertion(id) loadAssertions(selectedEntity) } return ( Assertions ({ value: e.id, label: e.name }))} /> {showAdd && ( setNewName(e.currentTarget.value)} size="xs" flex={1} />
Kind
Severity
setNewRule(e.currentTarget.value)} placeholder="risk_score > 70" size="xs" flex={1} />
)} Name Kind Rule Severity Result Actions {assertions.map(a => { const result = results.find(r => r.assertion_id === a.id) return ( {a.name} {a.kind} {a.rule} {a.severity} {result ? ( {result.status} ) : '—'} } variant="subtle" size="sm" color="red" onClick={() => handleDelete(a.id)} /> ) })} {assertions.length === 0 && ( {selectedEntity ? 'No assertions for this entity' : 'Select an entity to view assertions'} )}
) }