1
0
mirror of https://github.com/Unleash/unleash.git synced 2024-10-23 20:07:40 +02:00
unleash.unleash/frontend/src/component/strategies/strategy-details-component.jsx

82 lines
2.7 KiB
React
Raw Normal View History

import React, { PropTypes, Component } from 'react';
import { hashHistory } from 'react-router';
import { Tabs, Tab, ProgressBar, Grid, Cell } from 'react-mdl';
2016-12-17 14:37:11 +01:00
import ShowStrategy from './show-strategy-component';
import EditStrategy from './edit-container';
import { HeaderTitle } from '../common';
const TABS = {
view: 0,
edit: 1,
};
2016-12-17 14:37:11 +01:00
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,
2016-12-17 14:37:11 +01:00
}
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) {
2016-12-17 14:37:11 +01:00
return <EditStrategy strategy={this.props.strategy} />;
} else {
return (<ShowStrategy
strategy={this.props.strategy}
toggles={this.props.toggles}
applications={this.props.applications} />);
}
}
goToTab (tabName) {
hashHistory.push(`/strategies/${tabName}/${this.props.strategyName}`);
}
2016-12-17 14:37:11 +01:00
render () {
const activeTabId = TABS[this.props.activeTab] ? TABS[this.props.activeTab] : TABS.view;
2016-12-17 14:37:11 +01:00
const strategy = this.props.strategy;
if (!strategy) {
return <ProgressBar indeterminate />;
}
const tabContent = this.getTabContent(activeTabId);
2016-12-17 14:37:11 +01:00
return (<Grid className="mdl-color--white">
2017-06-29 09:11:28 +02:00
<Cell col={12}>
<HeaderTitle title={strategy.name} subtitle={strategy.description} />
{strategy.editable === false ? '' : <Tabs activeTab={activeTabId} ripple>
<Tab onClick={() => this.goToTab('view')}>
Details
2017-06-29 09:11:28 +02:00
</Tab>
<Tab onClick={() => this.goToTab('edit')}>
Edit
2017-06-29 09:11:28 +02:00
</Tab>
</Tabs>}
2017-06-29 09:11:28 +02:00
<section>
<div className="content">
{tabContent}
</div>
</section>
</Cell>
</Grid>);
2016-12-17 14:37:11 +01:00
}
}