2021-01-28 23:25:10 +01: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.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
import './recorder.css';
|
|
|
|
|
import * as React from 'react';
|
|
|
|
|
import { Toolbar } from '../components/toolbar';
|
|
|
|
|
import { ToolbarButton } from '../components/toolbarButton';
|
2021-02-12 19:11:30 +01:00
|
|
|
import { Source as SourceView } from '../components/source';
|
2021-02-13 03:53:46 +01:00
|
|
|
import type { CallLog, Mode, Source } from '../../server/supplements/recorder/recorderTypes';
|
|
|
|
|
import { SplitView } from '../components/splitView';
|
2021-02-05 23:24:27 +01:00
|
|
|
|
2021-02-01 01:37:13 +01:00
|
|
|
declare global {
|
|
|
|
|
interface Window {
|
2021-02-05 23:24:27 +01:00
|
|
|
playwrightSetMode: (mode: Mode) => void;
|
2021-02-13 03:53:46 +01:00
|
|
|
playwrightSetPaused: (paused: boolean) => void;
|
|
|
|
|
playwrightSetSources: (sources: Source[]) => void;
|
|
|
|
|
playwrightUpdateLogs: (callLogs: CallLog[]) => void;
|
2021-02-05 23:24:27 +01:00
|
|
|
dispatch(data: any): Promise<void>;
|
2021-02-13 03:53:46 +01:00
|
|
|
playwrightSourceEchoForTest: string;
|
2021-02-01 01:37:13 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-01-28 23:25:10 +01:00
|
|
|
export interface RecorderProps {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export const Recorder: React.FC<RecorderProps> = ({
|
|
|
|
|
}) => {
|
2021-02-13 03:53:46 +01:00
|
|
|
const [source, setSource] = React.useState<Source>({ file: '', language: 'javascript', text: '', highlight: [] });
|
|
|
|
|
const [paused, setPaused] = React.useState(false);
|
|
|
|
|
const [log, setLog] = React.useState(new Map<number, CallLog>());
|
2021-02-05 23:24:27 +01:00
|
|
|
const [mode, setMode] = React.useState<Mode>('none');
|
|
|
|
|
|
|
|
|
|
window.playwrightSetMode = setMode;
|
2021-02-13 03:53:46 +01:00
|
|
|
window.playwrightSetSources = sources => {
|
|
|
|
|
let s = sources.find(s => s.revealLine);
|
|
|
|
|
if (!s)
|
|
|
|
|
s = sources.find(s => s.file === source.file);
|
|
|
|
|
if (!s)
|
|
|
|
|
s = sources[0];
|
|
|
|
|
setSource(s);
|
|
|
|
|
};
|
2021-02-05 23:24:27 +01:00
|
|
|
window.playwrightSetPaused = setPaused;
|
2021-02-13 03:53:46 +01:00
|
|
|
window.playwrightUpdateLogs = callLogs => {
|
|
|
|
|
const newLog = new Map<number, CallLog>(log);
|
|
|
|
|
for (const callLog of callLogs)
|
|
|
|
|
newLog.set(callLog.id, callLog);
|
|
|
|
|
setLog(newLog);
|
|
|
|
|
};
|
2021-02-01 01:37:13 +01:00
|
|
|
|
2021-02-13 03:53:46 +01:00
|
|
|
window.playwrightSourceEchoForTest = source.text;
|
|
|
|
|
|
|
|
|
|
const messagesEndRef = React.createRef<HTMLDivElement>();
|
|
|
|
|
React.useLayoutEffect(() => {
|
|
|
|
|
messagesEndRef.current?.scrollIntoView({ block: 'center', inline: 'nearest' });
|
|
|
|
|
}, [messagesEndRef]);
|
|
|
|
|
|
|
|
|
|
return <div className='recorder'>
|
2021-01-28 23:25:10 +01:00
|
|
|
<Toolbar>
|
2021-02-13 03:53:46 +01:00
|
|
|
<ToolbarButton icon='record' title='Record' toggled={mode == 'recording'} onClick={() => {
|
2021-02-05 23:24:27 +01:00
|
|
|
window.dispatch({ event: 'setMode', params: { mode: mode === 'recording' ? 'none' : 'recording' }}).catch(() => { });
|
|
|
|
|
}}></ToolbarButton>
|
2021-02-13 03:53:46 +01:00
|
|
|
<ToolbarButton icon='question' title='Inspect' toggled={mode == 'inspecting'} onClick={() => {
|
2021-02-05 23:24:27 +01:00
|
|
|
window.dispatch({ event: 'setMode', params: { mode: mode === 'inspecting' ? 'none' : 'inspecting' }}).catch(() => { });
|
2021-02-01 01:37:13 +01:00
|
|
|
}}></ToolbarButton>
|
2021-02-13 03:53:46 +01:00
|
|
|
<ToolbarButton icon='files' title='Copy' disabled={!source.text} onClick={() => {
|
2021-02-05 23:24:27 +01:00
|
|
|
copy(source.text);
|
2021-02-01 01:37:13 +01:00
|
|
|
}}></ToolbarButton>
|
2021-02-13 03:53:46 +01:00
|
|
|
<ToolbarButton icon='debug-continue' title='Resume' disabled={!paused} onClick={() => {
|
2021-02-14 07:13:51 +01:00
|
|
|
setPaused(false);
|
2021-02-12 19:11:30 +01:00
|
|
|
window.dispatch({ event: 'resume' }).catch(() => {});
|
|
|
|
|
}}></ToolbarButton>
|
2021-02-13 03:53:46 +01:00
|
|
|
<ToolbarButton icon='debug-pause' title='Pause' disabled={paused} onClick={() => {
|
2021-02-12 19:11:30 +01:00
|
|
|
window.dispatch({ event: 'pause' }).catch(() => {});
|
|
|
|
|
}}></ToolbarButton>
|
2021-02-13 03:53:46 +01:00
|
|
|
<ToolbarButton icon='debug-step-over' title='Step over' disabled={!paused} onClick={() => {
|
2021-02-14 07:13:51 +01:00
|
|
|
setPaused(false);
|
2021-02-12 19:11:30 +01:00
|
|
|
window.dispatch({ event: 'step' }).catch(() => {});
|
|
|
|
|
}}></ToolbarButton>
|
2021-02-13 03:53:46 +01:00
|
|
|
<div style={{flex: 'auto'}}></div>
|
|
|
|
|
<ToolbarButton icon='clear-all' title='Clear' disabled={!source.text} onClick={() => {
|
2021-02-05 23:24:27 +01:00
|
|
|
window.dispatch({ event: 'clear' }).catch(() => {});
|
|
|
|
|
}}></ToolbarButton>
|
2021-01-28 23:25:10 +01:00
|
|
|
</Toolbar>
|
2021-02-13 03:53:46 +01:00
|
|
|
<SplitView sidebarSize={200}>
|
|
|
|
|
<SourceView text={source.text} language={source.language} highlight={source.highlight} revealLine={source.revealLine}></SourceView>
|
|
|
|
|
<div className='vbox'>
|
|
|
|
|
<div className='recorder-log-header' style={{flex: 'none'}}>Log</div>
|
|
|
|
|
<div className='recorder-log' style={{flex: 'auto'}}>
|
|
|
|
|
{[...log.values()].map(callLog => {
|
2021-02-14 07:13:51 +01:00
|
|
|
return <div className={`recorder-log-call ${callLog.status}`} key={callLog.id}>
|
|
|
|
|
<div className='recorder-log-call-header'>
|
2021-02-13 03:53:46 +01:00
|
|
|
<span className={'codicon ' + iconClass(callLog)}></span>{ callLog.title }
|
|
|
|
|
</div>
|
|
|
|
|
{ callLog.messages.map((message, i) => {
|
|
|
|
|
return <div className='recorder-log-message' key={i}>
|
2021-02-14 07:13:51 +01:00
|
|
|
{ message.trim() }
|
2021-02-13 03:53:46 +01:00
|
|
|
</div>;
|
|
|
|
|
})}
|
2021-02-14 07:13:51 +01:00
|
|
|
{ callLog.error ? <div className='recorder-log-message error'>
|
|
|
|
|
{ callLog.error }
|
|
|
|
|
</div> : undefined }
|
2021-02-13 03:53:46 +01:00
|
|
|
</div>
|
|
|
|
|
})}
|
|
|
|
|
<div ref={messagesEndRef}></div>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
</SplitView>
|
2021-01-28 23:25:10 +01:00
|
|
|
</div>;
|
|
|
|
|
};
|
2021-02-01 01:37:13 +01:00
|
|
|
|
|
|
|
|
function copy(text: string) {
|
|
|
|
|
const textArea = document.createElement('textarea');
|
|
|
|
|
textArea.style.position = 'absolute';
|
|
|
|
|
textArea.style.zIndex = '-1000';
|
|
|
|
|
textArea.value = text;
|
|
|
|
|
document.body.appendChild(textArea);
|
|
|
|
|
textArea.select();
|
|
|
|
|
document.execCommand('copy');
|
|
|
|
|
textArea.remove();
|
|
|
|
|
}
|
2021-02-13 03:53:46 +01:00
|
|
|
|
|
|
|
|
function iconClass(callLog: CallLog): string {
|
|
|
|
|
switch (callLog.status) {
|
|
|
|
|
case 'done': return 'codicon-check';
|
|
|
|
|
case 'in-progress': return 'codicon-clock';
|
|
|
|
|
case 'paused': return 'codicon-debug-pause';
|
|
|
|
|
case 'error': return 'codicon-error';
|
|
|
|
|
}
|
|
|
|
|
}
|