import { ClearOutlined } from '@ant-design/icons'; import { Button, Col, Layout, Modal, Row, Select, Tag } from 'antd'; import { usePlugin, useValue } from 'flipper-plugin'; import React, { useState } from 'react'; import { plugin } from '../../..'; import { renderValue } from '../../../utils/Renderer'; import { getDefault, TypeInput, TypeInputProps } from './TypeInput'; export const MixedInput = ({ set, defaultValue, isPrimary, }: TypeInputProps) => { const [reset, setReset] = useState(0); const [chosen, setChosen] = useState(false); const [visible, setVisible] = useState(false); const [chosenType, setChosenType] = useState('string'); const [value, setValue] = useState( defaultValue === null ? undefined : defaultValue ); const { state, downloadData } = usePlugin(plugin); const { schemas } = useValue(state); const addObject = () => { set(value); // setChosenType() setReset((v) => v + 1); setChosen(true); hideModal(); }; const hideModal = () => { setVisible(false); }; const cancelWindow = () => { set(null); setValue(null); setChosenType('string'); setReset((v) => v + 1); hideModal(); }; const onChangeSelect = (newType: string) => { setChosenType(newType); const typeObj = { type: newType, optional: false, }; const defaultValue = getDefault(typeObj); setValue(defaultValue); }; const renderChosen = () => { const objectType = schemas.find((schema) => schema.name === chosenType); let type; if (objectType) { type = 'object'; } else { type = chosenType; } return ( {chosenType} {renderValue(value, { type, objectType: objectType?.name }, schemas, {downloadData})} ); }; const renderSelector = () => { const typeList = [ // 'objectId', // 'uuid', 'bool', 'int', 'float', 'double', // 'decimal128', 'string', // 'data', // 'date', ].reverse(); return (
Select a type:
{ setValue(val); }} defaultValue={value} extraProps={{ style: { width: '100%' } }} >
); }; return chosen ? renderChosen() : renderSelector(); };