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
|
import { h, Component } from 'preact'
import { bindActionCreators } from 'redux'
import { connect } from 'react-redux'
import util from '../util'
import actions from '../actions'
import { FileList, FileRow } from '../common/fileList.component'
import Loading from '../common/loading.component'
const fieldSet = util.fieldSet(new Set(['input', 'status', 'checkpoint', 'output']))
class DatasetComponent extends Component {
render(){
let { loading, progress, fields, module, data, folder, match, history } = this.props
if (loading) {
return <Loading progress={progress} />
}
if (!data.folders.length) {
console.log('no folders, redirect to /new')
return history.push('/' + module.name + '/new/')
}
if (!folder || !folder.name) return
fields = fieldSet(fields)
return (
<div class='rows params datasets'>
<div class='row row-heading dataset'>
{fields.has('input') &&
<div class='col'>input</div>
}
{fields.has('status') &&
<div class='col'>status</div>
}
{fields.has('checkpoint') &&
<div class='col'>checkpoint</div>
}
{fields.has('output') &&
<div class='col'>output</div>
}
</div>
{this.renderGroups()}
</div>
)
}
renderGroups(){
let { module, data, folder, fields, runner, onPickDataset, onPickFile, datasetActions } = this.props
fields = fieldSet(fields)
const { datasetLookup, fileLookup } = data
const { mapFn, sortFn } = util.sort.orderByFn('date desc')
const moduleOnCPU = runner && runner.cpu.task && runner.cpu.task.module === module.name
const moduleOnGPU = runner && runner.gpu.task && runner.gpu.task.module === module.name
const datasets = folder.datasets.map(name => datasetLookup[name]).map(mapFn).sort(sortFn).map(pair => {
const dataset = pair[1]
let status = ''
let isProcessing = false, isFetching = false
if (moduleOnGPU && runner.gpu.task.dataset === dataset) {
status = util.gerund(runner.gpu.task.activity)
isProcessing = true
} else if (moduleOnCPU && runner.cpu.task.activity === 'fetch' && runner.cpu.task.opt.file_id === dataset.input[0]) {
isProcessing = true
isFetching = true
}
return (
<div key={dataset.name} className='row dataset' onClick={() => onPickDataset && onPickDataset(dataset)}>
{this.props.beforeRow && this.props.beforeRow(dataset)}
{fields.has('input') &&
<div className='col'>
{!!dataset.input.length &&
<FileList
files={dataset.input.map(id => fileLookup[id])}
className='input_files'
fileListClassName=''
rowClassName='input_file'
fields={'name date size delete'}
onClick={onPickFile}
onDelete={(file) => this.onDeleteFile(file)}
/>
}
</div>
}
{fields.has('status') &&
<div className={[
'col', 'quiet',
(dataset.isBuilt ? 'built' : 'not_built'),
(isProcessing ? 'processing': 'not_processing')
].join(' ')}>
{this.props.datasetActions && this.props.datasetActions(dataset, isFetching, isProcessing)}
{status}
</div>
}
{fields.has('checkpoint') &&
<div className='col checkpoint'>
{!!dataset.checkpoints.length &&
<FileRow
file={dataset.checkpoints[0]}
fields={'name date epoch'}
className='row checkpoint'
/>
}
</div>
}
{fields.has('output') &&
<div className='col'>
{!!dataset.output.length &&
<FileList
files={dataset.output.map(id => fileLookup[id])}
orderBy='epoch desc'
fields={'name date epoch size'}
onClick={onPickFile}
onDelete={(file) => this.onDeleteFile(file)}
/>
}
</div>
}
{this.props.afterRow && this.props.afterRow(dataset)}
</div>
)
})
return datasets
}
onDeleteFile(file){
const yes = confirm('Are you sure you want to delete this file?')
if (yes) {
console.log('delete: confirmed')
if (this.props.onDeleteFile) {
console.log('calling custom deletefile function')
this.props.onDeleteFile(file)
} else {
actions.file.destroy(file)
}
}
}
}
const mapStateToProps = state => ({
runner: state.system.runner,
})
const mapDispatchToProps = (dispatch, ownProps) => ({
})
export default connect(mapStateToProps, mapDispatchToProps)(DatasetComponent)
|