-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathStoryList.js
More file actions
186 lines (166 loc) · 6.33 KB
/
Copy pathStoryList.js
File metadata and controls
186 lines (166 loc) · 6.33 KB
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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
import { connect } from "react-redux";
import React, { Component } from "react";
import { bindActionCreators } from 'redux';
import UtterIcon from '../icons/UtterIcon';
import { message } from "../utils/messages";
import IntentIcon from '../icons/IntentIcon';
import CheckpointIcon from '../icons/CheckpointIcon';
import { Grid, Card } from '@material-ui/core';
import DeleteIcon from '@material-ui/icons/Delete';
import IconButton from '@material-ui/core/IconButton';
import Typography from '@material-ui/core/Typography';
import SnackbarDelete from '../components/DeleteSnackbar';
import { Creators as StoryAction } from "../ducks/stories";
import { DragDropContext, Droppable, Draggable } from "react-beautiful-dnd";
const styles = {
intent_icon: {
fill: '#4b3953',
},
utter_icon: {
fill: '#f26a53',
},
card_intent: {
border: '1px solid #4b3953',
color: '#4b3953',
boxShadow: 'none',
padding: "12px 12px 6px",
},
card_utter: {
border: '1px solid #f26a53',
color: '#f26a53',
marginLeft: '24px',
boxShadow: 'none',
padding: "12px 12px 6px",
}
}
const grid = 8;
const getItemStyle = (isDragging, draggableStyle) => ({
userSelect: "none",
padding: grid * 2,
margin: `0 0 ${grid}px 0`,
display: 'flex',
background: 'white',
...draggableStyle
});
const getUtterStyle = (isDragging, draggableStyle) => ({
...getItemStyle(isDragging, draggableStyle),
...styles.card_utter
})
const getIntentStyle = (isDragging, draggableStyle) => ({
...getItemStyle(isDragging, draggableStyle),
...styles.card_intent
})
const getListStyle = isDraggingOver => ({
background: isDraggingOver ? "#f6f9f9" : "white",
padding: grid,
width: "420px",
});
class StoryList extends Component {
constructor(props) {
super(props);
this.onDragEnd = this.onDragEnd.bind(this);
this.state = {
undo_delete: false
}
this.handleSnackbarClick = this.handleSnackbarClick.bind(this)
}
getIcon(type) {
if(type === "intent")
return <IntentIcon style={styles.intent_icon} />
else if (type === "utter")
return <UtterIcon style={styles.utter_icon} />
else
return <CheckpointIcon style={styles.utter_icon} />
}
onDragEnd(result) {
if (!result.destination) {
return;
}
this.props.reorderContent(result.source.index, result.destination.index)
}
getDrag(provided, snapshot) {
return (
<div
{...provided.droppableProps}
ref={provided.innerRef}
style={getListStyle(snapshot.isDraggingOver)}
>
{this.props.content.map((item, content_position) => (
<Draggable key={'list_' + content_position} draggableId={'item' + content_position} index={content_position}>
{(provided, snapshot) => (
<div key={"card_" + item.id}
ref={provided.innerRef}
{...provided.draggableProps}
{...provided.dragHandleProps}
>
<Grid container spacing={2}>
<Grid item xs={11}>
<Card style={item.type === "intent" ?
getIntentStyle(
provided.draggableProps.style,
) : getUtterStyle(
provided.draggableProps.style,
)}
>
<Grid container>
<Grid item xs={1}>
{this.getIcon(item.type)}
</Grid>
<Grid item xs={11}>
<Typography varant="body1" noWrap>{item.name}</Typography>
</Grid>
</Grid>
</Card>
</Grid>
<Grid item xs={1}>
<IconButton color="primary" m={0}
onClick={() => this.handleDelete(content_position)}>
<DeleteIcon style={{ opacity: 0.5 }} />
</IconButton>
</Grid>
</Grid>
</div>
)}
</Draggable>
))}
</div>
)
}
getContent() {
if (this.props.content.length !== 0) {
return (
<div>
<DragDropContext onDragEnd={this.onDragEnd}>
<Droppable droppableId="droppable">
{(provided, snapshot) => this.getDrag(provided, snapshot)}
</Droppable>
</DragDropContext>
</div>
)
} else {
return <div style={{padding:'24px'}}><Typography variant="body1">{message.no_dialogs}</Typography></div>
}
}
handleSnackbarClick(value) {
this.setState({ undo_delete: value });
}
handleDelete(content_position) {
this.handleSnackbarClick(true);
this.props.deleteContent(content_position);
}
render() {
return (
<div>
{this.getContent()}
<SnackbarDelete
handleSnackbarClick={this.handleSnackbarClick}
handleUndo={this.props.undoDeleteContent}
undo={this.state.undo_delete}
/>
</div>
);
}
}
const mapStateToProps = state => { return { ...state.story } };
const mapDispatchToProps = dispatch => bindActionCreators(StoryAction, dispatch);
export default connect(mapStateToProps, mapDispatchToProps)(StoryList);