#1 PDF Application on GitHub that lets you edit PDFs on any device anywhere
TypeScript dockerhacktoberfestjavapdfpdf-converterpdf-editorpdf-manipulationpdf-mergerpdf-ocrpdf-toolspdf-web-appspdfmergerself-hosted
Show teams with no members yet in the user directory (#7855)
Anthony Stirling07b9708506db
diff --git a/frontend/editor/src/portal/components/users/UsersDirectory.test.tsx b/frontend/editor/src/portal/components/users/UsersDirectory.test.tsxindex 21e68f24d4..f9ac46ce30 100644--- a/frontend/editor/src/portal/components/users/UsersDirectory.test.tsx+++ b/frontend/editor/src/portal/components/users/UsersDirectory.test.tsx@@ -93,6 +93,16 @@ describe("UsersDirectory — remove action gating", () => {).not.toBeInTheDocument();expect(screen.queryByText("Rename team")).not.toBeInTheDocument();});++ it("lists a team with no members yet, so its first member can be added", () => {+ renderDirectory(selfHostedCaps, [+ ...TEAMS,+ { id: 2, name: "Brand new", userCount: 0, owners: [] },+ ]);++ expect(screen.getByText("Brand new team")).toBeInTheDocument();+ expect(screen.getAllByText("Add to team")).toHaveLength(2);+ });});describe("flavor capabilities — invitations + remove scope", () => {diff --git a/frontend/editor/src/portal/components/users/directory.test.ts b/frontend/editor/src/portal/components/users/directory.test.tsnew file mode 100644index 0000000000..2ef9c8c9d2--- /dev/null+++ b/frontend/editor/src/portal/components/users/directory.test.ts@@ -0,0 +1,66 @@+import { describe, expect, it } from "vitest";+import { buildDirectory } from "@portal/components/users/directory";+import type { Member } from "@portal/api/users";+import type { Team } from "@portal/api/teams";++const member = (overrides: Partial<Member> = {}): Member => ({+ id: "2",+ name: "Priya",+ email: "[email protected]",+ username: "[email protected]",+ role: "member",+ status: "active",+ lastActive: "-",+ teamId: 1,+ teamName: "Acme",+ ...overrides,+});++const team = (id: number, name: string): Team => ({+ id,+ name,+ userCount: 0,+ owners: [],+});++describe("buildDirectory", () => {+ it("keeps a team that has no members yet", () => {+ const dir = buildDirectory(+ [member()],+ [team(1, "Acme"), team(2, "Brand new")],+ );++ expect(dir.teams.map((t) => t.name)).toEqual(["Acme", "Brand new"]);+ expect(dir.teams[1].members).toEqual([]);+ });++ it("sorts teams by name regardless of how many members they have", () => {+ const dir = buildDirectory(+ [member()],+ [team(3, "Zephyr"), team(1, "Acme"), team(2, "Meridian")],+ );++ expect(dir.teams.map((t) => t.name)).toEqual([+ "Acme",+ "Meridian",+ "Zephyr",+ ]);+ });++ it("still keeps admins and guests out of their team's section", () => {+ const dir = buildDirectory(+ [+ member({ id: "1", username: "root", role: "admin" }),+ member({ id: "3", username: "vendor", role: "guest" }),+ member(),+ ],+ [team(1, "Acme")],+ );++ expect(dir.organization).toHaveLength(1);+ expect(dir.guests).toHaveLength(1);+ expect(dir.teams[0].members.map((m) => m.username)).toEqual([+ "[email protected]",+ ]);+ });+});diff --git a/frontend/editor/src/portal/components/users/directory.ts b/frontend/editor/src/portal/components/users/directory.tsindex a779c57954..becb171af8 100644--- a/frontend/editor/src/portal/components/users/directory.ts+++ b/frontend/editor/src/portal/components/users/directory.ts@@ -22,8 +22,8 @@ export interface Directory {/*** Group the flat roster into the directory shape the Users page renders:* admins are the Organization owners, web-only users are Guests, and everyone- * else sits under their team. Empty teams are omitted from the roster (they're- * still creatable / visible via team management).+ * else sits under their team. A team with no members still gets a section, so+ * a newly created one can be found and given its first member.*/export function buildDirectory(members: Member[], teams: Team[]): Directory {const organization = members.filter((m) => m.role === "admin");@@ -46,7 +46,6 @@ export function buildDirectory(members: Member[], teams: Team[]): Directory {members: byTeam.get(t.id) ?? [],isPersonal: t.isPersonal,}))- .filter((g) => g.members.length > 0).sort((a, b) => a.name.localeCompare(b.name));return { organization, teams: teamGroups, guests };