From 1b1f20c6b91867da6058d5578bd527964f939cba Mon Sep 17 00:00:00 2001 From: vedfordev Date: Wed, 14 Feb 2024 14:01:07 +0530 Subject: [PATCH 1/2] #889 | fix:re rendering of OrgManager is fixed --- src/adminApp/OrgManager.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/adminApp/OrgManager.js b/src/adminApp/OrgManager.js index 743c087c6..365708674 100644 --- a/src/adminApp/OrgManager.js +++ b/src/adminApp/OrgManager.js @@ -41,6 +41,7 @@ import CurrentUserService from "../common/service/CurrentUserService"; import DeploymentManager from "./DeploymentManager"; import UserInfo from "../common/model/UserInfo"; import { Privilege } from "openchs-models"; +import _ from "lodash"; class OrgManager extends Component { static childContextTypes = { @@ -50,6 +51,9 @@ class OrgManager extends Component { getChildContext() { return { store }; } + shouldComponentUpdate(nextProps, nextState, nextContext) { + return !_.isEqual(_.omit(nextProps, ["location"]), _.omit(this.props, ["location"])); + } render() { const { organisation, user, userInfo } = this.props; From fae0db45d552c08cb73c9f92aa35eaf0a0196646 Mon Sep 17 00:00:00 2001 From: vedfordev Date: Wed, 14 Feb 2024 17:00:00 +0530 Subject: [PATCH 2/2] #889 | update:changed solution using useContext --- src/adminApp/OrgManager.js | 217 +++++++++++++++--------------- src/adminApp/OrgManagerContext.js | 4 + src/adminApp/user.js | 74 +++++----- 3 files changed, 153 insertions(+), 142 deletions(-) create mode 100644 src/adminApp/OrgManagerContext.js diff --git a/src/adminApp/OrgManager.js b/src/adminApp/OrgManager.js index 365708674..a92b87b89 100644 --- a/src/adminApp/OrgManager.js +++ b/src/adminApp/OrgManager.js @@ -41,7 +41,7 @@ import CurrentUserService from "../common/service/CurrentUserService"; import DeploymentManager from "./DeploymentManager"; import UserInfo from "../common/model/UserInfo"; import { Privilege } from "openchs-models"; -import _ from "lodash"; +import OrgManagerContext from "./OrgManagerContext"; class OrgManager extends Component { static childContextTypes = { @@ -51,9 +51,6 @@ class OrgManager extends Component { getChildContext() { return { store }; } - shouldComponentUpdate(nextProps, nextState, nextContext) { - return !_.isEqual(_.omit(nextProps, ["location"]), _.omit(this.props, ["location"])); - } render() { const { organisation, user, userInfo } = this.props; @@ -76,118 +73,120 @@ class OrgManager extends Component { const canEditCatchment = hasPrivilege(userInfo, EditCatchment); return ( - - + + + + + + {hasPrivilege(userInfo, EditUserConfiguration) ? ( + + ) : ( +
+ )} + {hasMultiplePrivileges(userInfo, [EditUserGroup, EditUserConfiguration]) ? ( + + ) : ( +
+ )} + + + {hasPrivilege(userInfo, UploadMetadataAndData) ? ( + + ) : ( +
)} - /> - - - - {hasPrivilege(userInfo, EditUserConfiguration) ? ( + - ) : ( -
- )} - {hasMultiplePrivileges(userInfo, [EditUserGroup, EditUserConfiguration]) ? ( - - ) : ( -
- )} - - - {hasPrivilege(userInfo, UploadMetadataAndData) ? ( - - ) : ( -
- )} - - - - {hasPrivilege(userInfo, PhoneVerification) ? ( - ) : ( -
- )} - + {hasPrivilege(userInfo, PhoneVerification) ? ( + + ) : ( +
+ )} + + ); } } diff --git a/src/adminApp/OrgManagerContext.js b/src/adminApp/OrgManagerContext.js new file mode 100644 index 000000000..38cdbb060 --- /dev/null +++ b/src/adminApp/OrgManagerContext.js @@ -0,0 +1,4 @@ +import { createContext } from "react"; + +const OrgManagerContext = createContext(); +export default OrgManagerContext; diff --git a/src/adminApp/user.js b/src/adminApp/user.js index f20677e36..774e1cd78 100644 --- a/src/adminApp/user.js +++ b/src/adminApp/user.js @@ -1,5 +1,5 @@ import _, { filter, get, isEmpty, isFinite, isNil, map, some, startCase, sortBy } from "lodash"; -import React, { cloneElement, Fragment, useEffect, useState } from "react"; +import React, { cloneElement, Fragment, useContext, useEffect, useState } from "react"; import { ArrayField, ArrayInput, @@ -62,6 +62,7 @@ import ConceptService from "../common/service/ConceptService"; import Select from "react-select"; import ReactSelectHelper from "../common/utils/ReactSelectHelper"; import IdpDetails from "../rootApp/security/IdpDetails"; +import OrgManagerContext from "./OrgManagerContext"; export const UserCreate = ({ user, organisation, userInfo, ...props }) => ( @@ -96,38 +97,45 @@ export const StringToLabelObject = ({ record, children, ...rest }) => ...rest }); -export const UserList = ({ organisation, ...props }) => ( - } - title={`${organisation.name} Users`} - > - - - - - - - - - - - user.voided === true ? "Deleted" : user.disabledInCognito === true ? "Disabled" : "Active" - } - /> - - -); +export const UserList = ({ ...props }) => { + const { organisation } = useContext(OrgManagerContext); + return ( + } + title={`${organisation.name} Users`} + > + + + + + + + + + + + user.voided === true + ? "Deleted" + : user.disabledInCognito === true + ? "Disabled" + : "Active" + } + /> + + + ); +}; const CustomShowActions = ({ hasEditUserPrivilege, basePath, data, resource }) => { return (