import React from 'react'; import type { Option } from 'react-select'; import Select from 'react-select'; import type { ICronTriggerConfigProps } from './cronConfig'; export interface ICronMinutesState { minutes?: string; } export class CronMinutes extends React.Component { private minuteOptions: string[] = ['1', '2', '3', '4', '5', '6', '10', '12', '15', '20', '30']; constructor(props: ICronTriggerConfigProps) { super(props); this.state = { minutes: '1' }; } public componentDidMount() { const regex = /0 0\/(\d+) \* 1\/1 \* \? \*/g; const matches = regex.exec(this.props.trigger.cronExpression); if (matches) { this.setState({ minutes: matches[1] }); } else { this.props.triggerUpdated({ ...this.props.trigger, cronExpression: '0 0/' + this.state.minutes + ' * 1/1 * ? *', }); } } private onUpdateTrigger = (option: Option) => { const minutes = option.value; this.setState({ minutes }); this.props.triggerUpdated({ ...this.props.trigger, cronExpression: '0 0/' + minutes + ' * 1/1 * ? *', }); }; public render() { const { minutes } = this.state; return (
Every