Newer
Older
import React from 'react'
import { withStyles } from '@material-ui/core/styles'
import Button from '@src/js/components/common/form/Button.jsx'
import Dialog from '@src/js/components/common/dialog/Dialog.jsx'
import messages from '@src/js/common/messages.js'
import logger from '@src/js/common/logger.js'
import { DialogContentText } from '@material-ui/core'
import autoBind from 'auto-bind'
import ItemIcon from '@src/js/components/database/data-browser/ItemIcon.jsx'
import Grid from '@src/js/components/common/grid/Grid.jsx'
import DataBrowserController from '@src/js/components/database/data-browser/DataBrowserController.js'
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
const styles = theme => ({
button: {
marginLeft: theme.spacing(1)
},
icon: {
fontSize: '2rem',
paddingRight: '0.5rem'
},
grid: {
flexGrow: 1,
flex: 1,
height: 'auto',
overflowY: 'auto',
paddingTop: 0,
paddingBottom: 0
},
nameCell: {
display: 'flex',
alignItems: 'center',
'&>span': {
flex: 1,
whiteSpace: 'nowrap',
overflow: 'hidden',
textOverflow: 'ellipsis'
}
},
})
class LocationDialog extends React.Component {
constructor(props) {
super(props)
autoBind(this)
const { path, sessionToken, datastoreServer} = this.props
this.controller = new DataBrowserController()
this.controller.attach(this)
this.datastoreServer = datastoreServer
this.controller.setSessionToken(sessionToken)
// this.state = {
// path
// }
this.controller.setPath(path)
this.handleClose = this.handleClose.bind(this)
}
handleClose() {
const { onCancel } = this.props
if (onCancel) {
onCancel()
}
}
updateValue(event) {
const path = event.target.value
// this.setState({
// path
// })
this.controller.setPath(path)
}
handleConfirmClick() {
const { onConfirm } = this.props
const { path } = this.state
onConfirm(path)
//
// if (!this.props.path) {
// this.clearLocation()
// }
}
handleCancelClick() {
const { onCancel } = this.props
onCancel()
// if (!this.props.path) {
// this.clearLocation()
// }
// clearLocation() {
// this.setState({
// path: ''
// })
// }
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
async setPath(path) {
if (this.state.path !== path + '/') {
this.setState({ path: path + '/' })
this.controller.setPath(path + '/')
await this.controller.gridController.load()
}
}
async handleRowDoubleClick(row) {
const { directory, path } = row.data
if (directory) {
await this.setPath(path)
}
}
async onError(error) {
await AppController.getInstance().errorChange(error)
}
renderButtons() {
const { classes } = this.props
return (
<div>
<Button
name='confirm'
label={messages.get(messages.CONFIRM)}
type={this.getButtonType()}
styles={{ root: classes.button }}
onClick={this.handleConfirmClick}
/>
<Button
name='cancel'
label={messages.get(messages.CANCEL)}
styles={{ root: classes.button }}
onClick={this.handleCancelClick}
/>
</div>
)
}
renderGrid() {
const { classes } = this.props
return (
<Grid
id='location-grid'
key='location-grid'
controllerRef={this.handleGridControllerRef}
filterModes={[]}
header='Folders'
classes={{ container: classes.grid }}
columns={[
{
name: 'name',
label: 'Name',
sortable: true,
getValue: ({ row }) => row.name,
renderValue: ({ row }) => (
<div className={classes.nameCell}>
<ItemIcon
file={row}
classes={{ icon: classes.icon }}
/>
<span>{row.name}</span>
</div>
),
renderFilter: null
}
]}
loadRows={this.controller.loadFolders}
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
exportable={false}
selectable={false}
multiselectable={false}
loadSettings={null}
onSettingsChange={null}
onError={this.onError}
onRowDoubleClick={this.handleRowDoubleClick}
exportXLS={null}
/>
)
}
getMessageType() {
const type = this.getType()
if (type === 'warning') {
return 'warning'
} else if (type === 'info') {
return 'info'
} else {
throw new Error('Unsupported type: ' + type)
}
}
getButtonType() {
const type = this.getType()
if (type === 'warning') {
return 'risky'
} else if (type === 'info') {
return null
} else {
throw new Error('Unsupported type: ' + type)
}
}
getType() {
return this.props.type || 'warning'
}
render() {
logger.log(logger.DEBUG, 'LocationDialog.render')
const { open, title, content } = this.props
return (
<Dialog
open={open}
onClose={this.handleClose}
title={title}
content={[<DialogContentText key='dialog-content'>{content}</DialogContentText>,
this.renderGrid()]}
actions={this.renderButtons()}
/>
)
}
}
export default withStyles(styles)(LocationDialog)