import { Button, Form, Input, Typography } from 'antd'; import React, { useMemo } from 'react'; import styled from 'styled-components'; import cronstrue from 'cronstrue'; import { CheckCircleOutlined } from '@ant-design/icons'; import { SourceBuilderState, StepProps } from './types'; import { TimezoneSelect } from './TimezoneSelect'; import { ANTD_GRAY, REDESIGN_COLORS } from '../../../entity/shared/constants'; import { lowerFirstLetter } from '../../../shared/textUtil'; import { IngestionSourceBuilderStep } from './steps'; const Section = styled.div` display: flex; flex-direction: column; padding-bottom: 16px; padding-top: 0px; `; const SelectTemplateHeader = styled(Typography.Title)` && { margin-bottom: 8px; } `; const CronText = styled(Typography.Paragraph)` &&& { margin-top: 8px; margin-bottom: 0px; } color: ${ANTD_GRAY[7]}; `; const CronSuccessCheck = styled(CheckCircleOutlined)` color: ${REDESIGN_COLORS.BLUE}; margin-right: 4px; `; const ControlsContainer = styled.div` display: flex; justify-content: space-between; margin-top: 8px; `; const ItemDescriptionText = styled(Typography.Paragraph)``; export const CreateScheduleStep = ({ state, updateState, goTo, prev }: StepProps) => { const interval = state.schedule?.interval || ''; const timezone = state.schedule?.timezone || Intl.DateTimeFormat().resolvedOptions().timeZone; const setTimezone = (tz: string) => { const newState: SourceBuilderState = { ...state, schedule: { ...state.schedule, timezone: tz, }, }; updateState(newState); }; const setCronInterval = (int: string) => { const newState: SourceBuilderState = { ...state, schedule: { ...state.schedule, interval: int, }, }; updateState(newState); }; const cronAsText = useMemo(() => { if (interval) { try { return { text: `Runs ${lowerFirstLetter(cronstrue.toString(interval))}.`, error: false, }; } catch (e) { return { text: undefined, error: true, }; } } return { text: undefined, error: false, }; }, [interval]); const onClickNext = () => { setTimezone(timezone); goTo(IngestionSourceBuilderStep.NAME_SOURCE); }; const onClickSkip = () => { const newState: SourceBuilderState = { ...state, schedule: undefined, }; updateState(newState); goTo(IngestionSourceBuilderStep.NAME_SOURCE); }; return ( <>
Create an Execution Schedule Configure your ingestion source to run on a schedule.
Schedule}> Provide a custom cron schedule. setCronInterval(e.target.value)} placeholder="* * * * *" /> {cronAsText.error && <>Invalid cron schedule. Cron must be of UNIX form:} {!cronAsText.text && ( minute, hour, day, month, day of week )} {cronAsText.text && ( <> {cronAsText.text} )} Timezone}> Select the timezone to run the cron schedule in.
); };