import { useTranslation } from 'react-i18next' import { Dialog, DialogContent, DialogHeader, DialogTitle, DialogFooter, DialogDescription } from '@/components/ui/Dialog' import Button from '@/components/ui/Button' import Checkbox from '@/components/ui/Checkbox' interface PropertyEditDialogProps { isOpen: boolean onClose: () => void onSave: () => void | Promise propertyName: string value: string allowMerge: boolean onValueChange: (value: string) => void onAllowMergeChange: (allowMerge: boolean) => void isSubmitting?: boolean errorMessage?: string | null } /** * Dialog component for editing property values * Provides a modal with a title, multi-line text input, and save/cancel buttons */ const PropertyEditDialog = ({ isOpen, onClose, onSave, propertyName, value, allowMerge, onValueChange, onAllowMergeChange, isSubmitting = false, errorMessage = null }: PropertyEditDialogProps) => { const { t } = useTranslation() // Get translated property name const getPropertyNameTranslation = (name: string) => { const translationKey = `graphPanel.propertiesView.node.propertyNames.${name}` const translation = t(translationKey) return translation === translationKey ? name : translation } // Get textarea configuration based on property name const getTextareaConfig = (propertyName: string) => { switch (propertyName) { case 'description': return { // No rows attribute for description to allow auto-sizing className: 'max-h-[50vh] min-h-[10em] resize-y', // Maximum height 70% of viewport, minimum height ~20 lines, allow vertical resizing style: { height: '70vh', // Set initial height to 70% of viewport minHeight: '20em', // Minimum height ~20 lines resize: 'vertical' as const // Allow vertical resizing, using 'as const' to fix type } }; case 'entity_id': return { rows: 2, className: '', style: {} }; case 'keywords': return { rows: 4, className: '', style: {} }; default: return { rows: 5, className: '', style: {} }; } }; const handleSave = async () => { const trimmedValue = value.trim() if (trimmedValue !== '') { await onSave() } } return ( !open && onClose()}> {t('graphPanel.propertiesView.editProperty', { property: getPropertyNameTranslation(propertyName) })} {t('graphPanel.propertiesView.editPropertyDescription')} {/* Display error message if save fails */} {errorMessage && (
{errorMessage}
)} {/* Multi-line text input using textarea */}
{(() => { const config = getTextareaConfig(propertyName); return propertyName === 'description' ? (