-
Notifications
You must be signed in to change notification settings - Fork 30
/
Copy pathSimpleDropdownTask.js
41 lines (34 loc) · 1.21 KB
/
SimpleDropdownTask.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
import cuid from 'cuid'
import { types } from 'mobx-state-tree'
import { legacyDropdownAdapter } from './helpers'
import Task from '../../models/Task'
import SimpleDropdownAnnotation from './SimpleDropdownAnnotation'
// TODO: should we make question/instruction consistent between task types?
// What should be it called? I think we should use 'instruction'
const MIN_OPTIONS = 4
const MAX_OPTIONS = 20
const MenuOptions = types.refinement('MenuOptions',
types.array(types.string),
value => value.length >= MIN_OPTIONS && value.length <= MAX_OPTIONS
)
const SimpleDropdown = types.model('SimpleDropdown', {
allowCreate: types.optional(types.boolean, false),
annotation: types.safeReference(SimpleDropdownAnnotation),
options: MenuOptions,
type: types.literal('dropdown-simple'),
})
.preProcessSnapshot(snapshot => {
return legacyDropdownAdapter(snapshot)
})
.views(self => ({
defaultAnnotation (id = cuid()) {
return SimpleDropdownAnnotation.create({
id,
task: self.taskKey,
taskType: self.type
})
}
}))
const SimpleDropdownTask = types.compose('SimpleDropdownTask', Task, SimpleDropdown)
export default SimpleDropdownTask
export { MIN_OPTIONS, MAX_OPTIONS }