1
0
mirror of https://github.com/Unleash/unleash.git synced 2025-01-01 00:08:27 +01:00

add dummy strategies

This commit is contained in:
Ivar 2016-10-17 22:23:08 +02:00
parent f9d19d9b79
commit 9020f0b300
5 changed files with 40 additions and 7 deletions

View File

@ -3,6 +3,9 @@ import { connect } from 'react-redux';
import { Input, Switch, Button } from 'react-toolbox'; import { Input, Switch, Button } from 'react-toolbox';
import { createFeatureToggles } from '../../store/feature-actions'; import { createFeatureToggles } from '../../store/feature-actions';
const mapStateToProps = (state) => ({
strategies: state.strategies.toJS(),
});
class AddFeatureToggle extends React.Component { class AddFeatureToggle extends React.Component {
constructor () { constructor () {
@ -23,6 +26,7 @@ class AddFeatureToggle extends React.Component {
static propTypes () { static propTypes () {
return { return {
dispatch: PropTypes.func.isRequired, dispatch: PropTypes.func.isRequired,
strategies: PropTypes.array,
}; };
} }
@ -51,7 +55,12 @@ class AddFeatureToggle extends React.Component {
renderAddStrategy () { renderAddStrategy () {
if (this.state.showAddStrategy) { if (this.state.showAddStrategy) {
return <h4>Adding strat</h4>; return (
<div>
<h4>Adding strat</h4>
<p>Possible: {this.props.strategies.map(s => s.name).join(', ')}</p>
</div>
);
} else { } else {
return <a onClick={this.addStrategy} href="#addStrategy">Add strategy..</a>; return <a onClick={this.addStrategy} href="#addStrategy">Add strategy..</a>;
} }
@ -101,4 +110,4 @@ class AddFeatureToggle extends React.Component {
} }
} }
export default connect()(AddFeatureToggle); export default connect(mapStateToProps)(AddFeatureToggle);

View File

@ -4,6 +4,7 @@ import FeatureList from './FeatureList';
const mapStateToProps = (state) => ({ const mapStateToProps = (state) => ({
features: state.features.toJS(), features: state.features.toJS(),
strategies: state.strategies.toJS(),
}); });
const mapDispatchToProps = { const mapDispatchToProps = {

View File

@ -1,4 +1,4 @@
import { List, Map } from 'immutable'; import { List, Map as $Map } from 'immutable';
import { import {
@ -11,17 +11,17 @@ import {
const features = (state = new List([]), action) => { const features = (state = new List([]), action) => {
switch (action.type) { switch (action.type) {
case ADD_FEATURE_TOGGLE: case ADD_FEATURE_TOGGLE:
return state.push(new Map(action.featureToggle)); return state.push(new $Map(action.featureToggle));
case UPDATE_FEATURE_TOGGLE: case UPDATE_FEATURE_TOGGLE:
return state.map(t => { return state.$Map(t => {
if (t.get('name') === action.featureToggle.name) { if (t.get('name') === action.featureToggle.name) {
return new Map(action.featureToggle); return new $Map(action.featureToggle);
} else { } else {
return t; return t;
} }
}); });
case RECEIVE_FEATURE_TOGGLES: case RECEIVE_FEATURE_TOGGLES:
return new List(action.featureToggles.map(t => new Map(t))); return new List(action.featureToggles.$Map(t => new $Map(t)));
default: default:
return state; return state;
} }

View File

@ -1,8 +1,10 @@
import { combineReducers } from 'redux'; import { combineReducers } from 'redux';
import features from './feature-store'; import features from './feature-store';
import strategies from './strategy-store';
const unleashStore = combineReducers({ const unleashStore = combineReducers({
features, features,
strategies,
}); });
export default unleashStore; export default unleashStore;

View File

@ -0,0 +1,21 @@
import { List, Map as $Map } from 'immutable';
const init = new List([
new $Map({ name: 'default', description: 'Default on/off strategy' }),
new $Map(
{
name: 'ActiveForUserWithEmail',
description: 'Active for user with specified email',
parametersTemplate: { emails: 'string' },
}),
]);
const strategies = (state = init, action) => {
switch (action.type) {
default:
return state;
}
};
export default strategies;