mirror of
https://github.com/outline/outline.git
synced 2026-11-29 16:40:27 +03:00
feat: Show who added a member in the group members table (#14000)
* feat: Show who added a member in the group members table * fix: Make timestamps with tooltip detail keyboard accessible
This commit is contained in:
1 parent
bd1d4e518a
commit
8433475ef6
7 files changed
+109
-4
No files matched your search
@@ -10,15 +10,24 @@ export type Props = {
|
||||
shorten?: boolean;
|
||||
relative?: boolean;
|
||||
format?: Partial<Record<keyof typeof locales, string>>;
|
||||
/** Additional content shown below the date in the tooltip. */
|
||||
tooltipDetail?: React.ReactNode;
|
||||
};
|
||||
|
||||
const LocaleTime: React.FC<Props> = ({ children, ...rest }: Props) => {
|
||||
const LocaleTime: React.FC<Props> = ({
|
||||
children,
|
||||
tooltipDetail,
|
||||
...rest
|
||||
}: Props) => {
|
||||
const { tooltipContent, content } = useLocaleTime(rest);
|
||||
const [isInteractive, setIsInteractive] = React.useState(false);
|
||||
// Detail is only available in the tooltip, so it must be reachable by keyboard.
|
||||
const hasDetail = !!tooltipDetail;
|
||||
|
||||
const time = (
|
||||
<time
|
||||
dateTime={rest.dateTime}
|
||||
tabIndex={hasDetail ? 0 : undefined}
|
||||
onPointerEnter={() => setIsInteractive(true)}
|
||||
onFocus={() => setIsInteractive(true)}
|
||||
>
|
||||
@@ -26,8 +35,21 @@ const LocaleTime: React.FC<Props> = ({ children, ...rest }: Props) => {
|
||||
</time>
|
||||
);
|
||||
|
||||
return isInteractive ? (
|
||||
<Tooltip content={tooltipContent} placement="bottom">
|
||||
return isInteractive || hasDetail ? (
|
||||
<Tooltip
|
||||
content={
|
||||
hasDetail ? (
|
||||
<>
|
||||
{tooltipContent}
|
||||
<br />
|
||||
{tooltipDetail}
|
||||
</>
|
||||
) : (
|
||||
tooltipContent
|
||||
)
|
||||
}
|
||||
placement="bottom"
|
||||
>
|
||||
{time}
|
||||
</Tooltip>
|
||||
) : (
|
||||
|
||||
@@ -31,6 +31,13 @@ class GroupUser extends Model {
|
||||
@Relation(() => Group, { onDelete: "cascade" })
|
||||
group: Group;
|
||||
|
||||
/** The ID of the user that added the user to the group. */
|
||||
createdById: string;
|
||||
|
||||
/** The user that added the user to the group. */
|
||||
@Relation(() => User, { onDelete: "null" })
|
||||
createdBy?: User;
|
||||
|
||||
/** The permission of the user in the group. */
|
||||
@Field
|
||||
@observable
|
||||
|
||||
@@ -117,6 +117,36 @@ export const GroupMembersTable = observer(function GroupMembersTable({
|
||||
),
|
||||
width: "1fr",
|
||||
},
|
||||
{
|
||||
type: "data",
|
||||
id: "addedAt",
|
||||
header: t("Added"),
|
||||
sortable: false,
|
||||
accessor: (user) =>
|
||||
groupUsers.membership(group.id, user.id)?.createdAt ?? "",
|
||||
component: (user) => {
|
||||
const membership = groupUsers.membership(group.id, user.id);
|
||||
if (!membership?.createdAt) {
|
||||
return null;
|
||||
}
|
||||
return (
|
||||
<Time
|
||||
dateTime={membership.createdAt}
|
||||
tooltipDetail={
|
||||
membership.createdBy && !group.isExternallyManaged
|
||||
? t("Added by {{ userName }}", {
|
||||
userName: membership.createdBy.name,
|
||||
})
|
||||
: undefined
|
||||
}
|
||||
addSuffix
|
||||
shorten
|
||||
/>
|
||||
);
|
||||
},
|
||||
width: "1fr",
|
||||
hideOnMobile: true,
|
||||
},
|
||||
{
|
||||
type: "data",
|
||||
id: "role",
|
||||
|
||||
@@ -10,6 +10,8 @@ export default function presentGroupUser(
|
||||
userId: membership.userId,
|
||||
groupId: membership.groupId,
|
||||
permission: membership.permission,
|
||||
createdById: membership.createdById,
|
||||
createdAt: membership.createdAt,
|
||||
user: options?.includeUser ? presentUser(membership.user) : undefined,
|
||||
};
|
||||
}
|
||||
@@ -684,6 +684,32 @@ describe("#groups.memberships", () => {
|
||||
expect(body.data.groupMemberships[0].user.id).toEqual(user.id);
|
||||
});
|
||||
|
||||
it("should return the user that added each member", async () => {
|
||||
const admin = await buildAdmin();
|
||||
const user = await buildUser({ teamId: admin.teamId });
|
||||
const group = await buildGroup({
|
||||
teamId: admin.teamId,
|
||||
});
|
||||
await group.$add("user", user, {
|
||||
through: {
|
||||
createdById: admin.id,
|
||||
},
|
||||
});
|
||||
const res = await server.post("/api/groups.memberships", user, {
|
||||
body: {
|
||||
id: group.id,
|
||||
},
|
||||
});
|
||||
const body = await res.json();
|
||||
expect(res.status).toEqual(200);
|
||||
expect(body.data.groupMemberships.length).toEqual(1);
|
||||
expect(body.data.groupMemberships[0].createdById).toEqual(admin.id);
|
||||
expect(body.data.groupMemberships[0].createdAt).toBeTruthy();
|
||||
expect(body.data.users.map((u: { id: string }) => u.id).sort()).toEqual(
|
||||
[admin.id, user.id].sort()
|
||||
);
|
||||
});
|
||||
|
||||
it("should allow filtering members in group by name", async () => {
|
||||
const user = await buildUser();
|
||||
const user2 = await buildUser({
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import { compact, uniqBy } from "es-toolkit";
|
||||
import Router from "koa-router";
|
||||
import type { WhereOptions } from "sequelize";
|
||||
import { Op } from "sequelize";
|
||||
@@ -434,18 +435,33 @@ router.post(
|
||||
GroupUser.findAll({
|
||||
...options,
|
||||
order: [["createdAt", "DESC"]],
|
||||
include: [
|
||||
...options.include,
|
||||
{
|
||||
model: User,
|
||||
as: "createdBy",
|
||||
required: false,
|
||||
},
|
||||
],
|
||||
offset: ctx.state.pagination.offset,
|
||||
limit: ctx.state.pagination.limit,
|
||||
}),
|
||||
]);
|
||||
|
||||
const users = uniqBy(
|
||||
compact(
|
||||
groupUsers.flatMap((groupUser) => [groupUser.user, groupUser.createdBy])
|
||||
),
|
||||
(u) => u.id
|
||||
);
|
||||
|
||||
ctx.body = {
|
||||
pagination: { ...ctx.state.pagination, total },
|
||||
data: {
|
||||
groupMemberships: groupUsers.map((groupUser) =>
|
||||
presentGroupUser(groupUser, { includeUser: true })
|
||||
),
|
||||
users: groupUsers.map((groupUser) => presentUser(groupUser.user)),
|
||||
users: users.map((u) => presentUser(u)),
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
@@ -1334,6 +1334,8 @@
|
||||
"No people matching your search": "No people matching your search",
|
||||
"No people left to add": "No people left to add",
|
||||
"Last active": "Last active",
|
||||
"Added": "Added",
|
||||
"Added by {{ userName }}": "Added by {{ userName }}",
|
||||
"Role": "Role",
|
||||
"All permissions": "All permissions",
|
||||
"All sources": "All sources",
|
||||
|
||||
Reference in new issue
Block a user