/*
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 React, { PropTypes } from 'react';
import Reflux from 'reflux';
import withStyles from 'isomorphic-style-loader/lib/withStyles';
import s from './ReplicaView.scss';
import Header from '../Header';
import Link from '../Link';
import MigrationStore from '../../stores/MigrationStore';
import MigrationActions from '../../actions/MigrationActions';
import LoadingIcon from '../LoadingIcon';
import TextTruncate from 'react-text-truncate';
import Location from '../../core/Location';
import ConfirmationDialog from '../ConfirmationDialog'
class ReplicaView extends Reflux.Component {
static propTypes = {
type: PropTypes.string
}
static contextTypes = {
onSetTitle: PropTypes.func.isRequired,
};
constructor(props) {
super(props)
this.store = MigrationStore
this.state = {
title: 'Coriolis: View Replica',
confirmationDialog: {
visible: false,
message: "Are you sure?",
onConfirm: null,
onCancel: null
}
}
}
componentWillMount() {
super.componentWillMount.call(this)
MigrationActions.setReplica(this.props.replicaId)
}
componentDidMount() {
this.context.onSetTitle(this.state.title);
}
executeReplica() {
let item = this.state.replicas.filter(replica => replica.id == this.props.replicaId)[0]
MigrationActions.executeReplica(item)
}
goBack() {
Location.push('/replicas')
}
onMigrationActionsChange(option) {
let item = this.state.replicas.filter(replica => replica.id == this.props.replicaId)[0]
switch (option.value) {
case "delete":
MigrationActions.deleteReplica(item)
Location.push('/cloud-endpoints')
break
case "start":
MigrationActions.executeReplica(item)
break
default:
break
}
}
currentReplica(replicaId) {
if (this.state.replicas) {
return this.state.replicas.filter(replica => replica.id == replicaId)[0]
} else {
return null
}
}
render() {
let item = this.currentReplica(this.props.replicaId)
let title = "Edit"
if (item) {
title = "Edit Replica"
let disabled = item.executions.length && item.executions[item.executions.length - 1].status != "COMPLETED"
if (item.executions.length == 0) {
disabled = true
}
let itemStatus = item.status
if (item.executions.length) {
itemStatus = item.executions[item.executions.length - 1].status
}
return (