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 {useContext} from 'react';
    
  12. import {ProfilerContext} from './ProfilerContext';
    
  13. import Button from '../Button';
    
  14. import ButtonIcon from '../ButtonIcon';
    
  15. import {StoreContext} from '../context';
    
  16. import {TimelineContext} from 'react-devtools-timeline/src/TimelineContext';
    
  17. 
    
  18. export default function ClearProfilingDataButton(): React.Node {
    
  19.   const store = useContext(StoreContext);
    
  20.   const {didRecordCommits, isProfiling} = useContext(ProfilerContext);
    
  21.   const {file, setFile} = useContext(TimelineContext);
    
  22.   const {profilerStore} = store;
    
  23. 
    
  24.   const doesHaveInMemoryData = didRecordCommits;
    
  25.   const doesHaveUserTimingData = file !== null;
    
  26. 
    
  27.   const clear = () => {
    
  28.     if (doesHaveInMemoryData) {
    
  29.       profilerStore.clear();
    
  30.     }
    
  31.     if (doesHaveUserTimingData) {
    
  32.       setFile(null);
    
  33.     }
    
  34.   };
    
  35. 
    
  36.   return (
    
  37.     <Button
    
  38.       disabled={
    
  39.         isProfiling || !(doesHaveInMemoryData || doesHaveUserTimingData)
    
  40.       }
    
  41.       onClick={clear}
    
  42.       title="Clear profiling data">
    
  43.       <ButtonIcon type="clear" />
    
  44.     </Button>
    
  45.   );
    
  46. }