@@ -15,6 +15,8 @@ import * as telemetry from '../../common/telemetry';
15
15
import { Icon } from 'office-ui-fabric-react/lib/Icon' ;
16
16
17
17
import filter from 'lodash/filter' ;
18
+ import omit from 'lodash/omit' ;
19
+ import functions from 'lodash/functions' ;
18
20
import { SearchBox } from 'office-ui-fabric-react/lib/SearchBox' ;
19
21
import { Guid } from '@microsoft/sp-core-library' ;
20
22
@@ -90,7 +92,7 @@ export class ListView extends React.Component<IListViewProps, IListViewState> {
90
92
* Lifecycle hook when component is mounted
91
93
*/
92
94
public componentDidMount ( ) : void {
93
- this . _processProperties ( ) ;
95
+ this . _processProperties ( this . props ) ;
94
96
}
95
97
96
98
public componentWillUnmount ( ) : void {
@@ -109,29 +111,37 @@ export class ListView extends React.Component<IListViewProps, IListViewState> {
109
111
* @param prevProps
110
112
* @param prevState
111
113
*/
112
- public componentDidUpdate ( prevProps : IListViewProps , prevState : IListViewState ) : void {
114
+ public componentWillReceiveProps ( nextProps : IListViewProps ) : void {
113
115
114
- if ( ! isEqual ( this . _filterFunctions ( prevProps ) , this . _filterFunctions ( this . props ) ) ) {
115
- // select default items
116
- this . _setSelectedItems ( ) ;
116
+ const modifiedNextProps = this . _filterFunctions ( nextProps ) ;
117
+ const modifiedProps = this . _filterFunctions ( this . props ) ;
118
+
119
+ if ( ! isEqual ( modifiedProps , modifiedNextProps ) ) {
117
120
// Reset the selected items
118
121
if ( this . _selection ) {
119
- this . _selection . setItems ( this . props . items , true ) ;
122
+ if ( ! isEqual ( modifiedNextProps . items , modifiedProps . items ) ) {
123
+ this . _selection . setItems ( nextProps . items , true ) ;
124
+ }
125
+ if ( ! isEqual ( modifiedNextProps . defaultSelection , modifiedProps . defaultSelection ) ) {
126
+ this . _selection . setAllSelected ( false ) ;
127
+ // select default items
128
+ this . _setSelectedItems ( nextProps ) ;
129
+ }
120
130
}
121
131
// Process list view properties
122
- this . _processProperties ( ) ;
132
+ this . _processProperties ( nextProps ) ;
123
133
}
124
134
}
125
135
126
136
/**
127
137
* Select all the items that should be selected by default
128
138
*/
129
- private _setSelectedItems ( ) : void {
130
- if ( this . props . items &&
131
- this . props . items . length > 0 &&
132
- this . props . defaultSelection &&
133
- this . props . defaultSelection . length > 0 ) {
134
- for ( const index of this . props . defaultSelection ) {
139
+ private _setSelectedItems ( props : IListViewProps ) : void {
140
+ if ( props . items &&
141
+ props . items . length > 0 &&
142
+ props . defaultSelection &&
143
+ props . defaultSelection . length > 0 ) {
144
+ for ( const index of props . defaultSelection ) {
135
145
if ( index > - 1 ) {
136
146
this . _selection . setIndexSelected ( index , true , false ) ;
137
147
}
@@ -224,8 +234,8 @@ export class ListView extends React.Component<IListViewProps, IListViewState> {
224
234
/**
225
235
* Process all the component properties
226
236
*/
227
- private _processProperties ( ) {
228
- const { dragDropFiles, items, iconFieldName, viewFields, groupByFields, showFilter } = this . props ;
237
+ private _processProperties ( props : IListViewProps ) {
238
+ const { dragDropFiles, items, iconFieldName, viewFields, groupByFields, showFilter } = props ;
229
239
230
240
let tempState : IListViewState = cloneDeep ( this . state ) ;
231
241
let columns : IColumn [ ] = null ;
@@ -550,14 +560,15 @@ export class ListView extends React.Component<IListViewProps, IListViewState> {
550
560
return result ;
551
561
}
552
562
553
- private _filterRenderFunction ( f : IViewField ) {
554
- const { render, ...fields } = f ;
555
- return fields ;
556
- }
557
-
558
563
private _filterFunctions ( p : IListViewProps ) {
559
- const { selection : s , viewFields : v , ...otherProps } = p ;
560
- return { ...otherProps , viewFields : ( v || [ ] ) . map ( this . _filterRenderFunction ) } ;
564
+ const modifiedProps = omit ( p , functions ( p ) ) ;
565
+ if ( modifiedProps . items ) {
566
+ modifiedProps . items = modifiedProps . items . map ( i => omit ( i , functions ( i ) ) ) ;
567
+ }
568
+ if ( modifiedProps . viewFields ) {
569
+ modifiedProps . viewFields = modifiedProps . viewFields . map ( vf => omit ( vf , functions ( vf ) ) as IViewField ) ;
570
+ }
571
+ return modifiedProps ;
561
572
}
562
573
563
574
/**
0 commit comments