<commit_before>import Genid from 'genid';
import ComponentStack from 'lib/componentStack';
import React from 'react';
import Sandbox from 'sandboxjs';

import { CreateCronJobStrategy, CreateWebtaskStrategy, EditCronJobStrategy, EditWebtaskStrategy } from './strategies';

import PaneSelector from './paneSelector';
import WebtaskUrl from './webtaskUrl';


import 'styles/editor.less';


export default class WebtaskEditor extends React.Component {
    constructor(props) {
        super(props);
        
        this.strategy = this.props.cron
            ?   this.props.edit
                ?   EditCronJobStrategy
                :   CreateCronJobStrategy
            :   this.props.edit
                ?   EditWebtaskStrategy
                :   CreateWebtaskStrategy;
        
        this.state = {
            code: this.props.code || this.strategy.defaultCode,
            currentPane: this.strategy.defaultPane,
            jobState: this.props.jobState,
            mergeBody: typeof this.props.mergeBody !== 'undefined'
                ?   this.props.mergeBody
                :   this.strategy.defaultMergeBody,
            name: props.name,
            parseBody: typeof this.props.parseBody !== 'undefined'
                ?   this.props.parseBody
                :   this.strategy.defaultParseBody,
            runInProgress: false,
            saveInProgress: false,
            schedule: props.schedule,
            secrets: props.secrets,
            subject: props.edit,
        };
        
    }
    
    render() {
        const editorBody = this.state.currentPane.renderBody.call(this);
        const urlInfo = this.strategy.getUrlInfo(this.props.sandbox);
        
        const error = this.state.error
            ?   (
                    <div className="a0-error-message"
                        onClick={ e => this.onClickError() }
                    >
                        { this.state.error.message }
                    </div>
                )
            :   null;
        
        const paneSelector = (
            <PaneSelector
                currentPane={ this.state.currentPane }
                panes={ this.strategy.panes }
                onChange={ pane => this.onChangePane(pane) }
            />
        );
        
        const runButton = (
            <button className="a0-inline-button -success"
                disabled={ this.state.runInProgress }
                onClick={ e => this.onClickRun() }
            >Run</button>
        );
        
        const saveButton = (
            <button className="a0-inline-button -primary"
                disabled={ this.state.saveInProgress }
                onClick={ e => this.onClickSave() }
            >Save</button>
        );
        
        const sidebarBody = this.strategy.panes.map(pane => (
            <div key={ pane.name } className={ 'a0-sidebar-pane ' + (pane === this.state.currentPane ? '-active' : '') }>
                { pane.renderSidebar.call(this) }
            </div>
        ));

        const webtaskUrl = (
            <WebtaskUrl
                copyButton={ urlInfo.copyButton }
                disabled={ this.state.saveInProgress }
                name={ this.state.name }
                onChangeName={ name => this.setState({ name }) }
                prefix={ urlInfo.prefix }
                readonly={ urlInfo.readonly }
            />
        );
        
        return (
            <div className="a0-editor-widget">
                <div className="a0-editor-split">
                    <div className="a0-editor-left">
                        <div className="a0-editor-toolbar">
                            { this.props.backButton }
                        </div>
                        <div className="a0-editor-body">
                            { error }<commit_msg>Show progress indication for save and run buttons<commit_after>import Genid from 'genid';
import ComponentStack from 'lib/componentStack';
import React from 'react';
import Sandbox from 'sandboxjs';

import { CreateCronJobStrategy, CreateWebtaskStrategy, EditCronJobStrategy, EditWebtaskStrategy } from './strategies';

import PaneSelector from './paneSelector';
import WebtaskUrl from './webtaskUrl';


import 'styles/editor.less';


export default class WebtaskEditor extends React.Component {
    constructor(props) {
        super(props);
        
        this.strategy = this.props.cron
            ?   this.props.edit
                ?   EditCronJobStrategy
                :   CreateCronJobStrategy
            :   this.props.edit
                ?   EditWebtaskStrategy
                :   CreateWebtaskStrategy;
        
        this.state = {
            code: this.props.code || this.strategy.defaultCode,
            currentPane: this.strategy.defaultPane,
            jobState: this.props.jobState,
            mergeBody: typeof this.props.mergeBody !== 'undefined'
                ?   this.props.mergeBody
                :   this.strategy.defaultMergeBody,
            name: props.name,
            parseBody: typeof this.props.parseBody !== 'undefined'
                ?   this.props.parseBody
                :   this.strategy.defaultParseBody,
            runInProgress: false,
            saveInProgress: false,
            schedule: props.schedule,
            secrets: props.secrets,
            subject: props.edit,
        };
        
    }
    
    render() {
        const editorBody = this.state.currentPane.renderBody.call(this);
        const urlInfo = this.strategy.getUrlInfo(this.props.sandbox);
        
        const error = this.state.error
            ?   (
                    <div className="a0-error-message"
                        onClick={ e => this.onClickError() }
                    >
                        { this.state.error.message }
                    </div>
                )
            :   null;
        
        const paneSelector = (
            <PaneSelector
                currentPane={ this.state.currentPane }
                panes={ this.strategy.panes }
                onChange={ pane => this.onChangePane(pane) }
            />
        );
        
        const runButton = (
            <button className="a0-inline-button -success"
                disabled={ this.state.runInProgress }
                onClick={ e => this.onClickRun() }
            >
                { this.state.runInProgress
                ?   'Running...'
                :   'Run'
                }
            </button>
        );
        
        const saveButton = (
            <button className="a0-inline-button -primary"
                disabled={ this.state.saveInProgress }
                onClick={ e => this.onClickSave() }
            >
                { this.state.saveInProgress
                ?   'Saving...'
                :   'Save'
                }
            </button>
        );
        
        const sidebarBody = this.strategy.panes.map(pane => (
            <div key={ pane.name } className={ 'a0-sidebar-pane ' + (pane === this.state.currentPane ? '-active' : '') }>
                { pane.renderSidebar.call(this) }
            </div>
        ));

        const webtaskUrl = (
            <WebtaskUrl
                copyButton={ urlInfo.copyButton }
                disabled={ this.state.saveInProgress }
                name={ this.state.name }
                onChangeName={ name => this.setState({ name }) }
                prefix={ urlInfo.prefix }
                readonly={ urlInfo.readonly }
            />
        );
        
        return (
            <div className="a0-editor-widget">
                <div className="a0-editor-split">
                    <div className="a0-editor-left">
                        <div className="a0-editor-toolbar">
                            { this.props.backButton }
                        </div>
                        <div className="a0-editor-body">
                            { error }
{'fraction_non_alphanumeric': 0.10297829379101464, 'fraction_numerical': 0.002271580010095911, 'mean_word_length': 1.3377581120943953, 'pattern_counts': {'":': 0, '<': 35, '<?xml version=': 0, '>': 47, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6062403', 'n_tokens_mistral': 2073, 'n_tokens_neox': 1998, 'n_words': 363}