main
js 61 lines 1.57 KB
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
12 import Button from 'react-devtools-shared/src/devtools/views/Button';
13 import ButtonIcon from 'react-devtools-shared/src/devtools/views/ButtonIcon';
14
15 import type {ReactFunctionLocation} from 'shared/ReactTypes';
16 import type {SourceMappedLocation} from 'react-devtools-shared/src/symbolicateSource';
17
18 import {checkConditions} from '../Editor/utils';
19
20 type Props = {
21 editorURL: string,
22 source: ReactFunctionLocation,
23 symbolicatedSourcePromise: Promise<SourceMappedLocation | null>,
24 };
25
26 function OpenSymbolicatedSourceInEditorButton({
27 editorURL,
28 source,
29 symbolicatedSourcePromise,
30 }: Props): React.Node {
31 const symbolicatedSource = React.use(symbolicatedSourcePromise);
32
33 const {url, shouldDisableButton} = checkConditions(
34 editorURL,
35 symbolicatedSource ? symbolicatedSource.location : source,
36 );
37
38 return (
39 <Button
40 disabled={shouldDisableButton}
41 onClick={() => window.open(url)}
42 title="Open in editor">
43 <ButtonIcon type="editor" />
44 </Button>
45 );
46 }
47
48 function OpenInEditorButton(props: Props): React.Node {
49 return (
50 <React.Suspense
51 fallback={
52 <Button disabled={true} title="retrieving original source…">
53 <ButtonIcon type="editor" />
54 </Button>
55 }>
56 <OpenSymbolicatedSourceInEditorButton {...props} />
57 </React.Suspense>
58 );
59 }
60
61 export default OpenInEditorButton;