Commit 466f16eb authored by StyleZhang's avatar StyleZhang

node name

parent 04d54c03
...@@ -12,7 +12,7 @@ import ToolDefault from './nodes/tool/default' ...@@ -12,7 +12,7 @@ import ToolDefault from './nodes/tool/default'
import VariableAssignerDefault from './nodes/variable-assigner/default' import VariableAssignerDefault from './nodes/variable-assigner/default'
import EndNodeDefault from './nodes/end/default' import EndNodeDefault from './nodes/end/default'
export const NodeInitialData = { export const NODES_INITIAL_DATA = {
[BlockEnum.Start]: { [BlockEnum.Start]: {
type: BlockEnum.Start, type: BlockEnum.Start,
title: '', title: '',
......
import { useCallback } from 'react' import { useCallback } from 'react'
import { useTranslation } from 'react-i18next'
import produce from 'immer' import produce from 'immer'
import type { import type {
EdgeMouseHandler, EdgeMouseHandler,
...@@ -19,13 +20,24 @@ import type { ...@@ -19,13 +20,24 @@ import type {
Node, Node,
SelectedNode, SelectedNode,
} from './types' } from './types'
import { NodeInitialData } from './constants' import { NODES_INITIAL_DATA } from './constants'
import { getLayoutByDagre } from './utils' import { getLayoutByDagre } from './utils'
import { useStore } from './store' import { useStore } from './store'
export const useNodesInitialData = () => {
const { t } = useTranslation()
return produce(NODES_INITIAL_DATA, (draft) => {
Object.keys(draft).forEach((key) => {
draft[key as BlockEnum].title = t(`workflow.blocks.${key}`)
})
})
}
export const useWorkflow = () => { export const useWorkflow = () => {
const store = useStoreApi() const store = useStoreApi()
const reactFlow = useReactFlow() const reactFlow = useReactFlow()
const nodesInitialData = useNodesInitialData()
const handleLayout = useCallback(async () => { const handleLayout = useCallback(async () => {
const { const {
...@@ -267,7 +279,7 @@ export const useWorkflow = () => { ...@@ -267,7 +279,7 @@ export const useWorkflow = () => {
id: `${Date.now()}`, id: `${Date.now()}`,
type: 'custom', type: 'custom',
data: { data: {
...NodeInitialData[nodeType], ...nodesInitialData[nodeType],
_selected: true, _selected: true,
}, },
position: { position: {
...@@ -311,7 +323,7 @@ export const useWorkflow = () => { ...@@ -311,7 +323,7 @@ export const useWorkflow = () => {
id: `${Date.now()}`, id: `${Date.now()}`,
type: 'custom', type: 'custom',
data: { data: {
...NodeInitialData[nodeType], ...nodesInitialData[nodeType],
_selected: currentNode.data._selected, _selected: currentNode.data._selected,
}, },
position: { position: {
......
...@@ -17,7 +17,10 @@ import type { ...@@ -17,7 +17,10 @@ import type {
Edge, Edge,
Node, Node,
} from './types' } from './types'
import { useWorkflow } from './hooks' import {
useNodesInitialData,
useWorkflow,
} from './hooks'
import Header from './header' import Header from './header'
import CustomNode from './nodes' import CustomNode from './nodes'
import Operator from './operator' import Operator from './operator'
...@@ -26,7 +29,6 @@ import CustomConnectionLine from './custom-connection-line' ...@@ -26,7 +29,6 @@ import CustomConnectionLine from './custom-connection-line'
import Panel from './panel' import Panel from './panel'
import Features from './features' import Features from './features'
import { useStore } from './store' import { useStore } from './store'
import { NodeInitialData } from './constants'
import { import {
fetchWorkflowDraft, fetchWorkflowDraft,
syncWorkflowDraft, syncWorkflowDraft,
...@@ -115,11 +117,12 @@ const WorkflowWrap: FC<WorkflowProps> = ({ ...@@ -115,11 +117,12 @@ const WorkflowWrap: FC<WorkflowProps> = ({
}) => { }) => {
const appId = useParams().appId const appId = useParams().appId
const { data, isLoading, error } = useSWR(`/apps/${appId}/workflows/draft`, fetchWorkflowDraft) const { data, isLoading, error } = useSWR(`/apps/${appId}/workflows/draft`, fetchWorkflowDraft)
const nodesInitialData = useNodesInitialData()
const startNode = { const startNode = {
id: `${Date.now()}`, id: `${Date.now()}`,
type: 'custom', type: 'custom',
data: NodeInitialData.start, data: nodesInitialData.start,
position: { position: {
x: 100, x: 100,
y: 100, y: 100,
......
...@@ -39,23 +39,17 @@ const BaseNode: FC<BaseNodeProps> = ({ ...@@ -39,23 +39,17 @@ const BaseNode: FC<BaseNodeProps> = ({
{data.title} {data.title}
</div> </div>
</div> </div>
{
children && (
<div className='mb-1'> <div className='mb-1'>
{cloneElement(children, { id, data })} {cloneElement(children, { id, data })}
</div> </div>
)
}
<div className='pb-1'>
{ {
data.desc && ( data.desc && (
<div className='px-3 pt-1 pb-2 text-xs leading-[18px] text-gray-500 whitespace-pre-line break-words'> <div className='px-3 pt-s1 pb-2 text-xs leading-[18px] text-gray-500 whitespace-pre-line break-words'>
{data.desc} {data.desc}
</div> </div>
) )
} }
</div> </div>
</div>
) )
} }
......
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 to comment