forked from baron/baron-sso
feat: display UserGroups in the tenant organization tab
This commit is contained in:
@@ -56,9 +56,11 @@ import {
|
||||
TabsTrigger,
|
||||
} from "../../../components/ui/tabs";
|
||||
import {
|
||||
type GroupSummary,
|
||||
type TenantSummary,
|
||||
type UserSummary,
|
||||
createUser,
|
||||
fetchGroups,
|
||||
fetchTenants,
|
||||
fetchUsers,
|
||||
updateTenant,
|
||||
@@ -705,7 +707,15 @@ const TenantTreeRow: React.FC<{
|
||||
variant="ghost"
|
||||
size="icon"
|
||||
className="h-8 w-8"
|
||||
onClick={() => navigate(`/tenants/${node.id}`)}
|
||||
onClick={() => {
|
||||
if (node.type === "USER_GROUP") {
|
||||
// User groups have a different detail path
|
||||
const baseTenantId = node.tenantId || tenantId;
|
||||
navigate(`/tenants/${baseTenantId}/organization/${node.id}`);
|
||||
} else {
|
||||
navigate(`/tenants/${node.id}`);
|
||||
}
|
||||
}}
|
||||
title={t("ui.common.manage", "관리")}
|
||||
>
|
||||
<ArrowRight size={14} />
|
||||
@@ -760,6 +770,23 @@ function TenantUserGroupsTab() {
|
||||
queryFn: () => fetchTenants(1000, 0),
|
||||
});
|
||||
|
||||
const { data: groupsData, isLoading: isGroupsLoading } = useQuery({
|
||||
queryKey: ["tenant-groups", tenantId],
|
||||
queryFn: () => fetchGroups(tenantId),
|
||||
enabled: !!tenantId,
|
||||
});
|
||||
|
||||
const groupNodes = useMemo(() => {
|
||||
if (!groupsData) return [];
|
||||
return groupsData.map((g) => ({
|
||||
...g,
|
||||
type: "USER_GROUP",
|
||||
children: [], // Simplified for now, just a list or separate tree
|
||||
memberCount: g.members?.length || 0,
|
||||
recursiveMemberCount: g.members?.length || 0,
|
||||
})) as unknown as TenantNode[];
|
||||
}, [groupsData]);
|
||||
|
||||
const updateParentMutation = useMutation({
|
||||
mutationFn: ({
|
||||
id,
|
||||
@@ -775,10 +802,17 @@ function TenantUserGroupsTab() {
|
||||
|
||||
const allTenants = data?.items ?? [];
|
||||
|
||||
const { currentBase, subTree } = useMemo(
|
||||
() => buildTenantFullTree(allTenants, tenantId),
|
||||
[allTenants, tenantId],
|
||||
);
|
||||
const { currentBase, subTree } = useMemo(() => {
|
||||
const tree = buildTenantFullTree(allTenants, tenantId);
|
||||
if (tree.currentBase) {
|
||||
// Merge backend-provided UserGroups into the tree as virtual children
|
||||
tree.currentBase.children = [
|
||||
...tree.currentBase.children,
|
||||
...groupNodes,
|
||||
];
|
||||
}
|
||||
return tree;
|
||||
}, [allTenants, tenantId, groupNodes]);
|
||||
|
||||
const handleAdd = (id: string) =>
|
||||
updateParentMutation.mutate({ id, parentId: tenantId });
|
||||
|
||||
Reference in New Issue
Block a user