/** * Copyright (c) Facebook, Inc. and its affiliates. * * This source code is licensed under the MIT license found in the * LICENSE file in the root directory of this source tree. * * @flow */ import * as React from 'react'; import {useState} from 'react'; import Store from '../../store'; import EditableName from './EditableName'; import EditableValue from './EditableValue'; import {parseHookPathForEdit} from './utils'; import styles from './NewKeyValue.css'; import type {InspectedElement} from './types'; import type {FrontendBridge} from 'react-devtools-shared/src/bridge'; type Props = {| bridge: FrontendBridge, depth: number, hidden: boolean, hookID?: ?number, inspectedElement: InspectedElement, path: Array, store: Store, type: 'props' | 'state' | 'hooks' | 'context', |}; export default function NewKeyValue({ bridge, depth, hidden, hookID, inspectedElement, path, store, type, }: Props) { const [newPropKey, setNewPropKey] = useState(0); const [newPropName, setNewPropName] = useState(''); const overrideNewEntryName = (oldPath, newPath) => { setNewPropName(newPath[newPath.length - 1]); }; const overrideNewEntryValue = (newPath, value) => { if (!newPropName) { return; } setNewPropName(''); setNewPropKey(newPropKey + 1); const {id} = inspectedElement; const rendererID = store.getRendererIDForElement(id); if (rendererID !== null) { let basePath = newPath; if (hookID != null) { basePath = parseHookPathForEdit(basePath); } bridge.send('overrideValueAtPath', { type, hookID, id, path: basePath, rendererID, value, }); } }; return ( ); }