Add Invited by and Joined columns to the users table (#13325)

* Add Invited by and Joined columns to users table

* Move responsive column hiding into column definitions

Adds a hideOnMobile flag to the table column type, handled in the Table
component, replacing per-column isMobile ternaries in the users table.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com>
This commit is contained in:
Tom MoorandClaude Opus 5 authored and GitHub committed 2026-08-06 22:11:41 -04:00
1 parent 355d15ad4f
commit 59ea433420
7 files changed
+105 -20

No files matched your search

+8 -7
View File
@@ -63,6 +63,8 @@ export type Column<TData> = {
id: string;
component: (data: TData) => React.ReactNode;
width: string;
/** Whether the column is hidden on narrow viewports (defaults to false). */
hideOnMobile?: boolean;
} & (DataColumn<TData> | ActionColumn);
/** The minimum shape of a row, rows are identified by the model identifier. */
@@ -163,13 +165,12 @@ function TableViewInner<TData extends RowData>({
const visibleColumns = React.useMemo(
() =>
id
? columns.filter(
(column) =>
column.type !== "data" || !hiddenColumns.includes(column.id)
)
: columns,
[id, columns, hiddenColumns]
columns.filter(
(column) =>
(!isMobile || !column.hideOnMobile) &&
(!id || column.type !== "data" || !hiddenColumns.includes(column.id))
),
[id, columns, hiddenColumns, isMobile]
);
const allColumns = React.useMemo(() => {
+8
View File
@@ -19,6 +19,7 @@ import type Group from "./Group";
import type UserMembership from "./UserMembership";
import ParanoidModel from "./base/ParanoidModel";
import Field from "./decorators/Field";
import Relation from "./decorators/Relation";
import type { Searchable } from "./interfaces/Searchable";
class User extends ParanoidModel implements Searchable {
@@ -80,6 +81,13 @@ class User extends ParanoidModel implements Searchable {
@observable
isSuspended: boolean;
@observable
invitedById: string | undefined;
/** The user that invited this user, if they were invited. */
@Relation(() => User)
invitedBy: User | undefined;
@computed
get searchContent(): string[] {
return [this.name, this.email, this.initials].filter(Boolean);
+43 -11
View File
@@ -16,6 +16,7 @@ import { ContextMenu } from "~/components/Menu/ContextMenu";
import { ActionContextProvider } from "~/hooks/useActionContext";
import { useUserMenuActions } from "~/hooks/useUserMenuActions";
import Time from "~/components/Time";
import { UserHoverCard } from "~/components/UserHoverCard";
import useCurrentUser from "~/hooks/useCurrentUser";
import useMobile from "~/hooks/useMobile";
import UserMenu from "~/menus/UserMenu";
@@ -101,7 +102,7 @@ export function UsersTable({ canManage, ...rest }: Props) {
),
width: "4fr",
},
canManage && !isMobile
canManage
? {
type: "data",
id: "email",
@@ -109,21 +110,52 @@ export function UsersTable({ canManage, ...rest }: Props) {
accessor: (user) => user.email,
component: (user) => <>{user.email}</>,
width: "4fr",
hideOnMobile: true,
}
: undefined,
isMobile
? undefined
: {
{
type: "data",
id: "lastActiveAt",
header: t("Last active"),
accessor: (user) => user.lastActiveAt,
component: (user) =>
user.lastActiveAt ? (
<Time dateTime={user.lastActiveAt} addSuffix shorten />
) : null,
width: "2fr",
hideOnMobile: true,
},
canManage
? {
type: "data",
id: "lastActiveAt",
header: t("Last active"),
accessor: (user) => user.lastActiveAt,
id: "invitedBy",
header: t("Invited by"),
accessor: (user) => user.invitedBy?.name,
component: (user) =>
user.lastActiveAt ? (
<Time dateTime={user.lastActiveAt} addSuffix shorten />
user.invitedBy ? (
<UserHoverCard user={user.invitedBy}>
<Text selectable ellipsis>
{user.invitedBy.name}
</Text>
</UserHoverCard>
) : null,
sortable: false,
width: "2fr",
},
hideOnMobile: true,
}
: undefined,
{
type: "data",
id: "createdAt",
header: t("Joined"),
accessor: (user) => user.createdAt,
component: (user) =>
user.createdAt ? (
<Time dateTime={user.createdAt} addSuffix shorten />
) : null,
width: "2fr",
hideOnMobile: true,
},
{
type: "data",
id: "role",
@@ -144,7 +176,7 @@ export function UsersTable({ canManage, ...rest }: Props) {
{user.isSuspended && <Badge>{t("Suspended")}</Badge>}
</HStack>
),
width: "2fr",
width: "1.4fr",
},
canManage
? {
+6
View File
@@ -27,6 +27,7 @@ type UserPresentation = {
preferences?: UserPreferences | null;
notificationSettings?: NotificationSettings;
timezone?: string | null;
invitedBy?: UserPresentation;
};
export default function presentUser(
@@ -58,5 +59,10 @@ export default function presentUser(
userData.email = user.email;
}
// Only included when the association has been eager-loaded by the caller.
if (user.invitedBy) {
userData.invitedBy = presentUser(user.invitedBy);
}
return userData;
}
+32
View File
@@ -38,6 +38,38 @@ describe("#users.list", () => {
expect(body.data[0].id).toEqual(user.id);
});
it("should return the inviting user for admins", async () => {
const admin = await buildAdmin();
const invite = await buildInvite({ teamId: admin.teamId });
const res = await server.post("/api/users.list", admin, {
body: { filter: "all" },
});
const body = await res.json();
expect(res.status).toEqual(200);
const invited = body.data.find(
(item: { id: string }) => item.id === invite.id
);
expect(invited.invitedBy.id).toEqual(invite.invitedById);
});
it("should not return the inviting user for non-admins", async () => {
const invite = await buildInvite();
const user = await buildUser({ teamId: invite.teamId });
const res = await server.post("/api/users.list", user, {
body: { filter: "all" },
});
const body = await res.json();
expect(res.status).toEqual(200);
const invited = body.data.find(
(item: { id: string }) => item.id === invite.id
);
expect(invited.invitedBy).toEqual(undefined);
});
it("should treat LIKE wildcards in the query as literal characters", async () => {
const user = await buildUser({
name: "Underscore",
+6 -2
View File
@@ -131,10 +131,10 @@ router.post(
[Op.and]: {
[Op.or]: [
Sequelize.literal(
`unaccent(LOWER(email)) like unaccent(LOWER(:query))`
`unaccent(LOWER("user"."email")) like unaccent(LOWER(:query))`
),
Sequelize.literal(
`unaccent(LOWER(name)) like unaccent(LOWER(:query))`
`unaccent(LOWER("user"."name")) like unaccent(LOWER(:query))`
),
],
},
@@ -161,6 +161,10 @@ router.post(
User.findAll({
where,
replacements,
// Only admins can see who invited a user.
include: actor.isAdmin
? [{ association: "invitedBy", required: false }]
: undefined,
order: [[sort, direction]],
offset: ctx.state.pagination.offset,
limit: ctx.state.pagination.limit,
@@ -1325,6 +1325,8 @@
"All roles": "All roles",
"Admins": "Admins",
"Editors": "Editors",
"Invited by": "Invited by",
"Joined": "Joined",
"All status": "All status",
"Active": "Active",
"Could not load emojis": "Could not load emojis",