Home / File/ NewKeyValue.js — react Source File

NewKeyValue.js — react Source File

Architecture documentation for NewKeyValue.js, a javascript file in the react codebase. 10 imports, 2 dependents.

File javascript BabelCompiler Validation 10 imports 2 dependents 1 functions

Entity Profile

Dependency Diagram

graph LR
  0e638bf4_827b_30d0_21d6_77d4d615d353["NewKeyValue.js"]
  bba85af0_a356_d0c5_4d12_914508b89593["store.js"]
  0e638bf4_827b_30d0_21d6_77d4d615d353 --> bba85af0_a356_d0c5_4d12_914508b89593
  04e82e8f_4cf5_68df_3f32_fe28fb509921["EditableName.js"]
  0e638bf4_827b_30d0_21d6_77d4d615d353 --> 04e82e8f_4cf5_68df_3f32_fe28fb509921
  ca8114b4_a39e_775f_8cfb_ea560d8ed77f["EditableName"]
  0e638bf4_827b_30d0_21d6_77d4d615d353 --> ca8114b4_a39e_775f_8cfb_ea560d8ed77f
  dc084a98_cfc9_b696_ce0b_8abf1ee07f6f["EditableValue.js"]
  0e638bf4_827b_30d0_21d6_77d4d615d353 --> dc084a98_cfc9_b696_ce0b_8abf1ee07f6f
  0e75ec50_6792_4e19_9cef_0f7f8a5ca3af["EditableValue"]
  0e638bf4_827b_30d0_21d6_77d4d615d353 --> 0e75ec50_6792_4e19_9cef_0f7f8a5ca3af
  7a30ca2b_8808_58b2_56bc_12441f27a1e1["utils.js"]
  0e638bf4_827b_30d0_21d6_77d4d615d353 --> 7a30ca2b_8808_58b2_56bc_12441f27a1e1
  753f918c_26a9_3624_fde1_0d931568be00["NewKeyValue.css"]
  0e638bf4_827b_30d0_21d6_77d4d615d353 --> 753f918c_26a9_3624_fde1_0d931568be00
  ac587885_e294_a1e9_b13f_5e7b920fdb42["react"]
  0e638bf4_827b_30d0_21d6_77d4d615d353 --> ac587885_e294_a1e9_b13f_5e7b920fdb42
  aec7978f_0a19_ba93_de9e_ac8cf5ddc74b["types"]
  0e638bf4_827b_30d0_21d6_77d4d615d353 --> aec7978f_0a19_ba93_de9e_ac8cf5ddc74b
  4077b620_5c59_61c2_0910_273f565da757["bridge"]
  0e638bf4_827b_30d0_21d6_77d4d615d353 --> 4077b620_5c59_61c2_0910_273f565da757
  816abfef_4d5d_bc7e_fc00_1acadf628d28["InspectedElementPropsTree.js"]
  816abfef_4d5d_bc7e_fc00_1acadf628d28 --> 0e638bf4_827b_30d0_21d6_77d4d615d353
  276bc34e_3008_101e_3cd7_cc895fcd3848["KeyValue.js"]
  276bc34e_3008_101e_3cd7_cc895fcd3848 --> 0e638bf4_827b_30d0_21d6_77d4d615d353
  style 0e638bf4_827b_30d0_21d6_77d4d615d353 fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

/**
 * Copyright (c) Meta Platforms, Inc. and 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 'react-devtools-shared/src/frontend/types';
import type {FrontendBridge} from 'react-devtools-shared/src/bridge';

type Props = {
  bridge: FrontendBridge,
  depth: number,
  hidden: boolean,
  hookID?: ?number,
  inspectedElement: InspectedElement,
  path: Array<string | number>,
  store: Store,
  type: 'props' | 'state' | 'hooks' | 'context',
};

export default function NewKeyValue({
  bridge,
  depth,
  hidden,
  hookID,
  inspectedElement,
  path,
  store,
  type,
}: Props): React.Node {
  const [newPropKey, setNewPropKey] = useState<number>(0);
  const [newPropName, setNewPropName] = useState<string>('');

  // $FlowFixMe[missing-local-annot]
  const overrideNewEntryName = (oldPath: any, newPath) => {
    setNewPropName(newPath[newPath.length - 1]);
  };

  const overrideNewEntryValue = (
    newPath: Array<string | number>,
    value: any,
  ) => {
    if (!newPropName) {
      return;
    }

    setNewPropName('');
    setNewPropKey(newPropKey + 1);

    const {id} = inspectedElement;
    const rendererID = store.getRendererIDForElement(id);
    if (rendererID !== null) {
      let basePath: Array<string | number> = newPath;
      if (hookID != null) {
        basePath = parseHookPathForEdit(basePath);
      }

      bridge.send('overrideValueAtPath', {
        type,
        hookID,
        id,
        path: basePath,
        rendererID,
        value,
      });
    }
  };

  return (
    <div
      data-testname="NewKeyValue"
      key={newPropKey}
      hidden={hidden}
      style={{
        paddingLeft: `${(depth - 1) * 0.75}rem`,
      }}>
      <div className={styles.NewKeyValue}>
        <EditableName
          autoFocus={newPropKey > 0}
          className={styles.EditableName}
          overrideName={overrideNewEntryName}
          path={[]}
        />
        :&nbsp;
        <EditableValue
          className={styles.EditableValue}
          overrideValue={overrideNewEntryValue}
          path={[...path, newPropName]}
          value={''}
        />
      </div>
    </div>
  );
}

Domain

Subdomains

Functions

Frequently Asked Questions

What does NewKeyValue.js do?
NewKeyValue.js is a source file in the react codebase, written in javascript. It belongs to the BabelCompiler domain, Validation subdomain.
What functions are defined in NewKeyValue.js?
NewKeyValue.js defines 1 function(s): NewKeyValue.
What does NewKeyValue.js depend on?
NewKeyValue.js imports 10 module(s): EditableName, EditableName.js, EditableValue, EditableValue.js, NewKeyValue.css, bridge, react, store.js, and 2 more.
What files import NewKeyValue.js?
NewKeyValue.js is imported by 2 file(s): InspectedElementPropsTree.js, KeyValue.js.
Where is NewKeyValue.js in the architecture?
NewKeyValue.js is located at packages/react-devtools-shared/src/devtools/views/Components/NewKeyValue.js (domain: BabelCompiler, subdomain: Validation, directory: packages/react-devtools-shared/src/devtools/views/Components).

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free