-
Notifications
You must be signed in to change notification settings - Fork 4.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add context menu & comment node (#2834)
* feat: add comment node * useMemo
- Loading branch information
1 parent
7bdff9c
commit 7c829fe
Showing
14 changed files
with
440 additions
and
113 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import { FlowNodeTypeEnum } from '../../node/constant'; | ||
import { FlowNodeTemplateType } from '../../type/node.d'; | ||
import { | ||
FlowNodeTemplateTypeEnum, | ||
NodeInputKeyEnum, | ||
WorkflowIOValueTypeEnum | ||
} from '../../constants'; | ||
import { getHandleConfig } from '../utils'; | ||
|
||
export const CommentNode: FlowNodeTemplateType = { | ||
id: FlowNodeTypeEnum.comment, | ||
templateType: FlowNodeTemplateTypeEnum.systemInput, | ||
flowNodeType: FlowNodeTypeEnum.comment, | ||
sourceHandle: getHandleConfig(false, false, false, false), | ||
targetHandle: getHandleConfig(false, false, false, false), | ||
avatar: '', | ||
name: '', | ||
intro: '', | ||
version: '4811', | ||
inputs: [ | ||
{ | ||
key: NodeInputKeyEnum.commentText, | ||
renderTypeList: [], | ||
valueType: WorkflowIOValueTypeEnum.string, | ||
label: '', | ||
value: '' | ||
}, | ||
{ | ||
key: NodeInputKeyEnum.commentSize, | ||
renderTypeList: [], | ||
valueType: WorkflowIOValueTypeEnum.object, | ||
label: '', | ||
value: { | ||
width: 240, | ||
height: 140 | ||
} | ||
} | ||
], | ||
outputs: [] | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
83 changes: 83 additions & 0 deletions
83
...ts/app/src/pages/app/detail/components/WorkflowComponents/Flow/components/ContextMenu.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
import { Box, Flex } from '@chakra-ui/react'; | ||
import React from 'react'; | ||
import MyIcon from '@fastgpt/web/components/common/Icon'; | ||
import { useTranslation } from 'react-i18next'; | ||
import { nodeTemplate2FlowNode } from '@/web/core/workflow/utils'; | ||
import { CommentNode } from '@fastgpt/global/core/workflow/template/system/comment'; | ||
import { useContextSelector } from 'use-context-selector'; | ||
import { WorkflowContext } from '../../context'; | ||
import { useReactFlow } from 'reactflow'; | ||
|
||
type ContextMenuProps = { | ||
top: number; | ||
left: number; | ||
}; | ||
|
||
const ContextMenu = ({ top, left }: ContextMenuProps) => { | ||
const { t } = useTranslation(); | ||
const setNodes = useContextSelector(WorkflowContext, (ctx) => ctx.setNodes); | ||
const setMenu = useContextSelector(WorkflowContext, (ctx) => ctx.setMenu); | ||
|
||
const { screenToFlowPosition } = useReactFlow(); | ||
const newNode = nodeTemplate2FlowNode({ | ||
template: CommentNode, | ||
position: screenToFlowPosition({ x: left, y: top }), | ||
t | ||
}); | ||
|
||
return ( | ||
<Box position="relative"> | ||
<Box | ||
position="absolute" | ||
top={`${top - 6}px`} | ||
left={`${left + 10}px`} | ||
width={0} | ||
height={0} | ||
borderLeft="6px solid transparent" | ||
borderRight="6px solid transparent" | ||
borderBottom="6px solid white" | ||
zIndex={2} | ||
filter="drop-shadow(0px -1px 2px rgba(0, 0, 0, 0.1))" | ||
/> | ||
<Flex | ||
position={'absolute'} | ||
top={top} | ||
left={left} | ||
bg={'white'} | ||
w={'120px'} | ||
height={9} | ||
p={1} | ||
rounded={'md'} | ||
boxShadow={'0px 2px 4px 0px #A1A7B340'} | ||
className="context-menu" | ||
alignItems={'center'} | ||
color={'myGray.600'} | ||
cursor={'pointer'} | ||
_hover={{ | ||
color: 'primary.500' | ||
}} | ||
onClick={() => { | ||
setMenu(null); | ||
setNodes((state) => { | ||
const newState = state | ||
.map((node) => ({ | ||
...node, | ||
selected: false | ||
})) | ||
// @ts-ignore | ||
.concat(newNode); | ||
return newState; | ||
}); | ||
}} | ||
zIndex={1} | ||
> | ||
<MyIcon name="comment" w={'16px'} h={'16px'} ml={1} /> | ||
<Box fontSize={'12px'} fontWeight={'500'} ml={1.5}> | ||
{t('workflow:context_menu.add_comment')} | ||
</Box> | ||
</Flex> | ||
</Box> | ||
); | ||
}; | ||
|
||
export default React.memo(ContextMenu); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.