Skip to content

feat: add user groups column to users table #10284

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

Merged
merged 44 commits into from
Oct 19, 2023
Merged

Conversation

Parkreiner
Copy link
Member

@Parkreiner Parkreiner commented Oct 16, 2023

Closes #4566

Changes made

  • Updates the users table to include a Groups column
    • Hovering over the Groups cell for a user's row will display a popup listing all the groups for that user
  • Updates the Roles column to auto-truncate itself. Truncated roles will be listed like "+2 more". Truncation only happens if a user has 2+ roles, and omitted roles can still be seen by hovering over them
Screen.Recording.2023-10-18.at.4.32.52.PM.mov

Changes that were out of scope

  • If a user doesn't have permission to view the Users page, they still have no way to see their groups. From some brief brainstorming, it felt like it would be best to put this information in the Account page, and resolve via a separate PR (including a new Figma mockup)
  • This does not let users/admins modify groups from the Users page. Navigating to the Groups page is still the only way to do that (for now).

Other notes

  • This feature is partly waiting on some work from Bruno to update how we use Popovers in the codebase. This code is hopefully so error-free that it could be merged as-is, but I'm hoping to refactor this code to use the new Popovers (the swap shouldn't require any major changes)

sm: (theme) => ({
width: theme.spacing(3),
height: theme.spacing(3),
fontSize: theme.spacing(1.5),
fontWeight: 600,
Copy link
Member Author

Choose a reason for hiding this comment

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

Noticed that as the letters for the fallback avatars got smaller, they needed to be beefed up a little to still stand out against the background properly

import { useFilter } from "components/Filter/filter";
import { useDashboard } from "components/Dashboard/DashboardProvider";
import { useMutation, useQuery, useQueryClient } from "react-query";
import { type FC, type ReactNode, useState } from "react";
Copy link
Member Author

@Parkreiner Parkreiner Oct 18, 2023

Choose a reason for hiding this comment

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

Almost all the diffs for this file are me just moving things around to group them better, and renaming some variables for clarity. The major things to look for are any code involving groupsByUserIdQuery

user.roles.length === 0
? [fallbackRole]
: sortRoles(user.roles);
{users?.map((user) => (
Copy link
Member Author

Choose a reason for hiding this comment

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

Not too much changed here, but because the indentation level changed, it might help to view this file with whitespace changes off

@Parkreiner Parkreiner marked this pull request as ready for review October 18, 2023 22:52
@Parkreiner Parkreiner requested review from a team and BrunoQuaresma and removed request for a team October 18, 2023 22:52
@BrunoQuaresma
Copy link
Collaborator

I loved the design changes. +1000 for the way you reduced the role spacing.

I just have one minor thing. I would remove the "See details" below the group amount, and I would make the "1 Group" the trigger directly. It is the same idea that you used for the "+3 roles" in which you didn't add an extra link or element to display the popover. Makes sense?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Lol I had to do the same in other PRs 😆

return userIdMapper as GroupsByUserId;
},
} satisfies UseQueryOptions<Group[], unknown, GroupsByUserId>;
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

We use lodash so maybe it can be helpful to simplify some of these logic.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah, I've never used Lodash before, so to be honest, I keep forgetting that we have it, but I'll see if some of their utilities can help out

Copy link
Member Author

Choose a reason for hiding this comment

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

Tried going through the documentation, but it didn't seem like Lodash has support for Map objects, and I didn't want to "downgrade" the type by turning it into a regular JS object (which would mean losing better memory usage, easy iteration, and easy size checking)

I did refactor the code to consolidate some loops, though

@@ -5,16 +5,23 @@ import { FC } from "react";
import { css, type Interpolation, type Theme } from "@emotion/react";

export type AvatarProps = MuiAvatarProps & {
size?: "sm" | "md" | "xl";
size?: "xs" | "sm" | "md" | "xl";
Copy link
Collaborator

Choose a reason for hiding this comment

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

Nice added!

const activateUserMutation = useMutation(activateUser(queryClient));

const [confirmDeleteUser, setConfirmDeleteUser] = useState<User>();
const [userToDelete, setUserToDelete] = useState<User>();
Copy link
Collaborator

Choose a reason for hiding this comment

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

Way better names 🙏

const updateRolesMutation = useMutation(updateRoles(queryClient));

// Indicates if oidc roles are synced from the oidc idp.
// Assign 'false' if unknown.
const oidcRoleSyncEnabled =
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is this used somewhere?

Copy link
Member Author

Choose a reason for hiding this comment

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

Honestly, I'm not completely sure. I didn't change the code or the comment, and I didn't dig deep enough into some of the components to see where it was actually used

const closePopover = () => setAnchorEl(null);
const openPopover = (event: PointerEvent<HTMLButtonElement>) => {
setAnchorEl(event.currentTarget);
};
Copy link
Collaborator

Choose a reason for hiding this comment

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

I merged the <Popover> component so maybe it can be helpful here

Copy link
Collaborator

@BrunoQuaresma BrunoQuaresma left a comment

Choose a reason for hiding this comment

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

Nice work! I just left a few comments that are not blockers. About the golang errors, you just need to update your branch with main 👍

@Parkreiner Parkreiner merged commit ab2904a into main Oct 19, 2023
@Parkreiner Parkreiner deleted the mes/table-user-groups branch October 19, 2023 18:31
@github-actions github-actions bot locked and limited conversation to collaborators Oct 19, 2023
@Parkreiner Parkreiner restored the mes/table-user-groups branch October 19, 2023 18:32
@Parkreiner Parkreiner deleted the mes/table-user-groups branch October 19, 2023 18:32
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

feat: Show groups a user belongs to, from Users UI
2 participants