Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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
onChange(this.props.selectedValue || '');
} else {
// value prop exists and onChange is not defined:
// we need to put the current value back into the store
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;
this.setValue(selectedItem, true);
}
}
}
TextField.prototype.componentWillReceiveProps = function componentWillReceiveProps(nextProps) {
if (!isEqual(nextProps.react, this.props.react)) {
this.setReact(nextProps);
}
if (this.props.defaultSelected !== nextProps.defaultSelected) {
this.setValue(nextProps.defaultSelected, true);
} else if (this.state.currentValue !== nextProps.selectedValue) {
this.setValue(nextProps.selectedValue || "", true);
}
};
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);
}
}
}
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.selectItem({
item: this.props.value,
isDefaultValue: 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.selectItem({ item: this.props.selectedValue || null, isDefaultValue: true });
} else if (onChange) {
this.selectItem({
item: this.props.selectedValue || null,
});
} else {
const selectedValuesArray = Object.keys(this.state.selectedValues);
this.selectItem({
item: selectedValuesArray,
isDefaultValue: true,
});
}
componentWillReceiveProps(nextProps) {
checkPropChange(this.props.react, nextProps.react, () => this.setReact(nextProps));
checkPropChange(this.props.dataField, nextProps.dataField, () => {
this.updateQuery(this.state.currentValue, nextProps);
});
if (!isEqual(this.props.defaultSelected, nextProps.defaultSelected)) {
this.selectItem(nextProps.defaultSelected, true);
} else if (
!isEqual(this.state.currentValue, nextProps.selectedValue) &&
(nextProps.selectedValue || nextProps.selectedValue === null)
) {
this.selectItem(nextProps.selectedValue, true);
}
}
if (!isEqual(nextProps.react, this.props.react)) {
this.setReact(nextProps);
}
if (!isEqual(nextProps.options, this.props.options)) {
this.setState({
options: nextProps.options[nextProps.dataField].buckets || []
});
}
var selectedValue = Object.keys(this.state.currentValue).filter(function (item) {
return _this2.state.currentValue[item];
});
if (this.props.defaultSelected !== nextProps.defaultSelected) {
this.setValue(nextProps.defaultSelected, true);
} else if (!isEqual(selectedValue, nextProps.selectedValue)) {
this.setValue(nextProps.selectedValue, true);
}
};
componentDidUpdate(prevProps) {
const updatedState = {};
if (
this.props.sortBy !== prevProps.sortBy
|| this.props.size !== prevProps.size
|| !isEqual(this.props.dataField, prevProps.dataField)
) {
const options = getQueryOptions(this.props);
options.from = 0;
if (this.props.sortBy) {
options.sort = [
{
[this.props.dataField]: {
order: this.props.sortBy,
},
},
];
}
updatedState.from = 0;
updatedState.currentPage = 0;
this.props.setQueryOptions(this.props.componentId, options, true);
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.currentDate ? this.formatInputDate(this.state.currentDate) : null,
this.props,
),
);
if (!isEqual(this.props.value, prevProps.value)) {
this.handleDateChange(this.props.value, true, this.props);
} else if (
!isEqual(this.formatInputDate(this.state.currentDate), this.props.selectedValue)
&& !isEqual(this.props.selectedValue, prevProps.selectedValue)
) {
this.handleDateChange(this.props.selectedValue || '', true, this.props);
}
}
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];
}
}
if (!isEqual(this.props.defaultSelected, nextProps.defaultSelected)) {
this.setValue(nextProps.defaultSelected, true);
} else if (!isEqual(selectedValue, nextProps.selectedValue)) {
this.setValue(nextProps.selectedValue || [], true);
}
}