/* Copyright (C) 2017 Cloudbase Solutions SRL This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more details. You should have received a copy of the GNU Affero General Public License along with this program. If not, see . */ import { observer } from "mobx-react"; import React from "react"; import styled from "styled-components"; import { ReplicaItemDetails } from "@src/@types/MainItem"; import { MinionPool } from "@src/@types/MinionPool"; import DetailsNavigation from "@src/components/modules/NavigationModule/DetailsNavigation"; import Executions from "@src/components/modules/TransferModule/Executions"; import MainDetails from "@src/components/modules/TransferModule/MainDetails"; import Schedule from "@src/components/modules/TransferModule/Schedule"; import { ThemeProps } from "@src/components/Theme"; import Button from "@src/components/ui/Button"; import scheduleStore from "@src/stores/ScheduleStore"; import configLoader from "@src/utils/Config"; import type { Instance } from "@src/@types/Instance"; import type { Endpoint, StorageBackend } from "@src/@types/Endpoint"; import type { Execution, ExecutionTasks } from "@src/@types/Execution"; import type { Network } from "@src/@types/Network"; import type { Field } from "@src/@types/Field"; import type { Schedule as ScheduleType } from "@src/@types/Schedule"; const Wrapper = styled.div` display: flex; justify-content: center; `; const Buttons = styled.div` display: flex; justify-content: space-between; margin-top: 24px; `; const ButtonColumn = styled.div` display: flex; flex-direction: column; button { margin-top: 16px; &:first-child { margin-top: 0; } } `; const DetailsBody = styled.div` ${ThemeProps.exactWidth(ThemeProps.contentWidth)} `; const NavigationItems = [ { label: "Replica", value: "", }, { label: "Executions", value: "executions", }, { label: "Schedule", value: "schedule", }, ]; type TimezoneValue = "utc" | "local"; type Props = { item?: ReplicaItemDetails | null; itemId: string; endpoints: Endpoint[]; sourceSchema: Field[]; sourceSchemaLoading: boolean; destinationSchema: Field[]; destinationSchemaLoading: boolean; networks: Network[]; instancesDetails: Instance[]; instancesDetailsLoading: boolean; scheduleStore: typeof scheduleStore; page: string; detailsLoading: boolean; executions: Execution[]; executionsLoading: boolean; executionsTasksLoading: boolean; executionsTasks: ExecutionTasks[]; minionPools: MinionPool[]; storageBackends: StorageBackend[]; onExecutionChange: (executionId: string) => void; onCancelExecutionClick: ( execution: Execution | null, force?: boolean ) => void; onDeleteExecutionClick: (execution: Execution | null) => void; onExecuteClick: () => void; onCreateDeploymentClick: () => void; onDeleteReplicaClick: () => void; onAddScheduleClick: (schedule: ScheduleType) => void; onScheduleChange: ( scheduleId: string | null, data: ScheduleType, forceSave?: boolean ) => void; onScheduleRemove: (scheduleId: string | null) => void; onScheduleSave: (schedule: ScheduleType) => void; }; type State = { timezone: TimezoneValue; }; @observer class ReplicaDetailsContent extends React.Component { state: State = { timezone: "local", }; getLastExecution() { return this.props.item?.executions?.length ? this.props.item.executions[this.props.item.executions.length - 1] : null; } getStatus() { return this.getLastExecution()?.status; } isEndpointMissing() { return ( this.props.endpoints.filter( e => e.id === this.props.item?.origin_endpoint_id || e.id === this.props.item?.destination_endpoint_id ).length < 2 ); } handleTimezoneChange(timezone: TimezoneValue) { this.setState({ timezone }); } renderBottomControls() { return ( ); } renderMainDetails() { if (this.props.page !== "") { return null; } return ( ); } renderExecutions() { if (this.props.page !== "executions") { return null; } return ( ); } renderSchedule() { if (this.props.page !== "schedule") { return null; } return ( p === this.props.endpoints.find( e => e.id === this.props.item?.origin_endpoint_id )?.type )} schedules={this.props.scheduleStore.schedules} unsavedSchedules={this.props.scheduleStore.unsavedSchedules} adding={this.props.scheduleStore.adding} loading={this.props.scheduleStore.loading} onAddScheduleClick={this.props.onAddScheduleClick} onChange={this.props.onScheduleChange} onRemove={this.props.onScheduleRemove} onSaveSchedule={this.props.onScheduleSave} timezone={this.state.timezone} onTimezoneChange={timezone => { this.handleTimezoneChange(timezone); }} savingIds={this.props.scheduleStore.savingIds} enablingIds={this.props.scheduleStore.enablingIds} deletingIds={this.props.scheduleStore.deletingIds} /> ); } render() { return ( {this.renderMainDetails()} {this.renderExecutions()} {this.renderSchedule()} ); } } export default ReplicaDetailsContent;