import React, { Component } from 'react';
import PropTypes from 'prop-types';
import { Tabs, Tab, ProgressBar, Grid, Cell } from 'react-mdl';
import ShowStrategy from './show-strategy-component';
import EditStrategy from './edit-container';
import { HeaderTitle } from '../common';
const TABS = {
view: 0,
edit: 1,
};
export default class StrategyDetails extends Component {
static propTypes = {
strategyName: PropTypes.string.isRequired,
toggles: PropTypes.array,
applications: PropTypes.array,
activeTab: PropTypes.string.isRequired,
strategy: PropTypes.object.isRequired,
fetchStrategies: PropTypes.func.isRequired,
fetchApplications: PropTypes.func.isRequired,
fetchFeatureToggles: PropTypes.func.isRequired,
history: PropTypes.object.isRequired,
};
componentDidMount() {
if (!this.props.strategy) {
this.props.fetchStrategies();
}
if (!this.props.applications || this.props.applications.length === 0) {
this.props.fetchApplications();
}
if (!this.props.toggles || this.props.toggles.length === 0) {
this.props.fetchFeatureToggles();
}
}
getTabContent(activeTabId) {
if (activeTabId === TABS.edit) {
return ;
} else {
return (
);
}
}
goToTab(tabName) {
this.props.history.push(`/strategies/${tabName}/${this.props.strategyName}`);
}
render() {
const activeTabId = TABS[this.props.activeTab] ? TABS[this.props.activeTab] : TABS.strategies;
const strategy = this.props.strategy;
if (!strategy) {
return ;
}
const tabContent = this.getTabContent(activeTabId);
return (
{strategy.editable === false ? (
''
) : (
this.goToTab('view')}>Details
this.goToTab('edit')}>Edit
)}
|
);
}
}