Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
componentWillReceiveProps(nextProps) {
checkPropChange(this.props.react, nextProps.react, () => {
this.setReact(nextProps);
});
checkSomePropChange(this.props, nextProps, ['dataField', 'nestedField'], () => {
this.updateQuery(this.state.currentValue, nextProps);
});
if (this.props.defaultSelected !== nextProps.defaultSelected) {
this.setValue(nextProps.defaultSelected, true, nextProps);
} else if (
// since, selectedValue will be updated when currentValue changes,
// we must only check for the changes introduced by
// clear action from SelectedFilters component in which case,
// the currentValue will never match the updated selectedValue
this.props.selectedValue !== nextProps.selectedValue
&& this.state.currentValue !== nextProps.selectedValue
) {
this.setValue(nextProps.selectedValue || '', true, nextProps);
}
}
componentDidUpdate(prevProps) {
checkSomePropChange(this.props, prevProps, getValidPropsKeys(this.props), () => {
this.props.updateComponentProps(this.props.componentId, this.props);
});
checkPropChange(this.props.react, prevProps.react, () => this.setReact(this.props));
checkPropChange(this.props.options, prevProps.options, () => {
const { showLoadMore, dataField, options } = this.props;
if (showLoadMore) {
const { buckets } = options[dataField];
const after = options[dataField].after_key;
const prevAfter = prevProps.options && prevProps.options[dataField].after_key;
// detect the last bucket by checking if the after key is absent
const isLastBucket = !after;
this.setState(
state => ({
...state,
prevAfter: prevAfter ? { after: prevAfter } : state.prevAfter,
after: after ? { after } : state.after,
componentDidUpdate(prevProps) {
checkSomePropChange(this.props, prevProps, getValidPropsKeys(this.props), () => {
this.props.updateComponentProps(this.props.componentId, this.props);
});
checkPropChange(this.props.react, prevProps.react, () => {
this.setReact(this.props);
});
checkSomePropChange(this.props, prevProps, ['dataField', 'nestedField'], () => {
this.updateQuery(this.state.currentValue, this.props);
});
if (!isEqual(this.props.value, prevProps.value)) {
this.handleToggle(this.props.value, true, this.props);
} else if (this.props.multiSelect) {
// for multiselect selectedValue will be an array
if (
!isEqual(this.state.currentValue, this.props.selectedValue)
&& !isEqual(prevProps.selectedValue, this.props.selectedValue)
) {
const { value, onChange } = this.props;
if (value === undefined) {
this.handleToggle(this.props.selectedValue || [], true, this.props);
} else if (onChange) {
// value prop exists
if (value.length) this.setValue(value, true);
},
);
}
});
// Treat defaultQuery and customQuery as reactive props
if (!isIdentical(this.props.defaultQuery, prevProps.defaultQuery)) {
this.updateDefaultQuery();
this.updateQuery([], this.props);
}
if (!isIdentical(this.props.customQuery, prevProps.customQuery)) {
this.updateQuery(Object.keys(this.state.currentValue), this.props);
}
checkSomePropChange(this.props, prevProps, ['size', 'sortBy'], () =>
this.updateQueryOptions(this.props),
);
checkPropChange(this.props.dataField, prevProps.dataField, () => {
this.updateQueryOptions(this.props);
this.updateQuery(Object.keys(this.state.currentValue), this.props);
});
let selectedValue = Object.keys(this.state.currentValue);
const { selectAllLabel } = this.props;
if (selectAllLabel) {
selectedValue = selectedValue.filter(val => val !== selectAllLabel);
if (this.state.currentValue[selectAllLabel]) {
selectedValue = [selectAllLabel];
}
componentDidUpdate(prevProps) {
checkSomePropChange(this.props, prevProps, getValidPropsKeys(this.props), () => {
this.props.updateComponentProps(this.props.componentId, this.props);
});
checkPropChange(this.props.react, prevProps.react, () => this.setReact(this.props));
checkSomePropChange(this.props, prevProps, ['dataField', 'nestedField'], () => {
this.updateQuery(this.state.currentValue, prevProps);
});
if (!isEqual(this.props.value, prevProps.value)) {
this.setValue(this.props.value, true);
} else if (
!isEqual(this.state.currentValue, this.props.selectedValue)
&& !isEqual(this.props.selectedValue, prevProps.selectedValue)
) {
const { value, onChange } = this.props;
if (value === undefined) {
componentWillReceiveProps(nextProps) {
checkPropChange(this.props.react, nextProps.react, () => this.setReact(nextProps));
checkPropChange(this.props.options, nextProps.options, () => {
this.setState({
options: nextProps.options[nextProps.dataField]
? nextProps.options[nextProps.dataField].buckets
: [],
});
});
checkSomePropChange(this.props, nextProps, ['size', 'sortBy'], () =>
this.updateQueryOptions(nextProps),
);
checkPropChange(this.props.dataField, nextProps.dataField, () => {
this.updateQueryOptions(nextProps);
this.updateQuery(Object.keys(this.state.currentValue), nextProps);
});
let selectedValue = Object.keys(this.state.currentValue);
if (this.props.selectAllLabel) {
selectedValue = selectedValue.filter(val => val !== this.props.selectAllLabel);
if (this.state.currentValue[this.props.selectAllLabel]) {
selectedValue = [this.props.selectAllLabel];
}
componentDidUpdate(prevProps) {
checkSomePropChange(this.props, prevProps, getValidPropsKeys(this.props), () => {
this.props.updateComponentProps(this.props.componentId, this.props);
});
checkPropChange(this.props.react, prevProps.react, () => this.setReact(this.props));
checkSomePropChange(this.props, prevProps, ['dataField', 'nestedField'], () => {
this.updateQuery(this.state.currentValue, prevProps);
});
if (!isEqual(this.props.value, prevProps.value)) {
this.setValue(this.props.value, true);
} else if (
!isEqual(this.state.currentValue, this.props.selectedValue)
&& !isEqual(this.props.selectedValue, prevProps.selectedValue)
) {
const { value, onChange } = this.props;
if (value === undefined) {
this.setValue(this.props.selectedValue || null, true);
} else if (onChange) {
onChange(this.props.selectedValue || null);
} else {
const selectedItem = this.state.currentValue.label;
componentDidUpdate(prevProps) {
checkSomePropChange(this.props, prevProps, getValidPropsKeys(this.props), () => {
this.props.updateComponentProps(this.props.componentId, this.props);
});
checkPropChange(this.props.react, prevProps.react, () => this.setReact(this.props));
checkSomePropChange(this.props, prevProps, ['dataField', 'nestedField'], () => {
this.updateQuery(Object.keys(this.state.currentValue), this.props);
if (this.props.showCount) {
this.updateQueryOptions(this.props);
}
});
checkPropChange(this.props.data, prevProps.data, () => {
if (this.props.showCount) {
this.updateQueryOptions(this.props);
}
});
checkPropChange(this.props.options, prevProps.options, () => {
if (this.props.options[this.props.dataField]) {
this.updateStateOptions(this.props.options[this.props.dataField].buckets);
componentDidUpdate(prevProps) {
checkSomePropChange(this.props, prevProps, getValidPropsKeys(this.props), () => {
this.props.updateComponentProps(this.props.componentId, this.props);
});
checkPropChange(this.props.react, prevProps.react, () => this.setReact(this.props));
checkSomePropChange(this.props, prevProps, ['dataField', 'nestedField'], () => {
this.updateQuery(this.state.currentValue, this.props);
});
if (!isEqual(this.props.value, prevProps.value)) {
this.setValue(this.props.value);
} else if (
!isEqual(this.state.currentValue, this.props.selectedValue)
&& !isEqual(this.props.selectedValue, prevProps.selectedValue)
) {
const { value, onChange } = this.props;
if (value === undefined) {
this.setValue(this.props.selectedValue || null);
} else if (onChange) {
onChange(this.props.selectedValue || null);
} else {
this.setValue(this.state.currentValue);
componentDidUpdate(prevProps) {
const totalPages = Math.ceil(this.props.total / this.props.size) || 0;
checkSomePropChange(this.props, prevProps, getValidPropsKeys(this.props), () => {
this.props.updateComponentProps(this.props.componentId, this.props);
});
if (this.props.onData) {
checkSomePropChange(
this.props,
prevProps,
['hits', 'streamHits', 'promotedResults', 'total', 'size', 'time'],
() => {
this.props.onData(this.getData());
},
);
}
if (
!isEqual(this.props.sortOptions, prevProps.sortOptions)
|| this.props.sortBy !== prevProps.sortBy
|| this.props.size !== prevProps.size