1
0
mirror of https://github.com/Unleash/unleash.git synced 2024-10-18 20:09:08 +02:00
unleash.unleash/frontend/src/component/feature/view-component.jsx

99 lines
3.2 KiB
React
Raw Normal View History

import React, { PropTypes } from 'react';
import { Tabs, Tab, ProgressBar } from 'react-mdl';
import { hashHistory, Link } from 'react-router';
import HistoryComponent from '../history/history-list-toggle-container';
import MetricComponent from './metric-container';
import EditFeatureToggle from './form-edit-container.jsx';
2017-01-06 11:41:52 +01:00
import { formatFullDateTime } from '../common/util';
const TABS = {
view: 0,
edit: 1,
history: 2,
};
export default class ViewFeatureToggleComponent extends React.Component {
constructor (props) {
super(props);
}
static propTypes () {
return {
activeTab: PropTypes.string.isRequired,
featureToggleName: PropTypes.string.isRequired,
features: PropTypes.array.isRequired,
fetchFeatureToggles: PropTypes.array.isRequired,
featureToggle: PropTypes.object.isRequired,
};
}
componentWillMount () {
if (this.props.features.length === 0) {
this.props.fetchFeatureToggles();
}
}
getTabContent (activeTab) {
const {
featureToggle,
featureToggleName,
} = this.props;
if (TABS[activeTab] === TABS.history) {
return <HistoryComponent toggleName={featureToggleName} />;
} else if (TABS[activeTab] === TABS.edit) {
return <EditFeatureToggle featureToggle={featureToggle} />;
} else {
return <MetricComponent featureToggle={featureToggle} />;
}
}
goToTab (tabName, featureToggleName) {
hashHistory.push(`/features/${tabName}/${featureToggleName}`);
}
render () {
const {
featureToggle,
features,
activeTab,
featureToggleName,
} = this.props;
if (!featureToggle) {
if (features.length === 0 ) {
return <ProgressBar indeterminate />;
}
return (
2016-12-20 19:31:14 +01:00
<span>
Could not find the toggle <Link to={{ pathname: '/features/create', query: { name: featureToggleName } }}>
{featureToggleName}</Link>
</span>
);
}
const activeTabId = TABS[this.props.activeTab] ? TABS[this.props.activeTab] : TABS.view;
const tabContent = this.getTabContent(activeTab);
return (
<div>
<h4>{featureToggle.name} <small>{featureToggle.enabled ? 'is enabled' : 'is disabled'}</small>
<small style={{ float: 'right', lineHeight: '38px' }}>
2017-01-06 11:41:52 +01:00
Created {formatFullDateTime(featureToggle.createdAt)}
</small>
</h4>
2017-01-02 09:26:36 +01:00
<div className="mdl-color-text--grey"><small>{featureToggle.description}</small></div>
<Tabs activeTab={activeTabId} ripple style={{ marginBottom: '10px' }}>
<Tab onClick={() => this.goToTab('view', featureToggleName)}>Metrics</Tab>
<Tab onClick={() => this.goToTab('edit', featureToggleName)}>Edit</Tab>
<Tab onClick={() => this.goToTab('history', featureToggleName)}>History</Tab>
</Tabs>
{tabContent}
</div>
);
}
2016-12-20 19:31:14 +01:00
}