mirror of
https://github.com/labring/FastGPT.git
synced 2025-10-17 08:37:59 +00:00
perf: search key refresh parentId (#5530)
This commit is contained in:
@@ -776,14 +776,6 @@ export async function dispatchWorkFlow(data: Props): Promise<DispatchFlowRespons
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
// Focus try to run pluginOutput
|
|
||||||
const pluginOutputModule = runtimeNodes.find(
|
|
||||||
(item) => item.flowNodeType === FlowNodeTypeEnum.pluginOutput
|
|
||||||
);
|
|
||||||
if (pluginOutputModule && data.mode !== 'debug') {
|
|
||||||
workflowQueue.nodeRunWithActive(pluginOutputModule);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Get interactive node response.
|
// Get interactive node response.
|
||||||
const interactiveResult = (() => {
|
const interactiveResult = (() => {
|
||||||
if (workflowQueue.nodeInteractiveResponse) {
|
if (workflowQueue.nodeInteractiveResponse) {
|
||||||
|
@@ -12,7 +12,6 @@ export const dispatchPluginOutput = (props: PluginOutputProps): PluginOutputResp
|
|||||||
|
|
||||||
return {
|
return {
|
||||||
[DispatchNodeResponseKeyEnum.nodeResponse]: {
|
[DispatchNodeResponseKeyEnum.nodeResponse]: {
|
||||||
totalPoints: 0,
|
|
||||||
pluginOutput: params
|
pluginOutput: params
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@@ -24,9 +24,11 @@ const NodeTemplatesModal = ({ isOpen, onClose }: ModuleTemplateListProps) => {
|
|||||||
const {
|
const {
|
||||||
templateType,
|
templateType,
|
||||||
parentId,
|
parentId,
|
||||||
|
searchKey,
|
||||||
|
setSearchKey,
|
||||||
templatesIsLoading,
|
templatesIsLoading,
|
||||||
templates,
|
templates,
|
||||||
loadNodeTemplates,
|
onUpdateTemplateType,
|
||||||
onUpdateParentId
|
onUpdateParentId
|
||||||
} = useNodeTemplates();
|
} = useNodeTemplates();
|
||||||
|
|
||||||
@@ -79,8 +81,10 @@ const NodeTemplatesModal = ({ isOpen, onClose }: ModuleTemplateListProps) => {
|
|||||||
<NodeTemplateListHeader
|
<NodeTemplateListHeader
|
||||||
onClose={onClose}
|
onClose={onClose}
|
||||||
templateType={templateType}
|
templateType={templateType}
|
||||||
loadNodeTemplates={loadNodeTemplates}
|
onUpdateTemplateType={onUpdateTemplateType}
|
||||||
parentId={parentId || ''}
|
parentId={parentId}
|
||||||
|
searchKey={searchKey}
|
||||||
|
setSearchKey={setSearchKey}
|
||||||
onUpdateParentId={onUpdateParentId}
|
onUpdateParentId={onUpdateParentId}
|
||||||
/>
|
/>
|
||||||
<NodeTemplateList
|
<NodeTemplateList
|
||||||
|
@@ -24,9 +24,11 @@ const NodeTemplatesPopover = () => {
|
|||||||
const {
|
const {
|
||||||
templateType,
|
templateType,
|
||||||
parentId,
|
parentId,
|
||||||
|
searchKey,
|
||||||
|
setSearchKey,
|
||||||
templatesIsLoading,
|
templatesIsLoading,
|
||||||
templates,
|
templates,
|
||||||
loadNodeTemplates,
|
onUpdateTemplateType,
|
||||||
onUpdateParentId
|
onUpdateParentId
|
||||||
} = useNodeTemplates();
|
} = useNodeTemplates();
|
||||||
|
|
||||||
@@ -116,9 +118,11 @@ const NodeTemplatesPopover = () => {
|
|||||||
<NodeTemplateListHeader
|
<NodeTemplateListHeader
|
||||||
isPopover={true}
|
isPopover={true}
|
||||||
templateType={templateType}
|
templateType={templateType}
|
||||||
loadNodeTemplates={loadNodeTemplates}
|
onUpdateTemplateType={onUpdateTemplateType}
|
||||||
parentId={parentId || ''}
|
parentId={parentId}
|
||||||
onUpdateParentId={onUpdateParentId}
|
onUpdateParentId={onUpdateParentId}
|
||||||
|
searchKey={searchKey}
|
||||||
|
setSearchKey={setSearchKey}
|
||||||
/>
|
/>
|
||||||
<NodeTemplateList
|
<NodeTemplateList
|
||||||
onAddNode={onAddNode}
|
onAddNode={onAddNode}
|
||||||
|
@@ -1,4 +1,5 @@
|
|||||||
import React, { useEffect, useState } from 'react';
|
import type { Dispatch, SetStateAction } from 'react';
|
||||||
|
import React from 'react';
|
||||||
import { Box, Flex, IconButton, Input, InputGroup, InputLeftElement } from '@chakra-ui/react';
|
import { Box, Flex, IconButton, Input, InputGroup, InputLeftElement } from '@chakra-ui/react';
|
||||||
import FillRowTabs from '@fastgpt/web/components/common/Tabs/FillRowTabs';
|
import FillRowTabs from '@fastgpt/web/components/common/Tabs/FillRowTabs';
|
||||||
import MyIcon from '@fastgpt/web/components/common/Icon';
|
import MyIcon from '@fastgpt/web/components/common/Icon';
|
||||||
@@ -9,7 +10,7 @@ import { useRequest2 } from '@fastgpt/web/hooks/useRequest';
|
|||||||
import { getSystemPluginPaths } from '@/web/core/app/api/plugin';
|
import { getSystemPluginPaths } from '@/web/core/app/api/plugin';
|
||||||
import { getAppFolderPath } from '@/web/core/app/api/app';
|
import { getAppFolderPath } from '@/web/core/app/api/app';
|
||||||
import FolderPath from '@/components/common/folder/Path';
|
import FolderPath from '@/components/common/folder/Path';
|
||||||
import { useDebounceEffect } from 'ahooks';
|
import type { ParentIdType } from '@fastgpt/global/common/parentFolder/type';
|
||||||
|
|
||||||
export enum TemplateTypeEnum {
|
export enum TemplateTypeEnum {
|
||||||
'basic' = 'basic',
|
'basic' = 'basic',
|
||||||
@@ -21,12 +22,10 @@ export type NodeTemplateListHeaderProps = {
|
|||||||
onClose?: () => void;
|
onClose?: () => void;
|
||||||
isPopover?: boolean;
|
isPopover?: boolean;
|
||||||
templateType: TemplateTypeEnum;
|
templateType: TemplateTypeEnum;
|
||||||
parentId: string;
|
parentId: ParentIdType;
|
||||||
loadNodeTemplates: (params: {
|
searchKey: string;
|
||||||
parentId?: string;
|
setSearchKey: Dispatch<SetStateAction<string>>;
|
||||||
type?: TemplateTypeEnum;
|
onUpdateTemplateType: (type: TemplateTypeEnum) => void;
|
||||||
searchVal?: string;
|
|
||||||
}) => Promise<any>;
|
|
||||||
onUpdateParentId: (parentId: string) => void;
|
onUpdateParentId: (parentId: string) => void;
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -35,33 +34,15 @@ const NodeTemplateListHeader = ({
|
|||||||
isPopover = false,
|
isPopover = false,
|
||||||
templateType,
|
templateType,
|
||||||
parentId,
|
parentId,
|
||||||
loadNodeTemplates,
|
searchKey,
|
||||||
|
setSearchKey,
|
||||||
|
onUpdateTemplateType,
|
||||||
onUpdateParentId
|
onUpdateParentId
|
||||||
}: NodeTemplateListHeaderProps) => {
|
}: NodeTemplateListHeaderProps) => {
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
const { feConfigs } = useSystemStore();
|
const { feConfigs } = useSystemStore();
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
|
|
||||||
const [searchKey, setSearchKey] = useState('');
|
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
setSearchKey('');
|
|
||||||
}, [templateType]);
|
|
||||||
|
|
||||||
useDebounceEffect(
|
|
||||||
() => {
|
|
||||||
loadNodeTemplates({
|
|
||||||
type: templateType,
|
|
||||||
parentId: '',
|
|
||||||
searchVal: searchKey
|
|
||||||
});
|
|
||||||
},
|
|
||||||
[searchKey, loadNodeTemplates, templateType],
|
|
||||||
{
|
|
||||||
wait: 300
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
// Get paths
|
// Get paths
|
||||||
const { data: paths = [] } = useRequest2(
|
const { data: paths = [] } = useRequest2(
|
||||||
() => {
|
() => {
|
||||||
@@ -80,7 +61,7 @@ const NodeTemplateListHeader = ({
|
|||||||
{/* Tabs */}
|
{/* Tabs */}
|
||||||
<Flex flex={'1 0 0'} alignItems={'center'} gap={2}>
|
<Flex flex={'1 0 0'} alignItems={'center'} gap={2}>
|
||||||
<Box flex={'1 0 0'}>
|
<Box flex={'1 0 0'}>
|
||||||
<FillRowTabs
|
<FillRowTabs<TemplateTypeEnum>
|
||||||
list={[
|
list={[
|
||||||
{
|
{
|
||||||
icon: 'core/modules/basicNode',
|
icon: 'core/modules/basicNode',
|
||||||
@@ -109,10 +90,7 @@ const NodeTemplateListHeader = ({
|
|||||||
: {})}
|
: {})}
|
||||||
value={templateType}
|
value={templateType}
|
||||||
onChange={(e) => {
|
onChange={(e) => {
|
||||||
loadNodeTemplates({
|
onUpdateTemplateType(e);
|
||||||
type: e as TemplateTypeEnum,
|
|
||||||
parentId: ''
|
|
||||||
});
|
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
</Box>
|
</Box>
|
||||||
|
@@ -1,4 +1,4 @@
|
|||||||
import { useState, useMemo, useCallback } from 'react';
|
import { useState, useMemo, useCallback, useRef } from 'react';
|
||||||
import { useRequest2 } from '@fastgpt/web/hooks/useRequest';
|
import { useRequest2 } from '@fastgpt/web/hooks/useRequest';
|
||||||
import { useSystemStore } from '@/web/common/system/useSystemStore';
|
import { useSystemStore } from '@/web/common/system/useSystemStore';
|
||||||
import type { NodeTemplateListItemType } from '@fastgpt/global/core/workflow/type/node';
|
import type { NodeTemplateListItemType } from '@fastgpt/global/core/workflow/type/node';
|
||||||
@@ -8,10 +8,15 @@ import { TemplateTypeEnum } from './header';
|
|||||||
import { useContextSelector } from 'use-context-selector';
|
import { useContextSelector } from 'use-context-selector';
|
||||||
import { WorkflowContext } from '../../../context';
|
import { WorkflowContext } from '../../../context';
|
||||||
import type { ParentIdType } from '@fastgpt/global/common/parentFolder/type';
|
import type { ParentIdType } from '@fastgpt/global/common/parentFolder/type';
|
||||||
|
import { useDebounceEffect } from 'ahooks';
|
||||||
|
|
||||||
export const useNodeTemplates = () => {
|
export const useNodeTemplates = () => {
|
||||||
const { feConfigs } = useSystemStore();
|
const { feConfigs } = useSystemStore();
|
||||||
const [templateType, setTemplateType] = useState(TemplateTypeEnum.basic);
|
const [templateType, setTemplateType] = useState(TemplateTypeEnum.basic);
|
||||||
|
|
||||||
|
const [searchKey, setSearchKey] = useState('');
|
||||||
|
const searchKeyLock = useRef(false);
|
||||||
|
|
||||||
const [parentId, setParentId] = useState<ParentIdType>('');
|
const [parentId, setParentId] = useState<ParentIdType>('');
|
||||||
|
|
||||||
const basicNodeTemplates = useContextSelector(WorkflowContext, (v) => v.basicNodeTemplates);
|
const basicNodeTemplates = useContextSelector(WorkflowContext, (v) => v.basicNodeTemplates);
|
||||||
@@ -72,9 +77,9 @@ export const useNodeTemplates = () => {
|
|||||||
runAsync: loadNodeTemplates
|
runAsync: loadNodeTemplates
|
||||||
} = useRequest2(
|
} = useRequest2(
|
||||||
async ({
|
async ({
|
||||||
parentId = '',
|
parentId,
|
||||||
type = templateType,
|
type = templateType,
|
||||||
searchVal = ''
|
searchVal
|
||||||
}: {
|
}: {
|
||||||
parentId?: ParentIdType;
|
parentId?: ParentIdType;
|
||||||
type?: TemplateTypeEnum;
|
type?: TemplateTypeEnum;
|
||||||
@@ -96,23 +101,40 @@ export const useNodeTemplates = () => {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
onSuccess(res, [{ parentId = '', type = templateType }]) {
|
onSuccess() {
|
||||||
setParentId(parentId);
|
searchKeyLock.current = false;
|
||||||
setTemplateType(type);
|
}
|
||||||
},
|
|
||||||
refreshDeps: [templateType]
|
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
const onUpdateParentId = useCallback(
|
useDebounceEffect(
|
||||||
(parentId: ParentIdType) => {
|
() => {
|
||||||
loadNodeTemplates({
|
if (searchKeyLock.current) {
|
||||||
parentId
|
return;
|
||||||
});
|
}
|
||||||
|
|
||||||
|
loadNodeTemplates({ parentId, searchVal: searchKey });
|
||||||
},
|
},
|
||||||
[loadNodeTemplates]
|
[searchKey],
|
||||||
|
{
|
||||||
|
wait: 300
|
||||||
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
|
const onUpdateParentId = useCallback((parentId: ParentIdType) => {
|
||||||
|
searchKeyLock.current = true;
|
||||||
|
setSearchKey('');
|
||||||
|
setParentId(parentId);
|
||||||
|
loadNodeTemplates({ parentId });
|
||||||
|
}, []);
|
||||||
|
const onUpdateTemplateType = useCallback((type: TemplateTypeEnum) => {
|
||||||
|
searchKeyLock.current = true;
|
||||||
|
setSearchKey('');
|
||||||
|
setParentId('');
|
||||||
|
setTemplateType(type);
|
||||||
|
loadNodeTemplates({ type });
|
||||||
|
}, []);
|
||||||
|
|
||||||
const templates = useMemo(() => {
|
const templates = useMemo(() => {
|
||||||
if (templateType === TemplateTypeEnum.basic) {
|
if (templateType === TemplateTypeEnum.basic) {
|
||||||
return basicNodes || [];
|
return basicNodes || [];
|
||||||
@@ -125,7 +147,9 @@ export const useNodeTemplates = () => {
|
|||||||
parentId,
|
parentId,
|
||||||
templatesIsLoading,
|
templatesIsLoading,
|
||||||
templates,
|
templates,
|
||||||
loadNodeTemplates,
|
onUpdateParentId,
|
||||||
onUpdateParentId
|
onUpdateTemplateType,
|
||||||
|
searchKey,
|
||||||
|
setSearchKey
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
@@ -52,10 +52,8 @@ const ListItem = () => {
|
|||||||
content: t('app:move.hint')
|
content: t('app:move.hint')
|
||||||
});
|
});
|
||||||
|
|
||||||
const { myApps, loadMyApps, onUpdateApp, setMoveAppId, folderDetail } = useContextSelector(
|
const { myApps, loadMyApps, onUpdateApp, setMoveAppId, folderDetail, setSearchKey } =
|
||||||
AppListContext,
|
useContextSelector(AppListContext, (v) => v);
|
||||||
(v) => v
|
|
||||||
);
|
|
||||||
|
|
||||||
const [editedApp, setEditedApp] = useState<EditResourceInfoFormType>();
|
const [editedApp, setEditedApp] = useState<EditResourceInfoFormType>();
|
||||||
const [editHttpPlugin, setEditHttpPlugin] = useState<EditHttpPluginProps>();
|
const [editHttpPlugin, setEditHttpPlugin] = useState<EditHttpPluginProps>();
|
||||||
@@ -185,6 +183,7 @@ const ListItem = () => {
|
|||||||
}}
|
}}
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
if (AppFolderTypeList.includes(app.type)) {
|
if (AppFolderTypeList.includes(app.type)) {
|
||||||
|
setSearchKey('');
|
||||||
router.push({
|
router.push({
|
||||||
query: {
|
query: {
|
||||||
...router.query,
|
...router.query,
|
||||||
|
@@ -41,7 +41,6 @@ async function handler(
|
|||||||
}))
|
}))
|
||||||
.filter((item) => {
|
.filter((item) => {
|
||||||
if (searchKey) {
|
if (searchKey) {
|
||||||
if (item.isFolder) return false;
|
|
||||||
const regx = new RegExp(`${replaceRegChars(searchKey)}`, 'i');
|
const regx = new RegExp(`${replaceRegChars(searchKey)}`, 'i');
|
||||||
return regx.test(String(item.name)) || regx.test(String(item.intro || ''));
|
return regx.test(String(item.name)) || regx.test(String(item.intro || ''));
|
||||||
}
|
}
|
||||||
|
@@ -56,7 +56,8 @@ const MyApps = ({ MenuIcon }: { MenuIcon: JSX.Element }) => {
|
|||||||
isFetchingApps,
|
isFetchingApps,
|
||||||
folderDetail,
|
folderDetail,
|
||||||
refetchFolderDetail,
|
refetchFolderDetail,
|
||||||
setSearchKey
|
setSearchKey,
|
||||||
|
searchKey
|
||||||
} = useContextSelector(AppListContext, (v) => v);
|
} = useContextSelector(AppListContext, (v) => v);
|
||||||
const { userInfo } = useUserStore();
|
const { userInfo } = useUserStore();
|
||||||
|
|
||||||
@@ -164,6 +165,7 @@ const MyApps = ({ MenuIcon }: { MenuIcon: JSX.Element }) => {
|
|||||||
{isPc && (
|
{isPc && (
|
||||||
<SearchInput
|
<SearchInput
|
||||||
maxW={['auto', '250px']}
|
maxW={['auto', '250px']}
|
||||||
|
value={searchKey}
|
||||||
onChange={(e) => setSearchKey(e.target.value)}
|
onChange={(e) => setSearchKey(e.target.value)}
|
||||||
placeholder={t('app:search_app')}
|
placeholder={t('app:search_app')}
|
||||||
maxLength={30}
|
maxLength={30}
|
||||||
@@ -244,6 +246,7 @@ const MyApps = ({ MenuIcon }: { MenuIcon: JSX.Element }) => {
|
|||||||
{
|
{
|
||||||
<SearchInput
|
<SearchInput
|
||||||
maxW={['auto', '250px']}
|
maxW={['auto', '250px']}
|
||||||
|
value={searchKey}
|
||||||
onChange={(e) => setSearchKey(e.target.value)}
|
onChange={(e) => setSearchKey(e.target.value)}
|
||||||
placeholder={t('app:search_app')}
|
placeholder={t('app:search_app')}
|
||||||
maxLength={30}
|
maxLength={30}
|
||||||
|
Reference in New Issue
Block a user