1
0
mirror of https://github.com/Unleash/unleash.git synced 2024-12-22 19:07:54 +01:00

add history for feature toggles

This commit is contained in:
ivaosthu 2016-11-22 22:04:30 +01:00
parent 0c0c61d5a3
commit edf0075282
9 changed files with 93 additions and 11 deletions

View File

@ -8,7 +8,7 @@ const ArchivedFeature = ({ feature, revive }) => {
const { name, description, enabled, strategies } = feature; const { name, description, enabled, strategies } = feature;
const actions = [ const actions = [
<div>{strategies && strategies.map(s => <Chip><small>{s.name}</small></Chip>)}</div>, <div>{strategies && strategies.map(s => <Chip><small>{s.name}</small></Chip>)}</div>,
<FontIcon style={{ cursor: 'pointer' }} value="restore" onClick={() => revive(feature)} />, <FontIcon style={{ cursor: 'pointer' }} value="undo" onClick={() => revive(feature)} />,
]; ];
const leftActions = [ const leftActions = [

View File

@ -24,6 +24,9 @@ const Feature = ({
<Link key="change" to={`/features/edit/${name}`} title={`Edit ${name}`}> <Link key="change" to={`/features/edit/${name}`} title={`Edit ${name}`}>
<FontIcon value="edit" className={style.action} /> <FontIcon value="edit" className={style.action} />
</Link>, </Link>,
<Link key="history" to={`/history/${name}`} title={`History for ${name}`}>
<FontIcon value="history" className={style.action} />
</Link>,
<FontIcon key="delete" className={style.action} value="delete" onClick={() => onFeatureRemove(name)} />, <FontIcon key="delete" className={style.action} value="delete" onClick={() => onFeatureRemove(name)} />,
]; ];

View File

@ -0,0 +1,28 @@
import React, { Component } from 'react';
import HistoryList from './history-list-component';
class History extends Component {
componentDidMount () {
this.props.fetchHistory();
}
toggleShowDiff () {
this.setState({ showData: !this.state.showData });
}
render () {
const { history } = this.props;
if (history.length < 0) {
return;
}
return (
<div>
<h5>Last 100 changes</h5>
<HistoryList history={history} />
</div>
);
}
}
export default History;

View File

@ -1,5 +1,5 @@
import { connect } from 'react-redux'; import { connect } from 'react-redux';
import ListComponent from './history-list-component'; import HistoryComponent from './history-component';
import { fetchHistory } from '../../store/history-actions'; import { fetchHistory } from '../../store/history-actions';
const mapStateToProps = (state) => { const mapStateToProps = (state) => {
@ -10,6 +10,6 @@ const mapStateToProps = (state) => {
}; };
}; };
const HistoryListContainer = connect(mapStateToProps, { fetchHistory })(ListComponent); const HistoryListContainer = connect(mapStateToProps, { fetchHistory })(HistoryComponent);
export default HistoryListContainer; export default HistoryListContainer;

View File

@ -11,26 +11,20 @@ class HistoryList extends Component {
this.state = { showData: false }; this.state = { showData: false };
} }
componentDidMount () {
this.props.fetchHistory();
}
toggleShowDiff () { toggleShowDiff () {
this.setState({ showData: !this.state.showData }); this.setState({ showData: !this.state.showData });
} }
render () { render () {
const { history } = this.props; const { history } = this.props;
if (history.length < 0) { if (!history || history.length < 0) {
return; return null;
} }
const entries = history.map((entry) => <HistoryItem key={`log${entry.id}`} entry={entry} showData={this.state.showData} />); const entries = history.map((entry) => <HistoryItem key={`log${entry.id}`} entry={entry} showData={this.state.showData} />);
return ( return (
<div> <div>
<h5>History</h5>
<Switch <Switch
checked={this.state.showData} checked={this.state.showData}
label="Show full events" label="Show full events"

View File

@ -0,0 +1,38 @@
import React, { Component, PropTypes } from 'react';
import ListComponent from './history-list-component';
import { fetchHistoryForToggle } from '../../data/history-api';
class HistoryListToggle extends Component {
constructor (props) {
super(props);
this.state = {
fetching: true,
history: undefined,
};
}
static propTypes () {
return {
toggleName: PropTypes.string.isRequired,
};
}
componentDidMount () {
fetchHistoryForToggle(this.props.toggleName)
.then((res) => this.setState({ history: res, fetching: false }));
}
render () {
if (this.state.fetching) {
return <span>fetching..</span>;
}
return (
<div>
<h5>Showing history for toggle: <strong>{this.props.toggleName}</strong></h5>
<ListComponent history={this.state.history} />
</div>
);
}
}
export default HistoryListToggle;

View File

@ -8,6 +8,13 @@ function fetchAll () {
.then(response => response.json()); .then(response => response.json());
} }
function fetchHistoryForToggle (toggleName) {
return fetch(`${URI}/${toggleName}`)
.then(throwIfNotSuccess)
.then(response => response.json());
}
module.exports = { module.exports = {
fetchAll, fetchAll,
fetchHistoryForToggle,
}; };

View File

@ -15,6 +15,7 @@ import EditFeatureToggle from './page/features/edit';
import Strategies from './page/strategies'; import Strategies from './page/strategies';
import CreateStrategies from './page/strategies/create'; import CreateStrategies from './page/strategies/create';
import HistoryPage from './page/history'; import HistoryPage from './page/history';
import HistoryTogglePage from './page/history/toggle';
import Archive from './page/archive'; import Archive from './page/archive';
import Metrics from './page/metrics'; import Metrics from './page/metrics';
import ClientStrategies from './page/client-strategies'; import ClientStrategies from './page/client-strategies';
@ -38,6 +39,7 @@ ReactDOM.render(
<Route path="/strategies" component={Strategies} /> <Route path="/strategies" component={Strategies} />
<Route path="/strategies/create" component={CreateStrategies} /> <Route path="/strategies/create" component={CreateStrategies} />
<Route path="/history" component={HistoryPage} /> <Route path="/history" component={HistoryPage} />
<Route path="/history/:toggleName" component={HistoryTogglePage} />
<Route path="/archive" component={Archive} /> <Route path="/archive" component={Archive} />
<Route path="/metrics" component={Metrics} /> <Route path="/metrics" component={Metrics} />
<Route path="/client-strategies" component={ClientStrategies} /> <Route path="/client-strategies" component={ClientStrategies} />

View File

@ -0,0 +1,10 @@
import React, { PropTypes } from 'react';
import HistoryListToggle from '../../component/history/history-list-toggle-component';
const render = ({ params }) => <HistoryListToggle toggleName={params.toggleName} />;
render.propTypes = {
params: PropTypes.object.isRequired,
};
export default render;