Skip to content

Commit

Permalink
Merge pull request #344 from we3x/feature/add-service
Browse files Browse the repository at this point in the history
Feature/add service
  • Loading branch information
mekanix authored Jul 23, 2016
2 parents 9cac6d2 + 7816195 commit 75c6f57
Show file tree
Hide file tree
Showing 7 changed files with 90 additions and 1 deletion.
51 changes: 51 additions & 0 deletions src/components/molecules/dragable-service/actions/add.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import { createAction } from 'redux-actions';
import { fetch } from '../../../../utils';
import { API_URL } from '../../../../backend_url';
import { ADD_SERVICE } from '../constants';

export const reset = createAction(ADD_SERVICE, () => ({
status: 'initial',
}));

export const begin = createAction(ADD_SERVICE, () => ({
status: 'pending',
}));

export const success = createAction(ADD_SERVICE, service => ({
service,
status: 'success',
}));

export const fail = createAction(ADD_SERVICE, error => ({
status: 'error',
error,
}));

export const add = (clusterId, itemId) =>
dispatch => {
dispatch(begin());
fetch({
url: `${API_URL}/clusters/${clusterId}/services`,
method: 'POST',
body: {
service_id: itemId,
},
})
.then(cluster => {
dispatch(success(cluster));
return cluster;
})
.catch(error => {
dispatch(fail(error.message));
});
};

const actions = {
reset,
begin,
success,
fail,
add,
};

export default actions;
1 change: 1 addition & 0 deletions src/components/molecules/dragable-service/constants.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export const ADD_SERVICE = 'ADD_SERVICE';
3 changes: 2 additions & 1 deletion src/components/molecules/dragable-service/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import React from 'react';
import { DragSource } from 'react-dnd';
import ItemTypes from './item-types';
import store from '../../../store';
import actions from './actions/add';


const serviceSource = {
Expand All @@ -16,7 +17,7 @@ const serviceSource = {
const dropResult = monitor.getDropResult();
const cluster = store.getState().clusterDetail.cluster;
if (dropResult) {
console.log(`You dropped ${item.id} into ${dropResult.name} with id ${cluster.id}!`);
store.dispatch(actions.add(cluster.id, item.id));
}
},
};
Expand Down
13 changes: 13 additions & 0 deletions src/components/molecules/dragable-service/reducers/add.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { ADD_SERVICE } from '../constants';

export default function applicationList(
state = { status: 'initial' },
action
) {
switch (action.type) {
case ADD_SERVICE:
return action.payload;
default:
return state;
}
}
9 changes: 9 additions & 0 deletions src/components/molecules/dragable-service/reducers/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import addService from './add';


const reducers = [
addService,
];


export default reducers;
8 changes: 8 additions & 0 deletions src/components/pages/cluster/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import ServiceProvision from '../service-provision';
import Add from '../../atoms/add';
import Sidebar from '../../atoms/sidebar';
import AllServices from '../../organisms/service-list';
import addService from '../../molecules/dragable-service/actions/add';


const mapStateToProps = (state) => {
Expand All @@ -36,6 +37,7 @@ const mapStateToProps = (state) => {
providerRemoveStatus: state.providerRemove.status,
serviceRemove: state.clusterServiceRemove.service,
serviceRemoveStatus: state.clusterServiceRemove.status,
/* addServiceStatus: state.addService.status,*/
};
if (state.clusterEdit.cluster) {
data.cluster = state.clusterEdit.cluster;
Expand All @@ -56,6 +58,7 @@ const ClusterDetail = React.createClass({
providerRemoveStatus: React.PropTypes.string,
serviceRemove: React.PropTypes.object,
serviceRemoveStatus: React.PropTypes.string,
addServiceStatus: React.PropTypes.string,
},

getDefaultProps() {
Expand All @@ -77,6 +80,7 @@ const ClusterDetail = React.createClass({
},

componentWillMount() {
console.log(store.getState());
store.dispatch(actions.get(this.props.params.clusterId));
store.dispatch(pluginActions.get());
},
Expand All @@ -92,6 +96,10 @@ const ClusterDetail = React.createClass({
} else if (nextProps.serviceRemoveStatus === 'success') {
store.dispatch(actions.get(this.props.params.clusterId));
store.dispatch(serviceActionsRemove.reset());
} else if (nextProps.addServiceStatus === 'success') {
store.dispatch(actions.get(this.props.params.clusterId));
store.dispatch(addService.reset());
console.log('here');
}
},

Expand Down
6 changes: 6 additions & 0 deletions src/reducers.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import service from './components/pages/service/reducers';
import serviceList from './components/pages/service-list/reducers';
import serviceProvision from './components/pages/service-provision/reducers';
import clusterServiceRemove from './components/organisms/cluster-service-list/reducers';
import addService from './components/molecules/dragable-service/reducers';


const reducers = {
Expand Down Expand Up @@ -73,6 +74,11 @@ application.map(reducer => {
return undefined;
});

addService.map(reducer => {
reducers[reducer.name] = reducer;
return undefined;
});


const rootReducer = combineReducers(reducers);

Expand Down

0 comments on commit 75c6f57

Please sign in to comment.