Skip to content

Commit

Permalink
perf: rename function
Browse files Browse the repository at this point in the history
  • Loading branch information
c121914yu committed Jan 3, 2025
1 parent 31e1853 commit 0124cae
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 23 deletions.
2 changes: 1 addition & 1 deletion packages/global/support/user/team/org/constant.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { OrgSchemaType } from './type';
export const OrgCollectionName = 'team_orgs';
export const OrgMemberCollectionName = 'team_org_members';

export const getChildrenPath = (org: OrgSchemaType) => `${org.path}/${org.pathId}`;
export const getOrgChildrenPath = (org: OrgSchemaType) => `${org.path}/${org.pathId}`;

// export enum OrgMemberRole {
// owner = 'owner',
Expand Down
13 changes: 9 additions & 4 deletions packages/service/support/permission/org/controllers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ import type { OrgSchemaType } from '@fastgpt/global/support/user/team/org/type';
import type { ClientSession } from 'mongoose';
import { MongoOrgModel } from './orgSchema';
import { MongoOrgMemberModel } from './orgMemberSchema';
import { getChildrenPath } from '@fastgpt/global/support/user/team/org/constant';
import { getOrgChildrenPath } from '@fastgpt/global/support/user/team/org/constant';
import { getNanoid } from '@fastgpt/global/common/string/tools';

export const getOrgsByTmbId = async ({ teamId, tmbId }: { teamId: string; tmbId: string }) =>
MongoOrgMemberModel.find({ teamId, tmbId }, 'orgId').lean();
Expand Down Expand Up @@ -43,9 +44,13 @@ export const getChildrenByOrg = async ({
teamId: string;
session?: ClientSession;
}) => {
return MongoOrgModel.find({ teamId, path: { $regex: `^${getChildrenPath(org)}` } }, undefined, {
session
}).lean();
return MongoOrgModel.find(
{ teamId, path: { $regex: `^${getOrgChildrenPath(org)}` } },
undefined,
{
session
}
).lean();
};

export const getOrgAndChildren = async ({
Expand Down
8 changes: 3 additions & 5 deletions packages/service/support/permission/org/orgSchema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,6 @@ import { OrgMemberCollectionName } from './orgMemberSchema';
import { getNanoid } from '@fastgpt/global/common/string/tools';
const { Schema } = connectionMongo;

function requiredStringPath(this: OrgSchemaType) {
return typeof this.path !== 'string';
}

export const OrgSchema = new Schema(
{
teamId: {
Expand All @@ -25,7 +21,9 @@ export const OrgSchema = new Schema(
},
path: {
type: String,
required: requiredStringPath // allow empty string, but not null
required: function (this: OrgSchemaType) {
return typeof this.path !== 'string';
} // allow empty string, but not null
},
name: {
type: String,
Expand Down
2 changes: 1 addition & 1 deletion projects/app/src/pages/account/components/TeamSelector.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ const TeamSelector = ({
key={'manage'}
alignItems={'center'}
borderRadius={'md'}
cursor={'default'}
cursor={'pointer'}
gap={3}
onClick={() => router.push('/account/team')}
>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +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';
import { getOrgChildrenPath } from '@fastgpt/global/support/user/team/org/constant';

function OrgTreeNode({
org,
Expand All @@ -20,7 +20,7 @@ function OrgTreeNode({
index?: number;
}) {
const children = useMemo(
() => list.filter((item) => item.path === getChildrenPath(org)),
() => list.filter((item) => item.path === getOrgChildrenPath(org)),
[org, list]
);
const [isExpanded, toggleIsExpanded] = useToggle(index === 0);
Expand Down
27 changes: 17 additions & 10 deletions projects/app/src/pages/account/team/components/OrgManage/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ 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';
import { getOrgChildrenPath } from '@fastgpt/global/support/user/team/org/constant';

const OrgInfoModal = dynamic(() => import('./OrgInfoModal'));
const OrgMemberManageModal = dynamic(() => import('./OrgMemberManageModal'));
Expand Down Expand Up @@ -88,17 +88,20 @@ function OrgTable() {
});
const currentOrgs = useMemo(() => {
if (orgs.length === 0) return [];
// Auto select the first org(root org is team)
if (parentPath === '') {
setParentPath(`/${orgs[0].pathId}`);
setParentPath(getOrgChildrenPath(orgs[0]));
return [];
}

return orgs
.filter((org) => org.path === parentPath)
.map((item) => {
return {
...item,
// Member + org
count:
item.members.length + orgs.filter((org) => org.path === getChildrenPath(item)).length
item.members.length + orgs.filter((org) => org.path === getOrgChildrenPath(item)).length
};
});
}, [orgs, parentPath]);
Expand All @@ -109,6 +112,7 @@ function OrgTable() {

return orgs.find((org) => org.pathId === currentOrgId);
}, [orgs, parentPath]);

const paths = useMemo(() => {
const splitPath = parentPath.split('/').filter(Boolean);
return splitPath
Expand All @@ -118,7 +122,7 @@ function OrgTable() {
if (org.path === '') return;

return {
parentId: getChildrenPath(org),
parentId: getOrgChildrenPath(org),
parentName: org.name
};
})
Expand Down Expand Up @@ -175,7 +179,10 @@ function OrgTable() {
{currentOrgs.map((org) => (
<Tr key={org._id} overflow={'unset'}>
<Td>
<HStack cursor={'pointer'} onClick={() => setParentPath(getChildrenPath(org))}>
<HStack
cursor={'pointer'}
onClick={() => setParentPath(getOrgChildrenPath(org))}
>
<MemberTag name={org.name} avatar={org.avatar} />
<Tag size="sm">{org.count}</Tag>
<MyIcon
Expand Down Expand Up @@ -286,13 +293,13 @@ function OrgTable() {
});
}}
/>
<ActionButton
icon="common/administrator"
text={t('account_team:manage_member')}
onClick={() => setManageMemberOrg(currentOrg)}
/>
{currentOrg?.path !== '' && (
<>
<ActionButton
icon="common/administrator"
text={t('account_team:manage_member')}
onClick={() => setManageMemberOrg(currentOrg)}
/>
<ActionButton
icon="common/file/move"
text={t('account_team:move_org')}
Expand Down

0 comments on commit 0124cae

Please sign in to comment.