Skip to content

Commit 07a0d21

Browse files
committed
FieldCollectionData enhancements
1 parent 085ceea commit 07a0d21

File tree

8 files changed

+300
-24
lines changed

8 files changed

+300
-24
lines changed

docs/documentation/docs/controls/FieldCollectionData.md

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ The `FieldCollectionData` control can be configured with the following propertie
9696
| saveAndAddBtnLabel | string | yes | Label of the save and add button. | |
9797
| cancelBtnLabel | string | yes | Label of the cancel button. | |
9898
| fields | ICustomCollectionField[] | yes | The fields to be used for the list of collection data. | |
99-
| value | string | yes | The collection data value. | |
99+
| value | any[] | yes | The collection data value. | |
100100
| enableSorting | boolean | no | Specify if you want to be able to sort the items in the collection. | false |
101101
| disabled | boolean | no | Specify if the control is disabled. | false |
102102
| disableItemCreation | boolean | no | Allows you to specify if user can create new items. | false |
@@ -106,6 +106,9 @@ The `FieldCollectionData` control can be configured with the following propertie
106106
| itemsPerPage | number | no | Allows you to specify the amount of items displayed per page. Paging control is added automatically. | |
107107
| executeFiltering | (searchFilter: string, item: any) => boolean | no | Allows you to show Search Box and specify own filtering logic. | |
108108
| panelProps | IPanelProps | no | Allows you to pass in props of the panel such as type and customWidth to control the underlying panel. | |
109+
| context | WebpartContext | no | Needed if **peoplepicker** field type is used | |
110+
| usePanel | boolean | no | Specify if you want the control to opened in a panel or directly on the page | true |
111+
| noDataMessage | string | no | Specify the message when no items are added to the collection ||
109112

110113
Interface `ICustomCollectionField`
111114

@@ -116,13 +119,18 @@ Interface `ICustomCollectionField`
116119
| type | CustomCollectionFieldType | yes | Specifies the type of field to render. |
117120
| disableEdit | boolean | no | Allows you to specify if a field is disabled for editing. |
118121
| required | boolean | no | Specify if the field is required. |
119-
| options | [IDropdownOption[]](https://developer.microsoft.com/en-us/fabric#/components/dropdown) | no | Dropdown options. Only necessary when dropdown type is used. |
122+
| options | [IDropdownOption[]](https://developer.microsoft.com/en-us/fabric#/components/dropdown) [IComboboxOption[]](https://developer.microsoft.com/en-us/fluentui#/controls/web/combobox) | no | Dropdown options. Only necessary when dropdown or combobox type is used. |
120123
| onRenderOption | IRenderFunction<ISelectableOption> | no | Dropdown custom options render method. Only for the **dropdown** field type. |
121124
| placeholder | string | no | Placehoder text which will be used for the input field. If not provided the input title will be used. |
122125
| defaultValue | any | no | Specify a default value for the input field. |
123126
| deferredValidationTime | number | no | Field will start to validate after users stop typing for `deferredValidationTime` milliseconds. Default: 200ms. |
124127
| onGetErrorMessage | (value: any, index: number, crntItem: any): string \| Promise<string> | no | The method is used to get the validation error message and determine whether the input value is valid or not. It provides you the current row index and the item you are currently editing. |
125128
| onCustomRender | (field: ICustomCollectionField, value: any, onUpdate: (fieldId: string, value: any) => void, item: any, itemUniqueId: string, onCustomFieldValidation: (fieldId: string, errorMessage: string) => void) => JSX.Element | no | This property is only required if you are using the `custom` field type and it can be used to specify the custom rendering of your control in the collection data. |
129+
| multiSelect | boolean| no | Specifies multiple options can be selected (**combobox**) or mutliple users can be selected (**peoplepicker**) |
130+
| allowFreeform | boolean | no | Specifies that own options can be entered. Only for **combobox** field type |
131+
| minimumUsers| number | no | Specifies the minimum number of users to has to be entered for **peoplepicker** field type |
132+
| minimumUsersMessage| string | no | Specifies the message to be displayed if minimumUsers are not entered for **peoplepicker** field type |
133+
| maximumUsers | number | no | Specifies the maximum number of users to be entered for **peoplepicker** field type |
126134

127135
Enum `CustomCollectionFieldType`
128136

@@ -132,8 +140,10 @@ Enum `CustomCollectionFieldType`
132140
| number | Number field |
133141
| boolean | Checkbox |
134142
| dropdown | Dropdown field. You will have to specify the `options` property when using this field type |
143+
| combobox | Combobox field. You wil have to specify the `options` property, optional specify `allowFreeform` and `multiSelect` |
135144
| fabricIcon | Name of the [Office UI Fabric icon](https://developer.microsoft.com/en-us/fabric#/styles/icons) |
136145
| url | URL field |
146+
| peoplepicker | Peoplepicker control |
137147
| custom | This gives you control over the whole field rendering. Be sure to provide the `onCustomRender` method to render your control in the collection data. |
138148

139149
![](https://telemetry.sharepointpnp.com/sp-dev-fx-property-controls/wiki/FieldCollectionData)

src/controls/fieldCollectionData/FieldCollectionData.module.scss

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,3 +177,7 @@
177177
border-bottom: 1px solid $ms-color-neutralTertiary;
178178
}
179179
}
180+
181+
.peoplePicker {
182+
background-color: #fff;
183+
}

src/controls/fieldCollectionData/FieldCollectionData.tsx

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -48,26 +48,36 @@ export class FieldCollectionData extends React.Component<IFieldCollectionDataPro
4848
}
4949

5050
public render(): JSX.Element {
51+
const _element: JSX.Element = this.getElement()
5152
return (
53+
_element
54+
);
55+
}
56+
57+
private getElement(): JSX.Element {
58+
const _element: JSX.Element = typeof this.props.usePanel === "boolean" && this.props.usePanel === false
59+
?
60+
<CollectionDataViewer {...this.props} fOnSave={this.onSave} fOnClose={this.closePanel} />
61+
:
5262
<div>
5363
<Label>{this.props.label}</Label>
5464

5565
<DefaultButton text={this.props.manageBtnLabel}
56-
onClick={this.openPanel}
57-
disabled={this.props.fields.length === 0 || this.props.disabled} />
66+
onClick={this.openPanel}
67+
disabled={this.props.fields.length === 0 || this.props.disabled} />
5868

5969
{
6070
(!this.props.fields || this.props.fields.length === 0) && //<FieldErrorMessage errorMessage={strings.CollectionDataEmptyFields} />
6171
<MessageBar messageBarType={MessageBarType.error}>{strings.CollectionDataItemMissingFields}</MessageBar>
6272
}
6373

6474
<Panel isOpen={this.state.panelOpen}
65-
onDismiss={this.closePanel}
66-
type={PanelType.large}
67-
headerText={this.props.panelHeader}
68-
onOuterClick={()=>{ /* no-op; */}}
69-
className={`FieldCollectionData__panel ${this.props.panelClassName || ""}`}
70-
{ ...this.props.panelProps ?? {}} >
75+
onDismiss={this.closePanel}
76+
type={PanelType.large}
77+
headerText={this.props.panelHeader}
78+
onOuterClick={()=>{ /* no-op; */}}
79+
className={`FieldCollectionData__panel ${this.props.panelClassName || ""}`}
80+
{ ...this.props.panelProps ?? {}} >
7181
{
7282
this.props.panelDescription && (
7383
<p className="FieldCollectionData__panel__description">{this.props.panelDescription}</p>
@@ -77,6 +87,7 @@ export class FieldCollectionData extends React.Component<IFieldCollectionDataPro
7787
<CollectionDataViewer {...this.props} fOnSave={this.onSave} fOnClose={this.closePanel} />
7888
</Panel>
7989
</div>
80-
);
90+
91+
return _element;
8192
}
8293
}

src/controls/fieldCollectionData/ICustomCollectionField.ts

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { IDropdownOption } from 'office-ui-fabric-react/lib/Dropdown';
22
import { IRenderFunction } from '@uifabric/utilities/lib/IRenderFunction';
33
import { ISelectableOption } from 'office-ui-fabric-react/lib/utilities/selectableOption/SelectableOption.types';
4+
import { IComboBoxOption } from 'office-ui-fabric-react';
45

56
export interface ICustomCollectionField {
67
/**
@@ -24,9 +25,17 @@ export interface ICustomCollectionField {
2425
*/
2526
required?: boolean;
2627
/**
27-
* Dropdown options. Only nescessary when dropdown type is used.
28+
* Dropdown / combobox options. Only nescessary when dropdown or combobox type is used.
2829
*/
29-
options?: IDropdownOption[];
30+
options?: IDropdownOption[] | IComboBoxOption[];
31+
/**
32+
* Whether multiple options can be selcted. Only when combobox or peoplepicker is used. Defaults to false (combobox) and true (peoplepicker)
33+
*/
34+
multiSelect?: boolean
35+
/**
36+
* Whether own options can be added. Only when combobox is used. Defaults to false
37+
*/
38+
allowFreeform?: boolean
3039
/**
3140
* Dropdown custom options render method.
3241
*/
@@ -35,6 +44,18 @@ export interface ICustomCollectionField {
3544
* Input placeholder text.
3645
*/
3746
placeholder?: string;
47+
/**
48+
* Minimum users to be selected. Only when people picker is used.
49+
*/
50+
minimumUsers?: number;
51+
/**
52+
* The message to be displayed when minimum users is not met. Only when people picker is used. If omitted, the default value is displayed
53+
*/
54+
minimumUsersMessage?: string;
55+
/**
56+
* Maximum users to be selected. Only when people picker is used.
57+
*/
58+
maximumUsers?: number;
3859
/**
3960
* Default value for the field
4061
*/
@@ -50,7 +71,7 @@ export interface ICustomCollectionField {
5071
* - If valid, it returns empty string.
5172
* - If invalid, the field will show a red border
5273
*/
53-
onGetErrorMessage?: (value: any, index: number, currentItem: any) => string | Promise<string>; // eslint-disable-line @typescript-eslint/no-explicit-any
74+
onGetErrorMessage?: (value: any, index: number, currentItem: any) => string | Promise<string>; // eslint-disable-line @typescript-eslint/no-explicit-any
5475

5576
/**
5677
* Custom field rendering support
@@ -72,6 +93,8 @@ export enum CustomCollectionFieldType {
7293
number,
7394
boolean,
7495
dropdown,
96+
combobox,
97+
peoplepicker,
7598
fabricIcon,
7699
url,
77100
custom

src/controls/fieldCollectionData/IFieldCollectionData.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { BaseComponentContext } from "@microsoft/sp-component-base";
12
import { ICustomCollectionField } from "./ICustomCollectionField";
23
import { IPanelProps } from "office-ui-fabric-react";
34

@@ -80,6 +81,19 @@ export interface IFieldCollectionDataProps {
8081
executeFiltering?: (searchFilter: string, item: any) => boolean; // eslint-disable-line @typescript-eslint/no-explicit-any
8182

8283
onChanged: (value: any[]) => void; // eslint-disable-line @typescript-eslint/no-explicit-any
84+
/**
85+
* Used for CustomCollectionFieldType peoplepicker
86+
*/
87+
context?: BaseComponentContext;
88+
/**
89+
* Show the collectionDataViewer inside the panel, defaults to true
90+
*/
91+
usePanel?: boolean;
92+
/**
93+
* The message when no data is added
94+
*/
95+
noDataMessage?: string;
96+
8397
}
8498

8599
export interface IFieldCollectionDataState {

0 commit comments

Comments
 (0)