mirror of
https://github.com/labring/FastGPT.git
synced 2025-07-23 13:03:50 +00:00

* feat: retry send * perf: qa default value * feat: dataset folder * feat: kb folder delete and path * fix: ts * perf: script load * feat: fileCard and dataCard * feat: search file * feat: max token * feat: select dataset * fix: preview chunk * perf: source update * export data limit file_id * docs * fix: export limit
86 lines
1.9 KiB
TypeScript
86 lines
1.9 KiB
TypeScript
import React, { useMemo, useRef } from 'react';
|
|
import { ModalFooter, ModalBody, Input, Button } from '@chakra-ui/react';
|
|
import MyModal from '@/components/MyModal';
|
|
import { useTranslation } from 'react-i18next';
|
|
import { useRequest } from '@/hooks/useRequest';
|
|
import { postCreateKb, putKbById } from '@/api/plugins/kb';
|
|
import { FolderAvatarSrc, KbTypeEnum } from '@/constants/kb';
|
|
|
|
const EditFolderModal = ({
|
|
onClose,
|
|
onSuccess,
|
|
id,
|
|
parentId,
|
|
name
|
|
}: {
|
|
onClose: () => void;
|
|
onSuccess: () => void;
|
|
id?: string;
|
|
parentId?: string;
|
|
name?: string;
|
|
}) => {
|
|
const { t } = useTranslation();
|
|
const inputRef = useRef<HTMLInputElement>(null);
|
|
|
|
const typeMap = useMemo(
|
|
() =>
|
|
id
|
|
? {
|
|
title: t('kb.Edit Folder')
|
|
}
|
|
: {
|
|
title: t('kb.Create Folder')
|
|
},
|
|
[id, t]
|
|
);
|
|
|
|
const { mutate: onSave, isLoading } = useRequest({
|
|
mutationFn: () => {
|
|
const val = inputRef.current?.value;
|
|
if (!val) return Promise.resolve('');
|
|
if (id) {
|
|
return putKbById({
|
|
id,
|
|
name: val
|
|
});
|
|
}
|
|
return postCreateKb({
|
|
parentId,
|
|
name: val,
|
|
type: KbTypeEnum.folder,
|
|
avatar: FolderAvatarSrc,
|
|
tags: []
|
|
});
|
|
},
|
|
onSuccess: (res) => {
|
|
if (!res) return;
|
|
onSuccess();
|
|
onClose();
|
|
}
|
|
});
|
|
|
|
return (
|
|
<MyModal isOpen onClose={onClose} title={typeMap.title}>
|
|
<ModalBody>
|
|
<Input
|
|
ref={inputRef}
|
|
defaultValue={name}
|
|
placeholder={t('kb.Folder Name') || ''}
|
|
autoFocus
|
|
maxLength={20}
|
|
/>
|
|
</ModalBody>
|
|
<ModalFooter>
|
|
<Button mr={3} variant={'base'} onClick={onClose}>
|
|
{t('common.Cancel')}
|
|
</Button>
|
|
<Button isLoading={isLoading} onClick={onSave}>
|
|
{t('Confirm')}
|
|
</Button>
|
|
</ModalFooter>
|
|
</MyModal>
|
|
);
|
|
};
|
|
|
|
export default EditFolderModal;
|