web: components: row: added custom shouldComponentUpdate function

This commit is contained in:
Andrey Savihin 2019-11-19 14:33:33 +03:00
parent b71faa8cb1
commit 325a42f66b
3 changed files with 22 additions and 2 deletions

View File

@ -39,6 +39,7 @@ import {
deleteUser
} from "../../../../../store/services/api";
import { isMobileOnly } from "react-device-detect";
import isEqual from "lodash/isEqual";
class SectionBodyContent extends React.PureComponent {
constructor(props) {
@ -461,6 +462,19 @@ class SectionBodyContent extends React.PureComponent {
});
};
needForUpdate = (currentProps, nextProps) => {
if (currentProps.checked !== nextProps.checked) {
return true;
}
if (currentProps.status !== nextProps.status) {
return true;
}
if (!isEqual(currentProps.data, nextProps.data)) {
return true;
}
return false;
};
render() {
console.log("Home SectionBodyContent render()");
const { users, viewer, selection, history, settings, t } = this.props;
@ -494,6 +508,7 @@ class SectionBodyContent extends React.PureComponent {
onSelect={this.onContentRowSelect}
{...checkedProps}
{...contextOptionsProps}
needForUpdate={this.needForUpdate}
>
<UserContent
user={user}

View File

@ -30,3 +30,4 @@ Displays content as row.
| `contextOptions` | `array` | - | | ` ` | Required to host the ContextMenuButton component. It is always located near the right border of the container, regardless of the contents of the child elements. If there is no value, the occupied space is distributed among the other child elements. |
| `data` | `object` | - | | ` ` | Current row item information. |
| `onSelect` | `function` | - | | ` ` | Event when selecting row element. Returns data value. |
| `needForUpdate` | `function` | - | | ` ` | Custom shouldComponentUpdate function |

View File

@ -58,6 +58,9 @@ const StyledOptionButton = styled.div`
class Row extends React.Component {
shouldComponentUpdate(nextProps) {
if (this.props.needForUpdate) {
return this.props.needForUpdate(this.props, nextProps);
}
return !isEqual(this.props, nextProps);
}
@ -117,7 +120,8 @@ Row.propTypes = {
children: PropTypes.element,
data: PropTypes.object,
contextOptions: PropTypes.array,
onSelect: PropTypes.func
onSelect: PropTypes.func,
needForUpdate: PropTypes.func
};
export default Row;