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

86 lines
2.8 KiB
React
Raw Normal View History

import React, { Component } from 'react';
import PropTypes from 'prop-types';
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() {
2016-12-17 14:37:11 +01:00
if (!this.props.strategy) {
this.props.fetchStrategies();
}
2016-12-17 14:37:11 +01:00
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}
/>
);
2016-12-17 14:37:11 +01:00
}
}
goToTab(tabName) {
hashHistory.push(`/strategies/${tabName}/${this.props.strategyName}`);
}
render() {
2017-08-28 21:40:44 +02:00
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">
<Cell col={12}>
2017-08-28 21:40:44 +02:00
<HeaderTitle title={strategy.name} subtitle={strategy.description} />
{strategy.editable === false ? (
''
) : (
<Tabs activeTab={activeTabId} ripple>
2017-08-28 21:40:44 +02:00
<Tab onClick={() => this.goToTab('view')}>Details</Tab>
<Tab onClick={() => this.goToTab('edit')}>Edit</Tab>
</Tabs>
)}
<section>
<div className="content">{tabContent}</div>
</section>
</Cell>
</Grid>
);
2016-12-17 14:37:11 +01:00
}
}