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:
@@ -61,6 +61,7 @@ import {
|
|||||||
serializeTenantImportCSV,
|
serializeTenantImportCSV,
|
||||||
} from "../utils/tenantCsvImport";
|
} from "../utils/tenantCsvImport";
|
||||||
import { isSeedTenant } from "../utils/protectedTenants";
|
import { isSeedTenant } from "../utils/protectedTenants";
|
||||||
|
import { buildTenantFullTree, type TenantNode } from "../../../lib/tenantTree";
|
||||||
|
|
||||||
const tenantCSVTemplate =
|
const tenantCSVTemplate =
|
||||||
"name,type,parent_tenant_slug,slug,memo,email_domain\n";
|
"name,type,parent_tenant_slug,slug,memo,email_domain\n";
|
||||||
@@ -211,8 +212,25 @@ function TenantListPage() {
|
|||||||
: null;
|
: null;
|
||||||
|
|
||||||
const allTenants = query.data?.items ?? [];
|
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(() => {
|
const tenants = React.useMemo(() => {
|
||||||
let filtered = allTenants;
|
let filtered = tenantsWithRecursiveCount;
|
||||||
if (search.trim()) {
|
if (search.trim()) {
|
||||||
const term = search.toLowerCase();
|
const term = search.toLowerCase();
|
||||||
filtered = filtered.filter(
|
filtered = filtered.filter(
|
||||||
@@ -232,7 +250,7 @@ function TenantListPage() {
|
|||||||
if (valA > valB) return sortOrder === "asc" ? 1 : -1;
|
if (valA > valB) return sortOrder === "asc" ? 1 : -1;
|
||||||
return 0;
|
return 0;
|
||||||
});
|
});
|
||||||
}, [allTenants, search, sortKey, sortOrder]);
|
}, [tenantsWithRecursiveCount, search, sortKey, sortOrder]);
|
||||||
|
|
||||||
const deletableTenants = React.useMemo(
|
const deletableTenants = React.useMemo(
|
||||||
() => tenants.filter((tenant) => !isSeedTenant(tenant)),
|
() => tenants.filter((tenant) => !isSeedTenant(tenant)),
|
||||||
@@ -701,9 +719,8 @@ function TenantListPage() {
|
|||||||
</Badge>
|
</Badge>
|
||||||
</TableCell>
|
</TableCell>
|
||||||
<TableCell className="font-medium">
|
<TableCell className="font-medium">
|
||||||
{tenant.memberCount}
|
{(tenant as unknown as TenantNode).recursiveMemberCount ?? tenant.memberCount}
|
||||||
</TableCell>
|
</TableCell> <TableCell className="text-xs">
|
||||||
<TableCell className="text-xs">
|
|
||||||
{tenant.updatedAt
|
{tenant.updatedAt
|
||||||
? new Date(tenant.updatedAt).toLocaleString("ko-KR")
|
? new Date(tenant.updatedAt).toLocaleString("ko-KR")
|
||||||
: "-"}
|
: "-"}
|
||||||
|
|||||||
Reference in New Issue
Block a user