@@ -10,7 +10,7 @@ import * as telemetry from '../../common/telemetry';
10
10
import isEqual from 'lodash/isEqual' ;
11
11
import { ITag } from 'office-ui-fabric-react/lib/components/pickers/TagPicker/TagPicker.types' ;
12
12
import { SPHelper } from '../../common/utilities/SPHelper' ;
13
-
13
+ import { Guid } from "@microsoft/sp-core-library"
14
14
15
15
export class ListItemPicker extends React . Component < IListItemPickerProps , IListItemPickerState > {
16
16
private _spservice : SPservice ;
@@ -27,17 +27,33 @@ export class ListItemPicker extends React.Component<IListItemPickerProps, IListI
27
27
showError : false ,
28
28
errorMessage : "" ,
29
29
suggestionsHeaderText : ! this . props . suggestionsHeaderText ? strings . ListItemPickerSelectValue : this . props . suggestionsHeaderText ,
30
- selectedItems : props . defaultSelectedItems || [ ]
30
+ selectedItems : props . defaultSelectedItems || [ ] ,
31
+ safeListId : props . listId ,
31
32
} ;
32
33
33
34
// Get SPService Factory
34
35
this . _spservice = new SPservice ( this . props . context ) ;
35
36
}
36
37
37
- public componentDidMount ( ) : void {
38
+ private ensureLoadField ( ) : void {
38
39
this . loadField ( this . props ) . then ( ( ) => { /* no-op; */ } ) . catch ( ( ) => { /* no-op; */ } ) ;
39
40
}
40
41
42
+ public componentDidMount ( ) : void {
43
+ // Ensure list ID if a list name is passed in listId parameter
44
+ if ( ! Guid . tryParse ( this . props . listId ) ) {
45
+ this . _spservice . getListId ( this . props . listId )
46
+ . then ( ( value ) => {
47
+ this . setState ( { ...this . state ,
48
+ safeListId : value } ) ;
49
+ this . ensureLoadField ( ) ;
50
+ } )
51
+ . catch ( ( ) => { /* no-op; */ } ) ;
52
+ } else {
53
+ this . ensureLoadField ( ) ;
54
+ }
55
+ }
56
+
41
57
public UNSAFE_componentWillReceiveProps ( nextProps : IListItemPickerProps ) : void {
42
58
let newSelectedItems : any [ ] | undefined ; // eslint-disable-line @typescript-eslint/no-explicit-any
43
59
if ( this . props . listId !== nextProps . listId ) {
@@ -54,8 +70,8 @@ export class ListItemPicker extends React.Component<IListItemPickerProps, IListI
54
70
if ( this . props . listId !== nextProps . listId
55
71
|| this . props . columnInternalName !== nextProps . columnInternalName
56
72
|| this . props . webUrl !== nextProps . webUrl ) {
57
- this . loadField ( nextProps ) . then ( ( ) => { /* no-op; */ } ) . catch ( ( ) => { /* no-op; */ } ) ;
58
- }
73
+ this . ensureLoadField ( ) ;
74
+ }
59
75
}
60
76
61
77
/**
@@ -158,15 +174,15 @@ export class ListItemPicker extends React.Component<IListItemPickerProps, IListI
158
174
* Function to load List Items
159
175
*/
160
176
private loadListItems = async ( filterText : string ) : Promise < { key : string ; name : string } [ ] > => {
161
- const { listId , columnInternalName, keyColumnInternalName, webUrl, filter, orderBy, substringSearch } = this . props ;
177
+ const { columnInternalName, keyColumnInternalName, webUrl, filter, orderBy, substringSearch } = this . props ;
162
178
const {
163
- field
179
+ field, safeListId
164
180
} = this . state ;
165
181
const arrayItems : { key : string ; name : string } [ ] = [ ] ;
166
182
const keyColumn : string = keyColumnInternalName || 'Id' ;
167
183
168
184
try {
169
- const listItems = await this . _spservice . getListItems ( filterText , listId , columnInternalName , field , keyColumn , webUrl , filter , substringSearch , orderBy ? orderBy : '' ) ; // JJ - 20200613 - find by substring as an option
185
+ const listItems = await this . _spservice . getListItems ( filterText , safeListId , columnInternalName , field , keyColumn , webUrl , filter , substringSearch , orderBy ? orderBy : '' ) ; // JJ - 20200613 - find by substring as an option
170
186
// Check if the list had items
171
187
if ( listItems . length > 0 ) {
172
188
for ( const item of listItems ) {
@@ -190,7 +206,7 @@ export class ListItemPicker extends React.Component<IListItemPickerProps, IListI
190
206
field : undefined
191
207
} ) ;
192
208
193
- const field = await this . _spservice . getField ( props . listId , props . columnInternalName , props . webUrl ) ;
209
+ const field = await this . _spservice . getField ( this . state . safeListId , props . columnInternalName , props . webUrl ) ;
194
210
195
211
this . setState ( {
196
212
field
0 commit comments