import React from 'react'; import type { ICronTriggerConfigProps } from './cronConfig'; export interface ICronHourlyState { hours?: string; minutes?: string; } export class CronHourly extends React.Component { constructor(props: ICronTriggerConfigProps) { super(props); this.state = { hours: '1', minutes: '1', }; } public componentDidMount() { const regex = /0 (\d+) 0\/(\d+) 1\/1 \* \? \*/g; const matches = regex.exec(this.props.trigger.cronExpression); if (matches) { this.setState({ minutes: matches[1], hours: matches[2], }); } else { this.props.triggerUpdated({ ...this.props.trigger, cronExpression: '0 ' + this.state.minutes + ' 0/' + this.state.hours + ' 1/1 * ? *', }); } } private onUpdateHourlyTrigger = (hours: string) => { this.setState({ hours }); const { minutes } = this.state; this.props.triggerUpdated({ ...this.props.trigger, cronExpression: '0 ' + minutes + ' 0/' + hours + ' 1/1 * ? *', }); }; private onUpdateMinuteTrigger = (minutes: string) => { this.setState({ minutes }); const { hours } = this.state; this.props.triggerUpdated({ ...this.props.trigger, cronExpression: '0 ' + minutes + ' 0/' + hours + ' 1/1 * ? *', }); }; public render() { const { hours, minutes } = this.state; return (
Every ) => this.onUpdateHourlyTrigger(event.target.value)} required={true} value={hours} /> hour(s) on minute ) => this.onUpdateMinuteTrigger(event.target.value)} value={minutes} />
); } }