<commit_before>import dedent from 'lib/dedent';


import { HistoryPane, LogsPane, SchedulePane, SecretsPane, SettingsPane } from './panes';


const defaultCode = dedent`
    module.exports = function (ctx, cb) {
        cb(null, 'Hello world');
    };
`.trim();



export const CreateWebtaskStrategy = {
    defaultCode,
    defaultMergeBody: false,
    defaultPane: SecretsPane,
    defaultParseBody: true,
    getJobState: () => undefined,
    getUrlInfo: (sandbox) => {
        return {
            copyButton: false,
            prefix: sandbox.url + '/api/run/' + sandbox.container + '/',
            readonly: false,
        };
    },
    onSave: saveWebtask,
    panes: [SecretsPane, SettingsPane, LogsPane],
};

export const EditWebtaskStrategy = {
    defaultCode,
    defaultMergeBody: false,
    defaultPane: SecretsPane,
    defaultParseBody: true,
    getJobState: () => undefined,
    getUrlInfo: (sandbox) => {
        return {
            copyButton: true,
            prefix: sandbox.url + '/api/run/' + sandbox.container + '/',
            readonly: false,
        };
    },
    onSave: saveWebtask,
    panes: [SecretsPane, SettingsPane, LogsPane],
};

export const CreateCronJobStrategy = {
    defaultCode,
    defaultMergeBody: false,
    defaultPane: SchedulePane,
    defaultParseBody: true,
    getJobState: function() { return this.state.jobState; },
    getUrlInfo: (sandbox) => {
        return {
            copyButton: false,
            prefix: 'Job name: ',
            readonly: false,
        };
    },
    onChangeState: function (state) {
        console.log('CronCronJobStrategy.onChangeState', state);
        this.setState({ jobState: state });
    },
    onSave: saveCronJob,
    panes: [SecretsPane, SchedulePane, LogsPane],
};

export const EditCronJobStrategy = {
    defaultCode,
    defaultMergeBody: false,
    defaultPane: HistoryPane,
    defaultParseBody: true,
    getJobState: function () { return this.state.subject.state; },
    getUrlInfo: (sandbox) => {
        return {
            copyButton: false,
            prefix: 'Job name: ',
            readonly: true,
        };
    },
    onChangeState: function (state) {
        this.setState({ jobStateChangePending: true });
        
        this.state.subject.setJobState({ state })
            .tap(job => this.forceUpdate())
            .catch(error => this.setState({ error }))
            .finally(() => this.setState({ jobStateChangePending: false }));
    },
    onSave: saveCronJob,
    panes: [SecretsPane, SchedulePane, HistoryPane, LogsPane],
};


function saveCronJob() {
    const jobState = this.getJobState();
    
    return saveWebtask.call(this, EditCronJobStrategy)
        .then(webtask => webtask.createCronJob({ schedule: this.state.schedule, state: jobState }))
        .tap(subject => this.setState({ subject }));
}

function saveWebtask(nextStrategy = EditWebtaskStrategy) {
    return this.props.sandbox.create(this.state.code, {
        name: this.state.name.trim(),
        mergeBody: this.state.mergeBody,
        parseBody: this.state.parseBody,
        secrets: this.state.secrets,<commit_msg>change position history tab<commit_after>import dedent from 'lib/dedent';


import { HistoryPane, LogsPane, SchedulePane, SecretsPane, SettingsPane } from './panes';


const defaultCode = dedent`
    module.exports = function (ctx, cb) {
        cb(null, 'Hello world');
    };
`.trim();



export const CreateWebtaskStrategy = {
    defaultCode,
    defaultMergeBody: false,
    defaultPane: SecretsPane,
    defaultParseBody: true,
    getJobState: () => undefined,
    getUrlInfo: (sandbox) => {
        return {
            copyButton: false,
            prefix: sandbox.url + '/api/run/' + sandbox.container + '/',
            readonly: false,
        };
    },
    onSave: saveWebtask,
    panes: [SecretsPane, SettingsPane, LogsPane],
};

export const EditWebtaskStrategy = {
    defaultCode,
    defaultMergeBody: false,
    defaultPane: SecretsPane,
    defaultParseBody: true,
    getJobState: () => undefined,
    getUrlInfo: (sandbox) => {
        return {
            copyButton: true,
            prefix: sandbox.url + '/api/run/' + sandbox.container + '/',
            readonly: false,
        };
    },
    onSave: saveWebtask,
    panes: [SecretsPane, SettingsPane, LogsPane],
};

export const CreateCronJobStrategy = {
    defaultCode,
    defaultMergeBody: false,
    defaultPane: SchedulePane,
    defaultParseBody: true,
    getJobState: function() { return this.state.jobState; },
    getUrlInfo: (sandbox) => {
        return {
            copyButton: false,
            prefix: 'Job name: ',
            readonly: false,
        };
    },
    onChangeState: function (state) {
        console.log('CronCronJobStrategy.onChangeState', state);
        this.setState({ jobState: state });
    },
    onSave: saveCronJob,
    panes: [SecretsPane, SchedulePane, LogsPane],
};

export const EditCronJobStrategy = {
    defaultCode,
    defaultMergeBody: false,
    defaultPane: HistoryPane,
    defaultParseBody: true,
    getJobState: function () { return this.state.subject.state; },
    getUrlInfo: (sandbox) => {
        return {
            copyButton: false,
            prefix: 'Job name: ',
            readonly: true,
        };
    },
    onChangeState: function (state) {
        this.setState({ jobStateChangePending: true });

        this.state.subject.setJobState({ state })
            .tap(job => this.forceUpdate())
            .catch(error => this.setState({ error }))
            .finally(() => this.setState({ jobStateChangePending: false }));
    },
    onSave: saveCronJob,
    panes: [SecretsPane, SchedulePane, LogsPane, HistoryPane],
};


function saveCronJob() {
    const jobState = this.getJobState();

    return saveWebtask.call(this, EditCronJobStrategy)
        .then(webtask => webtask.createCronJob({ schedule: this.state.schedule, state: jobState }))
        .tap(subject => this.setState({ subject }));
}

function saveWebtask(nextStrategy = EditWebtaskStrategy) {
    return this.props.sandbox.create(this.state.code, {
        name: this.state.name.trim(),
        mergeBody: this.state.mergeBody,
        parseBody: this.state.parseBody,
        secrets: this.state.secrets,
{'fraction_non_alphanumeric': 0.1245608431810923, 'fraction_numerical': 0.0, 'mean_word_length': 2.6118800461361014, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 25, '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': '110908', 'n_tokens_mistral': 1862, 'n_tokens_neox': 1871, 'n_words': 396}