import { useState } from 'react'; import { createPortal } from 'react-dom'; import PopupForm from '../PopupForm'; import FieldSelectForm from '../FieldSelectForm'; import FieldAggregateForm from '../FieldAggregateForm'; import FieldFilterForm from '../FieldFilterForm'; import styles from './FieldAddForm.module.css'; export function FieldAddForm({ fields = [], type, element, onAdd, onClose }) { const [selected, setSelected] = useState(); const handleSelect = value => { if (type === 'groups') { handleSave(value); return; } setSelected(value); }; const handleSave = value => { onAdd(type, value); onClose(); }; return createPortal( {!selected && } {selected && type === 'fields' && } {selected && type === 'filters' && } , document.body, ); } export default FieldAddForm;