Skip to content

Commit

Permalink
fix(forms): fix disapearing changes on device state update
Browse files Browse the repository at this point in the history
  • Loading branch information
nurikk-sa committed Mar 19, 2023
1 parent 3db4ecd commit 84882cc
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 6 deletions.
4 changes: 2 additions & 2 deletions src/components/device-page/bind.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useState } from "react";
import React, { useMemo, useState } from "react";
import { Device, Cluster, Endpoint } from "../../types";
import BindRow from "./bind-row";
import actions from "../../actions/actions";
Expand Down Expand Up @@ -59,7 +59,7 @@ export function Bind(props: BindProps & PropsFromStore & BindApi): JSX.Element {
// eslint-disable-next-line @typescript-eslint/no-unused-vars
const [newBindingRule] = useState<NiceBindingRule>({ isNew: Date.now(), target: {} as BindTarget, source: { 'ieee_address': device.ieee_address, endpoint: "" }, clusters: [] })

const bidingRules = convertBindingsIntoNiceStructure(device);
const bidingRules = useMemo(() => convertBindingsIntoNiceStructure(device), [device]);
return <div className="container-fluid">
{
[...bidingRules, newBindingRule]
Expand Down
4 changes: 2 additions & 2 deletions src/components/device-page/reporting.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useState } from "react";
import React, { useMemo, useState } from "react";
import { Device, Cluster, Endpoint, Attribute } from "../../types";

import actions, { ReportingApi } from "../../actions/actions";
Expand Down Expand Up @@ -51,7 +51,7 @@ function Reporting(props: ReportingProps & PropsFromStore & ReportingApi): JSX.E
cluster, attribute, minimum_report_interval, maximum_report_interval, reportable_change
});
}
const reportingRules = convertBindingsIntoNiceStructure(device);
const reportingRules = useMemo(() => convertBindingsIntoNiceStructure(device), [device]);
return (
<div className="container-fluid">
{
Expand Down
8 changes: 6 additions & 2 deletions src/components/features/composite/composite.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import groupBy from "lodash/groupBy";
import { Feature } from "./Feature";
import cx from "classnames";
import { WithTranslation, withTranslation } from "react-i18next";
import isEqual from "lodash/isEqual";

type CompositeType = "composite" | "light" | "switch" | "cover" | "lock" | "fan" | "climate";

Expand Down Expand Up @@ -140,5 +141,8 @@ export class Composite extends Component<CompositeProps & WithTranslation<"compo

}
}

export default withTranslation(["composite", "common"])(Composite);
function compositePropsAreEqual(prevProps: CompositeProps, nextProps: CompositeProps){
const checkProps: (keyof CompositeProps)[] = ['deviceState', 'device', 'feature'];
return checkProps.every(p => isEqual(prevProps[p], nextProps[p]));
}
export default withTranslation(["composite", "common"])(React.memo(Composite, compositePropsAreEqual));

0 comments on commit 84882cc

Please sign in to comment.