-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathworkflowView.js
102 lines (93 loc) · 2.91 KB
/
workflowView.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
import React, { Component, PropTypes } from 'react';
import { DragDropContext as dragDropContext } from 'react-dnd';
import HTML5Backend from 'react-dnd-html5-backend';
import List from './List/List';
import update from 'react/lib/update';
import { Button } from 'cf-component-button';
class WorkflowView extends Component {
constructor(props) {
super(props);
this.state = {
lists: props.webhookFlows
};
this.addFlow = this.addFlow.bind(this);
this.addCard = this.addCard.bind(this);
this.moveList = this.moveList.bind(this);
this.moveCard = this.moveCard.bind(this);
this.updateWorkflow = this.updateWorkflow.bind(this);
}
addFlow() {
const { actions } = this.props;
actions.webhookFlowCreate();
}
addCard() {
const { actions } = this.props;
actions.webhookCardCreate();
}
updateWorkflow() {
const { actions, webhook } = this.props;
actions.workflowUpdate(webhook.id, this.state.lists)
.then(() => {});
}
moveCard(item, target) {
const dragItem = this.state.lists[item.list].cardIds[item.index];
const remove = { lists: {} };
const insert = { lists: {} };
remove.lists[item.list] = { cardIds: { $splice: [[item.index, 1]] } };
insert.lists[target.list] = { cardIds: { $splice: [[target.index, 0, dragItem]] } };
this.setState(update(update(this.state, remove), insert));
item.index = target.index; // eslint-disable-line
item.list = target.list; // eslint-disable-line
}
moveList(list, target) {
const dragItem = this.state.lists[list.index];
this.setState(update(this.state, {
lists: {
$splice: [
[list.index, 1],
[target.index, 0, dragItem],
],
},
}));
list.index = target.index; // eslint-disable-line
}
render() {
const { lists } = this.state;
return (
<div className="workflow">
<div className="toolbar">
<Button type="primary" onClick={this.addFlow}>
Add Flow
</Button>
<Button type="primary" onClick={this.addCard}>
Add Card
</Button>
</div>
<div>
<div className="list-container">
{lists.map((list, index) => (
<List
index={index}
lists={list.cardIds}
moveList={this.moveList}
moveCard={this.moveCard}
key={list.id}
webhookCards={this.props.webhookCards}
listId={list.id}
name={list.name}
updateWorkflow={this.updateWorkflow}
/>
))}
</div>
</div>
</div>
);
}
}
WorkflowView.propTypes = {
actions: PropTypes.object.isRequired,
webhook: PropTypes.object.isRequired,
webhookFlows: PropTypes.array.isRequired,
webhookCards: PropTypes.array.isRequired
};
export default dragDropContext(HTML5Backend)(WorkflowView);