import {Component, Fragment} from 'react'; import {Observer} from 'mobx-react'; import Access from 'sentry/components/acl/access'; import Field from 'sentry/components/forms/field'; import Form from 'sentry/components/forms/form'; import NumberField from 'sentry/components/forms/numberField'; import SelectField from 'sentry/components/forms/selectField'; import TextCopyInput from 'sentry/components/forms/textCopyInput'; import TextField from 'sentry/components/forms/textField'; import {Panel, PanelBody, PanelHeader} from 'sentry/components/panels'; import {t, tct} from 'sentry/locale'; import {PageFilters, Project, SelectValue} from 'sentry/types'; import withPageFilters from 'sentry/utils/withPageFilters'; import withProjects from 'sentry/utils/withProjects'; import MonitorModel from './monitorModel'; import {Monitor, MonitorConfig, MonitorTypes, ScheduleType} from './types'; const SCHEDULE_TYPES: SelectValue[] = [ {value: 'crontab', label: 'Crontab'}, {value: 'interval', label: 'Interval'}, ]; const MONITOR_TYPES: SelectValue[] = [ {value: 'cron_job', label: 'Cron Job'}, ]; const INTERVALS: SelectValue[] = [ {value: 'minute', label: 'minute(s)'}, {value: 'hour', label: 'hour(s)'}, {value: 'day', label: 'day(s)'}, {value: 'week', label: 'week(s)'}, {value: 'month', label: 'month(s)'}, {value: 'year', label: 'year(s)'}, ]; type Props = { apiEndpoint: string; apiMethod: Form['props']['apiMethod']; onSubmitSuccess: Form['props']['onSubmitSuccess']; projects: Project[]; selection: PageFilters; monitor?: Monitor; }; class MonitorForm extends Component { form = new MonitorModel(); formDataFromConfig(type: MonitorTypes, config: MonitorConfig) { const rv = {}; switch (type) { case 'cron_job': rv['config.schedule_type'] = config.schedule_type; rv['config.checkin_margin'] = config.checkin_margin; rv['config.max_runtime'] = config.max_runtime; switch (config.schedule_type) { case 'interval': rv['config.schedule.frequency'] = config.schedule[0]; rv['config.schedule.interval'] = config.schedule[1]; break; case 'crontab': default: rv['config.schedule'] = config.schedule; } break; default: } return rv; } render() { const {monitor} = this.props; const selectedProjectId = this.props.selection.projects[0]; const selectedProject = selectedProjectId ? this.props.projects.find(p => p.id === selectedProjectId + '') : null; return ( {({hasAccess}) => (
{t('Details')} {monitor && (
{monitor.id}
)} p.isMember) .map(p => ({value: p.slug, label: p.slug}))} required />
{t('Config')} {() => { switch (this.form.getValue('type')) { case 'cron_job': return ( ); default: return null; } }} {() => { switch (this.form.getValue('config.schedule_type')) { case 'crontab': return ( , } )} /> ); case 'interval': return ( ); default: return null; } }}
)}
); } } export default withPageFilters(withProjects(MonitorForm));