Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update team table so that duplicate team members cannot be added #1551

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
Original file line number Diff line number Diff line change
Expand Up @@ -73,13 +73,34 @@ const useColumns = ({
return user ? `${user.first_name} ${user.last_name}` : "";
},
renderEditCell: (props) => {
// the team member object for the current row
const currentRowMember =
data?.moped_project_by_pk?.moped_proj_personnel.filter(
(user) => user.project_personnel_id === props.id
);
// the existing team members on this project
const existingTeamMembers =
data?.moped_project_by_pk?.moped_proj_personnel.map(
(option) => option.moped_user.email
);
// filter out existing team members from list of options unless they are the current row member
// that way the current member remains an option when editing a row
const teamMembersWithoutDuplicates = data?.moped_users.filter(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not 100% sold on this variable name. Because our existing list of users already does not have duplicates in it. This is a list of team members that aren't already on the project, so its preventing duplicates.

maybe unassignedTeamMembers?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cool i like that, just updated!

(user) => {
return (
!existingTeamMembers.includes(user.email) ||
user.email === currentRowMember?.[0]?.moped_user.email
);
}
);
return (
<TeamAutocompleteComponent
{...props}
name={"user"}
value={props.row.moped_user}
options={data.moped_users}
options={teamMembersWithoutDuplicates}
error={props.error}
workgroupLookup={workgroupLookup}
/>
);
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ import { useTheme } from "@mui/material/styles";
* @param {String} value - field value
* @param {String} field - name of field
* @param {Boolean} hasFocus - does this field have focus
* @param {Object} nameLookup - maps user id to user name
* @param {Boolean} error - toggles error style in textfield
* @param {Object} name - name of the field
* @param {Object} userWorkgroupLookup - mapping of user ids to their corresponding workgroup ids
* @param {Object} options - moped users to use in team member select
* @param {Object} workgroupLookup - lookup object to map workgroup ids to names
* @return {JSX.Element}
*/
const TeamAutocompleteComponent = ({
Expand All @@ -28,6 +28,7 @@ const TeamAutocompleteComponent = ({
error,
name,
options,
workgroupLookup,
}) => {
const theme = useTheme();
const apiRef = useGridApiContext();
Expand All @@ -49,7 +50,10 @@ const TeamAutocompleteComponent = ({
apiRef.current.setEditCellValue({
id,
field: "moped_workgroup",
value: { workgroup_id: newValue?.workgroup_id },
value: {
workgroup_id: newValue?.workgroup_id,
workgroup_name: workgroupLookup[newValue?.workgroup_id],
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this fixed a bug thats currently in prod where if you edit a row and click a new user and then in the same edit session click the old user again and save that, you would see [object Object] in the workgroup name field. also in other cases where you are actually saving a new user, [object Object] would just flash on the screen in the time between clicking save and this hook running which manually adds the workgroup_name to the row data

Copy link
Collaborator

@mddilley mddilley Mar 4, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice! Thank you for catching AND fixing this bug. 🚀 I was able to see the native object peek out in staging when I adjusted my connection speed. 🙏

FYI @chiaberry this probably affects your work on reusable autocompletes that have dependent fields

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for addressing this bug! I am going to check the milestones table to see if I see that same bug there.

},
});
};

Expand Down