mirror of
https://github.com/Unleash/unleash.git
synced 2024-12-22 19:07:54 +01:00
parent
be35162a94
commit
b3c9aa121d
@ -1,5 +1,5 @@
|
|||||||
import React, { Component } from 'react';
|
import React, { Component } from 'react';
|
||||||
import HistoryList from './history-list-component';
|
import HistoryList from './history-list-container';
|
||||||
|
|
||||||
class History extends Component {
|
class History extends Component {
|
||||||
|
|
||||||
|
@ -4,7 +4,6 @@ import { fetchHistory } from '../../store/history-actions';
|
|||||||
|
|
||||||
const mapStateToProps = (state) => {
|
const mapStateToProps = (state) => {
|
||||||
const history = state.history.get('list').toArray();
|
const history = state.history.get('list').toArray();
|
||||||
|
|
||||||
return {
|
return {
|
||||||
history,
|
history,
|
||||||
};
|
};
|
||||||
|
@ -6,27 +6,23 @@ import style from './history.scss';
|
|||||||
|
|
||||||
class HistoryList extends Component {
|
class HistoryList extends Component {
|
||||||
|
|
||||||
constructor (props) {
|
|
||||||
super(props);
|
|
||||||
this.state = { showData: false };
|
|
||||||
}
|
|
||||||
|
|
||||||
toggleShowDiff () {
|
toggleShowDiff () {
|
||||||
this.setState({ showData: !this.state.showData });
|
this.props.updateSetting('showData', !this.props.settings.showData);
|
||||||
}
|
}
|
||||||
|
|
||||||
render () {
|
render () {
|
||||||
|
const showData = this.props.settings.showData;
|
||||||
const { history } = this.props;
|
const { history } = this.props;
|
||||||
if (!history || history.length < 0) {
|
if (!history || history.length < 0) {
|
||||||
return null;
|
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={showData} />);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div>
|
<div>
|
||||||
<Switch
|
<Switch
|
||||||
checked={this.state.showData}
|
checked={showData}
|
||||||
label="Show full events"
|
label="Show full events"
|
||||||
onChange={this.toggleShowDiff.bind(this)}
|
onChange={this.toggleShowDiff.bind(this)}
|
||||||
/>
|
/>
|
||||||
|
21
frontend/src/component/history/history-list-container.jsx
Normal file
21
frontend/src/component/history/history-list-container.jsx
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
import { connect } from 'react-redux';
|
||||||
|
import HistoryListComponent from './history-list-component';
|
||||||
|
import { updateSettingForGroup } from '../../store/settings/actions';
|
||||||
|
|
||||||
|
const mapStateToProps = (state) => {
|
||||||
|
let settings = {};
|
||||||
|
const historySettings = state.settings.get('history');
|
||||||
|
if (historySettings) {
|
||||||
|
settings = historySettings.toJS();
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
settings,
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
const HistoryListContainer = connect(mapStateToProps, {
|
||||||
|
updateSetting: updateSettingForGroup('history'),
|
||||||
|
})(HistoryListComponent);
|
||||||
|
|
||||||
|
export default HistoryListContainer;
|
@ -1,5 +1,5 @@
|
|||||||
import React, { Component, PropTypes } from 'react';
|
import React, { Component, PropTypes } from 'react';
|
||||||
import ListComponent from './history-list-component';
|
import ListComponent from './history-list-container';
|
||||||
import { fetchHistoryForToggle } from '../../data/history-api';
|
import { fetchHistoryForToggle } from '../../data/history-api';
|
||||||
|
|
||||||
class HistoryListToggle extends Component {
|
class HistoryListToggle extends Component {
|
||||||
|
@ -9,6 +9,7 @@ import error from './error-store';
|
|||||||
import metrics from './metrics-store';
|
import metrics from './metrics-store';
|
||||||
import clientStrategies from './client-strategy-store';
|
import clientStrategies from './client-strategy-store';
|
||||||
import clientInstances from './client-instance-store';
|
import clientInstances from './client-instance-store';
|
||||||
|
import settings from './settings';
|
||||||
|
|
||||||
const unleashStore = combineReducers({
|
const unleashStore = combineReducers({
|
||||||
features,
|
features,
|
||||||
@ -21,6 +22,7 @@ const unleashStore = combineReducers({
|
|||||||
metrics,
|
metrics,
|
||||||
clientStrategies,
|
clientStrategies,
|
||||||
clientInstances,
|
clientInstances,
|
||||||
|
settings,
|
||||||
});
|
});
|
||||||
|
|
||||||
export default unleashStore;
|
export default unleashStore;
|
||||||
|
10
frontend/src/store/settings/actions.js
Normal file
10
frontend/src/store/settings/actions.js
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
export const UPDATE_SETTING = 'UPDATE_SETTING';
|
||||||
|
|
||||||
|
export const updateSetting = (group, field, value) => ({
|
||||||
|
type: UPDATE_SETTING,
|
||||||
|
group,
|
||||||
|
field,
|
||||||
|
value,
|
||||||
|
});
|
||||||
|
|
||||||
|
export const updateSettingForGroup = (group) => (field, value) => updateSetting(group, field, value);
|
39
frontend/src/store/settings/index.js
Normal file
39
frontend/src/store/settings/index.js
Normal file
@ -0,0 +1,39 @@
|
|||||||
|
import { fromJS, Map as $Map } from 'immutable';
|
||||||
|
import { UPDATE_SETTING } from './actions';
|
||||||
|
|
||||||
|
// TODO: provde a mock if localstorage does not exists?
|
||||||
|
const localStorage = window.localStorage || {};
|
||||||
|
const SETTINGS = 'settings';
|
||||||
|
|
||||||
|
function getInitState () {
|
||||||
|
try {
|
||||||
|
const state = JSON.parse(localStorage.getItem(SETTINGS));
|
||||||
|
return state ? fromJS(state) : new $Map();
|
||||||
|
} catch (e) {
|
||||||
|
return new $Map();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function updateSetting (state, action) {
|
||||||
|
let newState;
|
||||||
|
if (state.get(action.group)) {
|
||||||
|
newState = state.updateIn([action.group, action.field], () => action.value);
|
||||||
|
} else {
|
||||||
|
newState = state.set(action.group, new $Map())
|
||||||
|
.updateIn([action.group, action.field], () => action.value);
|
||||||
|
}
|
||||||
|
|
||||||
|
localStorage.setItem(SETTINGS, JSON.stringify(newState.toJSON()));
|
||||||
|
return newState;
|
||||||
|
}
|
||||||
|
|
||||||
|
const settingStore = (state = getInitState(), action) => {
|
||||||
|
switch (action.type) {
|
||||||
|
case UPDATE_SETTING:
|
||||||
|
return updateSetting(state, action);
|
||||||
|
default:
|
||||||
|
return state;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
export default settingStore;
|
Loading…
Reference in New Issue
Block a user