11import * as React from 'react' ;
22import styles from '../FieldCollectionData.module.scss' ;
3- import { ICollectionDataItemProps , ICollectionDataItemState } from '.' ;
3+ import { ICollectionDataItemProps } from './ICollectionDataItemProps' ;
4+ import { ICollectionDataItemState } from './ICollectionDataItemState' ;
45import { TextField } from 'office-ui-fabric-react/lib/components/TextField' ;
56import { Icon } from 'office-ui-fabric-react/lib/components/Icon' ;
67import { Link } from 'office-ui-fabric-react/lib/components/Link' ;
78import { Checkbox } from 'office-ui-fabric-react/lib/components/Checkbox' ;
89import * as strings from 'ControlStrings' ;
9- import { ICustomCollectionField , CustomCollectionFieldType , FieldValidator } from '..' ;
10+ import { CustomCollectionFieldType , ICustomCollectionField } from '../ICustomCollectionField ' ;
1011import { Dropdown , IDropdownOption } from 'office-ui-fabric-react/lib/components/Dropdown' ;
1112import { Callout , DirectionalHint } from 'office-ui-fabric-react/lib/components/Callout' ;
1213import { CollectionIconField } from '../collectionIconField' ;
1314import { clone , findIndex , sortBy } from '@microsoft/sp-lodash-subset' ;
1415import { CollectionNumberField } from '../collectionNumberField' ;
1516import { Guid } from '@microsoft/sp-core-library' ;
17+ import { FieldValidator } from '../FieldValidator' ;
1618
1719export 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
1921 private validation : FieldValidator = { } ;
2022 private calloutCellRef : HTMLElement ;
2123
2224 constructor ( props : ICollectionDataItemProps ) {
2325 super ( props ) ;
2426
2527 // Create an empty item with all properties
26- let emptyItem = this . generateEmptyItem ( ) ;
28+ const emptyItem = this . generateEmptyItem ( ) ;
2729
2830 this . state = {
2931 crntItem : clone ( this . props . item ) || { ...emptyItem } ,
@@ -51,7 +53,7 @@ export class CollectionDataItem extends React.Component<ICollectionDataItemProps
5153 /**
5254 * Update the item value on the field change
5355 */
54- private onValueChanged = ( fieldId : string , value : any ) : void => {
56+ private onValueChanged = ( fieldId : string , value : any ) : void => { // eslint-disable-line @typescript-eslint/no-explicit-any
5557 this . setState ( ( prevState : ICollectionDataItemState ) : ICollectionDataItemState => {
5658 const { crntItem } = prevState ;
5759 // Update the changed field
@@ -67,7 +69,7 @@ export class CollectionDataItem extends React.Component<ICollectionDataItemProps
6769 /**
6870 * Perform all required field checks at once
6971 */
70- private doAllFieldChecks ( ) {
72+ private doAllFieldChecks ( ) : void {
7173 const { crntItem } = this . state ;
7274
7375 // Check if current item is valid
@@ -90,7 +92,7 @@ export class CollectionDataItem extends React.Component<ICollectionDataItemProps
9092 /**
9193 * Check if all values of the required fields are provided
9294 */
93- private checkAllRequiredFieldsValid ( item : any ) : boolean {
95+ private checkAllRequiredFieldsValid ( item : any ) : boolean { // eslint-disable-line @typescript-eslint/no-explicit-any
9496 // Get all the required fields
9597 const requiredFields = this . props . fields . filter ( f => f . required ) ;
9698 // Check all the required field values
@@ -106,7 +108,7 @@ export class CollectionDataItem extends React.Component<ICollectionDataItemProps
106108 * Check if any of the fields contain a value
107109 * @param item
108110 */
109- private checkAnyFieldContainsValue ( item : any ) : boolean {
111+ private checkAnyFieldContainsValue ( item : any ) : boolean { // eslint-disable-line @typescript-eslint/no-explicit-any
110112 const { fields } = this . props ;
111113 for ( const field of fields ) {
112114 if ( typeof item [ field . id ] !== "undefined" && item [ field . id ] !== null && item [ field . id ] !== "" ) {
@@ -119,7 +121,7 @@ export class CollectionDataItem extends React.Component<ICollectionDataItemProps
119121 /**
120122 * Check if the add action needs to be disabled
121123 */
122- private disableAdd ( item : any ) {
124+ private disableAdd ( item : any ) : boolean { // eslint-disable-line @typescript-eslint/no-explicit-any
123125 return ! this . checkAllRequiredFieldsValid ( item ) || ! this . checkAnyFieldContainsValue ( item ) || ! this . checkAllFieldsAreValid ( ) || ! this . props . fAddItem ;
124126 }
125127
@@ -141,7 +143,7 @@ export class CollectionDataItem extends React.Component<ICollectionDataItemProps
141143 /**
142144 * Add the current row to the collection
143145 */
144- private addRow = ( ) => {
146+ private addRow = ( ) : void => {
145147 if ( this . props . fAddItem ) {
146148 const { crntItem } = this . state ;
147149 // Check if all the fields are correctly provided
@@ -150,7 +152,7 @@ export class CollectionDataItem extends React.Component<ICollectionDataItemProps
150152 this . checkAllFieldsAreValid ( ) ) {
151153 this . props . fAddItem ( crntItem ) ;
152154 // Clear all field values
153- let emptyItem = this . generateEmptyItem ( ) ;
155+ const emptyItem = this . generateEmptyItem ( ) ;
154156 this . setState ( {
155157 crntItem : { ...emptyItem }
156158 } ) ;
@@ -161,7 +163,7 @@ export class CollectionDataItem extends React.Component<ICollectionDataItemProps
161163 /**
162164 * Add the current row to the collection
163165 */
164- private updateItem = ( ) => {
166+ private updateItem = ( ) : void => {
165167 const { crntItem } = this . state ;
166168 const isValid = this . checkAllRequiredFieldsValid ( crntItem ) && this . checkAnyFieldContainsValue ( crntItem ) && this . checkAllFieldsAreValid ( ) ;
167169
@@ -181,7 +183,7 @@ export class CollectionDataItem extends React.Component<ICollectionDataItemProps
181183 /**
182184 * Delete the item from the collection
183185 */
184- private deleteRow = ( ) => {
186+ private deleteRow = ( ) : void => {
185187 if ( this . props . fDeleteItem ) {
186188 this . props . fDeleteItem ( this . props . index ) ;
187189 }
@@ -193,7 +195,7 @@ export class CollectionDataItem extends React.Component<ICollectionDataItemProps
193195 * @param field
194196 * @param value
195197 */
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
197199 let validation = "" ;
198200 // Do the custom validation check
199201 if ( field . onGetErrorMessage ) {
@@ -213,7 +215,7 @@ export class CollectionDataItem extends React.Component<ICollectionDataItemProps
213215 /**
214216 * Custom field validation
215217 */
216- private onCustomFieldValidation = ( fieldId : string , errorMsg : string ) => {
218+ private onCustomFieldValidation = ( fieldId : string , errorMsg : string ) : void => {
217219 console . log ( fieldId , errorMsg ) ;
218220 if ( fieldId ) {
219221 this . validation [ fieldId ] = errorMsg === "" ;
@@ -229,7 +231,7 @@ export class CollectionDataItem extends React.Component<ICollectionDataItemProps
229231 * @param value
230232 * @param item
231233 */
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
233235 let isValid = true ;
234236 let validation = "" ;
235237
@@ -240,7 +242,7 @@ export class CollectionDataItem extends React.Component<ICollectionDataItemProps
240242 isValid = validation === "" ;
241243 } else {
242244 // 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 @ : % _ + . ~ # ? & / / = ] * ) / ;
244246 isValid = ( value === null || value . length === 0 || regEx . test ( value ) ) ;
245247 validation = isValid ? "" : strings . InvalidUrlError ;
246248 }
@@ -260,9 +262,10 @@ export class CollectionDataItem extends React.Component<ICollectionDataItemProps
260262 * @param field
261263 * @param message
262264 */
263- private errorCalloutHandler ( fieldId : string , message : string ) {
265+ private errorCalloutHandler ( fieldId : string , message : string ) : void {
264266 this . setState ( ( prevState : ICollectionDataItemState ) => {
265- let { crntItem, errorMsgs } = prevState ;
267+ const { crntItem } = prevState ;
268+ let errorMsgs = prevState . errorMsgs ;
266269
267270 // Get the current field
268271 const fieldIdx = findIndex ( this . props . fields , f => f . id === fieldId ) ;
@@ -322,13 +325,13 @@ export class CollectionDataItem extends React.Component<ICollectionDataItemProps
322325 /**
323326 * Toggle the error callout
324327 */
325- private toggleErrorCallout = ( ) => {
328+ private toggleErrorCallout = ( ) : void => {
326329 this . setState ( ( prevState : ICollectionDataItemState ) => ( {
327330 showCallout : ! prevState . showCallout
328331 } ) ) ;
329332 }
330333
331- private hideErrorCallout = ( ) => {
334+ private hideErrorCallout = ( ) : void => {
332335 this . setState ( {
333336 showCallout : false
334337 } ) ;
@@ -340,7 +343,7 @@ export class CollectionDataItem extends React.Component<ICollectionDataItemProps
340343 * @param field
341344 * @param item
342345 */
343- private renderField ( field : ICustomCollectionField , item : any ) {
346+ private renderField ( field : ICustomCollectionField , item : any ) : JSX . Element { // eslint-disable-line @typescript-eslint/no-explicit-any
344347 const disableFieldOnEdit : boolean = field . disableEdit && ! ! this . props . fUpdateItem ;
345348
346349 switch ( field . type ) {
@@ -399,7 +402,7 @@ export class CollectionDataItem extends React.Component<ICollectionDataItemProps
399402 * Retrieve all dropdown options
400403 */
401404 private getSortingOptions ( ) : IDropdownOption [ ] {
402- let opts : IDropdownOption [ ] = [ ] ;
405+ const opts : IDropdownOption [ ] = [ ] ;
403406 const { totalItems } = this . props ;
404407 for ( let i = 1 ; i <= totalItems ; i ++ ) {
405408 opts . push ( {
@@ -413,9 +416,9 @@ export class CollectionDataItem extends React.Component<ICollectionDataItemProps
413416 /**
414417 * Creates an empty item with a unique id
415418 */
416- private generateEmptyItem ( ) : any {
419+ private generateEmptyItem ( ) : any { // eslint-disable-line @typescript-eslint/no-explicit-any
417420 // Create an empty item with all properties
418- let emptyItem : any = { } ;
421+ const emptyItem : any = { } ; // eslint-disable-line @typescript-eslint/no-explicit-any
419422 emptyItem . uniqueId = Guid . newGuid ( ) . toString ( ) ;
420423
421424 for ( const field of this . props . fields ) {
@@ -447,7 +450,7 @@ export class CollectionDataItem extends React.Component<ICollectionDataItemProps
447450 }
448451 {
449452 ( this . props . sortingEnabled && this . props . totalItems === null ) && (
450- < span className = { `${ styles . tableCell } ` } > </ span >
453+ < span className = { `${ styles . tableCell } ` } / >
451454 )
452455 }
453456 {
@@ -457,7 +460,7 @@ export class CollectionDataItem extends React.Component<ICollectionDataItemProps
457460 }
458461
459462 < span className = { styles . tableCell } >
460- < span ref = { ref => this . calloutCellRef = ref } >
463+ < span ref = { ref => { this . calloutCellRef = ref ; } } >
461464 < Link title = { strings . CollectionDataItemShowErrorsLabel }
462465 className = { styles . errorCalloutLink }
463466 disabled = { ! this . state . errorMsgs || this . state . errorMsgs . length === 0 }
0 commit comments