1
1
import * as React from 'react' ;
2
2
import styles from '../FieldCollectionData.module.scss' ;
3
- import { ICollectionDataItemProps , ICollectionDataItemState } from '.' ;
3
+ import { ICollectionDataItemProps } from './ICollectionDataItemProps' ;
4
+ import { ICollectionDataItemState } from './ICollectionDataItemState' ;
4
5
import { TextField } from 'office-ui-fabric-react/lib/components/TextField' ;
5
6
import { Icon } from 'office-ui-fabric-react/lib/components/Icon' ;
6
7
import { Link } from 'office-ui-fabric-react/lib/components/Link' ;
7
8
import { Checkbox } from 'office-ui-fabric-react/lib/components/Checkbox' ;
8
9
import * as strings from 'ControlStrings' ;
9
- import { ICustomCollectionField , CustomCollectionFieldType , FieldValidator } from '..' ;
10
+ import { CustomCollectionFieldType , ICustomCollectionField } from '../ICustomCollectionField ' ;
10
11
import { Dropdown , IDropdownOption } from 'office-ui-fabric-react/lib/components/Dropdown' ;
11
12
import { Callout , DirectionalHint } from 'office-ui-fabric-react/lib/components/Callout' ;
12
13
import { CollectionIconField } from '../collectionIconField' ;
13
14
import { clone , findIndex , sortBy } from '@microsoft/sp-lodash-subset' ;
14
15
import { CollectionNumberField } from '../collectionNumberField' ;
15
16
import { Guid } from '@microsoft/sp-core-library' ;
17
+ import { FieldValidator } from '../FieldValidator' ;
16
18
17
19
export class CollectionDataItem extends React . Component < ICollectionDataItemProps , ICollectionDataItemState > {
18
- private emptyItem : any = null ;
20
+ private emptyItem : any = null ; // eslint-disable-line @typescript-eslint/no-explicit-any
19
21
private validation : FieldValidator = { } ;
20
22
private calloutCellRef : HTMLElement ;
21
23
22
24
constructor ( props : ICollectionDataItemProps ) {
23
25
super ( props ) ;
24
26
25
27
// Create an empty item with all properties
26
- let emptyItem = this . generateEmptyItem ( ) ;
28
+ const emptyItem = this . generateEmptyItem ( ) ;
27
29
28
30
this . state = {
29
31
crntItem : clone ( this . props . item ) || { ...emptyItem } ,
@@ -51,7 +53,7 @@ export class CollectionDataItem extends React.Component<ICollectionDataItemProps
51
53
/**
52
54
* Update the item value on the field change
53
55
*/
54
- private onValueChanged = ( fieldId : string , value : any ) : void => {
56
+ private onValueChanged = ( fieldId : string , value : any ) : void => { // eslint-disable-line @typescript-eslint/no-explicit-any
55
57
this . setState ( ( prevState : ICollectionDataItemState ) : ICollectionDataItemState => {
56
58
const { crntItem } = prevState ;
57
59
// Update the changed field
@@ -67,7 +69,7 @@ export class CollectionDataItem extends React.Component<ICollectionDataItemProps
67
69
/**
68
70
* Perform all required field checks at once
69
71
*/
70
- private doAllFieldChecks ( ) {
72
+ private doAllFieldChecks ( ) : void {
71
73
const { crntItem } = this . state ;
72
74
73
75
// Check if current item is valid
@@ -90,7 +92,7 @@ export class CollectionDataItem extends React.Component<ICollectionDataItemProps
90
92
/**
91
93
* Check if all values of the required fields are provided
92
94
*/
93
- private checkAllRequiredFieldsValid ( item : any ) : boolean {
95
+ private checkAllRequiredFieldsValid ( item : any ) : boolean { // eslint-disable-line @typescript-eslint/no-explicit-any
94
96
// Get all the required fields
95
97
const requiredFields = this . props . fields . filter ( f => f . required ) ;
96
98
// Check all the required field values
@@ -106,7 +108,7 @@ export class CollectionDataItem extends React.Component<ICollectionDataItemProps
106
108
* Check if any of the fields contain a value
107
109
* @param item
108
110
*/
109
- private checkAnyFieldContainsValue ( item : any ) : boolean {
111
+ private checkAnyFieldContainsValue ( item : any ) : boolean { // eslint-disable-line @typescript-eslint/no-explicit-any
110
112
const { fields } = this . props ;
111
113
for ( const field of fields ) {
112
114
if ( typeof item [ field . id ] !== "undefined" && item [ field . id ] !== null && item [ field . id ] !== "" ) {
@@ -119,7 +121,7 @@ export class CollectionDataItem extends React.Component<ICollectionDataItemProps
119
121
/**
120
122
* Check if the add action needs to be disabled
121
123
*/
122
- private disableAdd ( item : any ) {
124
+ private disableAdd ( item : any ) : boolean { // eslint-disable-line @typescript-eslint/no-explicit-any
123
125
return ! this . checkAllRequiredFieldsValid ( item ) || ! this . checkAnyFieldContainsValue ( item ) || ! this . checkAllFieldsAreValid ( ) || ! this . props . fAddItem ;
124
126
}
125
127
@@ -141,7 +143,7 @@ export class CollectionDataItem extends React.Component<ICollectionDataItemProps
141
143
/**
142
144
* Add the current row to the collection
143
145
*/
144
- private addRow = ( ) => {
146
+ private addRow = ( ) : void => {
145
147
if ( this . props . fAddItem ) {
146
148
const { crntItem } = this . state ;
147
149
// Check if all the fields are correctly provided
@@ -150,7 +152,7 @@ export class CollectionDataItem extends React.Component<ICollectionDataItemProps
150
152
this . checkAllFieldsAreValid ( ) ) {
151
153
this . props . fAddItem ( crntItem ) ;
152
154
// Clear all field values
153
- let emptyItem = this . generateEmptyItem ( ) ;
155
+ const emptyItem = this . generateEmptyItem ( ) ;
154
156
this . setState ( {
155
157
crntItem : { ...emptyItem }
156
158
} ) ;
@@ -161,7 +163,7 @@ export class CollectionDataItem extends React.Component<ICollectionDataItemProps
161
163
/**
162
164
* Add the current row to the collection
163
165
*/
164
- private updateItem = ( ) => {
166
+ private updateItem = ( ) : void => {
165
167
const { crntItem } = this . state ;
166
168
const isValid = this . checkAllRequiredFieldsValid ( crntItem ) && this . checkAnyFieldContainsValue ( crntItem ) && this . checkAllFieldsAreValid ( ) ;
167
169
@@ -181,7 +183,7 @@ export class CollectionDataItem extends React.Component<ICollectionDataItemProps
181
183
/**
182
184
* Delete the item from the collection
183
185
*/
184
- private deleteRow = ( ) => {
186
+ private deleteRow = ( ) : void => {
185
187
if ( this . props . fDeleteItem ) {
186
188
this . props . fDeleteItem ( this . props . index ) ;
187
189
}
@@ -193,7 +195,7 @@ export class CollectionDataItem extends React.Component<ICollectionDataItemProps
193
195
* @param field
194
196
* @param value
195
197
*/
196
- private fieldValidation = async ( field : ICustomCollectionField , value : any ) : Promise < string > => {
198
+ private fieldValidation = async ( field : ICustomCollectionField , value : any ) : Promise < string > => { // eslint-disable-line @typescript-eslint/no-explicit-any
197
199
let validation = "" ;
198
200
// Do the custom validation check
199
201
if ( field . onGetErrorMessage ) {
@@ -213,7 +215,7 @@ export class CollectionDataItem extends React.Component<ICollectionDataItemProps
213
215
/**
214
216
* Custom field validation
215
217
*/
216
- private onCustomFieldValidation = ( fieldId : string , errorMsg : string ) => {
218
+ private onCustomFieldValidation = ( fieldId : string , errorMsg : string ) : void => {
217
219
console . log ( fieldId , errorMsg ) ;
218
220
if ( fieldId ) {
219
221
this . validation [ fieldId ] = errorMsg === "" ;
@@ -229,7 +231,7 @@ export class CollectionDataItem extends React.Component<ICollectionDataItemProps
229
231
* @param value
230
232
* @param item
231
233
*/
232
- private urlFieldValidation = async ( field : ICustomCollectionField , value : any , item : any ) : Promise < string > => {
234
+ private urlFieldValidation = async ( field : ICustomCollectionField , value : any , item : any ) : Promise < string > => { // eslint-disable-line @typescript-eslint/no-explicit-any
233
235
let isValid = true ;
234
236
let validation = "" ;
235
237
@@ -240,7 +242,7 @@ export class CollectionDataItem extends React.Component<ICollectionDataItemProps
240
242
isValid = validation === "" ;
241
243
} else {
242
244
// Check if entered value is a valid URL
243
- const regEx : RegExp = / ( h t t p | h t t p s ) ? : \/ \/ ( w w w \. ) ? [ - a - z A - Z 0 - 9 @ : % . _ \ +~ # = ] { 2 , 256 } \. [ a - z ] { 2 , 6 } \b ( [ - a - z A - Z 0 - 9 @ : % _ \ +. ~ # ? & \/ \ /= ] * ) / ;
245
+ const regEx : RegExp = / ( h t t p | h t t p s ) ? : \/ \/ ( w w w \. ) ? [ - a - z A - Z 0 - 9 @ : % . _ + ~ # = ] { 2 , 256 } \. [ a - z ] { 2 , 6 } \b ( [ - a - z A - Z 0 - 9 @ : % _ + . ~ # ? & / / = ] * ) / ;
244
246
isValid = ( value === null || value . length === 0 || regEx . test ( value ) ) ;
245
247
validation = isValid ? "" : strings . InvalidUrlError ;
246
248
}
@@ -260,9 +262,10 @@ export class CollectionDataItem extends React.Component<ICollectionDataItemProps
260
262
* @param field
261
263
* @param message
262
264
*/
263
- private errorCalloutHandler ( fieldId : string , message : string ) {
265
+ private errorCalloutHandler ( fieldId : string , message : string ) : void {
264
266
this . setState ( ( prevState : ICollectionDataItemState ) => {
265
- let { crntItem, errorMsgs } = prevState ;
267
+ const { crntItem } = prevState ;
268
+ let errorMsgs = prevState . errorMsgs ;
266
269
267
270
// Get the current field
268
271
const fieldIdx = findIndex ( this . props . fields , f => f . id === fieldId ) ;
@@ -322,13 +325,13 @@ export class CollectionDataItem extends React.Component<ICollectionDataItemProps
322
325
/**
323
326
* Toggle the error callout
324
327
*/
325
- private toggleErrorCallout = ( ) => {
328
+ private toggleErrorCallout = ( ) : void => {
326
329
this . setState ( ( prevState : ICollectionDataItemState ) => ( {
327
330
showCallout : ! prevState . showCallout
328
331
} ) ) ;
329
332
}
330
333
331
- private hideErrorCallout = ( ) => {
334
+ private hideErrorCallout = ( ) : void => {
332
335
this . setState ( {
333
336
showCallout : false
334
337
} ) ;
@@ -340,7 +343,7 @@ export class CollectionDataItem extends React.Component<ICollectionDataItemProps
340
343
* @param field
341
344
* @param item
342
345
*/
343
- private renderField ( field : ICustomCollectionField , item : any ) {
346
+ private renderField ( field : ICustomCollectionField , item : any ) : JSX . Element { // eslint-disable-line @typescript-eslint/no-explicit-any
344
347
const disableFieldOnEdit : boolean = field . disableEdit && ! ! this . props . fUpdateItem ;
345
348
346
349
switch ( field . type ) {
@@ -399,7 +402,7 @@ export class CollectionDataItem extends React.Component<ICollectionDataItemProps
399
402
* Retrieve all dropdown options
400
403
*/
401
404
private getSortingOptions ( ) : IDropdownOption [ ] {
402
- let opts : IDropdownOption [ ] = [ ] ;
405
+ const opts : IDropdownOption [ ] = [ ] ;
403
406
const { totalItems } = this . props ;
404
407
for ( let i = 1 ; i <= totalItems ; i ++ ) {
405
408
opts . push ( {
@@ -413,9 +416,9 @@ export class CollectionDataItem extends React.Component<ICollectionDataItemProps
413
416
/**
414
417
* Creates an empty item with a unique id
415
418
*/
416
- private generateEmptyItem ( ) : any {
419
+ private generateEmptyItem ( ) : any { // eslint-disable-line @typescript-eslint/no-explicit-any
417
420
// Create an empty item with all properties
418
- let emptyItem : any = { } ;
421
+ const emptyItem : any = { } ; // eslint-disable-line @typescript-eslint/no-explicit-any
419
422
emptyItem . uniqueId = Guid . newGuid ( ) . toString ( ) ;
420
423
421
424
for ( const field of this . props . fields ) {
@@ -447,7 +450,7 @@ export class CollectionDataItem extends React.Component<ICollectionDataItemProps
447
450
}
448
451
{
449
452
( this . props . sortingEnabled && this . props . totalItems === null ) && (
450
- < span className = { `${ styles . tableCell } ` } > </ span >
453
+ < span className = { `${ styles . tableCell } ` } / >
451
454
)
452
455
}
453
456
{
@@ -457,7 +460,7 @@ export class CollectionDataItem extends React.Component<ICollectionDataItemProps
457
460
}
458
461
459
462
< span className = { styles . tableCell } >
460
- < span ref = { ref => this . calloutCellRef = ref } >
463
+ < span ref = { ref => { this . calloutCellRef = ref ; } } >
461
464
< Link title = { strings . CollectionDataItemShowErrorsLabel }
462
465
className = { styles . errorCalloutLink }
463
466
disabled = { ! this . state . errorMsgs || this . state . errorMsgs . length === 0 }
0 commit comments