mirror of
https://github.com/labring/FastGPT.git
synced 2025-07-23 13:03:50 +00:00
fix: add delete all input guide lexicon button (#2241)
* fix: add delete all input guide lexicon button * fix * fix permisstion
This commit is contained in:
@@ -1,13 +1,15 @@
|
||||
{
|
||||
"Delete_all": "Delete all",
|
||||
"chat_input_guide_lexicon_is_empty": "The lexicon has not been configured",
|
||||
"config_input_guide": "Configure input boot",
|
||||
"config_input_guide_lexicon": "Config",
|
||||
"config_input_guide_lexicon_title": "Config lexicon",
|
||||
"csv_input_lexicon_tip": "Only CSV can be imported in batches. Click to download the template",
|
||||
"custom_input_guide_url": "Custom lexicon url",
|
||||
"delete_all_input_guide_confirm": "Confirm to delete all input guide lexicons",
|
||||
"input_guide": "Input guide",
|
||||
"input_guide_lexicon": "Lexicon",
|
||||
"input_guide_tip": "You can configure some preset questions. When the user enters a question, the relevant question is retrieved from these preset questions for prompt.",
|
||||
"insert_input_guide,_some_data_already_exists": "Duplicate data, automatically filtered, insert: {{len}} data",
|
||||
"new_input_guide_lexicon": "New lexicon"
|
||||
}
|
||||
}
|
||||
|
@@ -1,13 +1,15 @@
|
||||
{
|
||||
"Delete_all": "清空词库",
|
||||
"chat_input_guide_lexicon_is_empty": "还没有配置词库",
|
||||
"config_input_guide": "配置输入引导",
|
||||
"config_input_guide_lexicon": "配置词库",
|
||||
"config_input_guide_lexicon_title": "配置词库",
|
||||
"csv_input_lexicon_tip": "仅支持 CSV 批量导入,点击下载模板",
|
||||
"custom_input_guide_url": "自定义词库地址",
|
||||
"delete_all_input_guide_confirm": "确定要清空输入引导词库吗?",
|
||||
"input_guide": "输入引导",
|
||||
"input_guide_lexicon": "词库",
|
||||
"input_guide_tip": "可以配置一些预设的问题。在用户输入问题时,会从这些预设问题中获取相关问题进行提示。",
|
||||
"insert_input_guide,_some_data_already_exists": "有重复数据,已自动过滤,共插入 {{len}} 条数据",
|
||||
"new_input_guide_lexicon": "新词库"
|
||||
}
|
||||
}
|
||||
|
@@ -8,8 +8,7 @@ import {
|
||||
useDisclosure,
|
||||
Switch,
|
||||
Textarea,
|
||||
Checkbox,
|
||||
HStack
|
||||
Checkbox
|
||||
} from '@chakra-ui/react';
|
||||
import React, { useMemo, useState } from 'react';
|
||||
import { useTranslation } from 'next-i18next';
|
||||
@@ -21,6 +20,7 @@ import { useI18n } from '@/web/context/I18n';
|
||||
import { fileDownload } from '@/web/common/file/utils';
|
||||
import { getDocPath } from '@/web/common/system/doc';
|
||||
import {
|
||||
delAllChatInputGuide,
|
||||
delChatInputGuide,
|
||||
getChatInputGuideList,
|
||||
getCountChatInputGuideTotal,
|
||||
@@ -38,6 +38,7 @@ import HighlightText from '@fastgpt/web/components/common/String/HighlightText';
|
||||
import { defaultChatInputGuideConfig } from '@fastgpt/global/core/app/constants';
|
||||
import ChatFunctionTip from './Tip';
|
||||
import FormLabel from '@fastgpt/web/components/common/MyBox/FormLabel';
|
||||
import { useConfirm } from '@fastgpt/web/hooks/useConfirm';
|
||||
|
||||
const csvTemplate = `"第一列内容"
|
||||
"只会将第一列内容导入,其余列会被忽略"
|
||||
@@ -192,6 +193,10 @@ const LexiconConfigModal = ({ appId, onClose }: { appId: string; onClose: () =>
|
||||
|
||||
const [searchKey, setSearchKey] = useState('');
|
||||
|
||||
const { openConfirm: openConfirmDel, ConfirmModal: DelConfirmModal } = useConfirm({
|
||||
type: 'delete'
|
||||
});
|
||||
|
||||
const {
|
||||
list,
|
||||
setData,
|
||||
@@ -275,6 +280,12 @@ const LexiconConfigModal = ({ appId, onClose }: { appId: string; onClose: () =>
|
||||
dataIdList
|
||||
});
|
||||
};
|
||||
const onDeleteAllData = () => {
|
||||
setData([]);
|
||||
delAllChatInputGuide({
|
||||
appId
|
||||
});
|
||||
};
|
||||
|
||||
const onSelectFile = async (files: File[]) => {
|
||||
const file = files?.[0];
|
||||
@@ -346,6 +357,24 @@ const LexiconConfigModal = ({ appId, onClose }: { appId: string; onClose: () =>
|
||||
>
|
||||
{commonT('common.Delete')}
|
||||
</Button>
|
||||
<Button
|
||||
variant={'whiteBase'}
|
||||
display={selectedRows.length !== 0 ? 'none' : 'flex'}
|
||||
size={'sm'}
|
||||
leftIcon={<MyIcon name={'delete'} boxSize={4} />}
|
||||
onClick={() =>
|
||||
openConfirmDel(
|
||||
() => {
|
||||
onDeleteAllData();
|
||||
setSelectedRows([]);
|
||||
},
|
||||
undefined,
|
||||
t('chat:delete_all_input_guide_confirm')
|
||||
)()
|
||||
}
|
||||
>
|
||||
{t('chat:Delete_all')}
|
||||
</Button>
|
||||
<Button
|
||||
display={selectedRows.length !== 0 ? 'none' : 'flex'}
|
||||
onClick={() => {
|
||||
@@ -476,6 +505,7 @@ const LexiconConfigModal = ({ appId, onClose }: { appId: string; onClose: () =>
|
||||
})}
|
||||
</ScrollList>
|
||||
|
||||
<DelConfirmModal />
|
||||
<File onSelect={onSelectFile} />
|
||||
</MyModal>
|
||||
);
|
||||
|
@@ -2,21 +2,14 @@ import type { ApiRequestProps, ApiResponseType } from '@fastgpt/service/type/nex
|
||||
import { NextAPI } from '@/service/middleware/entry';
|
||||
import { authApp } from '@fastgpt/service/support/permission/app/auth';
|
||||
import { MongoChatInputGuide } from '@fastgpt/service/core/chat/inputGuide/schema';
|
||||
import { ReadPermissionVal } from '@fastgpt/global/support/permission/constant';
|
||||
|
||||
export type deleteChatInputGuideQuery = {};
|
||||
import { WritePermissionVal } from '@fastgpt/global/support/permission/constant';
|
||||
|
||||
export type deleteInputGuideBody = { appId: string; dataIdList: string[] };
|
||||
|
||||
export type deleteInputGuideResponse = {};
|
||||
|
||||
async function handler(
|
||||
req: ApiRequestProps<deleteInputGuideBody, deleteChatInputGuideQuery>,
|
||||
res: ApiResponseType<any>
|
||||
): Promise<deleteInputGuideResponse> {
|
||||
async function handler(req: ApiRequestProps<deleteInputGuideBody, ''>, res: ApiResponseType<any>) {
|
||||
const { appId, dataIdList } = req.body;
|
||||
await authApp({ req, appId, authToken: true, per: ReadPermissionVal });
|
||||
console.log(dataIdList);
|
||||
await authApp({ req, appId, authToken: true, per: WritePermissionVal });
|
||||
|
||||
await MongoChatInputGuide.deleteMany({
|
||||
_id: { $in: dataIdList },
|
||||
appId
|
||||
|
23
projects/app/src/pages/api/core/chat/inputGuide/deleteAll.ts
Normal file
23
projects/app/src/pages/api/core/chat/inputGuide/deleteAll.ts
Normal file
@@ -0,0 +1,23 @@
|
||||
import type { ApiRequestProps, ApiResponseType } from '@fastgpt/service/type/next';
|
||||
import { NextAPI } from '@/service/middleware/entry';
|
||||
import { authApp } from '@fastgpt/service/support/permission/app/auth';
|
||||
import { MongoChatInputGuide } from '@fastgpt/service/core/chat/inputGuide/schema';
|
||||
import { WritePermissionVal } from '@fastgpt/global/support/permission/constant';
|
||||
|
||||
export type deleteAllInputGuideBody = { appId: string };
|
||||
|
||||
async function handler(
|
||||
req: ApiRequestProps<deleteAllInputGuideBody, ''>,
|
||||
res: ApiResponseType<any>
|
||||
) {
|
||||
const { appId } = req.body;
|
||||
await authApp({ req, appId, authToken: true, per: WritePermissionVal });
|
||||
|
||||
await MongoChatInputGuide.deleteMany({
|
||||
appId
|
||||
});
|
||||
|
||||
return {};
|
||||
}
|
||||
|
||||
export default NextAPI(handler);
|
@@ -2,7 +2,7 @@ import type { ApiRequestProps, ApiResponseType } from '@fastgpt/service/type/nex
|
||||
import { NextAPI } from '@/service/middleware/entry';
|
||||
import { authApp } from '@fastgpt/service/support/permission/app/auth';
|
||||
import { MongoChatInputGuide } from '@fastgpt/service/core/chat/inputGuide/schema';
|
||||
import { ReadPermissionVal } from '@fastgpt/global/support/permission/constant';
|
||||
import { WritePermissionVal } from '@fastgpt/global/support/permission/constant';
|
||||
|
||||
export type updateChatInputGuideQuery = {};
|
||||
|
||||
@@ -19,7 +19,7 @@ async function handler(
|
||||
res: ApiResponseType<any>
|
||||
): Promise<updateInputGuideResponse> {
|
||||
const { appId, dataId, text } = req.body;
|
||||
await authApp({ req, appId, authToken: true, per: ReadPermissionVal });
|
||||
await authApp({ req, appId, authToken: true, per: WritePermissionVal });
|
||||
|
||||
await MongoChatInputGuide.findOneAndUpdate(
|
||||
{
|
||||
|
@@ -12,11 +12,12 @@ import type {
|
||||
createInputGuideResponse
|
||||
} from '@/pages/api/core/chat/inputGuide/create';
|
||||
import type { updateInputGuideBody } from '@/pages/api/core/chat/inputGuide/update';
|
||||
import type { deleteChatInputGuideQuery } from '@/pages/api/core/chat/inputGuide/delete';
|
||||
import type { deleteInputGuideBody } from '@/pages/api/core/chat/inputGuide/delete';
|
||||
import type {
|
||||
QueryChatInputGuideBody,
|
||||
QueryChatInputGuideResponse
|
||||
} from '@/pages/api/core/chat/inputGuide/query';
|
||||
import { deleteAllInputGuideBody } from '@/pages/api/core/chat/inputGuide/deleteAll';
|
||||
|
||||
export const getCountChatInputGuideTotal = (data: countChatInputGuideTotalQuery) =>
|
||||
GET<countChatInputGuideTotalResponse>(`/core/chat/inputGuide/countTotal`, data);
|
||||
@@ -39,5 +40,7 @@ export const postChatInputGuides = (data: createInputGuideBody) =>
|
||||
POST<createInputGuideResponse>(`/core/chat/inputGuide/create`, data);
|
||||
export const putChatInputGuide = (data: updateInputGuideBody) =>
|
||||
PUT(`/core/chat/inputGuide/update`, data);
|
||||
export const delChatInputGuide = (data: deleteChatInputGuideQuery) =>
|
||||
export const delChatInputGuide = (data: deleteInputGuideBody) =>
|
||||
POST(`/core/chat/inputGuide/delete`, data);
|
||||
export const delAllChatInputGuide = (data: deleteAllInputGuideBody) =>
|
||||
POST(`/core/chat/inputGuide/deleteAll`, data);
|
||||
|
Reference in New Issue
Block a user