@@ -26,7 +26,7 @@ export class CollectionDataItem extends React.Component<ICollectionDataItemProps
26
26
let emptyItem = this . generateEmptyItem ( ) ;
27
27
28
28
this . state = {
29
- crntItem : clone ( this . props . item ) || { ...emptyItem } ,
29
+ crntItem : clone ( this . props . item ) || { ...emptyItem } ,
30
30
errorMsgs : [ ] ,
31
31
showCallout : false
32
32
} ;
@@ -38,6 +38,9 @@ export class CollectionDataItem extends React.Component<ICollectionDataItemProps
38
38
* @param prevState
39
39
*/
40
40
public componentDidUpdate ( prevProps : ICollectionDataItemProps ) : void {
41
+ /**
42
+ * Compare if items are not equal
43
+ */
41
44
if ( this . props . item !== prevProps . item ) {
42
45
this . setState ( {
43
46
crntItem : clone ( this . props . item )
@@ -70,8 +73,8 @@ export class CollectionDataItem extends React.Component<ICollectionDataItemProps
70
73
// Check if current item is valid
71
74
if ( this . props . fAddInCreation ) {
72
75
if ( this . checkAllRequiredFieldsValid ( crntItem ) &&
73
- this . checkAnyFieldContainsValue ( crntItem ) &&
74
- this . checkAllFieldsAreValid ( ) ) {
76
+ this . checkAnyFieldContainsValue ( crntItem ) &&
77
+ this . checkAllFieldsAreValid ( ) ) {
75
78
this . props . fAddInCreation ( crntItem ) ;
76
79
} else {
77
80
this . props . fAddInCreation ( null ) ;
@@ -143,13 +146,13 @@ export class CollectionDataItem extends React.Component<ICollectionDataItemProps
143
146
const { crntItem } = this . state ;
144
147
// Check if all the fields are correctly provided
145
148
if ( this . checkAllRequiredFieldsValid ( crntItem ) &&
146
- this . checkAnyFieldContainsValue ( crntItem ) &&
147
- this . checkAllFieldsAreValid ( ) ) {
149
+ this . checkAnyFieldContainsValue ( crntItem ) &&
150
+ this . checkAllFieldsAreValid ( ) ) {
148
151
this . props . fAddItem ( crntItem ) ;
149
152
// Clear all field values
150
153
let emptyItem = this . generateEmptyItem ( ) ;
151
154
this . setState ( {
152
- crntItem : { ...emptyItem }
155
+ crntItem : { ...emptyItem }
153
156
} ) ;
154
157
}
155
158
}
@@ -340,21 +343,21 @@ export class CollectionDataItem extends React.Component<ICollectionDataItemProps
340
343
private renderField ( field : ICustomCollectionField , item : any ) {
341
344
const disableFieldOnEdit : boolean = field . disableEdit && ! ! this . props . fUpdateItem ;
342
345
343
- switch ( field . type ) {
346
+ switch ( field . type ) {
344
347
case CustomCollectionFieldType . boolean :
345
348
return < Checkbox checked = { item [ field . id ] ? item [ field . id ] : false }
346
- onChange = { ( ev , value ) => this . onValueChanged ( field . id , value ) }
347
- disabled = { disableFieldOnEdit }
348
- className = "PropertyFieldCollectionData__panel__boolean-field" /> ;
349
+ onChange = { ( ev , value ) => this . onValueChanged ( field . id , value ) }
350
+ disabled = { disableFieldOnEdit }
351
+ className = "PropertyFieldCollectionData__panel__boolean-field" /> ;
349
352
case CustomCollectionFieldType . dropdown :
350
353
return < Dropdown placeHolder = { field . placeholder || field . title }
351
- options = { field . options }
352
- selectedKey = { item [ field . id ] || null }
353
- required = { field . required }
354
- disabled = { disableFieldOnEdit }
355
- onChanged = { ( opt ) => this . onValueChanged ( field . id , opt . key ) }
356
- onRenderOption = { field . onRenderOption }
357
- className = "PropertyFieldCollectionData__panel__dropdown-field" /> ;
354
+ options = { field . options }
355
+ selectedKey = { item [ field . id ] || null }
356
+ required = { field . required }
357
+ disabled = { disableFieldOnEdit }
358
+ onChanged = { ( opt ) => this . onValueChanged ( field . id , opt . key ) }
359
+ onRenderOption = { field . onRenderOption }
360
+ className = "PropertyFieldCollectionData__panel__dropdown-field" /> ;
358
361
case CustomCollectionFieldType . number :
359
362
return (
360
363
< CollectionNumberField field = { field } item = { item } disableEdit = { disableFieldOnEdit } fOnValueChange = { this . onValueChanged } fValidation = { this . fieldValidation } />
@@ -365,30 +368,30 @@ export class CollectionDataItem extends React.Component<ICollectionDataItemProps
365
368
) ;
366
369
case CustomCollectionFieldType . url :
367
370
return < TextField placeholder = { field . placeholder || field . title }
368
- value = { item [ field . id ] ? item [ field . id ] : "" }
369
- required = { field . required }
370
- disabled = { disableFieldOnEdit }
371
- className = { styles . collectionDataField }
372
- onChanged = { ( value ) => this . onValueChanged ( field . id , value ) }
373
- deferredValidationTime = { field . deferredValidationTime || field . deferredValidationTime >= 0 ? field . deferredValidationTime : 200 }
374
- onGetErrorMessage = { async ( value : string ) => this . urlFieldValidation ( field , value , item ) }
375
- inputClassName = "PropertyFieldCollectionData__panel__url-field" /> ;
371
+ value = { item [ field . id ] ? item [ field . id ] : "" }
372
+ required = { field . required }
373
+ disabled = { disableFieldOnEdit }
374
+ className = { styles . collectionDataField }
375
+ onChanged = { ( value ) => this . onValueChanged ( field . id , value ) }
376
+ deferredValidationTime = { field . deferredValidationTime || field . deferredValidationTime >= 0 ? field . deferredValidationTime : 200 }
377
+ onGetErrorMessage = { async ( value : string ) => this . urlFieldValidation ( field , value , item ) }
378
+ inputClassName = "PropertyFieldCollectionData__panel__url-field" /> ;
376
379
case CustomCollectionFieldType . custom :
377
- if ( field . onCustomRender ) {
378
- return field . onCustomRender ( field , item [ field . id ] , this . onValueChanged , item , item . uniqueId , this . onCustomFieldValidation ) ;
379
- }
380
- return null ;
380
+ if ( field . onCustomRender ) {
381
+ return field . onCustomRender ( field , item [ field . id ] , this . onValueChanged , item , item . uniqueId , this . onCustomFieldValidation ) ;
382
+ }
383
+ return null ;
381
384
case CustomCollectionFieldType . string :
382
385
default :
383
386
return < TextField placeholder = { field . placeholder || field . title }
384
- className = { styles . collectionDataField }
385
- value = { item [ field . id ] ? item [ field . id ] : "" }
386
- required = { field . required }
387
- disabled = { disableFieldOnEdit }
388
- onChanged = { ( value ) => this . onValueChanged ( field . id , value ) }
389
- deferredValidationTime = { field . deferredValidationTime || field . deferredValidationTime >= 0 ? field . deferredValidationTime : 200 }
390
- onGetErrorMessage = { async ( value : string ) => await this . fieldValidation ( field , value ) }
391
- inputClassName = "PropertyFieldCollectionData__panel__string-field" /> ;
387
+ className = { styles . collectionDataField }
388
+ value = { item [ field . id ] ? item [ field . id ] : "" }
389
+ required = { field . required }
390
+ disabled = { disableFieldOnEdit }
391
+ onChanged = { ( value ) => this . onValueChanged ( field . id , value ) }
392
+ deferredValidationTime = { field . deferredValidationTime || field . deferredValidationTime >= 0 ? field . deferredValidationTime : 200 }
393
+ onGetErrorMessage = { async ( value : string ) => await this . fieldValidation ( field , value ) }
394
+ inputClassName = "PropertyFieldCollectionData__panel__string-field" /> ;
392
395
}
393
396
}
394
397
@@ -407,12 +410,12 @@ export class CollectionDataItem extends React.Component<ICollectionDataItemProps
407
410
return opts ;
408
411
}
409
412
410
- /**
411
- * Creates an empty item with a unique id
412
- */
413
+ /**
414
+ * Creates an empty item with a unique id
415
+ */
413
416
private generateEmptyItem ( ) : any {
414
417
// Create an empty item with all properties
415
- let emptyItem :any = { } ;
418
+ let emptyItem : any = { } ;
416
419
emptyItem . uniqueId = Guid . newGuid ( ) . toString ( ) ;
417
420
418
421
for ( const field of this . props . fields ) {
@@ -429,12 +432,16 @@ export class CollectionDataItem extends React.Component<ICollectionDataItemProps
429
432
const { crntItem } = this . state ;
430
433
const opts = this . getSortingOptions ( ) ;
431
434
435
+ if ( ! crntItem ) {
436
+ return null ;
437
+ }
438
+
432
439
return (
433
440
< div className = { `PropertyFieldCollectionData__panel__table-row ${ styles . tableRow } ${ this . props . index === null ? styles . tableFooter : "" } ` } >
434
441
{
435
442
( this . props . sortingEnabled && this . props . totalItems ) && (
436
443
< span className = { `PropertyFieldCollectionData__panel__sorting-field ${ styles . tableCell } ` } >
437
- < Dropdown options = { opts } selectedKey = { this . props . index + 1 } onChanged = { ( opt ) => this . props . fOnSorting ( this . props . index , opt . key as number ) } />
444
+ < Dropdown options = { opts } selectedKey = { this . props . index + 1 } onChanged = { ( opt ) => this . props . fOnSorting ( this . props . index , opt . key as number ) } />
438
445
</ span >
439
446
)
440
447
}
@@ -452,21 +459,21 @@ export class CollectionDataItem extends React.Component<ICollectionDataItemProps
452
459
< span className = { styles . tableCell } >
453
460
< span ref = { ref => this . calloutCellRef = ref } >
454
461
< Link title = { strings . CollectionDataItemShowErrorsLabel }
455
- className = { styles . errorCalloutLink }
456
- disabled = { ! this . state . errorMsgs || this . state . errorMsgs . length === 0 }
457
- onClick = { this . toggleErrorCallout } >
462
+ className = { styles . errorCalloutLink }
463
+ disabled = { ! this . state . errorMsgs || this . state . errorMsgs . length === 0 }
464
+ onClick = { this . toggleErrorCallout } >
458
465
< Icon iconName = "Error" />
459
466
</ Link >
460
467
</ span >
461
468
462
469
{
463
470
this . state . showCallout && (
464
471
< Callout className = { styles . errorCallout }
465
- target = { this . calloutCellRef }
466
- isBeakVisible = { true }
467
- directionalHint = { DirectionalHint . bottomLeftEdge }
468
- directionalHintForRTL = { DirectionalHint . rightBottomEdge }
469
- onDismiss = { this . hideErrorCallout } >
472
+ target = { this . calloutCellRef }
473
+ isBeakVisible = { true }
474
+ directionalHint = { DirectionalHint . bottomLeftEdge }
475
+ directionalHintForRTL = { DirectionalHint . rightBottomEdge }
476
+ onDismiss = { this . hideErrorCallout } >
470
477
{
471
478
( this . state . errorMsgs && this . state . errorMsgs . length > 0 ) && (
472
479
< div className = { styles . errorMsgs } >
@@ -487,18 +494,18 @@ export class CollectionDataItem extends React.Component<ICollectionDataItemProps
487
494
</ span >
488
495
489
496
< span className = { styles . tableCell } >
490
- {
491
- /* Check add or delete action */
492
- this . props . index !== null ? (
493
- < Link title = { strings . CollectionDeleteRowButtonLabel } disabled = { ! this . props . fDeleteItem || this . props . disableItemDeletion } onClick = { this . deleteRow } >
494
- < Icon iconName = "Clear" />
495
- </ Link >
496
- ) : (
497
- < Link title = { strings . CollectionAddRowButtonLabel } className = { `${ this . disableAdd ( crntItem ) ? "" : styles . addBtn } ` } disabled = { this . disableAdd ( crntItem ) } onClick = { this . addRow } >
498
- < Icon iconName = "Add" />
499
- </ Link >
500
- )
501
- }
497
+ {
498
+ /* Check add or delete action */
499
+ this . props . index !== null ? (
500
+ < Link title = { strings . CollectionDeleteRowButtonLabel } disabled = { ! this . props . fDeleteItem || this . props . disableItemDeletion } onClick = { this . deleteRow } >
501
+ < Icon iconName = "Clear" />
502
+ </ Link >
503
+ ) : (
504
+ < Link title = { strings . CollectionAddRowButtonLabel } className = { `${ this . disableAdd ( crntItem ) ? "" : styles . addBtn } ` } disabled = { this . disableAdd ( crntItem ) } onClick = { this . addRow } >
505
+ < Icon iconName = "Add" />
506
+ </ Link >
507
+ )
508
+ }
502
509
</ span >
503
510
</ div >
504
511
) ;
0 commit comments