import { Select } from '@headlessui/react' import { ChevronDownIcon } from '@heroicons/react/20/solid' import { TrashIcon } from '@heroicons/react/24/outline' import { PlusIcon } from '@heroicons/react/24/solid' import clsx from 'clsx' import { PluginsIcon } from '../icons/dual-tone/PluginsIcon' // Recursive component for rendering nested parameters const ParamRenderer = ({ param, subValue, setParam, path = [], value }) => { let content switch (param.type) { case 'string': content = ( setParam(path, e.target.value)} value={value || ''} /> ) break case 'number': content = ( setParam(path, Number.parseInt(e.target.value))} value={value || ''} /> ) break case 'object': content = (
{Object.entries(param.value).map(([key, value]) => ( setParam(path, value)} /> ))}
) break case 'array': content = (
{param.value.map((item, index) => (
{ const newValue = param.value newValue[index] = e.target.value setParam(path, newValue) }} value={item} /> { const newValue = param.value newValue.splice(index, 1) setParam(path, newValue) }} />
))} { // add item to array const newValue = param.value newValue.push('') setParam(path, newValue) }} />
) break case 'boolean': content = (
) break case 'option': content = (
) break case 'arrayKeyValuePair': content = (
{ const newValue = [e.target.value, value ? value[1] : ''] setParam(path, newValue) }} value={value ? value[0] : ''} /> { const newValue = [value ? value[0] : '', e.target.value] setParam(path, newValue) }} value={value ? value[1] : ''} />
) break default: content = {String(param.value)} } return (
{param.type} {param.required && ( required )}
{param.description}
{content}
) } const ApiParameterDisplay = ({ params, setParam, body }) => { return (
Body Params
{params.map((param) => ( setParam(path, value)} /> ))}
) } export default ApiParameterDisplay