main
js 38 lines 984 Bytes
Raw
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
17 export default function ClearProfilingDataButton(): React.Node {
18 const store = useContext(StoreContext);
19 const {didRecordCommits, isProfiling} = useContext(ProfilerContext);
20 const {profilerStore} = store;
21
22 const doesHaveInMemoryData = didRecordCommits;
23
24 const clear = () => {
25 if (doesHaveInMemoryData) {
26 profilerStore.clear();
27 }
28 };
29
30 return (
31 <Button
32 disabled={isProfiling || !doesHaveInMemoryData}
33 onClick={clear}
34 title="Clear profiling data">
35 <ButtonIcon type="clear" />
36 </Button>
37 );
38 }