-
Notifications
You must be signed in to change notification settings - Fork 51
/
EntryModal.js
190 lines (178 loc) · 5.86 KB
/
EntryModal.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
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
187
188
189
190
import React from 'react'
import { Component } from 'react'
import * as PropTypes from 'prop-types'
import { isEmpty } from 'lodash'
import { EditableText, Icon, LoaderText, Modal } from '../../components'
import { Button } from 'react-bootstrap'
/**
* Popup windows to display a glossary entry
*/
class EntryModal extends Component {
static propTypes = {
entry: PropTypes.object,
show: PropTypes.bool,
isSaving: PropTypes.bool,
canUpdate: PropTypes.bool,
selectedTransLocale: PropTypes.string,
handleResetTerm: PropTypes.func,
handleEntryModalDisplay: PropTypes.func,
handleUpdateTerm: PropTypes.func,
handleTermFieldUpdate: PropTypes.func
}
generateTermInfo = (term) => {
if (term) {
const person = term.lastModifiedBy
const date = term.lastModifiedDate
const isPersonEmpty = isEmpty(person)
const isDateEmpty = isEmpty(date)
if (!isPersonEmpty || !isDateEmpty) {
let parts = ['Last updated']
if (!isPersonEmpty) {
parts.push('by:')
parts.push(person)
}
if (!isDateEmpty) {
parts.push(date)
}
return parts.join(' ')
}
}
return undefined
}
render () {
const {
entry,
canUpdate,
selectedTransLocale,
show,
isSaving,
handleEntryModalDisplay,
handleResetTerm,
handleUpdateTerm,
handleTermFieldUpdate
} = this.props
const transContent = entry.transTerm ? entry.transTerm.content : ''
const transSelected = !!selectedTransLocale
const comment = entry.transTerm ? entry.transTerm.comment : ''
const enableComment = transSelected &&
entry.transTerm && !isEmpty(transContent)
const info = transSelected
? this.generateTermInfo(entry.transTerm)
: this.generateTermInfo(entry.srcTerm)
/* eslint-disable react/jsx-no-bind, react/jsx-boolean-value */
return (
<Modal show={show}
onHide={() => handleEntryModalDisplay(false)}>
<Modal.Header>
<Modal.Title>
Glossary Term
{transSelected
? (<span>
<Icon name='language' className='s1'
parentClassName='iconLanguage-neutral' />
<span className='u-textMuted'>{selectedTransLocale}</span>
</span>)
: (<span>
<Icon name='translate' className='s1'
parentClassName='iconTranslate-neutral' />
<span className='u-textMuted'>{entry.termsCount}</span>
</span>)
}
</Modal.Title>
</Modal.Header>
<Modal.Body>
<div className='modal-section'>
<label className='text-bold'>Term</label>
<EditableText
editable={false}
editing={false}>
{entry.srcTerm.content}
</EditableText>
</div>
<div className='modal-section'>
<label className='text-bold'>Part of speech</label>
<EditableText
editable={!transSelected}
editing
className='textState'
maxLength={255}
placeholder='Add part of speech…'
emptyReadOnlyText='No part of speech'
onChange={(e) => handleTermFieldUpdate('pos', e)}>
{entry.pos}
</EditableText>
</div>
<div className='modal-section'>
<label className='text-bold'>Description</label>
<EditableText
editable={!transSelected}
editing
maxLength={500}
placeholder='Add a description…'
emptyReadOnlyText='No description'
onChange={(e) => handleTermFieldUpdate('description', e)}>
{entry.description}
</EditableText>
</div>
{transSelected ? (
<div className='modal-section'>
<label className='text-bold'>Translation</label>
<EditableText
editable
editing
maxLength={500}
placeholder='Add a translation…'
emptyReadOnlyText='No translation'
onChange={(e) => handleTermFieldUpdate('locale', e)}>
{transContent}
</EditableText>
</div>
) : ''}
{transSelected ? (
<div className='modal-section'>
<label className='text-bold'>Comment</label><br />
<EditableText
maxLength={500}
editable={enableComment}
editing={enableComment}
placeholder='Add a comment…'
emptyReadOnlyText='No comment'
multiline
onChange={(e) => handleTermFieldUpdate('comment', e)}>
{comment}
</EditableText>
</div>
) : ''}
{!isEmpty(info) &&
<div className='modalText-muted'>{info}</div>
}
</Modal.Body>
<Modal.Footer>
<div className='u-pullRight'>
<Button bsStyle='link'
onClick={
() => {
handleResetTerm(entry.id); handleEntryModalDisplay(false)
}
}>
Cancel
</Button>
{isSaving
? (<Button bsStyle='primary'
type='button' disabled>
<LoaderText loading loadingText='Updating'>Update</LoaderText>
</Button>)
: (<Button bsStyle='primary'
type='button' onClick={() => handleUpdateTerm(entry)}
disabled={!canUpdate}>
Update
</Button>)
}
</div>
</Modal.Footer>
</Modal>
)
/* eslint-enable react/jsx-no-bind, react/jsx-boolean-value*/
}
}
export default EntryModal