mirror of
https://github.com/Unleash/unleash.git
synced 2025-01-01 00:08:27 +01:00
minor cleanup
This commit is contained in:
parent
616da25d1b
commit
d3090c123d
@ -1,7 +1,7 @@
|
|||||||
import React, { PropTypes } from 'react';
|
import React, { PropTypes } from 'react';
|
||||||
import { connect } from 'react-redux';
|
import { connect } from 'react-redux';
|
||||||
import { Input, Switch, Button } from 'react-toolbox';
|
import { Input, Switch, Button } from 'react-toolbox';
|
||||||
import { createFeatureToggles } from '../../store/featureToggleActions';
|
import { createFeatureToggles } from '../../store/feature-actions';
|
||||||
|
|
||||||
|
|
||||||
class AddFeatureToggle extends React.Component {
|
class AddFeatureToggle extends React.Component {
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
import { connect } from 'react-redux';
|
import { connect } from 'react-redux';
|
||||||
import { toggleFeature, fetchFeatureToggles } from '../../store/featureToggleActions';
|
import { toggleFeature, fetchFeatureToggles } from '../../store/feature-actions';
|
||||||
import FeatureList from './FeatureList';
|
import FeatureList from './FeatureList';
|
||||||
|
|
||||||
const mapStateToProps = (state) => ({
|
const mapStateToProps = (state) => ({
|
||||||
|
@ -1,10 +1,11 @@
|
|||||||
import { urls } from './urls';
|
import api from './feature-api';
|
||||||
|
|
||||||
export const ADD_FEATURE_TOGGLE = 'ADD_FEATURE_TOGGLE';
|
export const ADD_FEATURE_TOGGLE = 'ADD_FEATURE_TOGGLE';
|
||||||
export const UPDATE_FEATURE_TOGGLE = 'UPDATE_FEATURE_TOGGLE';
|
export const UPDATE_FEATURE_TOGGLE = 'UPDATE_FEATURE_TOGGLE';
|
||||||
export const TOGGLE_FEATURE_TOGGLE = 'TOGGLE_FEATURE_TOGGLE';
|
export const TOGGLE_FEATURE_TOGGLE = 'TOGGLE_FEATURE_TOGGLE';
|
||||||
export const REQUEST_FEATURE_TOGGLES = 'REQUEST_FEATURE_TOGGLES';
|
export const REQUEST_FEATURE_TOGGLES = 'REQUEST_FEATURE_TOGGLES';
|
||||||
export const REQUEST_UPDATE_FEATURE_TOGGLES = 'REQUEST_UPDATE_FEATURE_TOGGLES';
|
export const START_UPDATE_FEATURE_TOGGLE = 'START_UPDATE_FEATURE_TOGGLE';
|
||||||
|
export const START_CREATE_FEATURE_TOGGLE = 'START_CREATE_FEATURE_TOGGLE';
|
||||||
export const RECEIVE_FEATURE_TOGGLES = 'RECEIVE_FEATURE_TOGGLES';
|
export const RECEIVE_FEATURE_TOGGLES = 'RECEIVE_FEATURE_TOGGLES';
|
||||||
export const ERROR_RECEIVE_FEATURE_TOGGLES = 'ERROR_RECEIVE_FEATURE_TOGGLES';
|
export const ERROR_RECEIVE_FEATURE_TOGGLES = 'ERROR_RECEIVE_FEATURE_TOGGLES';
|
||||||
export const ERROR_CREATING_FEATURE_TOGGLE = 'ERROR_CREATING_FEATURE_TOGGLE';
|
export const ERROR_CREATING_FEATURE_TOGGLE = 'ERROR_CREATING_FEATURE_TOGGLE';
|
||||||
@ -62,9 +63,15 @@ function receiveFeatureToggles (json) {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
function requestUpdateFeatureToggles () {
|
function startUpdateFeatureToggle () {
|
||||||
return {
|
return {
|
||||||
type: REQUEST_UPDATE_FEATURE_TOGGLES,
|
type: START_UPDATE_FEATURE_TOGGLE,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
function startCreateFeatureToggle () {
|
||||||
|
return {
|
||||||
|
type: START_CREATE_FEATURE_TOGGLE,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -79,63 +86,30 @@ function errorReceiveFeatureToggles (statusCode) {
|
|||||||
export function fetchFeatureToggles () {
|
export function fetchFeatureToggles () {
|
||||||
return dispatch => {
|
return dispatch => {
|
||||||
dispatch(requestFeatureToggles());
|
dispatch(requestFeatureToggles());
|
||||||
return fetch(urls.features)
|
|
||||||
.then(response => {
|
return api.fetchAll()
|
||||||
if (response.ok) {
|
|
||||||
return response.json();
|
|
||||||
} else {
|
|
||||||
let error = new Error('failed fetching');
|
|
||||||
error.status = response.status;
|
|
||||||
throw error;
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.then(json => dispatch(receiveFeatureToggles(json)))
|
.then(json => dispatch(receiveFeatureToggles(json)))
|
||||||
.catch(error => dispatch(errorReceiveFeatureToggles(error)));
|
.catch(error => dispatch(errorReceiveFeatureToggles(error)));
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
const headers = {
|
|
||||||
'Accept': 'application/json',
|
|
||||||
'Content-Type': 'application/json',
|
|
||||||
};
|
|
||||||
|
|
||||||
export function createFeatureToggles (featureToggle) {
|
export function createFeatureToggles (featureToggle) {
|
||||||
return dispatch => {
|
return dispatch => {
|
||||||
dispatch(requestUpdateFeatureToggles());
|
dispatch(startCreateFeatureToggle());
|
||||||
return fetch(urls.features, {
|
|
||||||
method: 'POST',
|
return api.create(featureToggle)
|
||||||
headers,
|
.then(() => dispatch(addFeatureToggle(featureToggle)))
|
||||||
body: JSON.stringify(featureToggle),
|
.catch(error => dispatch(errorCreatingFeatureToggle(error)));
|
||||||
})
|
|
||||||
.then(response => {
|
|
||||||
if (!response.ok) {
|
|
||||||
let error = new Error('failed fetching');
|
|
||||||
error.status = response.status;
|
|
||||||
throw error;
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.then(() => dispatch(addFeatureToggle(featureToggle)))
|
|
||||||
.catch(error => dispatch(errorCreatingFeatureToggle(error)));
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
export function requestUpdateFeatureToggle (featureToggle) {
|
export function requestUpdateFeatureToggle (featureToggle) {
|
||||||
return dispatch => {
|
return dispatch => {
|
||||||
dispatch(requestUpdateFeatureToggles());
|
dispatch(startUpdateFeatureToggle());
|
||||||
return fetch(`${urls.features}/${featureToggle.name}`, {
|
|
||||||
method: 'PUT',
|
return api.update(featureToggle)
|
||||||
headers,
|
.then(() => dispatch(updateFeatureToggle(featureToggle)))
|
||||||
body: JSON.stringify(featureToggle),
|
.catch(error => dispatch(errorUpdatingFeatureToggle(error)));
|
||||||
})
|
|
||||||
.then(response => {
|
|
||||||
if (!response.ok) {
|
|
||||||
let error = new Error('failed fetching');
|
|
||||||
error.status = response.status;
|
|
||||||
throw error;
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.then(() => dispatch(updateFeatureToggle(featureToggle)))
|
|
||||||
.catch(error => dispatch(errorUpdatingFeatureToggle(error)));
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
43
packages/unleash-frontend-next/src/store/feature-api.js
Normal file
43
packages/unleash-frontend-next/src/store/feature-api.js
Normal file
@ -0,0 +1,43 @@
|
|||||||
|
const URI = '/features';
|
||||||
|
|
||||||
|
const headers = {
|
||||||
|
'Accept': 'application/json',
|
||||||
|
'Content-Type': 'application/json',
|
||||||
|
};
|
||||||
|
|
||||||
|
function throwIfNotSuccess (response) {
|
||||||
|
if (!response.ok) {
|
||||||
|
let error = new Error('API call failed');
|
||||||
|
error.status = response.status;
|
||||||
|
throw error;
|
||||||
|
}
|
||||||
|
return response;
|
||||||
|
}
|
||||||
|
|
||||||
|
function fetchAll () {
|
||||||
|
return fetch(URI)
|
||||||
|
.then(throwIfNotSuccess)
|
||||||
|
.then(response => response.json());
|
||||||
|
}
|
||||||
|
|
||||||
|
function create (featureToggle) {
|
||||||
|
return fetch(URI, {
|
||||||
|
method: 'POST',
|
||||||
|
headers,
|
||||||
|
body: JSON.stringify(featureToggle),
|
||||||
|
}).then(throwIfNotSuccess);
|
||||||
|
}
|
||||||
|
|
||||||
|
function update (featureToggle) {
|
||||||
|
return fetch(`${URI}/${featureToggle.name}`, {
|
||||||
|
method: 'PUT',
|
||||||
|
headers,
|
||||||
|
body: JSON.stringify(featureToggle),
|
||||||
|
}).then(throwIfNotSuccess);
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
fetchAll,
|
||||||
|
create,
|
||||||
|
update,
|
||||||
|
};
|
@ -2,7 +2,7 @@ import {
|
|||||||
ADD_FEATURE_TOGGLE,
|
ADD_FEATURE_TOGGLE,
|
||||||
RECEIVE_FEATURE_TOGGLES,
|
RECEIVE_FEATURE_TOGGLES,
|
||||||
UPDATE_FEATURE_TOGGLE,
|
UPDATE_FEATURE_TOGGLE,
|
||||||
} from './featureToggleActions';
|
} from './feature-actions';
|
||||||
|
|
||||||
const feature = (state = {}, action) => {
|
const feature = (state = {}, action) => {
|
||||||
switch (action.type) {
|
switch (action.type) {
|
||||||
|
Loading…
Reference in New Issue
Block a user