/* * Copyright OpenSearch Contributors * SPDX-License-Identifier: Apache-2.0 */ import React, { ChangeEvent, Component } from "react"; import { EuiSpacer, EuiTitle, EuiFlexGroup, EuiFlexItem } from "@elastic/eui"; import { RouteComponentProps } from "react-router-dom"; import { RollupService } from "../../../../services"; import { BREADCRUMBS, ROUTES } from "../../../../utils/constants"; import { getErrorMessage } from "../../../../utils/helpers"; import { Rollup } from "../../../../../models/interfaces"; import CreateRollupSteps from "../../components/CreateRollupSteps"; import Schedule from "../../components/Schedule"; import { CoreServicesContext } from "../../../../components/core_services"; interface CreateRollupProps extends RouteComponentProps { rollupService: RollupService; currentStep: number; jobEnabledByDefault: boolean; continuousJob: string; continuousDefinition: string; interval: number; intervalTimeunit: string; intervalError: string; cronExpression: string; cronTimezone: string; pageSize: number; delayTime: number | undefined; delayTimeunit: string; onChangeJobEnabledByDefault: () => void; onChangeCron: (e: ChangeEvent) => void; onChangeCronTimezone: (e: ChangeEvent) => void; onChangeDelayTime: (e: ChangeEvent) => void; onChangeIntervalTime: (e: ChangeEvent) => void; onChangePage: (e: ChangeEvent) => void; onChangeContinuousDefinition: (e: ChangeEvent) => void; onChangeContinuousJob: (optionId: string) => void; onChangeDelayTimeunit: (e: ChangeEvent) => void; onChangeIntervalTimeunit: (e: ChangeEvent) => void; } interface CreateRollupState { rollupId: string; rollupIdError: string; rollupSeqNo: number | null; rollupPrimaryTerm: number | null; submitError: string; isSubmitting: boolean; hasSubmitted: boolean; } export default class CreateRollupStep3 extends Component { static contextType = CoreServicesContext; constructor(props: CreateRollupProps) { super(props); this.state = { rollupSeqNo: null, rollupPrimaryTerm: null, rollupId: "", rollupIdError: "", submitError: "", isSubmitting: false, hasSubmitted: false, }; } componentDidMount = async (): Promise => { this.context.chrome.setBreadcrumbs([BREADCRUMBS.INDEX_MANAGEMENT, BREADCRUMBS.ROLLUPS]); }; onCreate = async (rollupId: string, rollup: Rollup): Promise => { const { rollupService } = this.props; try { const response = await rollupService.putRollup(rollup, rollupId); if (response.ok) { this.context.notifications.toasts.addSuccess(`Created rollup: ${response.response._id}`); this.props.history.push(ROUTES.ROLLUPS); } else { this.setState({ submitError: response.error }); } } catch (err) { this.setState({ submitError: getErrorMessage(err, "There was a problem creating the rollup") }); } }; onUpdate = async (rollupId: string, rollup: Rollup): Promise => { try { const { rollupService } = this.props; const { rollupPrimaryTerm, rollupSeqNo } = this.state; if (rollupSeqNo == null || rollupPrimaryTerm == null) { this.context.notifications.toasts.addDanger("Could not update rollup without seqNo and primaryTerm"); return; } const response = await rollupService.putRollup(rollup, rollupId, rollupSeqNo, rollupPrimaryTerm); if (response.ok) { this.context.notifications.toasts.addSuccess(`Updated rollup: ${response.response._id}`); this.props.history.push(ROUTES.ROLLUPS); } else { this.setState({ submitError: response.error }); } } catch (err) { this.setState({ submitError: getErrorMessage(err, "There was a problem updating the rollup") }); } }; onCancel = (): void => { this.props.history.push(ROUTES.ROLLUPS); }; onChange = (e: ChangeEvent): void => { const { hasSubmitted } = this.state; const rollupId = e.target.value; if (hasSubmitted) this.setState({ rollupId, rollupIdError: rollupId ? "" : "Required" }); else this.setState({ rollupId }); }; render() { if (this.props.currentStep != 3) return null; const { jobEnabledByDefault, continuousJob, continuousDefinition, interval, intervalTimeunit, cronExpression, pageSize, delayTime, delayTimeunit, onChangeJobEnabledByDefault, onChangeCron, onChangeDelayTime, onChangeIntervalTime, onChangePage, onChangeContinuousDefinition, onChangeContinuousJob, onChangeDelayTimeunit, onChangeIntervalTimeunit, } = this.props; const { rollupId, rollupIdError } = this.state; return (

Specify schedule

); } }