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 * as React from 'react';
    
  11. import {Fragment, useContext} from 'react';
    
  12. import {ProfilerContext} from './ProfilerContext';
    
  13. import {formatDuration} from './utils';
    
  14. import WhatChanged from './WhatChanged';
    
  15. import {StoreContext} from '../context';
    
  16. 
    
  17. import styles from './HoveredFiberInfo.css';
    
  18. 
    
  19. import type {ChartNode} from './FlamegraphChartBuilder';
    
  20. 
    
  21. export type TooltipFiberData = {
    
  22.   id: number,
    
  23.   name: string,
    
  24. };
    
  25. 
    
  26. export type Props = {
    
  27.   fiberData: ChartNode,
    
  28. };
    
  29. 
    
  30. export default function HoveredFiberInfo({fiberData}: Props): React.Node {
    
  31.   const {profilerStore} = useContext(StoreContext);
    
  32.   const {rootID, selectedCommitIndex} = useContext(ProfilerContext);
    
  33. 
    
  34.   const {id, name} = fiberData;
    
  35.   const {profilingCache} = profilerStore;
    
  36. 
    
  37.   const commitIndices = profilingCache.getFiberCommits({
    
  38.     fiberID: ((id: any): number),
    
  39.     rootID: ((rootID: any): number),
    
  40.   });
    
  41. 
    
  42.   let renderDurationInfo = null;
    
  43.   let i = 0;
    
  44.   for (i = 0; i < commitIndices.length; i++) {
    
  45.     const commitIndex = commitIndices[i];
    
  46.     if (selectedCommitIndex === commitIndex) {
    
  47.       const {fiberActualDurations, fiberSelfDurations} =
    
  48.         profilerStore.getCommitData(((rootID: any): number), commitIndex);
    
  49.       const actualDuration = fiberActualDurations.get(id) || 0;
    
  50.       const selfDuration = fiberSelfDurations.get(id) || 0;
    
  51. 
    
  52.       renderDurationInfo = (
    
  53.         <div key={commitIndex} className={styles.CurrentCommit}>
    
  54.           {formatDuration(selfDuration)}ms of {formatDuration(actualDuration)}ms
    
  55.         </div>
    
  56.       );
    
  57. 
    
  58.       break;
    
  59.     }
    
  60.   }
    
  61. 
    
  62.   return (
    
  63.     <Fragment>
    
  64.       <div className={styles.Toolbar}>
    
  65.         <div className={styles.Component}>{name}</div>
    
  66.       </div>
    
  67.       <div className={styles.Content}>
    
  68.         {renderDurationInfo || <div>Did not render.</div>}
    
  69.         <WhatChanged fiberID={((id: any): number)} />
    
  70.       </div>
    
  71.     </Fragment>
    
  72.   );
    
  73. }