Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
public UNSAFE_componentWillReceiveProps(nextProps: Readonly): void {
const old = this.props;
const {
files, folderChain, onSelectionChange, disableSelection,
view, options, sortProperty, sortOrder,
} = nextProps;
let selectionStatus = SelectionStatus.Ok;
if (!shallowEqualArrays(files, old.files)) {
selectionStatus = SelectionStatus.NeedsCleaning;
this.setState({rawFiles: files});
}
if (!shallowEqualArrays(folderChain, old.folderChain)) {
if (!isArray(folderChain) || getNonNil(folderChain, -1) !== getNonNil(old.folderChain, -1)) {
selectionStatus = SelectionStatus.NeedsResetting;
}
this.setState({folderChain});
}
if (disableSelection === true && disableSelection !== old.disableSelection) {
selectionStatus = SelectionStatus.NeedsResetting;
}
if (!isNil(view) && view !== old.view) this.setState({view});
if (isObject(options) && options !== old.options) {
this.setState(prevState => ({options: {...prevState.options, ...options}}));
public componentDidUpdate(prevProps: Readonly, prevState: Readonly): void {
const {onSelectionChange} = this.props;
const {
rawFiles: oldRawFiles, selection: oldSelection, options: oldOptions,
sortProperty: oldSortProperty, sortOrder: oldSortOrder,
} = prevState;
const {rawFiles, selection, options, sortProperty, sortOrder} = this.state;
let justChangedSelection = false;
const needToResort = !shallowEqualArrays(rawFiles, oldRawFiles)
|| !shallowEqualObjects(options, oldOptions)
|| sortProperty !== oldSortProperty
|| sortOrder !== oldSortOrder;
if (needToResort) {
const [sortedFiles, fileIndexMap] = FileUtil.sortFiles(rawFiles, options, sortProperty, sortOrder);
const newState: Partial = {sortedFiles, fileIndexMap};
const newSelection = {};
let additionCount = 0;
for (const file of sortedFiles) {
if (isNil(file) || selection[file.id] !== true) continue;
newSelection[file.id] = true;
additionCount++;
}
if (additionCount !== Object.keys(selection).length) {
newState.selection = newSelection;
public UNSAFE_componentWillReceiveProps(nextProps: Readonly): void {
const old = this.props;
const {
files, folderChain, onSelectionChange, disableSelection,
view, options, sortProperty, sortOrder,
} = nextProps;
let selectionStatus = SelectionStatus.Ok;
if (!shallowEqualArrays(files, old.files)) {
selectionStatus = SelectionStatus.NeedsCleaning;
this.setState({rawFiles: files});
}
if (!shallowEqualArrays(folderChain, old.folderChain)) {
if (!isArray(folderChain) || getNonNil(folderChain, -1) !== getNonNil(old.folderChain, -1)) {
selectionStatus = SelectionStatus.NeedsResetting;
}
this.setState({folderChain});
}
if (disableSelection === true && disableSelection !== old.disableSelection) {
selectionStatus = SelectionStatus.NeedsResetting;
}
if (!isNil(view) && view !== old.view) this.setState({view});
if (isObject(options) && options !== old.options) {
this.setState(prevState => ({options: {...prevState.options, ...options}}));
}
if (!isNil(sortProperty) && sortProperty !== old.sortProperty) this.setState({sortProperty});
if (!isNil(sortOrder) && sortOrder !== old.sortOrder) this.setState({sortOrder});