import React, { useMemo } from 'react'; import { IconCaretDown, IconForms, IconBraces, IconCode, IconFileText, IconDatabase, IconFile, IconX } from '@tabler/icons'; import MenuDropdown from 'ui/MenuDropdown'; import { humanizeRequestBodyMode } from 'utils/collections'; import StyledWrapper from './StyledWrapper'; const DEFAULT_MODES = [ { name: 'Form', options: [ { id: 'multipartForm', label: 'Multipart Form', leftSection: IconForms }, { id: 'formUrlEncoded', label: 'Form URL Encoded', leftSection: IconForms } ] }, { name: 'Raw', options: [ { id: 'json', label: 'JSON', leftSection: IconBraces }, { id: 'xml', label: 'XML', leftSection: IconCode }, { id: 'text', label: 'TEXT', leftSection: IconFileText }, { id: 'sparql', label: 'SPARQL', leftSection: IconDatabase } ] }, { name: 'Other', options: [ { id: 'file', label: 'File / Binary', leftSection: IconFile }, { id: 'none', label: 'No Body', leftSection: IconX } ] } ]; const BodyModeSelector = ({ currentMode, onModeChange, modes = DEFAULT_MODES, disabled = false, className = '', wrapperClassName = '', placement = 'bottom-end' }) => { // Add onClick handlers to mode options const menuItems = useMemo(() => { return modes.map((group) => ({ ...group, options: group.options.map((option) => ({ ...option, onClick: () => onModeChange(option.id) })) })); }, [modes, onModeChange]); return (
{humanizeRequestBodyMode(currentMode)} {' '}
); }; export default BodyModeSelector;