forked from facebook/react
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Scheduling Profiler: Redesign with DevTools styling (facebook#19707)
Co-authored-by: Brian Vaughn <[email protected]>
- Loading branch information
Showing
20 changed files
with
577 additions
and
311 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
/** | ||
* 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. | ||
*/ | ||
|
||
const {execSync} = require('child_process'); | ||
const {readFileSync} = require('fs'); | ||
const {resolve} = require('path'); | ||
|
||
function getGitCommit() { | ||
try { | ||
return execSync('git show -s --format=%h') | ||
.toString() | ||
.trim(); | ||
} catch (error) { | ||
// Mozilla runs this command from a git archive. | ||
// In that context, there is no Git revision. | ||
return null; | ||
} | ||
} | ||
|
||
function getVersionString() { | ||
const packageVersion = JSON.parse( | ||
readFileSync(resolve(__dirname, './package.json')), | ||
).version; | ||
|
||
const commit = getGitCommit(); | ||
|
||
return `${packageVersion}-${commit}`; | ||
} | ||
|
||
module.exports = { | ||
getVersionString, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
.DevTools { | ||
width: 100%; | ||
height: 100%; | ||
display: flex; | ||
flex-direction: column; | ||
background-color: var(--color-background); | ||
color: var(--color-text); | ||
} | ||
|
||
.TabContent { | ||
flex: 1 1 100%; | ||
overflow: auto; | ||
-webkit-app-region: no-drag; | ||
} | ||
|
||
.DevTools, .DevTools * { | ||
box-sizing: border-box; | ||
-webkit-font-smoothing: var(--font-smoothing); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 17 additions & 0 deletions
17
packages/react-devtools-scheduling-profiler/src/ImportButton.css
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
/** | ||
* https://developer.mozilla.org/en-US/docs/Web/API/File/Using_files_from_web_applications | ||
*/ | ||
.Input { | ||
position: absolute !important; | ||
height: 1px; | ||
width: 1px; | ||
overflow: hidden; | ||
clip: rect(1px, 1px, 1px, 1px); | ||
} | ||
|
||
.ErrorMessage { | ||
margin: 0.5rem 0; | ||
color: var(--color-dim); | ||
font-family: var(--font-family-monospace); | ||
font-size: var(--font-size-monospace-normal); | ||
} |
86 changes: 86 additions & 0 deletions
86
packages/react-devtools-scheduling-profiler/src/ImportButton.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
/** | ||
* 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, useContext, useRef} from 'react'; | ||
|
||
import Button from 'react-devtools-shared/src/devtools/views/Button'; | ||
import ButtonIcon from 'react-devtools-shared/src/devtools/views/ButtonIcon'; | ||
import {ModalDialogContext} from 'react-devtools-shared/src/devtools/views/ModalDialog'; | ||
|
||
import preprocessData from './utils/preprocessData'; | ||
import {readInputData} from './utils/readInputData'; | ||
|
||
import styles from './ImportButton.css'; | ||
|
||
type Props = {| | ||
onDataImported: (profilerData: ReactProfilerData) => void, | ||
|}; | ||
|
||
export default function ImportButton({onDataImported}: Props) { | ||
const inputRef = useRef<HTMLInputElement | null>(null); | ||
const {dispatch: modalDialogDispatch} = useContext(ModalDialogContext); | ||
|
||
const handleFiles = useCallback(async () => { | ||
const input = inputRef.current; | ||
if (input === null) { | ||
return; | ||
} | ||
|
||
if (input.files.length > 0) { | ||
try { | ||
const readFile = await readInputData(input.files[0]); | ||
const events: TimelineEvent[] = JSON.parse(readFile); | ||
if (events.length > 0) { | ||
onDataImported(preprocessData(events)); | ||
} | ||
} catch (error) { | ||
modalDialogDispatch({ | ||
type: 'SHOW', | ||
title: 'Import failed', | ||
content: ( | ||
<> | ||
<div>The profiling data you selected cannot be imported.</div> | ||
{error !== null && ( | ||
<div className={styles.ErrorMessage}>{error.message}</div> | ||
)} | ||
</> | ||
), | ||
}); | ||
} | ||
} | ||
|
||
// Reset input element to allow the same file to be re-imported | ||
input.value = ''; | ||
}, [onDataImported, modalDialogDispatch]); | ||
|
||
const uploadData = useCallback(() => { | ||
if (inputRef.current !== null) { | ||
inputRef.current.click(); | ||
} | ||
}, []); | ||
|
||
return ( | ||
<> | ||
<input | ||
ref={inputRef} | ||
className={styles.Input} | ||
type="file" | ||
onChange={handleFiles} | ||
tabIndex={-1} | ||
/> | ||
<Button onClick={uploadData} title="Load profile..."> | ||
<ButtonIcon type="import" /> | ||
</Button> | ||
</> | ||
); | ||
} |
Oops, something went wrong.