3
3
4
4
import React from 'react'
5
5
import PropTypes from 'prop-types'
6
- import { TwoLineEntry , QuickEditModel , SourcePicker , FileCountRenderer } from './'
6
+ import { TwoLineEntry , QuickEditModel , FileCountRenderer } from './'
7
7
import { Checkbox , OverlayTrigger , Tooltip , Popover } from 'react-bootstrap'
8
8
import { Tag } from 'antd'
9
9
import { get , isEqual , union } from 'lodash'
@@ -34,7 +34,7 @@ class DefinitionEntry extends React.Component {
34
34
}
35
35
}
36
36
static propTypes = {
37
- onChange : PropTypes . func ,
37
+ onChange : PropTypes . func . isRequired ,
38
38
onCurate : PropTypes . func ,
39
39
onInspect : PropTypes . func ,
40
40
activeFacets : PropTypes . array ,
@@ -60,7 +60,7 @@ class DefinitionEntry extends React.Component {
60
60
const newChanges = { ...component . changes }
61
61
if ( isChanged && proposedValue !== null ) newChanges [ field ] = proposedValue
62
62
else delete newChanges [ field ]
63
- onChange && onChange ( component , newChanges , field )
63
+ onChange ( component , newChanges , field )
64
64
}
65
65
}
66
66
@@ -90,10 +90,10 @@ class DefinitionEntry extends React.Component {
90
90
< ScoreRenderer scores = { scores } definition = { definition } />
91
91
</ span >
92
92
) : null
93
- const releasedDate = definition ?. described ?. releaseDate ? (
94
- < span className = "releasedDate-table" > { definition . described . releaseDate } </ span >
95
- ) : (
96
- < span className = "releasedDate-table" > -- -- -- < /span >
93
+ const releasedDate = (
94
+ < span className = "releasedDate-table" >
95
+ { this . renderFieldWithToolTipIfDifferent ( 'described.releaseDate' , a => a || '-- -- --' ) }
96
+ </ span >
97
97
)
98
98
const curationTag = isCurationPending ? (
99
99
< span >
@@ -125,7 +125,7 @@ class DefinitionEntry extends React.Component {
125
125
renderWithToolTipIfDifferent ( field , content , placement = 'right' , transform = x => x ) {
126
126
const toolTip = (
127
127
< Tooltip id = { `tooltip-${ field } ` } className = "definition__tooltip" >
128
- Original: { transform ( get ( this . props . otherDefinition , field ) ) }
128
+ Original: { transform ( this . getOriginalValue ( field ) ) }
129
129
</ Tooltip >
130
130
)
131
131
return this . ifDifferent (
@@ -137,14 +137,19 @@ class DefinitionEntry extends React.Component {
137
137
)
138
138
}
139
139
140
+ renderFieldWithToolTipIfDifferent ( field , transform = a => a ) {
141
+ const displayValue = transform ( this . getValue ( field ) )
142
+ return this . renderWithToolTipIfDifferent (
143
+ field ,
144
+ < span className = { this . classIfDifferent ( field ) } > { displayValue } </ span > ,
145
+ undefined ,
146
+ transform
147
+ )
148
+ }
149
+
140
150
renderMessage ( definition ) {
141
151
const licenseExpression = definition ? this . getValue ( 'licensed.declared' ) : null
142
- return licenseExpression
143
- ? this . renderWithToolTipIfDifferent (
144
- 'licensed.declared' ,
145
- < span className = { this . classIfDifferent ( 'licensed.declared' ) } > { licenseExpression } </ span >
146
- )
147
- : null
152
+ return licenseExpression ? this . renderFieldWithToolTipIfDifferent ( 'licensed.declared' ) : null
148
153
}
149
154
150
155
getPercentage ( count , total ) {
@@ -190,6 +195,23 @@ class DefinitionEntry extends React.Component {
190
195
this . setState ( { modelOpen : ! this . state . modelOpen } )
191
196
}
192
197
198
+ handleSaveEdit = updates => {
199
+ const { onChange, definition, component } = this . props
200
+
201
+ const newChanges = Object . entries ( updates ) . reduce ( ( changes , [ key , value ] ) => {
202
+ let field
203
+ if ( key === 'declared' ) field = 'licensed.declared'
204
+ if ( key === 'sourceComponent' ) field = 'described.sourceLocation'
205
+ if ( key === 'release' ) field = 'described.releaseDate'
206
+ return field ? Contribution . applyChanges ( definition , changes , field , value ) : changes
207
+ } , { } )
208
+
209
+ if ( Object . keys ( newChanges ) . length !== 0 ) {
210
+ const combinedChanges = { ...component . changes , ...newChanges }
211
+ onChange ( component , combinedChanges )
212
+ }
213
+ }
214
+
193
215
renderPanel ( rawDefinition ) {
194
216
if ( ! rawDefinition )
195
217
return (
@@ -201,13 +223,12 @@ class DefinitionEntry extends React.Component {
201
223
// TODO: find a way of calling this method less frequently. It's relatively expensive.
202
224
const definition = this . foldFacets ( rawDefinition , this . props . activeFacets )
203
225
const { licensed } = definition
204
- const { readOnly, onRevert } = this . props
205
226
return (
206
227
< div className = "row row-panel-details" >
207
228
< div className = "col-md-6 d-flex justify-content-start align-items-center" >
208
229
< span className = "panel-details__title" > { this . renderLabel ( 'Declared' ) } :</ span >
209
230
< div className = "panel-details__value" >
210
- < p > { this . getValue ( 'licensed.declared' ) } </ p >
231
+ { this . renderFieldWithToolTipIfDifferent ( 'licensed.declared' ) }
211
232
{ /* {this.renderWithToolTipIfDifferent(
212
233
'licensed.declared',
213
234
<LicensesRenderer
@@ -232,7 +253,7 @@ class DefinitionEntry extends React.Component {
232
253
< div className = "col-md-6 d-flex justify-content-start align-items-center" >
233
254
< span className = "panel-details__title" > { this . renderLabel ( 'Source' ) } :</ span >
234
255
< div className = "panel-details__value" >
235
- < p > { Contribution . printCoordinates ( this . getValue ( 'described.sourceLocation' ) ) } </ p >
256
+ { this . renderFieldWithToolTipIfDifferent ( 'described.sourceLocation' , a => Contribution . printCoordinates ( a ) ) }
236
257
{ /* {this.renderWithToolTipIfDifferent(
237
258
'described.sourceLocation',
238
259
<ModalEditor
@@ -263,7 +284,10 @@ class DefinitionEntry extends React.Component {
263
284
< div className = "col-md-6 d-flex justify-content-start align-items-center" >
264
285
< span className = "panel-details__title" > { this . renderLabel ( 'Release' ) } :</ span >
265
286
< div className = "panel-details__value" >
266
- < p > { Contribution . printDate ( this . getValue ( 'described.releaseDate' ) ) } </ p >
287
+ { this . renderFieldWithToolTipIfDifferent (
288
+ 'described.releaseDate' ,
289
+ a => Contribution . printDate ( a ) || '-- -- --'
290
+ ) }
267
291
{ /* {this.renderWithToolTipIfDifferent(
268
292
'described.releaseDate',
269
293
<InlineEditor
@@ -292,33 +316,12 @@ class DefinitionEntry extends React.Component {
292
316
< QuickEditModel
293
317
open = { this . state . modelOpen }
294
318
closeModel = { this . handleModel }
295
- definition = { definition }
296
- field = { 'described.sourceLocation' }
297
- extraClass = { this . classIfDifferent ( 'described.sourceLocation' ) }
298
- readOnly = { readOnly }
299
- initialValue = { {
300
- declared : this . getOriginalValue ( 'licensed.declared' ) ,
301
- source : Contribution . printCoordinates ( this . getOriginalValue ( 'described.sourceLocation' ) ) ,
302
- release : Contribution . printDate ( this . getOriginalValue ( 'described.releaseDate' ) ) ,
303
- repo : ''
304
- } }
305
- values = { {
319
+ initialValues = { {
306
320
declared : this . getValue ( 'licensed.declared' ) ,
307
- source : Contribution . printCoordinates ( this . getValue ( 'described.sourceLocation' ) ) ,
308
- release : Contribution . printDate ( this . getValue ( 'described.releaseDate' ) ) ,
309
- repo : ''
310
- } }
311
- onChange = { {
312
- declared : this . fieldChange ( 'licensed.declared' ) ,
313
- source : this . fieldChange ( 'described.sourceLocation' , isEqual , Contribution . toSourceLocation ) ,
314
- release : this . fieldChange ( 'described.releaseDate' ) ,
315
- repo : ''
321
+ sourceComponent : this . getValue ( 'described.sourceLocation' ) ,
322
+ release : Contribution . printDate ( this . getValue ( 'described.releaseDate' ) )
316
323
} }
317
- editor = { SourcePicker }
318
- validator = { value => true }
319
- placeholder = { 'Source location' }
320
- revertable
321
- onRevert = { ( ) => onRevert ( 'described.sourceLocation' ) }
324
+ onSave = { this . handleSaveEdit }
322
325
/>
323
326
< button onClick = { this . handleModel } className = "quick-edit-btn" >
324
327
Edit
0 commit comments