1
0
forked from baron/baron-sso

계층 표시 테스트 코드 추가

This commit is contained in:
2026-02-27 10:52:11 +09:00
parent ca45a14bae
commit f02ba3cbbd
6 changed files with 271 additions and 58 deletions

View File

@@ -65,11 +65,7 @@ import {
updateUser,
} from "../../../lib/adminApi";
import { t } from "../../../lib/i18n";
type TenantNode = TenantSummary & {
children: TenantNode[];
recursiveMemberCount: number;
};
import { type TenantNode, buildTenantFullTree } from "../../../lib/tenantTree";
const getTenantIcon = (type?: string) => {
switch (type?.toUpperCase()) {
@@ -779,58 +775,10 @@ function TenantUserGroupsTab() {
const allTenants = data?.items ?? [];
const { currentBase, subTree } = useMemo(() => {
if (allTenants.length === 0) return { currentBase: null, subTree: [] };
const tenantMap = new Map<string, TenantNode>();
for (const t of allTenants) {
tenantMap.set(t.id, {
...t,
children: [],
recursiveMemberCount: t.memberCount || 0,
});
}
// Build initial children relations
for (const t of allTenants) {
if (t.parentId) {
const parent = tenantMap.get(t.parentId);
const child = tenantMap.get(t.id);
if (parent && child) {
parent.children.push(child);
}
}
}
// Function to calculate recursive counts
const calculateRecursive = (node: TenantNode): number => {
let total = node.memberCount || 0;
for (const child of node.children) {
total += calculateRecursive(child);
}
node.recursiveMemberCount = total;
return total;
};
// Calculate for all root nodes (those without parent or top-level in current context)
for (const node of tenantMap.values()) {
// We only strictly need to calculate from the top-most nodes to cover everything
if (!node.parentId) {
calculateRecursive(node);
}
}
// Re-calculate specifically for our current tenant to be sure if it wasn't a global root
const base = tenantMap.get(tenantId);
if (base) {
calculateRecursive(base);
}
return {
currentBase: base || null,
subTree: base ? base.children : [],
};
}, [allTenants, tenantId]);
const { currentBase, subTree } = useMemo(
() => buildTenantFullTree(allTenants, tenantId),
[allTenants, tenantId],
);
const handleAdd = (id: string) =>
updateParentMutation.mutate({ id, parentId: tenantId });