({
value,
onChange,
inputParam,
nodes,
edges,
nodeId,
disabled = false,
isDarkMode = false,
isSequentialAgent = false
})
| 7 | import { getAvailableNodesForVariable } from '@/utils/genericHelper' |
| 8 | |
| 9 | export const JsonEditorInput = ({ |
| 10 | value, |
| 11 | onChange, |
| 12 | inputParam, |
| 13 | nodes, |
| 14 | edges, |
| 15 | nodeId, |
| 16 | disabled = false, |
| 17 | isDarkMode = false, |
| 18 | isSequentialAgent = false |
| 19 | }) => { |
| 20 | const [myValue, setMyValue] = useState(value ? JSON.parse(value) : {}) |
| 21 | const [availableNodesForVariable, setAvailableNodesForVariable] = useState([]) |
| 22 | const [mouseUpKey, setMouseUpKey] = useState('') |
| 23 | |
| 24 | const [anchorEl, setAnchorEl] = useState(null) |
| 25 | const openPopOver = Boolean(anchorEl) |
| 26 | |
| 27 | const handleClosePopOver = () => { |
| 28 | setAnchorEl(null) |
| 29 | } |
| 30 | |
| 31 | const setNewVal = (val) => { |
| 32 | const newVal = cloneDeep(myValue) |
| 33 | newVal[mouseUpKey] = val |
| 34 | onChange(JSON.stringify(newVal)) |
| 35 | setMyValue((params) => ({ |
| 36 | ...params, |
| 37 | [mouseUpKey]: val |
| 38 | })) |
| 39 | } |
| 40 | |
| 41 | const onClipboardCopy = (e) => { |
| 42 | const src = e.src |
| 43 | if (Array.isArray(src) || typeof src === 'object') { |
| 44 | navigator.clipboard.writeText(JSON.stringify(src, null, ' ')) |
| 45 | } else { |
| 46 | navigator.clipboard.writeText(src) |
| 47 | } |
| 48 | } |
| 49 | |
| 50 | useEffect(() => { |
| 51 | if (!disabled && nodes && edges && nodeId && inputParam) { |
| 52 | const nodesForVariable = inputParam?.acceptVariable ? getAvailableNodesForVariable(nodes, edges, nodeId, inputParam.id) : [] |
| 53 | setAvailableNodesForVariable(nodesForVariable) |
| 54 | } |
| 55 | }, [disabled, inputParam, nodes, edges, nodeId]) |
| 56 | |
| 57 | return ( |
| 58 | <> |
| 59 | <FormControl sx={{ mt: 1, width: '100%' }} size='small'> |
| 60 | {disabled && ( |
| 61 | <ReactJson |
| 62 | theme={isDarkMode ? 'ocean' : 'rjv-default'} |
| 63 | style={{ padding: 10, borderRadius: 10 }} |
| 64 | src={myValue} |
| 65 | name={null} |
| 66 | enableClipboard={(e) => onClipboardCopy(e)} |
nothing calls this directly
no test coverage detected