Skip to content

Commit 4bec615

Browse files
committed
wip
1 parent 3d326b4 commit 4bec615

39 files changed

+240
-237
lines changed

src/controls/fieldCollectionData/FieldCollectionData.tsx

-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import { Panel, PanelType } from 'office-ui-fabric-react/lib/components/Panel';
55
import { Label } from 'office-ui-fabric-react/lib/components/Label';
66
import { CollectionDataViewer } from './collectionDataViewer';
77
import { IFieldCollectionDataProps, IFieldCollectionDataState } from "./IFieldCollectionData";
8-
// import FieldErrorMessage from '../errorMessage/FieldErrorMessage';
98
import * as strings from 'ControlStrings';
109
import { MessageBar, MessageBarType } from 'office-ui-fabric-react/lib/MessageBar';
1110

src/controls/fieldCollectionData/ICustomCollectionField.ts

+12-3
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ export interface ICustomCollectionField {
3838
/**
3939
* Default value for the field
4040
*/
41-
defaultValue?: any;
41+
defaultValue?: any; // eslint-disable-line @typescript-eslint/no-explicit-any
4242
/**
4343
* Field will start to validate after users stop typing for `deferredValidationTime` milliseconds. Default: 200ms.
4444
*/
@@ -50,12 +50,21 @@ export interface ICustomCollectionField {
5050
* - If valid, it returns empty string.
5151
* - If invalid, the field will show a red border
5252
*/
53-
onGetErrorMessage?: (value: any, index: number, currentItem: any) => string | Promise<string>;
53+
onGetErrorMessage?: (value: any, index: number, currentItem: any) => string | Promise<string>; // eslint-disable-line @typescript-eslint/no-explicit-any
5454

5555
/**
5656
* Custom field rendering support
5757
*/
58-
onCustomRender?: (field: ICustomCollectionField, value: any, onUpdate: (fieldId: string, value: any) => void, item: any, rowUniqueId: string, onCustomFieldValidation: (fieldId: string, errorMessage: string) => void) => JSX.Element;
58+
onCustomRender?: (
59+
field: ICustomCollectionField,
60+
/* eslint-disable @typescript-eslint/no-explicit-any */
61+
value: any,
62+
onUpdate: (fieldId: string, value: any) => void,
63+
item: any,
64+
/* eslint-enable @typescript-eslint/no-explicit-any */
65+
rowUniqueId: string,
66+
onCustomFieldValidation: (fieldId: string, errorMessage: string) => void
67+
) => JSX.Element;
5968
}
6069

6170
export enum CustomCollectionFieldType {

src/controls/fieldCollectionData/IFieldCollectionData.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { ICustomCollectionField } from ".";
1+
import { ICustomCollectionField } from "./ICustomCollectionField";
22

33
export interface IFieldCollectionDataProps {
44
/**
@@ -40,7 +40,7 @@ export interface IFieldCollectionDataProps {
4040
/**
4141
* The collection data value.
4242
*/
43-
value: any[];
43+
value: any[]; // eslint-disable-line @typescript-eslint/no-explicit-any
4444
/**
4545
* Specify if you want to enable sorting
4646
*/
@@ -72,9 +72,9 @@ export interface IFieldCollectionDataProps {
7272
/**
7373
* Allows you to show Search Box and specify own filtering logic.
7474
*/
75-
executeFiltering?: (searchFilter: string, item: any) => boolean;
75+
executeFiltering?: (searchFilter: string, item: any) => boolean; // eslint-disable-line @typescript-eslint/no-explicit-any
7676

77-
onChanged: (value: any[]) => void;
77+
onChanged: (value: any[]) => void; // eslint-disable-line @typescript-eslint/no-explicit-any
7878
}
7979

8080
export interface IFieldCollectionDataState {

src/controls/fieldCollectionData/collectionDataItem/CollectionDataItem.tsx

+30-27
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,31 @@
11
import * as React from 'react';
22
import styles from '../FieldCollectionData.module.scss';
3-
import { ICollectionDataItemProps, ICollectionDataItemState } from '.';
3+
import { ICollectionDataItemProps } from './ICollectionDataItemProps';
4+
import { ICollectionDataItemState } from './ICollectionDataItemState';
45
import { TextField } from 'office-ui-fabric-react/lib/components/TextField';
56
import { Icon } from 'office-ui-fabric-react/lib/components/Icon';
67
import { Link } from 'office-ui-fabric-react/lib/components/Link';
78
import { Checkbox } from 'office-ui-fabric-react/lib/components/Checkbox';
89
import * as strings from 'ControlStrings';
9-
import { ICustomCollectionField, CustomCollectionFieldType, FieldValidator } from '..';
10+
import { CustomCollectionFieldType, ICustomCollectionField } from '../ICustomCollectionField';
1011
import { Dropdown, IDropdownOption } from 'office-ui-fabric-react/lib/components/Dropdown';
1112
import { Callout, DirectionalHint } from 'office-ui-fabric-react/lib/components/Callout';
1213
import { CollectionIconField } from '../collectionIconField';
1314
import { clone, findIndex, sortBy } from '@microsoft/sp-lodash-subset';
1415
import { CollectionNumberField } from '../collectionNumberField';
1516
import { Guid } from '@microsoft/sp-core-library';
17+
import { FieldValidator } from '../FieldValidator';
1618

1719
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
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 = /(http|https)?:\/\/(www\.)?[-a-zA-Z0-9@:%._\+~#=]{2,256}\.[a-z]{2,6}\b([-a-zA-Z0-9@:%_\+.~#?&\/\/=]*)/;
245+
const regEx: RegExp = /(http|https)?:\/\/(www\.)?[-a-zA-Z0-9@:%._+~#=]{2,256}\.[a-z]{2,6}\b([-a-zA-Z0-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}

src/controls/fieldCollectionData/collectionDataItem/ICollectionDataItemProps.ts

+4-2
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,18 @@
1-
import { ICustomCollectionField } from "..";
1+
import { ICustomCollectionField } from "../ICustomCollectionField";
22

33
export interface ICollectionDataItemProps {
44
fields: ICustomCollectionField[];
55
index?: number;
6-
item?: any;
6+
item?: any; // eslint-disable-line @typescript-eslint/no-explicit-any
77
sortingEnabled?: boolean;
88
totalItems?: number;
99
disableItemDeletion?: boolean;
1010

11+
/* eslint-disable @typescript-eslint/no-explicit-any */
1112
fAddItem?: (item: any) => void;
1213
fAddInCreation?: (item: any) => void;
1314
fUpdateItem?: (idx: number, item: any) => void;
15+
/* eslint-enable @typescript-eslint/no-explicit-any */
1416
fDeleteItem?: (idx: number) => void;
1517
fValidation?: (idx: number, isValid: boolean) => void;
1618
fOnSorting?: (oldIdx: number, newIdx: number) => void;
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import { ErrorMsg } from ".";
1+
import { ErrorMsg } from "./ErrorMsg";
22

33
export interface ICollectionDataItemState {
4-
crntItem: any;
4+
crntItem: any; // eslint-disable-line @typescript-eslint/no-explicit-any
55
errorMsgs?: ErrorMsg[];
66
showCallout?: boolean;
77
}

0 commit comments

Comments
 (0)