forked from facebook/react
-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathImportPage.js
More file actions
116 lines (106 loc) · 3.63 KB
/
ImportPage.js
File metadata and controls
116 lines (106 loc) · 3.63 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
/**
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @flow
*/
import type {TimelineEvent} from '@elg/speedscope';
import type {ReactProfilerData} from './types';
import * as React from 'react';
import {useCallback, useRef} from 'react';
import profilerBrowser from './assets/profilerBrowser.png';
import style from './ImportPage.css';
import preprocessData from './utils/preprocessData';
import {readInputData} from './utils/readInputData';
type Props = {|
onDataImported: (profilerData: ReactProfilerData) => void,
|};
export default function ImportPage({onDataImported}: Props) {
const processTimeline = useCallback(
(events: TimelineEvent[]) => {
if (events.length > 0) {
onDataImported(preprocessData(events));
}
},
[onDataImported],
);
const handleProfilerInput = useCallback(
async (event: SyntheticInputEvent<HTMLInputElement>) => {
const readFile = await readInputData(event.target.files[0]);
processTimeline(JSON.parse(readFile));
},
[processTimeline],
);
const upload = useRef(null);
return (
<div className={style.App}>
<div className={style.Card}>
<div className={style.Row}>
<div className={style.Column}>
<img
src={profilerBrowser}
className={style.Screenshot}
alt="logo"
/>
</div>
<div className={style.Column}>
<h2 className={style.Header}>React Concurrent Mode Profiler</h2>
<p>
Import a captured{' '}
<a
className={style.Link}
href="https://developers.google.com/web/tools/chrome-devtools/evaluate-performance">
performance profile
</a>{' '}
from Chrome Devtools. To zoom, scroll while holding down{' '}
<kbd>Ctrl</kbd> or <kbd>Shift</kbd>
</p>
<ul className={style.LegendKey}>
<li className={style.LegendItem}>
<svg height="20" width="20">
<circle cx="10" cy="10" r="5" fill="#ff718e" />
</svg>
State Update Scheduled
</li>
<li className={style.LegendItem}>
<svg height="20" width="20">
<circle cx="10" cy="10" r="5" fill="#9fc3f3" />
</svg>
State Update Scheduled
</li>
<li className={style.LegendItem}>
<svg height="20" width="20">
<circle cx="10" cy="10" r="5" fill="#a6e59f" />
</svg>
Suspended
</li>
</ul>
<div className={style.Buttons}>
<label htmlFor="upload">
<button
className={style.ImportButton}
onClick={() => upload.current && upload.current.click()}>
Import
</button>
<input
type="file"
ref={upload}
className={style.ImportButtonFile}
onChange={handleProfilerInput}
accept="application/json"
/>
</label>
<a href="https://github.com/facebook/react/tree/master/packages/react-devtools-scheduling-profiler">
<button className={style.ViewSourceButton}>
<span>Source </span>
</button>
</a>
</div>
</div>
</div>
</div>
</div>
);
}