import { useState } from 'react' import { Stack, Group, TextInput, Textarea, Text, NumberInput } from '@mantine/core' import { Dialog, DialogContent, DialogHeader, DialogTitle, DialogFooter, SimpleSelect, Button } from '@fn_library' import type { Entity, RelationInputDTO } from '../types' interface Props { entities: Entity[] relationPresets: string[] onSubmit: (input: RelationInputDTO) => void onClose: () => void } export function RelationDialog({ entities, relationPresets, onSubmit, onClose }: Props) { const [name, setName] = useState(relationPresets[0] ?? '') const [fromEntity, setFromEntity] = useState(entities[0]?.id ?? '') const [toEntity, setToEntity] = useState(entities[1]?.id ?? entities[0]?.id ?? '') const [description, setDescription] = useState('') const [weight, setWeight] = useState(1.0) const [notes, setNotes] = useState('') const handleSubmit = () => { const w = typeof weight === 'number' ? weight : parseFloat(String(weight)) onSubmit({ name, from_entity: fromEntity, to_entity: toEntity, description, weight: isNaN(w) ? null : w, tags: [], notes, }) } return ( { if (!open) onClose() }}> New Relation
Relation Type ({ value: p, label: p }))} />
From ({ value: e.id, label: e.name }))} />
To ({ value: e.id, label: e.name }))} />
setDescription(e.currentTarget.value)} size="sm" />