import { Button, ButtonGroup, Callout, Dialog, Label } from '@blueprintjs/core'; import { observer } from 'mobx-react'; import * as React from 'react'; import { RunnableVersion } from '../../interfaces'; import { Bisector } from '../bisect'; import { AppState } from '../state'; import { VersionSelect } from './version-select'; interface BisectDialogProps { appState: AppState; } interface BisectDialogState { startIndex: number; endIndex: number; allVersions: Array; showHelp?: boolean; } /** * The "add version" dialog allows users to add custom builds of Electron. * * @class BisectDialog * @extends {React.Component} */ @observer export class BisectDialog extends React.Component< BisectDialogProps, BisectDialogState > { constructor(props: BisectDialogProps) { super(props); this.onSubmit = this.onSubmit.bind(this); this.onAuto = this.onAuto.bind(this); this.onClose = this.onClose.bind(this); this.onBeginSelect = this.onBeginSelect.bind(this); this.onEndSelect = this.onEndSelect.bind(this); this.showHelp = this.showHelp.bind(this); this.isEarliestItemDisabled = this.isEarliestItemDisabled.bind(this); this.isLatestItemDisabled = this.isLatestItemDisabled.bind(this); this.state = { allVersions: this.props.appState.versionsToShow, startIndex: 10, endIndex: 0, }; } public onBeginSelect(version: RunnableVersion) { this.setState({ startIndex: this.state.allVersions.indexOf(version) }); } public onEndSelect(version: RunnableVersion) { this.setState({ endIndex: this.state.allVersions.indexOf(version) }); } getBisectRange(): RunnableVersion[] { const { endIndex, startIndex, allVersions } = this.state; return endIndex !== undefined && startIndex !== undefined ? allVersions.slice(endIndex, startIndex + 1).reverse() : []; } /** * Handles the submission of the dialog * * @returns {Promise} */ public async onSubmit(): Promise { const range = this.getBisectRange(); if (range.length > 1) { const { appState } = this.props; appState.Bisector = new Bisector(range); const initialBisectPivot = appState.Bisector.getCurrentVersion().version; appState.setVersion(initialBisectPivot); this.onClose(); } } public async onAuto(): Promise { const range = this.getBisectRange(); if (range.length > 1) { window.ElectronFiddle.app.runner.autobisect(range); this.onClose(); } } /** * Closes the dialog */ public onClose() { this.props.appState.isBisectDialogShowing = false; } /** * Shows the additional help */ public showHelp() { this.setState({ showHelp: true }); } /** * Can we get this show on the road? */ get canSubmit(): boolean { return this.state.startIndex > this.state.endIndex; } /** * Can we autobisect? */ get canAuto(): boolean { return this.canSubmit; } /** * Renders the buttons */ get buttons() { return [