1
0
forked from baron/baron-sso

fix: display recursive member count in TenantListPage

- Replace raw memberCount with recursiveMemberCount calculated via buildTenantFullTree to correctly aggregate member counts for parent tenants (e.g., 'hanmac-family') that only contain members in their sub-tenants.
This commit is contained in:
2026-05-06 17:47:33 +09:00
parent 3064126709
commit 5096930d68

View File

@@ -61,6 +61,7 @@ import {
serializeTenantImportCSV,
} from "../utils/tenantCsvImport";
import { isSeedTenant } from "../utils/protectedTenants";
import { buildTenantFullTree, type TenantNode } from "../../../lib/tenantTree";
const tenantCSVTemplate =
"name,type,parent_tenant_slug,slug,memo,email_domain\n";
@@ -211,8 +212,25 @@ function TenantListPage() {
: null;
const allTenants = query.data?.items ?? [];
const tenantsWithRecursiveCount = React.useMemo(() => {
// Build tree to calculate recursiveMemberCount, but we map it back to a flat array for the table
const { subTree } = buildTenantFullTree(allTenants);
const flatMap = new Map<string, TenantNode>();
const flatten = (nodes: TenantNode[]) => {
for (const node of nodes) {
flatMap.set(node.id, node);
flatten(node.children);
}
};
flatten(subTree);
// Map back to allTenants ensuring recursiveMemberCount is present
return allTenants.map((t) => flatMap.get(t.id) ?? { ...t, children: [], recursiveMemberCount: t.memberCount || 0 });
}, [allTenants]);
const tenants = React.useMemo(() => {
let filtered = allTenants;
let filtered = tenantsWithRecursiveCount;
if (search.trim()) {
const term = search.toLowerCase();
filtered = filtered.filter(
@@ -232,7 +250,7 @@ function TenantListPage() {
if (valA > valB) return sortOrder === "asc" ? 1 : -1;
return 0;
});
}, [allTenants, search, sortKey, sortOrder]);
}, [tenantsWithRecursiveCount, search, sortKey, sortOrder]);
const deletableTenants = React.useMemo(
() => tenants.filter((tenant) => !isSeedTenant(tenant)),
@@ -701,9 +719,8 @@ function TenantListPage() {
</Badge>
</TableCell>
<TableCell className="font-medium">
{tenant.memberCount}
</TableCell>
<TableCell className="text-xs">
{(tenant as unknown as TenantNode).recursiveMemberCount ?? tenant.memberCount}
</TableCell> <TableCell className="text-xs">
{tenant.updatedAt
? new Date(tenant.updatedAt).toLocaleString("ko-KR")
: "-"}