import { observer } from 'mobx-react' import React, { Component, createRef, RefObject, MouseEvent } from 'react' // @ts-ignore import Tooltip from '@cypress/react-tooltip' import cs from 'classnames' import events, { Events } from '../lib/events' import appState, { AppState } from '../lib/app-state' import Collapsible from '../collapsible/collapsible' import { indent } from '../lib/util' import runnablesStore, { RunnablesStore } from '../runnables/runnables-store' import TestModel from './test-model' import scroller, { Scroller } from '../lib/scroller' import Attempts from '../attempts/attempts' interface StudioControlsProps { events: Events model: TestModel } interface StudioControlsState { copySuccess: boolean } @observer class StudioControls extends Component { static defaultProps = { events, } state = { copySuccess: false, } _cancel = (e: MouseEvent) => { e.preventDefault() this.props.events.emit('studio:cancel') } _save = (e: MouseEvent) => { e.preventDefault() this.props.events.emit('studio:save') } _copy = (e: MouseEvent) => { e.preventDefault() this.props.events.emit('studio:copy:to:clipboard', () => { this.setState({ copySuccess: true }) }) } _endCopySuccess = () => { if (this.state.copySuccess) { this.setState({ copySuccess: false }) } } render () { const { studioIsNotEmpty } = this.props.model const { copySuccess } = this.state return (
) } } interface TestProps { events: Events appState: AppState runnablesStore: RunnablesStore scroller: Scroller model: TestModel } @observer class Test extends Component { static defaultProps = { events, appState, runnablesStore, scroller, } containerRef: RefObject constructor (props: TestProps) { super(props) this.containerRef = createRef() } componentDidMount () { this._scrollIntoView() } componentDidUpdate () { this._scrollIntoView() this.props.model.callbackAfterUpdate() } _scrollIntoView () { const { appState, model, scroller } = this.props const { state } = model if (appState.autoScrollingEnabled && (appState.isRunning || appState.studioActive) && state !== 'processing') { window.requestAnimationFrame(() => { // since this executes async in a RAF the ref might be null if (this.containerRef.current) { scroller.scrollIntoView(this.containerRef.current as HTMLElement) } }) } } render () { const { model } = this.props return ( {this._contents()} ) } _header () { const { model } = this.props return (<>