Skip to content

Commit

Permalink
perf: disabled change version when change version name (#2497)
Browse files Browse the repository at this point in the history
* perf: disabled change version when change version name

* fix

* fix

* toast condition
  • Loading branch information
newfish-cmyk authored Aug 24, 2024
1 parent ad63210 commit bb7adc9
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ const NodeTemplatesModal = ({ isOpen, onClose }: ModuleTemplateListProps) => {
},
{
manual: false,
refreshDeps: [members, basicNodeTemplates, nodeList, hasToolNode, templateType]
refreshDeps: [basicNodeTemplates, nodeList, hasToolNode, templateType]
}
);
const {
Expand Down Expand Up @@ -168,7 +168,7 @@ const NodeTemplatesModal = ({ isOpen, onClose }: ModuleTemplateListProps) => {
setParentId(parentId);
setTemplateType(type);
},
refreshDeps: [searchKey, templateType]
refreshDeps: [members, searchKey, templateType]
}
);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
import React, { useEffect, useMemo } from 'react';
import { Background, ControlButton, MiniMap, Panel, useReactFlow } from 'reactflow';
import { Background, ControlButton, MiniMap, Panel, useReactFlow, useViewport } from 'reactflow';
import { useContextSelector } from 'use-context-selector';
import { WorkflowContext } from '../../context';
import MyTooltip from '@fastgpt/web/components/common/MyTooltip';
import MyIcon from '@fastgpt/web/components/common/Icon';
import { Box } from '@chakra-ui/react';
import { useTranslation } from 'react-i18next';
import styles from './index.module.scss';
import { maxZoom, minZoom } from '..';

const FlowController = React.memo(function FlowController() {
const { fitView, zoomIn, zoomOut } = useReactFlow();
const { zoom } = useViewport();
const { undo, redo, canRedo, canUndo } = useContextSelector(WorkflowContext, (v) => v);
const { t } = useTranslation();

Expand Down Expand Up @@ -111,6 +113,7 @@ const FlowController = React.memo(function FlowController() {
onClick={() => zoomOut()}
style={buttonStyle}
className={`${styles.customControlButton}`}
disabled={zoom <= minZoom}
>
<MyIcon name={'common/subtract'} />
</ControlButton>
Expand All @@ -124,6 +127,7 @@ const FlowController = React.memo(function FlowController() {
onClick={() => zoomIn()}
style={buttonStyle}
className={`${styles.customControlButton}`}
disabled={zoom >= maxZoom}
>
<MyIcon name={'common/addLight'} />
</ControlButton>
Expand All @@ -145,7 +149,7 @@ const FlowController = React.memo(function FlowController() {
<Background />
</>
);
}, [isMac, t, undo, buttonStyle, canUndo, redo, canRedo, zoomOut, zoomIn, fitView]);
}, [isMac, t, undo, buttonStyle, canUndo, redo, canRedo, zoom, zoomOut, zoomIn, fitView]);

return Render;
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -259,15 +259,8 @@ export const useWorkflow = () => {
const { t } = useTranslation();

const { isDowningCtrl } = useKeyboard();
const {
setConnectingEdge,
nodes,
setNodes,
onNodesChange,
setEdges,
onEdgesChange,
setHoverEdgeId
} = useContextSelector(WorkflowContext, (v) => v);
const { setConnectingEdge, nodes, onNodesChange, setEdges, onEdgesChange, setHoverEdgeId } =
useContextSelector(WorkflowContext, (v) => v);

/* helper line */
const [helperLineHorizontal, setHelperLineHorizontal] = useState<THelperLine>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ import { useWorkflow } from './hooks/useWorkflow';
import HelperLines from './components/HelperLines';
import FlowController from './components/FlowController';

export const minZoom = 0.1;
export const maxZoom = 1.5;

const NodeSimple = dynamic(() => import('./nodes/NodeSimple'));
const nodeTypes: Record<FlowNodeTypeEnum, any> = {
[FlowNodeTypeEnum.emptyNode]: NodeSimple,
Expand Down Expand Up @@ -112,8 +115,8 @@ const Workflow = () => {
fitView
nodes={nodes}
edges={edges}
minZoom={0.1}
maxZoom={1.5}
minZoom={minZoom}
maxZoom={maxZoom}
defaultEdgeOptions={defaultEdgeOptions}
elevateEdgesOnSelect
connectionLineStyle={connectionLineStyle}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ const MyEdit = () => {
chatConfig: initialSnapshot.chatConfig,
customTitle: t(`app:app.version_initial_copy`)
});

if (res) {
resetSnapshot(initialSnapshot);
}
Expand Down Expand Up @@ -124,6 +125,7 @@ const MyEdit = () => {
if (res) {
resetSnapshot(item);
}

toast({
title: t('workflow:workflow.Switch_success'),
status: 'success'
Expand Down Expand Up @@ -245,7 +247,7 @@ const TeamCloud = () => {
_hover={{
bg: 'primary.50'
}}
onClick={() => onChangeVersion(item)}
onClick={() => editIndex === undefined && onChangeVersion(item)}
>
<MyPopover
trigger="hover"
Expand Down

0 comments on commit bb7adc9

Please sign in to comment.