refactor: org pathId (#3516)

This commit is contained in:
a.e.
2025-01-03 09:53:53 +08:00
committed by archer
parent d24d29ac48
commit a401d4d612
6 changed files with 33 additions and 14 deletions

View File

@@ -4,6 +4,7 @@ import Avatar from '@fastgpt/web/components/common/Avatar';
import { useToggle } from 'ahooks';
import { useMemo } from 'react';
import IconButton from './IconButton';
import { getChildrenPath } from '@fastgpt/global/support/user/team/org/constant';
function OrgTreeNode({
org,
@@ -19,7 +20,7 @@ function OrgTreeNode({
index?: number;
}) {
const children = useMemo(
() => list.filter((item) => item.path === `${org.path}/${org._id}`),
() => list.filter((item) => item.path === getChildrenPath(org)),
[org, list]
);
const [isExpanded, toggleIsExpanded] = useToggle(index === 0);

View File

@@ -30,12 +30,13 @@ import { TeamContext } from '../context';
import { getOrgList } from '@/web/support/user/team/org/api';
import IconButton from './IconButton';
import type { defaultOrgForm, OrgFormType } from './OrgInfoModal';
import { defaultOrgForm, type OrgFormType } from './OrgInfoModal';
import dynamic from 'next/dynamic';
import MyBox from '@fastgpt/web/components/common/MyBox';
import Path from '@/components/common/folder/Path';
import { ParentTreePathItemType } from '@fastgpt/global/common/parentFolder/type';
import { getChildrenPath } from '@fastgpt/global/support/user/team/org/constant';
const OrgInfoModal = dynamic(() => import('./OrgInfoModal'));
const OrgMemberManageModal = dynamic(() => import('./OrgMemberManageModal'));
@@ -88,7 +89,7 @@ function OrgTable() {
const currentOrgs = useMemo(() => {
if (orgs.length === 0) return [];
if (parentPath === '') {
setParentPath(`/${orgs[0]._id}`);
setParentPath(`/${orgs[0].pathId}`);
return [];
}
return orgs
@@ -97,8 +98,7 @@ function OrgTable() {
return {
...item,
count:
item.members.length +
orgs.filter((org) => org.path === `${item.path}/${item._id}`).length
item.members.length + orgs.filter((org) => org.path === getChildrenPath(item)).length
};
});
}, [orgs, parentPath]);
@@ -107,18 +107,18 @@ function OrgTable() {
const currentOrgId = splitPath[splitPath.length - 1];
if (!currentOrgId) return;
return orgs.find((org) => org._id === currentOrgId);
return orgs.find((org) => org.pathId === currentOrgId);
}, [orgs, parentPath]);
const paths = useMemo(() => {
const splitPath = parentPath.split('/').filter(Boolean);
return splitPath
.map((id) => {
const org = orgs.find((org) => org._id === id)!;
const org = orgs.find((org) => org.pathId === id)!;
if (org.path === '') return;
return {
parentId: `${org.path}/${org._id}`,
parentId: getChildrenPath(org),
parentName: org.name
};
})
@@ -175,10 +175,7 @@ function OrgTable() {
{currentOrgs.map((org) => (
<Tr key={org._id} overflow={'unset'}>
<Td>
<HStack
cursor={'pointer'}
onClick={() => setParentPath(`${org.path}/${org._id}`)}
>
<HStack cursor={'pointer'} onClick={() => setParentPath(getChildrenPath(org))}>
<MemberTag name={org.name} avatar={org.avatar} />
<Tag size="sm">{org.count}</Tag>
<MyIcon