Skip to content

Commit

Permalink
Merge pull request #1134 from vedfordev/master
Browse files Browse the repository at this point in the history
#889 | Re rendering of OrgManger is fixed.
  • Loading branch information
himeshr committed Feb 14, 2024
2 parents ca8b0ed + fae0db4 commit 033a597
Show file tree
Hide file tree
Showing 3 changed files with 153 additions and 138 deletions.
213 changes: 108 additions & 105 deletions src/adminApp/OrgManager.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 OrgManagerContext from "./OrgManagerContext";

class OrgManager extends Component {
static childContextTypes = {
Expand Down Expand Up @@ -72,118 +73,120 @@ class OrgManager extends Component {

const canEditCatchment = hasPrivilege(userInfo, EditCatchment);
return (
<Admin
title="Manage Organisation"
authProvider={authProvider}
history={adminHistory}
logoutButton={WithProps({ user }, LogoutButton)}
customRoutes={customRoutes}
appLayout={AdminLayout}
>
<Resource
name="language"
options={{ label: "Languages" }}
list={WithProps(
{
organisation,
hasEditPrivilege: hasPrivilege(userInfo, EditLanguage)
},
OrganisationConfig
<OrgManagerContext.Provider value={{ organisation }}>
<Admin
title="Manage Organisation"
authProvider={authProvider}
history={adminHistory}
logoutButton={WithProps({ user }, LogoutButton)}
customRoutes={customRoutes}
appLayout={AdminLayout}
>
<Resource
name="language"
options={{ label: "Languages" }}
list={WithProps(
{
organisation,
hasEditPrivilege: hasPrivilege(userInfo, EditLanguage)
},
OrganisationConfig
)}
/>
<Resource
name="addressLevelType"
options={{ label: "Location Types" }}
list={LocationTypeList}
show={LocationTypeDetail}
create={hasPrivilege(userInfo, EditLocationType) && LocationTypeCreate}
edit={hasPrivilege(userInfo, EditLocationType) && LocationTypeEdit}
/>
<Resource
name="locations"
options={{ label: "Locations" }}
list={LocationList}
show={LocationDetail}
create={hasPrivilege(userInfo, EditLocation) && LocationCreate}
edit={hasPrivilege(userInfo, EditLocation) && LocationEdit}
/>
<Resource
name="catchment"
list={CatchmentList}
show={WithProps({ hasEditPrivilege: canEditCatchment }, CatchmentDetail)}
create={canEditCatchment && CatchmentCreate}
edit={canEditCatchment && CatchmentEdit}
/>
{hasPrivilege(userInfo, EditUserConfiguration) ? (
<Resource
name="user"
list={UserList}
create={
hasPrivilege(userInfo, EditUserConfiguration) &&
WithProps({ organisation, userInfo }, UserCreate)
}
show={WithProps(
{ user, hasEditUserPrivilege: hasPrivilege(userInfo, EditUserConfiguration) },
UserDetail
)}
edit={hasPrivilege(userInfo, EditUserConfiguration) && UserEdit}
/>
) : (
<div />
)}
{hasMultiplePrivileges(userInfo, [EditUserGroup, EditUserConfiguration]) ? (
<Resource name="userGroups" options={{ label: "User Groups" }} list={UserGroups} />
) : (
<div />
)}
<Resource name="group" />
<Resource name="task" options={{ label: "Tasks" }} />
{hasPrivilege(userInfo, UploadMetadataAndData) ? (
<Resource name="upload" options={{ label: "Upload" }} list={UploadDashboard} />
) : (
<div />
)}
/>
<Resource
name="addressLevelType"
options={{ label: "Location Types" }}
list={LocationTypeList}
show={LocationTypeDetail}
create={hasPrivilege(userInfo, EditLocationType) && LocationTypeCreate}
edit={hasPrivilege(userInfo, EditLocationType) && LocationTypeEdit}
/>
<Resource
name="locations"
options={{ label: "Locations" }}
list={LocationList}
show={LocationDetail}
create={hasPrivilege(userInfo, EditLocation) && LocationCreate}
edit={hasPrivilege(userInfo, EditLocation) && LocationEdit}
/>
<Resource
name="catchment"
list={CatchmentList}
show={WithProps({ hasEditPrivilege: canEditCatchment }, CatchmentDetail)}
create={canEditCatchment && CatchmentCreate}
edit={canEditCatchment && CatchmentEdit}
/>
{hasPrivilege(userInfo, EditUserConfiguration) ? (
<Resource
name="user"
list={WithProps({ organisation }, UserList)}
name="identifierSource"
options={{ label: "Identifier Source" }}
list={IdentifierSourceList}
show={IdentifierSourceDetail}
create={hasPrivilege(userInfo, EditIdentifierSource) && IdentifierSourceCreate}
edit={hasPrivilege(userInfo, EditIdentifierSource) && IdentifierSourceEdit}
/>
<Resource
name="identifierUserAssignment"
options={{ label: "Identifier User Assignment" }}
list={IdentifierUserAssignmentList}
show={IdentifierUserAssignmentDetail}
create={
hasPrivilege(userInfo, EditUserConfiguration) &&
WithProps({ organisation, userInfo }, UserCreate)
hasPrivilege(userInfo, EditIdentifierUserAssignment) && IdentifierUserAssignmentCreate
}
edit={
hasPrivilege(userInfo, EditIdentifierUserAssignment) && IdentifierUserAssignmentEdit
}
show={WithProps(
{ user, hasEditUserPrivilege: hasPrivilege(userInfo, EditUserConfiguration) },
UserDetail
)}
edit={hasPrivilege(userInfo, EditUserConfiguration) && UserEdit}
/>
) : (
<div />
)}
{hasMultiplePrivileges(userInfo, [EditUserGroup, EditUserConfiguration]) ? (
<Resource name="userGroups" options={{ label: "User Groups" }} list={UserGroups} />
) : (
<div />
)}
<Resource name="group" />
<Resource name="task" options={{ label: "Tasks" }} />
{hasPrivilege(userInfo, UploadMetadataAndData) ? (
<Resource name="upload" options={{ label: "Upload" }} list={UploadDashboard} />
) : (
<div />
)}
<Resource
name="identifierSource"
options={{ label: "Identifier Source" }}
list={IdentifierSourceList}
show={IdentifierSourceDetail}
create={hasPrivilege(userInfo, EditIdentifierSource) && IdentifierSourceCreate}
edit={hasPrivilege(userInfo, EditIdentifierSource) && IdentifierSourceEdit}
/>
<Resource
name="identifierUserAssignment"
options={{ label: "Identifier User Assignment" }}
list={IdentifierUserAssignmentList}
show={IdentifierUserAssignmentDetail}
create={
hasPrivilege(userInfo, EditIdentifierUserAssignment) && IdentifierUserAssignmentCreate
}
edit={
hasPrivilege(userInfo, EditIdentifierUserAssignment) && IdentifierUserAssignmentEdit
}
/>
<Resource
name="organisationDetails"
options={{ label: "Organisation Details" }}
list={WithProps(
{
organisation,
hasEditPrivilege: hasPrivilege(userInfo, EditOrganisationConfiguration)
},
OrganisationDetail
)}
/>
{hasPrivilege(userInfo, PhoneVerification) ? (
<Resource
name="phoneNumberVerification"
options={{ label: "Phone Verification" }}
list={Msg91Config}
name="organisationDetails"
options={{ label: "Organisation Details" }}
list={WithProps(
{
organisation,
hasEditPrivilege: hasPrivilege(userInfo, EditOrganisationConfiguration)
},
OrganisationDetail
)}
/>
) : (
<div />
)}
</Admin>
{hasPrivilege(userInfo, PhoneVerification) ? (
<Resource
name="phoneNumberVerification"
options={{ label: "Phone Verification" }}
list={Msg91Config}
/>
) : (
<div />
)}
</Admin>
</OrgManagerContext.Provider>
);
}
}
Expand Down
4 changes: 4 additions & 0 deletions src/adminApp/OrgManagerContext.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import { createContext } from "react";

const OrgManagerContext = createContext();
export default OrgManagerContext;
74 changes: 41 additions & 33 deletions src/adminApp/user.js
Original file line number Diff line number Diff line change
@@ -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,
Expand Down Expand Up @@ -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 }) => (
<Paper>
Expand Down Expand Up @@ -96,38 +97,45 @@ export const StringToLabelObject = ({ record, children, ...rest }) =>
...rest
});

export const UserList = ({ organisation, ...props }) => (
<List
{...props}
bulkActions={false}
filter={{ organisationId: organisation.id }}
filters={<UserFilter />}
title={`${organisation.name} Users`}
>
<Datagrid rowClick="show">
<TextField label="Login ID" source="username" />
<TextField source="name" label="Name of the Person" />
<ReferenceField
label="Catchment"
source="catchmentId"
reference="catchment"
linkType="show"
allowEmpty
>
<TextField source="name" />
</ReferenceField>
<TextField source="email" label="Email Address" />
<TextField source="phoneNumber" label="Phone Number" />
<UserGroupsDisplay style={{ maxWidth: "40em" }} label="User Groups" />
<FunctionField
label="Status"
render={user =>
user.voided === true ? "Deleted" : user.disabledInCognito === true ? "Disabled" : "Active"
}
/>
</Datagrid>
</List>
);
export const UserList = ({ ...props }) => {
const { organisation } = useContext(OrgManagerContext);
return (
<List
{...props}
bulkActions={false}
filter={{ organisationId: organisation.id }}
filters={<UserFilter />}
title={`${organisation.name} Users`}
>
<Datagrid rowClick="show">
<TextField label="Login ID" source="username" />
<TextField source="name" label="Name of the Person" />
<ReferenceField
label="Catchment"
source="catchmentId"
reference="catchment"
linkType="show"
allowEmpty
>
<TextField source="name" />
</ReferenceField>
<TextField source="email" label="Email Address" />
<TextField source="phoneNumber" label="Phone Number" />
<UserGroupsDisplay style={{ maxWidth: "40em" }} label="User Groups" />
<FunctionField
label="Status"
render={user =>
user.voided === true
? "Deleted"
: user.disabledInCognito === true
? "Disabled"
: "Active"
}
/>
</Datagrid>
</List>
);
};

const CustomShowActions = ({ hasEditUserPrivilege, basePath, data, resource }) => {
return (
Expand Down

0 comments on commit 033a597

Please sign in to comment.