| 1 | /** |
| 2 | * Copyright (c) Meta Platforms, Inc. and affiliates. |
| 3 | * |
| 4 | * This source code is licensed under the MIT license found in the |
| 5 | * LICENSE file in the root directory of this source tree. |
| 6 | * |
| 7 | * @flow |
| 8 | */ |
| 9 | |
| 10 | import type {CommitTree} from './types'; |
| 11 | import type {SerializedElement} from 'react-devtools-shared/src/frontend/types'; |
| 12 | |
| 13 | import * as React from 'react'; |
| 14 | import {useContext} from 'react'; |
| 15 | import {ProfilerContext} from './ProfilerContext'; |
| 16 | import styles from './Updaters.css'; |
| 17 | import {ElementTypeRoot} from '../../../frontend/types'; |
| 18 | |
| 19 | export type Props = { |
| 20 | commitTree: CommitTree, |
| 21 | updaters: Array<SerializedElement>, |
| 22 | }; |
| 23 | |
| 24 | export default function Updaters({commitTree, updaters}: Props): React.Node { |
| 25 | const {selectFiber} = useContext(ProfilerContext); |
| 26 | |
| 27 | const children = |
| 28 | updaters.length > 0 ? ( |
| 29 | updaters.map((serializedElement: SerializedElement): React$Node => { |
| 30 | const {displayName, id, key, type} = serializedElement; |
| 31 | const isVisibleInTree = |
| 32 | commitTree.nodes.has(id) && type !== ElementTypeRoot; |
| 33 | if (isVisibleInTree) { |
| 34 | return ( |
| 35 | <button |
| 36 | key={id} |
| 37 | className={styles.Updater} |
| 38 | onClick={() => selectFiber(id, displayName)}> |
| 39 | {displayName} {key ? `key="${key}"` : ''} |
| 40 | </button> |
| 41 | ); |
| 42 | } else { |
| 43 | return ( |
| 44 | <div key={id} className={styles.UnmountedUpdater}> |
| 45 | {displayName} {key ? `key="${key}"` : ''} |
| 46 | </div> |
| 47 | ); |
| 48 | } |
| 49 | }) |
| 50 | ) : ( |
| 51 | <div key="none" className={styles.NoUpdaters}> |
| 52 | (unknown) |
| 53 | </div> |
| 54 | ); |
| 55 | |
| 56 | return <div className={styles.Updaters}>{children}</div>; |
| 57 | } |