2021-01-07 16:15:34 -08:00
|
|
|
/*
|
|
|
|
Copyright (c) Microsoft Corporation.
|
|
|
|
|
|
|
|
Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
you may not use this file except in compliance with the License.
|
|
|
|
You may obtain a copy of the License at
|
|
|
|
|
|
|
|
http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
|
|
|
Unless required by applicable law or agreed to in writing, software
|
|
|
|
distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
See the License for the specific language governing permissions and
|
|
|
|
limitations under the License.
|
|
|
|
*/
|
|
|
|
|
2021-05-13 20:41:32 -07:00
|
|
|
import { ActionTraceEvent } from '../../../server/trace/common/traceEvents';
|
|
|
|
import { ContextEntry } from '../../../server/trace/viewer/traceModel';
|
2021-01-07 16:15:34 -08:00
|
|
|
import { ActionList } from './actionList';
|
2021-02-17 17:51:57 -08:00
|
|
|
import { TabbedPane } from './tabbedPane';
|
2021-01-07 16:15:34 -08:00
|
|
|
import { Timeline } from './timeline';
|
|
|
|
import './workbench.css';
|
|
|
|
import * as React from 'react';
|
|
|
|
import { ContextSelector } from './contextSelector';
|
2021-02-17 17:51:57 -08:00
|
|
|
import { NetworkTab } from './networkTab';
|
|
|
|
import { SourceTab } from './sourceTab';
|
|
|
|
import { SnapshotTab } from './snapshotTab';
|
|
|
|
import { LogsTab } from './logsTab';
|
2021-03-11 11:22:59 -08:00
|
|
|
import { SplitView } from '../../components/splitView';
|
2021-04-08 22:59:05 +08:00
|
|
|
import { useAsyncMemo } from './helpers';
|
2021-03-11 11:22:59 -08:00
|
|
|
|
2021-01-07 16:15:34 -08:00
|
|
|
|
|
|
|
export const Workbench: React.FunctionComponent<{
|
2021-04-08 22:59:05 +08:00
|
|
|
debugNames: string[],
|
|
|
|
}> = ({ debugNames }) => {
|
|
|
|
const [debugName, setDebugName] = React.useState(debugNames[0]);
|
2021-05-13 20:41:32 -07:00
|
|
|
const [selectedAction, setSelectedAction] = React.useState<ActionTraceEvent | undefined>();
|
|
|
|
const [highlightedAction, setHighlightedAction] = React.useState<ActionTraceEvent | undefined>();
|
2021-01-07 16:15:34 -08:00
|
|
|
|
2021-04-08 22:59:05 +08:00
|
|
|
let context = useAsyncMemo(async () => {
|
|
|
|
return (await fetch(`/context/${debugName}`).then(response => response.json())) as ContextEntry;
|
|
|
|
}, [debugName], emptyContext);
|
|
|
|
|
2021-05-13 20:41:32 -07:00
|
|
|
const { actions, nextAction } = React.useMemo(() => {
|
|
|
|
const actions: ActionTraceEvent[] = [];
|
2021-01-07 16:15:34 -08:00
|
|
|
for (const page of context.pages)
|
|
|
|
actions.push(...page.actions);
|
2021-04-23 09:28:18 -07:00
|
|
|
actions.sort((a, b) => a.timestamp - b.timestamp);
|
2021-05-13 20:41:32 -07:00
|
|
|
const nextAction = selectedAction ? actions[actions.indexOf(selectedAction) + 1] : undefined;
|
|
|
|
return { actions, nextAction };
|
|
|
|
}, [context, selectedAction]);
|
2021-01-07 16:15:34 -08:00
|
|
|
|
2021-01-20 16:19:01 -08:00
|
|
|
const snapshotSize = context.created.viewportSize || { width: 1280, height: 720 };
|
2021-01-26 15:09:17 -08:00
|
|
|
const boundaries = { minimum: context.startTime, maximum: context.endTime };
|
2021-01-07 16:15:34 -08:00
|
|
|
|
|
|
|
return <div className='vbox workbench'>
|
|
|
|
<div className='hbox header'>
|
|
|
|
<div className='logo'>🎭</div>
|
|
|
|
<div className='product'>Playwright</div>
|
|
|
|
<div className='spacer'></div>
|
|
|
|
<ContextSelector
|
2021-04-08 22:59:05 +08:00
|
|
|
debugNames={debugNames}
|
|
|
|
debugName={debugName}
|
|
|
|
onChange={debugName => {
|
|
|
|
setDebugName(debugName);
|
2021-01-14 20:16:02 -08:00
|
|
|
setSelectedAction(undefined);
|
2021-01-07 16:15:34 -08:00
|
|
|
}}
|
|
|
|
/>
|
|
|
|
</div>
|
2021-04-19 19:50:11 -07:00
|
|
|
<div style={{ background: 'white', paddingLeft: '20px', flex: 'none', borderBottom: '1px solid #ddd' }}>
|
2021-01-07 16:15:34 -08:00
|
|
|
<Timeline
|
|
|
|
context={context}
|
2021-01-26 15:09:17 -08:00
|
|
|
boundaries={boundaries}
|
2021-01-14 20:16:02 -08:00
|
|
|
selectedAction={selectedAction}
|
|
|
|
highlightedAction={highlightedAction}
|
2021-01-27 19:42:51 -08:00
|
|
|
onSelected={action => setSelectedAction(action)}
|
2021-04-19 19:50:11 -07:00
|
|
|
onHighlighted={action => setHighlightedAction(action)}
|
2021-01-21 08:29:01 -08:00
|
|
|
/>
|
2021-01-07 16:15:34 -08:00
|
|
|
</div>
|
2021-04-19 19:50:11 -07:00
|
|
|
<SplitView sidebarSize={300} orientation='horizontal' sidebarIsFirst={true}>
|
|
|
|
<SplitView sidebarSize={300} orientation='horizontal'>
|
2021-05-13 20:41:32 -07:00
|
|
|
<SnapshotTab action={selectedAction} snapshotSize={snapshotSize} />
|
2021-03-11 11:22:59 -08:00
|
|
|
<TabbedPane tabs={[
|
2021-05-13 20:41:32 -07:00
|
|
|
{ id: 'logs', title: 'Log', render: () => <LogsTab action={selectedAction} /> },
|
|
|
|
{ id: 'source', title: 'Source', render: () => <SourceTab action={selectedAction} /> },
|
|
|
|
{ id: 'network', title: 'Network', render: () => <NetworkTab context={context} action={selectedAction} nextAction={nextAction}/> },
|
2021-03-11 11:22:59 -08:00
|
|
|
]}/>
|
|
|
|
</SplitView>
|
2021-04-06 11:27:57 +08:00
|
|
|
<ActionList
|
|
|
|
actions={actions}
|
|
|
|
selectedAction={selectedAction}
|
|
|
|
highlightedAction={highlightedAction}
|
|
|
|
onSelected={action => {
|
|
|
|
setSelectedAction(action);
|
|
|
|
}}
|
|
|
|
onHighlighted={action => setHighlightedAction(action)}
|
|
|
|
/>
|
|
|
|
</SplitView>
|
2021-01-07 16:15:34 -08:00
|
|
|
</div>;
|
|
|
|
};
|
2021-04-08 22:59:05 +08:00
|
|
|
|
|
|
|
const now = performance.now();
|
|
|
|
const emptyContext: ContextEntry = {
|
|
|
|
startTime: now,
|
|
|
|
endTime: now,
|
|
|
|
created: {
|
|
|
|
timestamp: now,
|
2021-04-23 20:39:09 -07:00
|
|
|
type: 'context-metadata',
|
2021-04-08 22:59:05 +08:00
|
|
|
browserName: '',
|
|
|
|
deviceScaleFactor: 1,
|
|
|
|
isMobile: false,
|
|
|
|
viewportSize: { width: 1280, height: 800 },
|
|
|
|
debugName: '<empty>',
|
|
|
|
},
|
2021-05-13 20:41:32 -07:00
|
|
|
pages: [],
|
|
|
|
resources: []
|
2021-04-08 22:59:05 +08:00
|
|
|
};
|