4.8.4 (#1746)
This commit is contained in:
@@ -2,7 +2,7 @@ import React from 'react';
|
||||
import MyModal from '@fastgpt/web/components/common/MyModal';
|
||||
import { useTranslation } from 'next-i18next';
|
||||
import { PermissionValueType } from '@fastgpt/global/support/permission/type';
|
||||
import { MemberManagerInputPropsType, CollaboratorContextProvider } from '../MemberManager/context';
|
||||
import CollaboratorContextProvider, { MemberManagerInputPropsType } from '../MemberManager/context';
|
||||
import { Box, Button, Flex, HStack, ModalBody } from '@chakra-ui/react';
|
||||
import Avatar from '@/components/Avatar';
|
||||
import DefaultPermissionList from '../DefaultPerList';
|
||||
|
||||
@@ -20,8 +20,11 @@ const PermissionIconText = ({
|
||||
|
||||
const per = useMemo(() => {
|
||||
if (permission) return permission;
|
||||
if (defaultPermission) {
|
||||
return new Permission({ per: defaultPermission }).hasReadPer ? 'public' : 'private';
|
||||
if (defaultPermission !== undefined) {
|
||||
const Per = new Permission({ per: defaultPermission });
|
||||
if (Per.hasWritePer) return PermissionTypeEnum.publicWrite;
|
||||
if (Per.hasReadPer) return PermissionTypeEnum.publicRead;
|
||||
return PermissionTypeEnum.clbPrivate;
|
||||
}
|
||||
return 'private';
|
||||
}, [defaultPermission, permission]);
|
||||
|
||||
@@ -26,12 +26,14 @@ import MyBox from '@fastgpt/web/components/common/MyBox';
|
||||
import { ChevronDownIcon } from '@chakra-ui/icons';
|
||||
import Avatar from '@/components/Avatar';
|
||||
import { useRequest } from '@fastgpt/web/hooks/useRequest';
|
||||
import { useTranslation } from 'next-i18next';
|
||||
|
||||
export type AddModalPropsType = {
|
||||
onClose: () => void;
|
||||
};
|
||||
|
||||
function AddMemberModal({ onClose }: AddModalPropsType) {
|
||||
const { t } = useTranslation();
|
||||
const { userInfo } = useUserStore();
|
||||
|
||||
const { permissionList, collaboratorList, onUpdateCollaborators, getPerLabelList } =
|
||||
@@ -63,9 +65,12 @@ function AddMemberModal({ onClose }: AddModalPropsType) {
|
||||
|
||||
const { mutate: onConfirm, isLoading: isUpdating } = useRequest({
|
||||
mutationFn: () => {
|
||||
return onUpdateCollaborators(selectedMemberIdList, selectedPermission);
|
||||
return onUpdateCollaborators({
|
||||
tmbIds: selectedMemberIdList,
|
||||
permission: selectedPermission
|
||||
});
|
||||
},
|
||||
successToast: '添加成功',
|
||||
successToast: t('common.Add Success'),
|
||||
errorToast: 'Error',
|
||||
onSuccess() {
|
||||
onClose();
|
||||
|
||||
@@ -39,7 +39,10 @@ function ManageModal({ onClose }: ManageModalProps) {
|
||||
|
||||
const { mutate: onUpdate, isLoading: isUpdating } = useRequest({
|
||||
mutationFn: ({ tmbId, per }: { tmbId: string; per: PermissionValueType }) => {
|
||||
return onUpdateCollaborators([tmbId], per);
|
||||
return onUpdateCollaborators({
|
||||
tmbIds: [tmbId],
|
||||
permission: per
|
||||
});
|
||||
},
|
||||
successToast: '更新成功',
|
||||
errorToast: 'Error'
|
||||
|
||||
@@ -6,7 +6,8 @@ import {
|
||||
MenuList,
|
||||
Box,
|
||||
Radio,
|
||||
useOutsideClick
|
||||
useOutsideClick,
|
||||
HStack
|
||||
} from '@chakra-ui/react';
|
||||
import React, { useMemo, useRef, useState } from 'react';
|
||||
import MyIcon from '@fastgpt/web/components/common/Icon';
|
||||
@@ -142,9 +143,15 @@ function PermissionSelect({
|
||||
bottom={0}
|
||||
left={0}
|
||||
/>
|
||||
<Box position={'relative'} cursor={'pointer'} userSelect={'none'}>
|
||||
<Flex
|
||||
alignItems={'center'}
|
||||
justifyContent={'center'}
|
||||
position={'relative'}
|
||||
cursor={'pointer'}
|
||||
userSelect={'none'}
|
||||
>
|
||||
{Button}
|
||||
</Box>
|
||||
</Flex>
|
||||
</Box>
|
||||
<MenuList
|
||||
minW={isOpen ? `${width}px !important` : 0}
|
||||
@@ -182,7 +189,7 @@ function PermissionSelect({
|
||||
<Box ml={4}>
|
||||
<Box>{item.name}</Box>
|
||||
<Box color={'myGray.500'} fontSize={'mini'}>
|
||||
{item.description}
|
||||
{t(item.description)}
|
||||
</Box>
|
||||
</Box>
|
||||
</Flex>
|
||||
@@ -236,7 +243,7 @@ function PermissionSelect({
|
||||
{onDelete && (
|
||||
<>
|
||||
<MyDivider my={2} h={'2px'} borderColor={'myGray.200'} />
|
||||
<Flex
|
||||
<HStack
|
||||
{...MenuStyle}
|
||||
onClick={() => {
|
||||
onDelete();
|
||||
@@ -244,8 +251,8 @@ function PermissionSelect({
|
||||
}}
|
||||
>
|
||||
<MyIcon name="delete" w="20px" color="red.600" />
|
||||
<Box color="red.600">{t('common.Delete')}</Box>
|
||||
</Flex>
|
||||
<Box color="red.600">{t('common.Remove')}</Box>
|
||||
</HStack>
|
||||
</>
|
||||
)}
|
||||
</MenuList>
|
||||
|
||||
@@ -1,5 +1,8 @@
|
||||
import { BoxProps, useDisclosure } from '@chakra-ui/react';
|
||||
import { CollaboratorItemType } from '@fastgpt/global/support/permission/collaborator';
|
||||
import {
|
||||
CollaboratorItemType,
|
||||
UpdateClbPermissionProps
|
||||
} from '@fastgpt/global/support/permission/collaborator';
|
||||
import { PermissionList } from '@fastgpt/global/support/permission/constant';
|
||||
import { Permission } from '@fastgpt/global/support/permission/controller';
|
||||
import { PermissionListType, PermissionValueType } from '@fastgpt/global/support/permission/type';
|
||||
@@ -9,6 +12,7 @@ import { createContext } from 'use-context-selector';
|
||||
import dynamic from 'next/dynamic';
|
||||
|
||||
import MemberListCard, { MemberListCardProps } from './MemberListCard';
|
||||
import { useRequest2 } from '@fastgpt/web/hooks/useRequest';
|
||||
const AddMemberModal = dynamic(() => import('./AddMemberModal'));
|
||||
const ManageModal = dynamic(() => import('./ManageModal'));
|
||||
|
||||
@@ -16,8 +20,9 @@ export type MemberManagerInputPropsType = {
|
||||
permission: Permission;
|
||||
onGetCollaboratorList: () => Promise<CollaboratorItemType[]>;
|
||||
permissionList: PermissionListType;
|
||||
onUpdateCollaborators: (tmbIds: string[], permission: PermissionValueType) => any;
|
||||
onUpdateCollaborators: (props: UpdateClbPermissionProps) => any;
|
||||
onDelOneCollaborator: (tmbId: string) => any;
|
||||
refreshDeps?: any[];
|
||||
};
|
||||
export type MemberManagerPropsType = MemberManagerInputPropsType & {
|
||||
collaboratorList: CollaboratorItemType[];
|
||||
@@ -55,24 +60,28 @@ export const CollaboratorContext = createContext<CollaboratorContextType>({
|
||||
permission: new Permission()
|
||||
});
|
||||
|
||||
export const CollaboratorContextProvider = ({
|
||||
const CollaboratorContextProvider = ({
|
||||
permission,
|
||||
onGetCollaboratorList,
|
||||
permissionList,
|
||||
onUpdateCollaborators,
|
||||
onDelOneCollaborator,
|
||||
refreshDeps = [],
|
||||
children
|
||||
}: MemberManagerInputPropsType & {
|
||||
children: (props: ChildrenProps) => ReactNode;
|
||||
}) => {
|
||||
const {
|
||||
data: collaboratorList = [],
|
||||
refetch: refetchCollaboratorList,
|
||||
isLoading: isFetchingCollaborator
|
||||
} = useQuery(['collaboratorList'], onGetCollaboratorList);
|
||||
runAsync: refetchCollaboratorList,
|
||||
loading: isFetchingCollaborator
|
||||
} = useRequest2(onGetCollaboratorList, {
|
||||
manual: false,
|
||||
refreshDeps
|
||||
});
|
||||
|
||||
const onUpdateCollaboratorsThen = async (tmbIds: string[], permission: PermissionValueType) => {
|
||||
await onUpdateCollaborators(tmbIds, permission);
|
||||
const onUpdateCollaboratorsThen = async (props: UpdateClbPermissionProps) => {
|
||||
await onUpdateCollaborators(props);
|
||||
refetchCollaboratorList();
|
||||
};
|
||||
const onDelOneCollaboratorThen = async (tmbId: string) => {
|
||||
@@ -136,3 +145,5 @@ export const CollaboratorContextProvider = ({
|
||||
</CollaboratorContext.Provider>
|
||||
);
|
||||
};
|
||||
|
||||
export default CollaboratorContextProvider;
|
||||
|
||||
@@ -0,0 +1,66 @@
|
||||
import React, { useMemo } from 'react';
|
||||
import { Permission } from '@fastgpt/global/support/permission/controller';
|
||||
import { PermissionListType } from '@fastgpt/global/support/permission/type';
|
||||
import { PermissionList } from '@fastgpt/global/support/permission/constant';
|
||||
import MyTag from '@fastgpt/web/components/common/Tag/index';
|
||||
import { HStack } from '@chakra-ui/react';
|
||||
import { useTranslation } from 'next-i18next';
|
||||
|
||||
const PermissionTag = ({
|
||||
permission,
|
||||
permissionList
|
||||
}: {
|
||||
permission: Permission;
|
||||
permissionList: PermissionListType;
|
||||
}) => {
|
||||
const { t } = useTranslation();
|
||||
|
||||
const { commonLabel, otherLabels } = useMemo(() => {
|
||||
const Per = new Permission({ per: permission.value });
|
||||
|
||||
const commonLabel = (() => {
|
||||
if (permission.isOwner) return t('permission.Owner');
|
||||
if (permission.hasManagePer) return PermissionList['manage'].name;
|
||||
if (permission.hasWritePer) return PermissionList['write'].name;
|
||||
if (permission.hasReadPer) return PermissionList['read'].name;
|
||||
|
||||
return;
|
||||
})();
|
||||
|
||||
const otherLabels: string[] = [];
|
||||
Object.values(permissionList).forEach((item) => {
|
||||
if (item.checkBoxType === 'multiple') {
|
||||
if (Per.checkPer(item.value)) {
|
||||
otherLabels.push(item.name);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
return {
|
||||
commonLabel,
|
||||
otherLabels
|
||||
};
|
||||
}, [
|
||||
permission.hasManagePer,
|
||||
permission.hasReadPer,
|
||||
permission.hasWritePer,
|
||||
permission.value,
|
||||
permissionList
|
||||
]);
|
||||
return (
|
||||
<HStack>
|
||||
{commonLabel && (
|
||||
<MyTag type="fill" colorSchema="blue">
|
||||
{commonLabel}
|
||||
</MyTag>
|
||||
)}
|
||||
{otherLabels.map((tag, i) => (
|
||||
<MyTag key={i} type="fill" colorSchema="purple">
|
||||
{tag}
|
||||
</MyTag>
|
||||
))}
|
||||
</HStack>
|
||||
);
|
||||
};
|
||||
|
||||
export default PermissionTag;
|
||||
Reference in New Issue
Block a user