Commit c9093194 authored by StyleZhang's avatar StyleZhang

base-node base-panel

parent c7ee8ac1
import type { import type {
FC, FC,
ReactNode, ReactElement,
} from 'react' } from 'react'
import { import {
cloneElement,
memo, memo,
useCallback, useCallback,
useMemo, useMemo,
} from 'react' } from 'react'
import { import type { NodeProps } from 'reactflow'
getOutgoers, import { getOutgoers } from 'reactflow'
useNodeId,
} from 'reactflow'
import { useWorkflowContext } from '../../context' import { useWorkflowContext } from '../../context'
import BlockSelector from '../../block-selector' import BlockSelector from '../../block-selector'
import { getBlockByType } from '../../block-selector/utils' import { getBlockByType } from '../../block-selector/utils'
...@@ -18,13 +17,14 @@ import BlockIcon from '../../block-icon' ...@@ -18,13 +17,14 @@ import BlockIcon from '../../block-icon'
import { Plus } from '@/app/components/base/icons/src/vender/line/general' import { Plus } from '@/app/components/base/icons/src/vender/line/general'
type BaseNodeProps = { type BaseNodeProps = {
children: ReactNode children: ReactElement
} } & Pick<NodeProps, 'id' | 'data'>
const BaseNode: FC<BaseNodeProps> = ({ const BaseNode: FC<BaseNodeProps> = ({
id: nodeId,
data,
children, children,
}) => { }) => {
const nodeId = useNodeId()
const { const {
nodes, nodes,
edges, edges,
...@@ -74,7 +74,7 @@ const BaseNode: FC<BaseNodeProps> = ({ ...@@ -74,7 +74,7 @@ const BaseNode: FC<BaseNodeProps> = ({
{getBlockByType(currentNode!.data.type)?.title} {getBlockByType(currentNode!.data.type)?.title}
</div> </div>
</div> </div>
{children} {cloneElement(children, { id: nodeId, data })}
<div className='px-3 pt-1 pb-1 text-xs text-gray-500'> <div className='px-3 pt-1 pb-1 text-xs text-gray-500'>
Define the initial parameters for launching a workflow Define the initial parameters for launching a workflow
</div> </div>
......
import type { import type {
FC, FC,
ReactNode, ReactElement,
} from 'react' } from 'react'
import {
cloneElement,
memo,
} from 'react'
import type { NodeProps } from 'reactflow'
import { useWorkflowContext } from '../../context' import { useWorkflowContext } from '../../context'
import BlockIcon from '../../block-icon' import BlockIcon from '../../block-icon'
import { getBlockByType } from '../../block-selector/utils' import { getBlockByType } from '../../block-selector/utils'
...@@ -10,10 +15,12 @@ import { XClose } from '@/app/components/base/icons/src/vender/line/general' ...@@ -10,10 +15,12 @@ import { XClose } from '@/app/components/base/icons/src/vender/line/general'
import { GitBranch01 } from '@/app/components/base/icons/src/vender/line/development' import { GitBranch01 } from '@/app/components/base/icons/src/vender/line/development'
type BasePanelProps = { type BasePanelProps = {
children?: ReactNode children: ReactElement
} } & Pick<NodeProps, 'id' | 'data'>
const BasePanel: FC<BasePanelProps> = ({ const BasePanel: FC<BasePanelProps> = ({
id,
data,
children, children,
}) => { }) => {
const { const {
...@@ -47,7 +54,7 @@ const BasePanel: FC<BasePanelProps> = ({ ...@@ -47,7 +54,7 @@ const BasePanel: FC<BasePanelProps> = ({
</div> </div>
</div> </div>
<div className='py-2 border-b-[0.5px] border-black/5'> <div className='py-2 border-b-[0.5px] border-black/5'>
{children} {cloneElement(children, { id, data })}
</div> </div>
<div className='p-4'> <div className='p-4'>
<div className='flex items-center mb-1 text-gray-700 text-[13px] font-semibold'> <div className='flex items-center mb-1 text-gray-700 text-[13px] font-semibold'>
...@@ -63,4 +70,4 @@ const BasePanel: FC<BasePanelProps> = ({ ...@@ -63,4 +70,4 @@ const BasePanel: FC<BasePanelProps> = ({
) )
} }
export default BasePanel export default memo(BasePanel)
import type { FC } from 'react' import type { FC } from 'react'
import BaseNode from '../_base/node'
const Node: FC = () => { const Node: FC = () => {
return ( return (
<BaseNode> <div>code</div>
<div>code</div>
</BaseNode>
) )
} }
......
import type { FC } from 'react' import type { FC } from 'react'
import BasePanel from '../_base/panel'
const Panel: FC = () => { const Panel: FC = () => {
return ( return (
<BasePanel> <div>start panel inputs</div>
<div>start panel inputs</div>
</BasePanel>
) )
} }
......
import type { FC } from 'react' import type { FC } from 'react'
import BaseNode from '../_base/node'
const Node: FC = () => { const Node: FC = () => {
return ( return (
<BaseNode> <div>directAnswer</div>
<div>directAnswer</div>
</BaseNode>
) )
} }
......
import type { FC } from 'react' import type { FC } from 'react'
import BasePanel from '../_base/panel'
const Panel: FC = () => { const Panel: FC = () => {
return ( return (
<BasePanel> <div>start panel inputs</div>
<div>start panel inputs</div>
</BasePanel>
) )
} }
......
import type { FC } from 'react' import type { FC } from 'react'
import BaseNode from '../_base/node'
const Node: FC = () => { const Node: FC = () => {
return ( return (
<BaseNode> <div>end</div>
<div>end</div>
</BaseNode>
) )
} }
......
import type { FC } from 'react' import type { FC } from 'react'
import BasePanel from '../_base/panel'
const Panel: FC = () => { const Panel: FC = () => {
return ( return (
<BasePanel> <div>start panel inputs</div>
<div>start panel inputs</div>
</BasePanel>
) )
} }
......
import type { FC } from 'react' import type { FC } from 'react'
import BaseNode from '../_base/node'
const Node: FC = () => { const Node: FC = () => {
return ( return (
<BaseNode> <div>http</div>
<div>http</div>
</BaseNode>
) )
} }
......
import type { FC } from 'react' import type { FC } from 'react'
import BasePanel from '../_base/panel'
const Panel: FC = () => { const Panel: FC = () => {
return ( return (
<BasePanel> <div>start panel inputs</div>
<div>start panel inputs</div>
</BasePanel>
) )
} }
......
import type { FC } from 'react' import type { FC } from 'react'
import BaseNode from '../_base/node'
const Node: FC = () => { const Node: FC = () => {
return ( return (
<BaseNode> <div>if else</div>
<div>if else</div>
</BaseNode>
) )
} }
......
import type { FC } from 'react' import type { FC } from 'react'
import BasePanel from '../_base/panel'
const Panel: FC = () => { const Panel: FC = () => {
return ( return (
<BasePanel> <div>start panel inputs</div>
<div>start panel inputs</div>
</BasePanel>
) )
} }
......
...@@ -9,8 +9,11 @@ import { ...@@ -9,8 +9,11 @@ import {
NodeMap, NodeMap,
PanelMap, PanelMap,
} from './constants' } from './constants'
import BaseNode from './_base/node'
import BasePanel from './_base/panel'
const CustomNode = ({ const CustomNode = ({
id,
data, data,
}: NodeProps) => { }: NodeProps) => {
const NodeComponent = NodeMap[data.type] const NodeComponent = NodeMap[data.type]
...@@ -22,7 +25,12 @@ const CustomNode = ({ ...@@ -22,7 +25,12 @@ const CustomNode = ({
position={Position.Top} position={Position.Top}
className='!-top-0.5 !w-2 !h-0.5 !bg-primary-500 !rounded-none !border-none !min-h-[2px]' className='!-top-0.5 !w-2 !h-0.5 !bg-primary-500 !rounded-none !border-none !min-h-[2px]'
/> />
<NodeComponent /> <BaseNode
id={id}
data={data}
>
<NodeComponent />
</BaseNode>
<Handle <Handle
type='source' type='source'
position={Position.Bottom} position={Position.Bottom}
...@@ -41,7 +49,12 @@ export const Panel = () => { ...@@ -41,7 +49,12 @@ export const Panel = () => {
const PanelComponent = PanelMap[selectedNode.data.type] const PanelComponent = PanelMap[selectedNode.data.type]
return ( return (
<PanelComponent /> <BasePanel
id={selectedNode.id}
data={selectedNode.data}
>
<PanelComponent />
</BasePanel>
) )
} }
......
import type { FC } from 'react' import type { FC } from 'react'
import BaseNode from '../_base/node'
const Node: FC = () => { const Node: FC = () => {
return ( return (
<BaseNode> <div>knowledge-retrieval</div>
<div>knowledge-retrieval</div>
</BaseNode>
) )
} }
......
import type { FC } from 'react' import type { FC } from 'react'
import BasePanel from '../_base/panel'
const Panel: FC = () => { const Panel: FC = () => {
return ( return (
<BasePanel> <div>start panel inputs</div>
<div>start panel inputs</div>
</BasePanel>
) )
} }
......
import type { FC } from 'react' import type { FC } from 'react'
import { useTranslation } from 'react-i18next' import { useTranslation } from 'react-i18next'
import BaseNode from '../_base/node'
const i18nPrefix = 'workflow.nodes.llm' const i18nPrefix = 'workflow.nodes.llm'
const Node: FC = () => { const Node: FC = () => {
const { t } = useTranslation() const { t } = useTranslation()
return ( return (
<BaseNode> <div>llm</div>
<div>
llm
</div>
</BaseNode>
) )
} }
......
import type { FC } from 'react' import type { FC } from 'react'
import { useTranslation } from 'react-i18next' import { useTranslation } from 'react-i18next'
import BasePanel from '../_base/panel'
import VarList from '../_base/components/variable/var-list' import VarList from '../_base/components/variable/var-list'
import useConfig from './use-config' import useConfig from './use-config'
import { mockLLMNodeData } from './mock' import { mockLLMNodeData } from './mock'
...@@ -29,75 +28,73 @@ const Panel: FC = () => { ...@@ -29,75 +28,73 @@ const Panel: FC = () => {
// const isChatMode = modelMode === 'chat' // const isChatMode = modelMode === 'chat'
return ( return (
<BasePanel> <div className='mt-2 px-4 space-y-4'>
<div className='mt-2 px-4 space-y-4'> <Field
<Field title={t(`${i18nPrefix}.model`)}
title={t(`${i18nPrefix}.model`)} >
> <ModelParameterModal
<ModelParameterModal popupClassName='!w-[387px]'
popupClassName='!w-[387px]' isAdvancedMode={true}
isAdvancedMode={true} mode={model?.mode}
mode={model?.mode} provider={model?.provider}
provider={model?.provider} completionParams={model.completion_params}
completionParams={model.completion_params} modelId={model.name}
modelId={model.name} setModel={handleModelChanged}
setModel={handleModelChanged} onCompletionParamsChange={handleCompletionParamsChange}
onCompletionParamsChange={handleCompletionParamsChange} hideDebugWithMultipleModel
hideDebugWithMultipleModel debugWithMultipleModel={false}
debugWithMultipleModel={false} />
/> </Field>
</Field>
<Field <Field
title={t(`${i18nPrefix}.variables`)} title={t(`${i18nPrefix}.variables`)}
operations={ operations={
<AddButton onClick={handleAddVariable} /> <AddButton onClick={handleAddVariable} />
} }
> >
<VarList <VarList
readonly={readOnly} readonly={readOnly}
list={inputs.variables} list={inputs.variables}
onChange={handleVarListChange} onChange={handleVarListChange}
/> />
</Field> </Field>
<Field <Field
title={t(`${i18nPrefix}.context`)} title={t(`${i18nPrefix}.context`)}
operations={ operations={
<Switch <Switch
defaultValue={inputs.context.enabled} defaultValue={inputs.context.enabled}
onChange={toggleContextEnabled} onChange={toggleContextEnabled}
size='md' size='md'
/> />
} }
> >
{inputs.context.enabled {inputs.context.enabled
? ( ? (
<div>Context</div> <div>Context</div>
) )
: null} : null}
</Field> </Field>
<Field <Field
title={t(`${i18nPrefix}.prompt`)} title={t(`${i18nPrefix}.prompt`)}
> >
Prompt Prompt
</Field> </Field>
<Split /> <Split />
<Field <Field
title={t(`${i18nPrefix}.vision`)} title={t(`${i18nPrefix}.vision`)}
inline
>
Vision
</Field>
{/* This version not support function */}
{/* <Field
title={t(`${i18nPrefix}.fu`)}
inline inline
> >
Vision Functions
</Field> </Field> */}
{/* This version not support function */} </div>
{/* <Field
title={t(`${i18nPrefix}.fu`)}
inline
>
Functions
</Field> */}
</div>
</BasePanel>
) )
} }
......
import type { FC } from 'react' import type { FC } from 'react'
import BaseNode from '../_base/node'
const Node: FC = () => { const Node: FC = () => {
return ( return (
<BaseNode> <div>question-classifier</div>
<div>question-classifier</div>
</BaseNode>
) )
} }
......
import type { FC } from 'react' import type { FC } from 'react'
import BasePanel from '../_base/panel'
const Panel: FC = () => { const Panel: FC = () => {
return ( return (
<BasePanel> <div>start panel inputs</div>
<div>start panel inputs</div>
</BasePanel>
) )
} }
......
import type { FC } from 'react' import type { FC } from 'react'
import BaseNode from '../_base/node'
const Node: FC = () => { const Node: FC = () => {
return ( return (
<BaseNode> <div>start node</div>
<div>start node</div>
</BaseNode>
) )
} }
......
import type { FC } from 'react' import type { FC } from 'react'
import BasePanel from '../_base/panel'
const Panel: FC = () => { const Panel: FC = () => {
return ( return (
<BasePanel> <div>start panel inputs</div>
<div>start panel inputs</div>
</BasePanel>
) )
} }
......
import type { FC } from 'react' import type { FC } from 'react'
import BaseNode from '../_base/node'
const Node: FC = () => { const Node: FC = () => {
return ( return (
<BaseNode> <div>template-transform</div>
<div>template-transform</div>
</BaseNode>
) )
} }
......
import type { FC } from 'react' import type { FC } from 'react'
import BasePanel from '../_base/panel'
const Panel: FC = () => { const Panel: FC = () => {
return ( return (
<BasePanel> <div>start panel inputs</div>
<div>start panel inputs</div>
</BasePanel>
) )
} }
......
import type { FC } from 'react' import type { FC } from 'react'
import BaseNode from '../_base/node'
const Node: FC = () => { const Node: FC = () => {
return ( return (
<BaseNode> <div>tool</div>
<div>tool</div>
</BaseNode>
) )
} }
......
import type { FC } from 'react' import type { FC } from 'react'
import BasePanel from '../_base/panel'
const Panel: FC = () => { const Panel: FC = () => {
return ( return (
<BasePanel> <div>start panel inputs</div>
<div>start panel inputs</div>
</BasePanel>
) )
} }
......
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