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