Skip to content

Commit 658d3f7

Browse files
committed
Merge branch 'thespooler-listview-state-fix' into dev
2 parents 3a3ed4f + 54ba9f4 commit 658d3f7

File tree

1 file changed

+36
-15
lines changed

1 file changed

+36
-15
lines changed

src/controls/listView/ListView.tsx

Lines changed: 36 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ import * as telemetry from '../../common/telemetry';
1515
import { Icon } from 'office-ui-fabric-react/lib/Icon';
1616

1717
import filter from 'lodash/filter';
18+
import omit from 'lodash/omit';
19+
import functions from 'lodash/functions';
1820
import { SearchBox } from 'office-ui-fabric-react/lib/SearchBox';
1921
import { Guid } from '@microsoft/sp-core-library';
2022

@@ -90,7 +92,7 @@ export class ListView extends React.Component<IListViewProps, IListViewState> {
9092
* Lifecycle hook when component is mounted
9193
*/
9294
public componentDidMount(): void {
93-
this._processProperties();
95+
this._processProperties(this.props);
9496
}
9597

9698
public componentWillUnmount(): void {
@@ -109,29 +111,37 @@ export class ListView extends React.Component<IListViewProps, IListViewState> {
109111
* @param prevProps
110112
* @param prevState
111113
*/
112-
public componentDidUpdate(prevProps: IListViewProps, prevState: IListViewState): void {
114+
public componentWillReceiveProps(nextProps: IListViewProps): void {
113115

114-
if (!isEqual(prevProps, 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)) {
117120
// Reset the selected items
118121
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+
}
120130
}
121131
// Process list view properties
122-
this._processProperties();
132+
this._processProperties(nextProps);
123133
}
124134
}
125135

126136
/**
127137
* Select all the items that should be selected by default
128138
*/
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) {
135145
if (index > -1) {
136146
this._selection.setIndexSelected(index, true, false);
137147
}
@@ -224,8 +234,8 @@ export class ListView extends React.Component<IListViewProps, IListViewState> {
224234
/**
225235
* Process all the component properties
226236
*/
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;
229239

230240
let tempState: IListViewState = cloneDeep(this.state);
231241
let columns: IColumn[] = null;
@@ -550,6 +560,17 @@ export class ListView extends React.Component<IListViewProps, IListViewState> {
550560
return result;
551561
}
552562

563+
private _filterFunctions(p: IListViewProps) {
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;
572+
}
573+
553574
/**
554575
* Stop listeners from onDragOver event.
555576
* @param e

0 commit comments

Comments
 (0)