Commit e4be02e2 by Xianquan Committed by GitHub

fix(chat): limit quick apps max amount to 3 (#7445)

* fix(chat): limit quick apps max amount to 3

* chore: remove frontend restrict

* fix(chat): validate legacy quick app settings
parent 4d6f95c6
...@@ -271,6 +271,7 @@ ...@@ -271,6 +271,7 @@
"setting.home.no_selected_app": "No selected App", "setting.home.no_selected_app": "No selected App",
"setting.home.quick_apps": "Quick Apps", "setting.home.quick_apps": "Quick Apps",
"setting.home.quick_apps.add": "Configure quick applications", "setting.home.quick_apps.add": "Configure quick applications",
"setting.home.quick_apps.over_limit": "You can add up to {{max}} quick apps. Remove the extras before saving.",
"setting.home.quick_apps.placeholder": "Please select an application", "setting.home.quick_apps.placeholder": "Please select an application",
"setting.home.slogan": "Slogan", "setting.home.slogan": "Slogan",
"setting.home.slogan.default": "今天想做点什么?", "setting.home.slogan.default": "今天想做点什么?",
......
...@@ -271,6 +271,7 @@ ...@@ -271,6 +271,7 @@
"setting.home.no_selected_app": "未选择应用", "setting.home.no_selected_app": "未选择应用",
"setting.home.quick_apps": "快捷应用", "setting.home.quick_apps": "快捷应用",
"setting.home.quick_apps.add": "配置快捷应用", "setting.home.quick_apps.add": "配置快捷应用",
"setting.home.quick_apps.over_limit": "快捷应用最多只能添加 {{max}} 个,请先移除多余应用后再保存",
"setting.home.quick_apps.placeholder": "请选择应用", "setting.home.quick_apps.placeholder": "请选择应用",
"setting.home.slogan": "Slogan", "setting.home.slogan": "Slogan",
"setting.home.slogan.default": "今天想做点什么?", "setting.home.slogan.default": "今天想做点什么?",
......
...@@ -267,6 +267,7 @@ ...@@ -267,6 +267,7 @@
"setting.home.no_selected_app": "未選擇應用", "setting.home.no_selected_app": "未選擇應用",
"setting.home.quick_apps": "快捷應用", "setting.home.quick_apps": "快捷應用",
"setting.home.quick_apps.add": "配置快捷應用", "setting.home.quick_apps.add": "配置快捷應用",
"setting.home.quick_apps.over_limit": "快捷應用最多只能添加 {{max}} 個,請先移除多餘應用後再保存",
"setting.home.quick_apps.placeholder": "請選擇應用", "setting.home.quick_apps.placeholder": "請選擇應用",
"setting.home.slogan": "Slogan", "setting.home.slogan": "Slogan",
"setting.home.slogan.default": "今天想做點什麼?", "setting.home.slogan.default": "今天想做點什麼?",
......
...@@ -17,6 +17,7 @@ import { AppTypeEnum } from '@fastgpt/global/core/app/constants'; ...@@ -17,6 +17,7 @@ import { AppTypeEnum } from '@fastgpt/global/core/app/constants';
import { getAppFolderPath } from '@/web/core/app/api/app'; import { getAppFolderPath } from '@/web/core/app/api/app';
import { ChevronRightIcon } from '@chakra-ui/icons'; import { ChevronRightIcon } from '@chakra-ui/icons';
import type { ParentIdType } from '@fastgpt/global/common/parentFolder/type'; import type { ParentIdType } from '@fastgpt/global/common/parentFolder/type';
import { MAX_QUICK_APP_COUNT } from './constants';
type Props = { type Props = {
selectedIds: string[]; selectedIds: string[];
...@@ -90,7 +91,7 @@ const AddQuickAppModal = ({ selectedIds, onClose, onConfirm }: Props) => { ...@@ -90,7 +91,7 @@ const AddQuickAppModal = ({ selectedIds, onClose, onConfirm }: Props) => {
}); });
return prev.filter((v) => v !== id); return prev.filter((v) => v !== id);
} }
if (prev.length >= 4) return prev; if (prev.length >= MAX_QUICK_APP_COUNT) return prev;
// add id and cache its info if available from current list // add id and cache its info if available from current list
const app = availableAppsMap.get(id); const app = availableAppsMap.get(id);
if (app) { if (app) {
...@@ -312,7 +313,7 @@ const AddQuickAppModal = ({ selectedIds, onClose, onConfirm }: Props) => { ...@@ -312,7 +313,7 @@ const AddQuickAppModal = ({ selectedIds, onClose, onConfirm }: Props) => {
<VStack spacing={2} alignItems="stretch" h="100%" minH={0} minW={0}> <VStack spacing={2} alignItems="stretch" h="100%" minH={0} minW={0}>
<Box pb={3} px={4} pt={4} fontSize="sm" color="myGray.600"> <Box pb={3} px={4} pt={4} fontSize="sm" color="myGray.600">
{t('chat:setting.favourite.selected_list', { {t('chat:setting.favourite.selected_list', {
num: `${checkedQuickApps.length} / 4` num: `${checkedQuickApps.length} / ${MAX_QUICK_APP_COUNT}`
})} })}
</Box> </Box>
...@@ -414,7 +415,12 @@ const AddQuickAppModal = ({ selectedIds, onClose, onConfirm }: Props) => { ...@@ -414,7 +415,12 @@ const AddQuickAppModal = ({ selectedIds, onClose, onConfirm }: Props) => {
<Button variant="whitePrimary" isDisabled={isUpdating} onClick={onClose}> <Button variant="whitePrimary" isDisabled={isUpdating} onClick={onClose}>
{t('chat:setting.home.cancel_button')} {t('chat:setting.home.cancel_button')}
</Button> </Button>
<Button variant="primary" isLoading={isUpdating} onClick={confirmSelect}> <Button
variant="primary"
isLoading={isUpdating}
isDisabled={checkedQuickApps.length > MAX_QUICK_APP_COUNT}
onClick={confirmSelect}
>
{t('chat:setting.home.confirm_button')} {t('chat:setting.home.confirm_button')}
</Button> </Button>
</HStack> </HStack>
......
...@@ -31,6 +31,8 @@ import { ...@@ -31,6 +31,8 @@ import {
import { useSystem } from '@fastgpt/web/hooks/useSystem'; import { useSystem } from '@fastgpt/web/hooks/useSystem';
import dynamic from 'next/dynamic'; import dynamic from 'next/dynamic';
import type { ChatSettingType } from '@fastgpt/global/core/chat/setting/type'; import type { ChatSettingType } from '@fastgpt/global/core/chat/setting/type';
import { useToast } from '@fastgpt/web/hooks/useToast';
import { MAX_QUICK_APP_COUNT } from './constants';
const AddQuickAppModal = dynamic( const AddQuickAppModal = dynamic(
() => import('@/pageComponents/chat/ChatSetting/HomepageSetting/AddQuickAppModal') () => import('@/pageComponents/chat/ChatSetting/HomepageSetting/AddQuickAppModal')
...@@ -44,6 +46,7 @@ type Props = { ...@@ -44,6 +46,7 @@ type Props = {
const HomepageSetting = ({ Header, onDiagramShow }: Props) => { const HomepageSetting = ({ Header, onDiagramShow }: Props) => {
const { isPc } = useSystem(); const { isPc } = useSystem();
const { t } = useTranslation(); const { t } = useTranslation();
const { toast } = useToast();
const { feConfigs } = useSystemStore(); const { feConfigs } = useSystemStore();
const chatSettings = useContextSelector(ChatPageContext, (v) => v.chatSettings); const chatSettings = useContextSelector(ChatPageContext, (v) => v.chatSettings);
...@@ -112,7 +115,7 @@ const HomepageSetting = ({ Header, onDiagramShow }: Props) => { ...@@ -112,7 +115,7 @@ const HomepageSetting = ({ Header, onDiagramShow }: Props) => {
[selectedTools, setValue] [selectedTools, setValue]
); );
const { runAsync: onSubmit, loading: isSaving } = useRequest( const { runAsync: saveChatSetting, loading: isSaving } = useRequest(
async (values: ChatSettingType) => { async (values: ChatSettingType) => {
const { quickAppList, ...params } = values; const { quickAppList, ...params } = values;
return updateChatSetting({ return updateChatSetting({
...@@ -132,6 +135,20 @@ const HomepageSetting = ({ Header, onDiagramShow }: Props) => { ...@@ -132,6 +135,20 @@ const HomepageSetting = ({ Header, onDiagramShow }: Props) => {
} }
); );
const onSubmit = useCallback(
(values: ChatSettingType) => {
if (values.quickAppList.length > MAX_QUICK_APP_COUNT) {
toast({
status: 'warning',
title: t('chat:setting.home.quick_apps.over_limit', { max: MAX_QUICK_APP_COUNT })
});
return;
}
return saveChatSetting(values);
},
[saveChatSetting, t, toast]
);
const { const {
isOpen: isOpenAddQuickApp, isOpen: isOpenAddQuickApp,
onOpen: onOpenAddQuickApp, onOpen: onOpenAddQuickApp,
......
...@@ -504,7 +504,7 @@ const HomeChatWindow = () => { ...@@ -504,7 +504,7 @@ const HomeChatWindow = () => {
onStartChat={onStartChat} onStartChat={onStartChat}
onMarkChatRead={postMarkChatRead} onMarkChatRead={postMarkChatRead}
onChatGenerateStatusChange={onChatGenerateStatusChange} onChatGenerateStatusChange={onChatGenerateStatusChange}
quickAppList={(chatSettings?.quickAppList || []).slice(0, 3)} quickAppList={chatSettings?.quickAppList || []}
onSwitchQuickApp={handleSwitchQuickApp} onSwitchQuickApp={handleSwitchQuickApp}
/> />
</Box> </Box>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment