Skip to content

Commit

Permalink
chore: adjust code
Browse files Browse the repository at this point in the history
  • Loading branch information
FinleyGe committed Jan 11, 2025
1 parent 80e298d commit f046b99
Show file tree
Hide file tree
Showing 37 changed files with 227 additions and 221 deletions.
6 changes: 3 additions & 3 deletions packages/global/core/app/type.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ import { TeamTagSchema as TeamTagsSchemaType } from '@fastgpt/global/support/use
import { StoreEdgeItemType } from '../workflow/type/edge';
import { AppPermission } from '../../support/permission/app/controller';
import { ParentIdType } from '../../common/parentFolder/type';
import { FlowNodeInputTypeEnum } from 'core/workflow/node/constant';
import { FlowNodeInputTypeEnum } from '../../core/workflow/node/constant';
import { WorkflowTemplateBasicType } from '@fastgpt/global/core/workflow/type';
import { SourceMember } from 'support/user/type';
import { SourceMemberType } from '../../support/user/type';

export type AppSchema = {
_id: string;
Expand Down Expand Up @@ -64,7 +64,7 @@ export type AppListItemType = {
permission: AppPermission;
inheritPermission?: boolean;
private?: boolean;
sourceMember?: SourceMember;
sourceMember: SourceMemberType;
};

export type AppDetailType = AppSchema & {
Expand Down
4 changes: 2 additions & 2 deletions packages/global/core/app/version.d.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { TeamMemberStatusEnum } from 'support/user/team/constant';
import { StoreEdgeItemType } from '../workflow/type/edge';
import { AppChatConfigType, AppSchema } from './type';
import { SourceMember } from 'support/user/type';
import { SourceMemberType } from 'support/user/type';

export type AppVersionSchemaType = {
_id: string;
Expand All @@ -22,5 +22,5 @@ export type VersionListItemType = {
time: Date;
isPublish: boolean | undefined;
tmbId: string;
sourceMember: SourceMember;
sourceMember: SourceMemberType;
};
4 changes: 2 additions & 2 deletions packages/global/core/dataset/type.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {
import { DatasetPermission } from '../../support/permission/dataset/controller';
import { Permission } from '../../support/permission/controller';
import { APIFileServer, FeishuServer, YuqueServer } from './apiDataset';
import { SourceMember } from 'support/user/type';
import { SourceMemberType } from 'support/user/type';

export type DatasetSchemaType = {
_id: string;
Expand Down Expand Up @@ -166,7 +166,7 @@ export type DatasetListItemType = {
vectorModel: VectorModelItemType;
inheritPermission: boolean;
private?: boolean;
sourceMember?: SourceMember;
sourceMember?: SourceMemberType;
};

export type DatasetItemType = Omit<DatasetSchemaType, 'vectorModel' | 'agentModel'> & {
Expand Down
1 change: 0 additions & 1 deletion packages/global/support/user/team/controller.d.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { PermissionValueType } from '../../permission/type';
import { SourceMember } from '../type';
import { TeamMemberRoleEnum } from './constant';
import { LafAccountType, TeamMemberSchema, ThirdPartyAccountType } from './type';

Expand Down
2 changes: 1 addition & 1 deletion packages/global/support/user/type.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export type UserType = {
permission: TeamPermission;
};

export type SourceMember = {
export type SourceMemberType = {
name: string;
avatar: string;
status: `${TeamMemberStatusEnum}`;
Expand Down
6 changes: 1 addition & 5 deletions packages/service/support/user/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ const { Schema } = connectionMongo;
import { hashStr } from '@fastgpt/global/common/string/tools';
import type { UserModelSchema } from '@fastgpt/global/support/user/type';
import { UserStatusEnum, userStatusMap } from '@fastgpt/global/support/user/constant';
import { getRandomUserAvatar } from '@fastgpt/global/support/user/utils';

export const userCollectionName = 'users';

Expand Down Expand Up @@ -60,10 +59,7 @@ const UserSchema = new Schema({
sourceDomain: String,

/** @deprecated */
avatar: {
type: String,
default: () => getRandomUserAvatar()
}
avatar: String
});

try {
Expand Down
2 changes: 1 addition & 1 deletion packages/web/common/fetch/type.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ type PaginationProps<T = {}> = T & {
pageNum: number | string;
}>;

type PaginationResponse<T = any> = {
type PaginationResponse<T = {}> = {
total: number;
list: T[];
};
74 changes: 38 additions & 36 deletions packages/web/components/common/MySelect/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -164,43 +164,45 @@ const MySelect = <T = any,>(
maxH={'40vh'}
overflowY={'auto'}
>
{ScrollData && (
<ScrollData>
{list.map((item, i) => (
<Box key={i}>
<MenuItem
{...menuItemStyles}
{...(value === item.value
? {
ref: SelectedItemRef,
color: 'primary.700',
bg: 'myGray.100',
fontWeight: '600'
}
: {
color: 'myGray.900'
})}
onClick={() => {
if (onChange && value !== item.value) {
onChange(item.value);
{(() => {
const component = list.map((item, i) => (
<Box key={i}>
<MenuItem
{...menuItemStyles}
{...(value === item.value
? {
ref: SelectedItemRef,
color: 'primary.700',
bg: 'myGray.100',
fontWeight: '600'
}
}}
whiteSpace={'pre-wrap'}
fontSize={'sm'}
display={'block'}
>
<Box>{item.label}</Box>
{item.description && (
<Box color={'myGray.500'} fontSize={'xs'}>
{item.description}
</Box>
)}
</MenuItem>
{item.showBorder && <MyDivider my={2} />}
</Box>
))}
</ScrollData>
)}
: {
color: 'myGray.900'
})}
onClick={() => {
if (onChange && value !== item.value) {
onChange(item.value);
}
}}
whiteSpace={'pre-wrap'}
fontSize={'sm'}
display={'block'}
>
<Box>{item.label}</Box>
{item.description && (
<Box color={'myGray.500'} fontSize={'xs'}>
{item.description}
</Box>
)}
</MenuItem>
{item.showBorder && <MyDivider my={2} />}
</Box>
));
if (ScrollData) {
return <ScrollData>{component}</ScrollData>;
}
return component;
})()}
</MenuList>
</Menu>
</Box>
Expand Down
30 changes: 30 additions & 0 deletions packages/web/components/common/UserBox/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { Box, HStack } from '@chakra-ui/react';
import { SourceMemberType } from '@fastgpt/global/support/user/type';
import React from 'react';
import Avatar from '../Avatar';
import { useTranslation } from 'next-i18next';
import Tag from '../Tag';

export type UserBoxProps = {
sourceMember: SourceMemberType;
fontSize?: string;
avatarSize?: string;
};
function UserBox({
sourceMember,
fontSize = 'sm',
avatarSize: AvatarWidth = '1.25rem'
}: UserBoxProps) {
const { t } = useTranslation();
return (
<HStack>
<Avatar src={sourceMember.avatar} w={AvatarWidth} />
<Box fontSize={fontSize} ml={1}>
{sourceMember.name}
{sourceMember.status === 'leave' && <Tag color="gray">{t('account_team:leaved')}</Tag>}
</Box>
</HStack>
);
}

export default React.memo(UserBox);
63 changes: 29 additions & 34 deletions packages/web/hooks/usePagination.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import { ArrowBackIcon, ArrowForwardIcon } from '@chakra-ui/icons';
import { useTranslation } from 'next-i18next';
import { useToast } from './useToast';
import { getErrText } from '@fastgpt/global/common/error/utils';

import {
useBoolean,
useLockFn,
Expand All @@ -14,37 +13,33 @@ import {
useThrottleEffect
} from 'ahooks';

const thresholdVal = 200;
import { PaginationProps, PaginationResponse } from '../common/fetch/type';

type PagingData<T> = {
pageNum: number;
pageSize: number;
data: T[];
total?: number;
};
const thresholdVal = 200;

export function usePagination<ResT = any>({
api,
pageSize = 10,
params = {},
defaultRequest = true,
type = 'button',
onChange,
refreshDeps,
scrollLoadType = 'bottom',
EmptyTip
}: {
api: (data: any) => Promise<PagingData<ResT>>;
pageSize?: number;
params?: Record<string, any>;
defaultRequest?: boolean;
type?: 'button' | 'scroll';
onChange?: (pageNum: number) => void;
refreshDeps?: any[];
throttleWait?: number;
scrollLoadType?: 'top' | 'bottom';
EmptyTip?: React.JSX.Element;
}) {
export function usePagination<DataT, ResT = {}>(
api: (data: PaginationProps<DataT>) => Promise<PaginationResponse<ResT>>,
{
pageSize = 10,
params,
defaultRequest = true,
type = 'button',
onChange,
refreshDeps,
scrollLoadType = 'bottom',
EmptyTip
}: {
pageSize?: number;
params?: DataT;
defaultRequest?: boolean;
type?: 'button' | 'scroll';
onChange?: (pageNum: number) => void;
refreshDeps?: any[];
throttleWait?: number;
scrollLoadType?: 'top' | 'bottom';
EmptyTip?: React.JSX.Element;
}
) {
const { toast } = useToast();
const { t } = useTranslation();

Expand All @@ -64,7 +59,7 @@ export function usePagination<ResT = any>({
setTrue();

try {
const res: PagingData<ResT> = await api({
const res = await api({
pageNum: num,
pageSize,
...params
Expand Down Expand Up @@ -93,13 +88,13 @@ export function usePagination<ResT = any>({
);
}

setData((prevData) => (num === 1 ? res.data : [...res.data, ...prevData]));
setData((prevData) => (num === 1 ? res.list : [...res.list, ...prevData]));
adjustScrollPosition();
} else {
setData((prevData) => (num === 1 ? res.data : [...prevData, ...res.data]));
setData((prevData) => (num === 1 ? res.list : [...prevData, ...res.list]));
}
} else {
setData(res.data);
setData(res.list);
}

onChange?.(num);
Expand Down
24 changes: 15 additions & 9 deletions packages/web/hooks/useScrollPagination.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import React, { ReactNode, RefObject, useMemo, useRef, useState } from 'react';
import { Box, BoxProps } from '@chakra-ui/react';
import { useToast } from './useToast';
import { getErrText } from '@fastgpt/global/common/error/utils';
import { PaginationResponse } from '../common/fetch/type';
import { PaginationProps, PaginationResponse } from '../common/fetch/type';
import {
useBoolean,
useLockFn,
Expand All @@ -29,8 +29,11 @@ export type ScrollListType = ({
isLoading?: boolean;
} & BoxProps) => React.JSX.Element;

export function useVirtualScrollPagination<TParams, TData>(
api: (data: TParams) => Promise<PaginationResponse<TData>>,
export function useVirtualScrollPagination<
TParams extends PaginationProps,
TData extends PaginationResponse
>(
api: (data: TParams) => Promise<TData>,
{
refreshDeps,
itemHeight = 50,
Expand All @@ -41,7 +44,7 @@ export function useVirtualScrollPagination<TParams, TData>(
}: {
refreshDeps?: any[];

itemHeight: number | ItemHeight<PaginationResponse<TData>['list'][0]>;
itemHeight: number | ItemHeight<TData['list'][0]>;
overscan?: number;

pageSize?: number;
Expand All @@ -53,13 +56,13 @@ export function useVirtualScrollPagination<TParams, TData>(
const wrapperRef = useRef(null);
const { toast } = useToast();

const [data, setData] = useState<PaginationResponse<TData>['list']>([]);
const [data, setData] = useState<TData['list']>([]);
const [total, setTotal] = useState(0);
const [isLoading, { setTrue, setFalse }] = useBoolean(false);

const noMore = data.length >= total;

const [list] = useVirtualList<PaginationResponse<TData>['list'][0]>(data, {
const [list] = useVirtualList<TData['list'][0]>(data, {
containerTarget: containerRef,
wrapperTarget: wrapperRef,
itemHeight,
Expand Down Expand Up @@ -174,8 +177,11 @@ export function useVirtualScrollPagination<TParams, TData>(
};
}

export function useScrollPagination<TParams, TData>(
api: (data: TParams) => Promise<PaginationResponse<TData>>,
export function useScrollPagination<
TParams extends PaginationProps,
TData extends PaginationResponse
>(
api: (data: TParams) => Promise<TData>,
{
refreshDeps,
scrollLoadType = 'bottom',
Expand All @@ -197,7 +203,7 @@ export function useScrollPagination<TParams, TData>(
const { t } = useTranslation();
const { toast } = useToast();

const [data, setData] = useState<PaginationResponse<TData>['list']>([]);
const [data, setData] = useState<TData['list']>([]);
const [total, setTotal] = useState(0);
const [isLoading, { setTrue, setFalse }] = useBoolean(false);
const isEmpty = total === 0 && !isLoading;
Expand Down
4 changes: 2 additions & 2 deletions projects/app/src/components/core/app/InputGuideConfig.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ const InputGuideConfig = ({
onChange: (e: ChatInputGuideConfigType) => void;
}) => {
const { t } = useTranslation();
const { chatT, commonT } = useI18n();
const { chatT } = useI18n();
const { isOpen, onOpen, onClose } = useDisclosure();
const {
isOpen: isOpenLexiconConfig,
Expand Down Expand Up @@ -220,7 +220,7 @@ const LexiconConfigModal = ({ appId, onClose }: { appId: string; onClose: () =>
});

const { run: createNewData, loading: isCreating } = useRequest2(
(textList: string[]) => {
async (textList: string[]) => {
if (textList.filter(Boolean).length === 0) {
return Promise.resolve();
}
Expand Down
Loading

0 comments on commit f046b99

Please sign in to comment.