Home / File/ InspectedElementContextTree.js — react Source File

InspectedElementContextTree.js — react Source File

Architecture documentation for InspectedElementContextTree.js, a javascript file in the react codebase. 16 imports, 1 dependents.

File javascript BabelCompiler Validation 16 imports 1 dependents 1 functions

Entity Profile

Dependency Diagram

graph LR
  0b54b2a8_1c5a_d85b_7742_10a526b0dedd["InspectedElementContextTree.js"]
  f9049b08_60f8_abce_a6a6_153f88447124["Button.js"]
  0b54b2a8_1c5a_d85b_7742_10a526b0dedd --> f9049b08_60f8_abce_a6a6_153f88447124
  f71ee326_17f0_7db4_4178_2763fb1c2ad1["Button"]
  0b54b2a8_1c5a_d85b_7742_10a526b0dedd --> f71ee326_17f0_7db4_4178_2763fb1c2ad1
  9f39024f_b905_9b0f_2fc7_e24785732638["ButtonIcon.js"]
  0b54b2a8_1c5a_d85b_7742_10a526b0dedd --> 9f39024f_b905_9b0f_2fc7_e24785732638
  4690d9c0_cb81_9593_7817_f9e61a49f9e7["ButtonIcon"]
  0b54b2a8_1c5a_d85b_7742_10a526b0dedd --> 4690d9c0_cb81_9593_7817_f9e61a49f9e7
  276bc34e_3008_101e_3cd7_cc895fcd3848["KeyValue.js"]
  0b54b2a8_1c5a_d85b_7742_10a526b0dedd --> 276bc34e_3008_101e_3cd7_cc895fcd3848
  b5067ef5_22cb_1a20_66d3_9a573b206f48["KeyValue"]
  0b54b2a8_1c5a_d85b_7742_10a526b0dedd --> b5067ef5_22cb_1a20_66d3_9a573b206f48
  d7b27d30_728f_ba37_ed97_d371fbd3de62["utils.js"]
  0b54b2a8_1c5a_d85b_7742_10a526b0dedd --> d7b27d30_728f_ba37_ed97_d371fbd3de62
  703db4ef_ef9f_8a4b_eecf_6dad80aa9ddd["alphaSortEntries"]
  0b54b2a8_1c5a_d85b_7742_10a526b0dedd --> 703db4ef_ef9f_8a4b_eecf_6dad80aa9ddd
  24a5b0f3_4e3a_ff70_e4ed_c4392045f885["serializeDataForCopy"]
  0b54b2a8_1c5a_d85b_7742_10a526b0dedd --> 24a5b0f3_4e3a_ff70_e4ed_c4392045f885
  bba85af0_a356_d0c5_4d12_914508b89593["store.js"]
  0b54b2a8_1c5a_d85b_7742_10a526b0dedd --> bba85af0_a356_d0c5_4d12_914508b89593
  2337051b_9399_908a_f16c_81724ab026b7["InspectedElementSharedStyles.css"]
  0b54b2a8_1c5a_d85b_7742_10a526b0dedd --> 2337051b_9399_908a_f16c_81724ab026b7
  1e290487_2c6f_fbaf_7be9_e14d5df52457["clipboard-js"]
  0b54b2a8_1c5a_d85b_7742_10a526b0dedd --> 1e290487_2c6f_fbaf_7be9_e14d5df52457
  ac587885_e294_a1e9_b13f_5e7b920fdb42["react"]
  0b54b2a8_1c5a_d85b_7742_10a526b0dedd --> ac587885_e294_a1e9_b13f_5e7b920fdb42
  aec7978f_0a19_ba93_de9e_ac8cf5ddc74b["types"]
  0b54b2a8_1c5a_d85b_7742_10a526b0dedd --> aec7978f_0a19_ba93_de9e_ac8cf5ddc74b
  style 0b54b2a8_1c5a_d85b_7742_10a526b0dedd 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 {copy} from 'clipboard-js';
import * as React from 'react';
import Button from '../Button';
import ButtonIcon from '../ButtonIcon';
import KeyValue from './KeyValue';
import {alphaSortEntries, serializeDataForCopy} from '../utils';
import Store from '../../store';
import styles from './InspectedElementSharedStyles.css';
import {
  ElementTypeClass,
  ElementTypeFunction,
} from 'react-devtools-shared/src/frontend/types';
import {withPermissionsCheck} from 'react-devtools-shared/src/frontend/utils/withPermissionsCheck';

import type {InspectedElement} from 'react-devtools-shared/src/frontend/types';
import type {FrontendBridge} from 'react-devtools-shared/src/bridge';
import type {Element} from 'react-devtools-shared/src/frontend/types';

type Props = {
  bridge: FrontendBridge,
  element: Element,
  inspectedElement: InspectedElement,
  store: Store,
};

export default function InspectedElementContextTree({
  bridge,
  element,
  inspectedElement,
  store,
}: Props): React.Node {
  const {hasLegacyContext, context, type} = inspectedElement;

  const isReadOnly = type !== ElementTypeClass && type !== ElementTypeFunction;

  if (context == null) {
    return null;
  }

  const entries = Object.entries(context);
  entries.sort(alphaSortEntries);
  const isEmpty = entries.length === 0;

  const handleCopy = withPermissionsCheck(
    {permissions: ['clipboardWrite']},
    () => copy(serializeDataForCopy(context)),
  );

  // We add an object with a "value" key as a wrapper around Context data
  // so that we can use the shared <KeyValue> component to display it.
  // This wrapper object can't be renamed.
  // $FlowFixMe[missing-local-annot]
  const canRenamePathsAtDepth = depth => depth > 1;

  if (isEmpty) {
    return null;
  } else {
    return (
      <div>
        <div className={styles.HeaderRow}>
          <div className={styles.Header}>
            {hasLegacyContext ? 'legacy context' : 'context'}
          </div>
          {!isEmpty && (
            <Button onClick={handleCopy} title="Copy to clipboard">
              <ButtonIcon type="copy" />
            </Button>
          )}
        </div>
        {isEmpty && <div className={styles.Empty}>None</div>}
        {!isEmpty &&
          (entries: any).map(([name, value]) => (
            <KeyValue
              key={name}
              alphaSort={true}
              bridge={bridge}
              canDeletePaths={!isReadOnly}
              canEditValues={!isReadOnly}
              canRenamePaths={!isReadOnly}
              canRenamePathsAtDepth={canRenamePathsAtDepth}
              depth={1}
              element={element}
              hidden={false}
              inspectedElement={inspectedElement}
              name={name}
              path={[name]}
              pathRoot="context"
              store={store}
              type="context"
              value={value}
            />
          ))}
      </div>
    );
  }
}

Domain

Subdomains

Frequently Asked Questions

What does InspectedElementContextTree.js do?
InspectedElementContextTree.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 InspectedElementContextTree.js?
InspectedElementContextTree.js defines 1 function(s): InspectedElementContextTree.
What does InspectedElementContextTree.js depend on?
InspectedElementContextTree.js imports 16 module(s): Button, Button.js, ButtonIcon, ButtonIcon.js, InspectedElementSharedStyles.css, KeyValue, KeyValue.js, alphaSortEntries, and 8 more.
What files import InspectedElementContextTree.js?
InspectedElementContextTree.js is imported by 1 file(s): InspectedElementView.js.
Where is InspectedElementContextTree.js in the architecture?
InspectedElementContextTree.js is located at packages/react-devtools-shared/src/devtools/views/Components/InspectedElementContextTree.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