From 1b79933cfb74f2dad950443a6093b2a4b7fbcf11 Mon Sep 17 00:00:00 2001 From: Michael Kimberlin Date: Thu, 11 Apr 2024 12:34:37 -0500 Subject: [PATCH] Fix some styles, filter add user list, and fix add user handler --- web-ui/src/components/admin/roles/Roles.css | 6 +- web-ui/src/components/admin/roles/Roles.jsx | 76 +++++++++---------- .../roles/__snapshots__/Roles.test.jsx.snap | 8 +- 3 files changed, 46 insertions(+), 44 deletions(-) diff --git a/web-ui/src/components/admin/roles/Roles.css b/web-ui/src/components/admin/roles/Roles.css index d010c43d37..57beadb291 100644 --- a/web-ui/src/components/admin/roles/Roles.css +++ b/web-ui/src/components/admin/roles/Roles.css @@ -139,8 +139,12 @@ } .roles-content .roles .roles-top-search-fields .role-select { + width: 50%; margin-right: 2rem; - margin-top: 12px; +} + +.roles-content .roles .roles-top-search-fields .member-role-search { + width: 50%; } @media screen and (max-width: 600px) { diff --git a/web-ui/src/components/admin/roles/Roles.jsx b/web-ui/src/components/admin/roles/Roles.jsx index d597fac978..4a5d34c80f 100644 --- a/web-ui/src/components/admin/roles/Roles.jsx +++ b/web-ui/src/components/admin/roles/Roles.jsx @@ -1,6 +1,6 @@ -import React, { useContext, useEffect, useState } from "react"; +import React, {useContext, useEffect, useState} from "react"; -import { AppContext } from "../../../context/AppContext"; +import {AppContext} from "../../../context/AppContext"; import { SET_ROLES, SET_USER_ROLES, @@ -41,15 +41,15 @@ import PersonAddIcon from "@mui/icons-material/PersonAdd"; import SearchIcon from "@mui/icons-material/Search"; import AddIcon from "@mui/icons-material/Add"; -import { isArrayPresent } from './../../../helpers/checks'; +import {isArrayPresent} from './../../../helpers/checks'; import "./Roles.css"; import {selectProfile} from "../../../context/selectors"; import EditIcon from "@mui/icons-material/Edit"; const Roles = () => { - const { state, dispatch } = useContext(AppContext); - const { csrf, memberProfiles, roles, userRoles } = state; + const {state, dispatch} = useContext(AppContext); + const {csrf, memberProfiles, roles, userRoles} = state; const [showAddUser, setShowAddUser] = useState(false); const [showEditRole, setShowEditRole] = useState(false); @@ -69,30 +69,28 @@ const Roles = () => { }, [roles]); useEffect(() => { - const memberMap = {}; - if(memberProfiles && memberProfiles.length > 0) { - for (const member of memberProfiles) { - memberMap[member.id] = member; - } + const memberMap = {}; + if (memberProfiles && memberProfiles.length > 0) { + for (const member of memberProfiles) { + memberMap[member.id] = member; } + } - const newRoleToMemberMap = {}; - for (const userRole of userRoles || []) { - const role = roles.find((role) => role.id === userRole?.memberRoleId?.roleId); - if(role) { - let memberList = newRoleToMemberMap[role.role]; - if (!memberList) { - memberList = newRoleToMemberMap[role.role] = []; - } - if (memberMap[userRole?.memberRoleId?.memberId] !== undefined) { - memberList.push({ ...memberMap[userRole?.memberRoleId?.memberId], roleId: role.id }); - } + const newRoleToMemberMap = {}; + for (const userRole of userRoles || []) { + const role = roles.find((role) => role.id === userRole?.memberRoleId?.roleId); + if (role) { + let memberList = newRoleToMemberMap[role.role]; + if (!memberList) { + memberList = newRoleToMemberMap[role.role] = []; + } + if (memberMap[userRole?.memberRoleId?.memberId] !== undefined) { + memberList.push({...memberMap[userRole?.memberRoleId?.memberId], roleId: role.id}); } } - setRoleToMemberMap(newRoleToMemberMap); - }, [userRoles, memberProfiles, roles]); - - const uniqueRoles = Object.keys(roleToMemberMap); + } + setRoleToMemberMap(newRoleToMemberMap); + }, [userRoles, memberProfiles, roles]); const getRoleStats = (role) => { let members = roleToMemberMap[role]; @@ -101,7 +99,7 @@ const Roles = () => { const removeFromRole = async (member, role) => { const members = roleToMemberMap[role]; - const { roleId } = members.find((m) => member.id === m.id); + const {roleId} = members.find((m) => member.id === m.id); let res = await removeUserFromRole(roleId, member.id, csrf); let data = res.payload && res.payload.status === 200 && !res.error @@ -125,7 +123,7 @@ const Roles = () => { }; const addToRole = async (member) => { - const role = roles.find((role) => role.role === currentRole); + const role = roles.find((role) => role.role === currentRole.role); let res = await addUserToRole(role.id, member.id, csrf); let data = res.payload && res.payload.data && !res.error ? res.payload.data : null; @@ -176,11 +174,11 @@ const Roles = () => { }; const setRoleName = (event) => { - setEditedRole({ ...editedRole, role: event?.target?.value }); + setEditedRole({...editedRole, role: event?.target?.value}); } const setRoleDescription = (event) => { - setEditedRole({ ...editedRole, description: event?.target?.value }); + setEditedRole({...editedRole, description: event?.target?.value}); } return ( @@ -189,7 +187,7 @@ const Roles = () => {
- + Roles