diff --git a/src/App.js b/src/App.js index 52f0470c08340..6ad892d4f9728 100644 --- a/src/App.js +++ b/src/App.js @@ -1,6 +1,10 @@ // @flow -import type {FlamechartData, ReactProfilerData} from './types'; +import type { + FlamechartData, + ReactProfilerData, + ReactProfilerDataV2, +} from './types'; import React, {useState, useCallback} from 'react'; import {unstable_batchedUpdates} from 'react-dom'; @@ -14,6 +18,10 @@ export default function App() { const [profilerData, setProfilerData] = useState( null, ); + const [ + profilerDataV2, + setProfilerDataV2, + ] = useState(null); const [flamechart, setFlamechart] = useState(null); const [schedulerCanvasHeight, setSchedulerCanvasHeight] = useState(0); @@ -34,15 +42,34 @@ export default function App() { }, ); - if (profilerData && flamechart) { + // TODO: Migrate and completely remove V2 stuff + const handleDataImportedV2 = useCallback( + ( + importedProfilerData: ReactProfilerDataV2, + importedFlamechart: FlamechartData, + ) => { + unstable_batchedUpdates(() => { + setProfilerDataV2(importedProfilerData); + setFlamechart(importedFlamechart); + }); + }, + ); + + if (profilerData && profilerDataV2 && flamechart) { return ( ); } else { - return ; + return ( + + ); } } diff --git a/src/CanvasPage.js b/src/CanvasPage.js index e445946208099..87aeea6930e2a 100644 --- a/src/CanvasPage.js +++ b/src/CanvasPage.js @@ -30,6 +30,7 @@ import type { ReactHoverContextInfo, ReactMeasure, ReactProfilerData, + ReactProfilerDataV2, } from './types'; type ContextMenuContextData = {| @@ -41,11 +42,17 @@ type ContextMenuContextData = {| type Props = {| profilerData: ReactProfilerData, + profilerDataV2: ReactProfilerDataV2, flamechart: FlamechartData, schedulerCanvasHeight: number, |}; -function CanvasPage({profilerData, flamechart, schedulerCanvasHeight}: Props) { +function CanvasPage({ + profilerData, + profilerDataV2, + flamechart, + schedulerCanvasHeight, +}: Props) { return (
( void, + onDataImportedV2: ( + profilerData: ReactProfilerDataV2, + flamechart: FlamechartData, + ) => void, |}; -export default function ImportPage({onDataImported}: Props) { +export default function ImportPage({onDataImported, onDataImportedV2}: Props) { useEffect(() => { fetch(JSON_PATH) .then(res => res.json()) @@ -36,6 +46,23 @@ export default function ImportPage({onDataImported}: Props) { }); }, []); + useEffect(() => { + fetch(JSON_PATHV2) + .then(res => res.json()) + .then((events: TimelineEvent[]) => { + // Filter null entries and sort by timestamp. + // I would not expect to have to do either of this, + // but some of the data being passed in requires it. + events = events.filter(Boolean).sort((a, b) => (a.ts > b.ts ? 1 : -1)); + + if (events.length > 0) { + const processedData = preprocessDataV2(events); + const processedFlamechart = preprocessFlamechart(events); + onDataImportedV2(processedData, processedFlamechart); + } + }); + }, []); + return (
LOADING. TODO: Turn this into an import page. This page currently just