diff --git a/packages/unleash-frontend-next/package.json b/packages/unleash-frontend-next/package.json index 1bc5a34c67..eb6e15f538 100644 --- a/packages/unleash-frontend-next/package.json +++ b/packages/unleash-frontend-next/package.json @@ -32,6 +32,7 @@ }, "main": "./index.js", "dependencies": { + "debug": "^2.2.0", "immutability-helper": "^2.0.0", "immutable": "^3.8.1", "normalize.css": "^4.2.0", diff --git a/packages/unleash-frontend-next/src/component/feature/FeatureList.jsx b/packages/unleash-frontend-next/src/component/feature/FeatureList.jsx index 6c3d2e11c5..dc35045d6e 100644 --- a/packages/unleash-frontend-next/src/component/feature/FeatureList.jsx +++ b/packages/unleash-frontend-next/src/component/feature/FeatureList.jsx @@ -16,10 +16,7 @@ export default class FeatureList extends React.Component { } componentDidMount () { - // TODO: only fetch from server if we don't know about any toggles. - if (this.props.features.length === 0) { - this.props.fetchFeatureToggles(); - } + this.props.fetchFeatureToggles(); } render () { diff --git a/packages/unleash-frontend-next/src/component/feature/FeatureListContainer.jsx b/packages/unleash-frontend-next/src/component/feature/FeatureListContainer.jsx index d2da4d3b2e..c7341c5600 100644 --- a/packages/unleash-frontend-next/src/component/feature/FeatureListContainer.jsx +++ b/packages/unleash-frontend-next/src/component/feature/FeatureListContainer.jsx @@ -3,7 +3,7 @@ import { toggleFeature, fetchFeatureToggles } from '../../store/feature-actions' import FeatureList from './FeatureList'; const mapStateToProps = (state) => ({ - features: state.features, + features: state.features.toJS(), }); const mapDispatchToProps = { diff --git a/packages/unleash-frontend-next/src/store/feature-actions.js b/packages/unleash-frontend-next/src/store/feature-actions.js index 9caebb131d..e73f49e22c 100644 --- a/packages/unleash-frontend-next/src/store/feature-actions.js +++ b/packages/unleash-frontend-next/src/store/feature-actions.js @@ -1,4 +1,5 @@ import api from './feature-api'; +const debug = require('debug')('unleash:feature-actions'); export const ADD_FEATURE_TOGGLE = 'ADD_FEATURE_TOGGLE'; export const UPDATE_FEATURE_TOGGLE = 'UPDATE_FEATURE_TOGGLE'; @@ -42,6 +43,7 @@ function errorUpdatingFeatureToggle (statusCode) { } export function toggleFeature (featureToggle) { + debug('Toggle feature toggle ', featureToggle); return dispatch => { const newValue = Object.assign({}, featureToggle, { enabled: !featureToggle.enabled }); dispatch(requestUpdateFeatureToggle(newValue)); @@ -84,6 +86,7 @@ function errorReceiveFeatureToggles (statusCode) { } export function fetchFeatureToggles () { + debug('Start fetching feature toggles'); return dispatch => { dispatch(requestFeatureToggles()); diff --git a/packages/unleash-frontend-next/src/store/feature-store.js b/packages/unleash-frontend-next/src/store/feature-store.js index 3c6506178a..dc3de3d06b 100644 --- a/packages/unleash-frontend-next/src/store/feature-store.js +++ b/packages/unleash-frontend-next/src/store/feature-store.js @@ -1,4 +1,5 @@ -import Immutable from 'immutable'; +import { List, Map } from 'immutable'; + import { ADD_FEATURE_TOGGLE, @@ -6,23 +7,21 @@ import { UPDATE_FEATURE_TOGGLE, } from './feature-actions'; -const features = (state = [], action) => { + +const features = (state = new List([]), action) => { switch (action.type) { case ADD_FEATURE_TOGGLE: - return [ - ...state, - action.featureToggle, - ]; + return state.push(new Map(action.featureToggle)); case UPDATE_FEATURE_TOGGLE: return state.map(t => { - if (t.name !== action.featureToggle.name) { + if (t.get('name') === action.featureToggle.name) { + return new Map(action.featureToggle); + } else { return t; } - return action.featureToggle; }); - case RECEIVE_FEATURE_TOGGLES: { - return action.featureToggles; - } + case RECEIVE_FEATURE_TOGGLES: + return new List(action.featureToggles.map(t => new Map(t))); default: return state; }