1
1
import React from 'react' ;
2
2
import { Link } from 'react-router' ;
3
3
import { DropTarget } from 'react-dnd' ;
4
+ import { connect as reduxConnect } from 'react-redux' ;
5
+ import store from '../../../store' ;
4
6
import Service from '../../molecules/service' ;
5
7
import List from '../../molecules/transition-appear' ;
8
+ import actions from '../../molecules/dragable-service/actions/add' ;
6
9
import removeActions from './actions/remove' ;
7
10
import ItemTypes from '../../molecules/dragable-service/item-types' ;
8
11
@@ -16,9 +19,15 @@ const clusterTarget = {
16
19
} ;
17
20
18
21
22
+ const mapStateToProps = ( state ) => ( {
23
+ addService : state . clusterServiceAdd . service ,
24
+ } ) ;
25
+
26
+
19
27
const ClusterServiceList = React . createClass ( {
20
28
propTypes : {
21
29
services : React . PropTypes . array ,
30
+ addService : React . PropTypes . object ,
22
31
children : React . PropTypes . node ,
23
32
clusterId : React . PropTypes . string . isRequired ,
24
33
connectDropTarget : React . PropTypes . func . isRequired ,
@@ -32,9 +41,28 @@ const ClusterServiceList = React.createClass({
32
41
} ;
33
42
} ,
34
43
44
+ getInitialState ( ) {
45
+ return {
46
+ services : [ ] ,
47
+ } ;
48
+ } ,
49
+
50
+ componentWillReceiveProps ( nextProps ) {
51
+ const services = nextProps . services ;
52
+ if ( nextProps . addService ) {
53
+ services . push ( nextProps . addService ) ;
54
+ }
55
+ if ( services !== this . state . services ) {
56
+ this . setState ( { services } ) ;
57
+ }
58
+ if ( nextProps . addService ) {
59
+ store . dispatch ( actions . reset ( ) ) ;
60
+ }
61
+ } ,
62
+
35
63
render ( ) {
36
64
const clusterUrl = `clusters/${ this . props . clusterId } ` ;
37
- const serviceContent = this . props . services . map ( service => {
65
+ const serviceContent = this . state . services . map ( service => {
38
66
const url = `${ clusterUrl } /services/${ service . id } /provision` ;
39
67
const iconId = `${ clusterUrl } /services/${ service . id } ` ;
40
68
return (
@@ -47,7 +75,7 @@ const ClusterServiceList = React.createClass({
47
75
</ Link >
48
76
) ;
49
77
} ) ;
50
- const content = this . props . services ? serviceContent : this . props . children ;
78
+ const content = this . state . services ? serviceContent : this . props . children ;
51
79
const { canDrop, isOver, connectDropTarget } = this . props ;
52
80
const isActive = canDrop && isOver ;
53
81
@@ -73,9 +101,13 @@ const ClusterServiceList = React.createClass({
73
101
74
102
75
103
/* eslint-disable new-cap */
76
- export default DropTarget ( ItemTypes . SERVICE , clusterTarget , ( connect , monitor ) => ( {
104
+ const ClusterServiceDNDList = DropTarget ( ItemTypes . SERVICE , clusterTarget , ( connect , monitor ) => ( {
77
105
/* eslint-enable */
78
106
connectDropTarget : connect . dropTarget ( ) ,
79
107
isOver : monitor . isOver ( ) ,
80
108
canDrop : monitor . canDrop ( ) ,
81
109
} ) ) ( ClusterServiceList ) ;
110
+ const ClusterServiceConnect = reduxConnect ( mapStateToProps , actions ) ( ClusterServiceDNDList ) ;
111
+
112
+
113
+ export default ClusterServiceConnect ;
0 commit comments