/* 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'; import { Source as SourceView } from '../components/source'; import type { CallLog, Mode, Source } from '../../server/supplements/recorder/recorderTypes'; import { SplitView } from '../components/splitView'; declare global { interface Window { playwrightSetMode: (mode: Mode) => void; playwrightSetPaused: (paused: boolean) => void; playwrightSetSources: (sources: Source[]) => void; playwrightUpdateLogs: (callLogs: CallLog[]) => void; dispatch(data: any): Promise; playwrightSourceEchoForTest: string; } } export interface RecorderProps { } export const Recorder: React.FC = ({ }) => { const [source, setSource] = React.useState({ file: '', language: 'javascript', text: '', highlight: [] }); const [paused, setPaused] = React.useState(false); const [log, setLog] = React.useState(new Map()); const [mode, setMode] = React.useState('none'); window.playwrightSetMode = setMode; 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); }; window.playwrightSetPaused = setPaused; window.playwrightUpdateLogs = callLogs => { const newLog = new Map(log); for (const callLog of callLogs) newLog.set(callLog.id, callLog); setLog(newLog); }; window.playwrightSourceEchoForTest = source.text; const messagesEndRef = React.createRef(); React.useLayoutEffect(() => { messagesEndRef.current?.scrollIntoView({ block: 'center', inline: 'nearest' }); }, [messagesEndRef]); return
{ window.dispatch({ event: 'setMode', params: { mode: mode === 'recording' ? 'none' : 'recording' }}).catch(() => { }); }}> { window.dispatch({ event: 'setMode', params: { mode: mode === 'inspecting' ? 'none' : 'inspecting' }}).catch(() => { }); }}> { copy(source.text); }}> { window.dispatch({ event: 'resume' }).catch(() => {}); }}> { window.dispatch({ event: 'pause' }).catch(() => {}); }}> { window.dispatch({ event: 'step' }).catch(() => {}); }}>
{ window.dispatch({ event: 'clear' }).catch(() => {}); }}>
Log
{[...log.values()].map(callLog => { return
{ callLog.title }
{ callLog.messages.map((message, i) => { return
{ message }
; })}
})}
; }; 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(); } 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'; } }