mirror of
https://github.com/Unleash/unleash.git
synced 2025-02-04 00:18:01 +01:00
make history-list-toggle use same store
This commit is contained in:
parent
b35ad9a91b
commit
e88e3aeb88
@ -1,5 +1,5 @@
|
|||||||
import { connect } from 'react-redux';
|
import { connect } from 'react-redux';
|
||||||
import HistoryListComponent from './history-list-component';
|
import HistoryListToggleComponent from './history-list-component';
|
||||||
import { updateSettingForGroup } from '../../store/settings/actions';
|
import { updateSettingForGroup } from '../../store/settings/actions';
|
||||||
|
|
||||||
const mapStateToProps = (state) => {
|
const mapStateToProps = (state) => {
|
||||||
@ -12,6 +12,6 @@ const mapStateToProps = (state) => {
|
|||||||
|
|
||||||
const HistoryListContainer = connect(mapStateToProps, {
|
const HistoryListContainer = connect(mapStateToProps, {
|
||||||
updateSetting: updateSettingForGroup('history'),
|
updateSetting: updateSettingForGroup('history'),
|
||||||
})(HistoryListComponent);
|
})(HistoryListToggleComponent);
|
||||||
|
|
||||||
export default HistoryListContainer;
|
export default HistoryListContainer;
|
||||||
|
@ -1,17 +1,8 @@
|
|||||||
import React, { Component, PropTypes } from 'react';
|
import React, { Component, PropTypes } from 'react';
|
||||||
import ListComponent from './history-list-container';
|
import ListComponent from './history-list-container';
|
||||||
import { fetchHistoryForToggle } from '../../data/history-api';
|
|
||||||
|
|
||||||
class HistoryListToggle extends Component {
|
class HistoryListToggle extends Component {
|
||||||
|
|
||||||
constructor (props) {
|
|
||||||
super(props);
|
|
||||||
this.state = {
|
|
||||||
fetching: true,
|
|
||||||
history: undefined,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
static propTypes () {
|
static propTypes () {
|
||||||
return {
|
return {
|
||||||
toggleName: PropTypes.string.isRequired,
|
toggleName: PropTypes.string.isRequired,
|
||||||
@ -19,21 +10,21 @@ class HistoryListToggle extends Component {
|
|||||||
}
|
}
|
||||||
|
|
||||||
componentDidMount () {
|
componentDidMount () {
|
||||||
fetchHistoryForToggle(this.props.toggleName)
|
this.props.fetchHistoryForToggle(this.props.toggleName);
|
||||||
.then((res) => this.setState({ history: res.events, fetching: false }));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
render () {
|
render () {
|
||||||
if (this.state.fetching) {
|
if (!this.props.history || this.props.history.length === 0) {
|
||||||
return <span>fetching..</span>;
|
return <span>fetching..</span>;
|
||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div>
|
<div>
|
||||||
<h5>Showing history for toggle: <strong>{this.props.toggleName}</strong></h5>
|
<h5>Showing history for toggle: <strong>{this.props.toggleName}</strong></h5>
|
||||||
<ListComponent history={this.state.history} />
|
<ListComponent history={this.props.history} />
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export default HistoryListToggle;
|
export default HistoryListToggle;
|
||||||
|
@ -0,0 +1,25 @@
|
|||||||
|
import { connect } from 'react-redux';
|
||||||
|
import HistoryListToggleComponent from './history-list-toggle-component';
|
||||||
|
import { fetchHistoryForToggle } from '../../store/history-actions';
|
||||||
|
|
||||||
|
function getHistoryFromToggle (state, toggleName) {
|
||||||
|
if (!toggleName) {
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
|
||||||
|
if (state.history.hasIn(['toggles', toggleName])) {
|
||||||
|
return state.history.getIn(['toggles', toggleName]).toArray();
|
||||||
|
}
|
||||||
|
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
|
||||||
|
const mapStateToProps = (state, props) => ({
|
||||||
|
history: getHistoryFromToggle(state, props.toggleName),
|
||||||
|
});
|
||||||
|
|
||||||
|
const HistoryListToggleContainer = connect(mapStateToProps, {
|
||||||
|
fetchHistoryForToggle,
|
||||||
|
})(HistoryListToggleComponent);
|
||||||
|
|
||||||
|
export default HistoryListToggleContainer;
|
@ -1,5 +1,5 @@
|
|||||||
import React, { PropTypes } from 'react';
|
import React, { PropTypes } from 'react';
|
||||||
import HistoryListToggle from '../../component/history/history-list-toggle-component';
|
import HistoryListToggle from '../../component/history/history-list-toggle-container';
|
||||||
|
|
||||||
const render = ({ params }) => <HistoryListToggle toggleName={params.toggleName} />;
|
const render = ({ params }) => <HistoryListToggle toggleName={params.toggleName} />;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user