feat: get and set data use context

This commit is contained in:
Joel
2024-03-04 20:14:09 +08:00
parent ccd3e519ea
commit 4376813951
36 changed files with 236 additions and 117 deletions

View File

@ -1,12 +1,15 @@
import type { FC } from 'react'
import { useTranslation } from 'react-i18next'
import { mockData } from './mock'
import type { EndNodeType } from './types'
import type { NodeProps } from '@/app/components/workflow/types'
const i18nPrefix = 'workflow.nodes.end'
const Node: FC = () => {
const Node: FC<NodeProps<EndNodeType>> = ({
data,
}) => {
const { t } = useTranslation()
const { outputs } = mockData
const { outputs } = data
return (
<div className='px-3'>
<div className='flex items-center h-6 justify-between bg-gray-100 rounded-md px-1 space-x-1 text-xs font-normal text-gray-700'>

View File

@ -3,11 +3,13 @@ import { useTranslation } from 'react-i18next'
import cn from 'classnames'
import VarReferencePicker from '../_base/components/variable/var-reference-picker'
import useConfig from './use-config'
import { mockData } from './mock'
import type { EndNodeType } from './types'
import { EndVarType } from './types'
import VarList from '@/app/components/workflow/nodes/_base/components/variable/var-list'
import Field from '@/app/components/workflow/nodes/_base/components/field'
import AddButton from '@/app/components/base/button/add-button'
import type { NodeProps } from '@/app/components/workflow/types'
const i18nPrefix = 'workflow.nodes.end'
const TypeItem = ({ type, current, onClick }: { type: EndVarType; current: EndVarType; onClick: (type: EndVarType) => void }) => {
@ -33,7 +35,10 @@ const TypeItem = ({ type, current, onClick }: { type: EndVarType; current: EndVa
const allTypes = [EndVarType.plainText, EndVarType.structured, EndVarType.none]
const Panel: FC = () => {
const Panel: FC<NodeProps<EndNodeType>> = ({
id,
data,
}) => {
const { t } = useTranslation()
const readOnly = false
@ -43,7 +48,7 @@ const Panel: FC = () => {
handleVarListChange,
handelPlainTextSelectorChange,
handleAddVariable,
} = useConfig(mockData)
} = useConfig(id, data)
const outputs = inputs.outputs
return (

View File

@ -1,10 +1,11 @@
import produce from 'immer'
import { useCallback, useState } from 'react'
import { useCallback } from 'react'
import useVarList from '../_base/hooks/use-var-list'
import type { EndNodeType, EndVarType, OutPuts } from './types'
import useNodeCrud from '@/app/components/workflow/nodes/_base/hooks/use-node-crud'
const useConfig = (initInputs: EndNodeType) => {
const [inputs, setInputs] = useState<EndNodeType>(initInputs)
const useConfig = (id: string, payload: EndNodeType) => {
const { inputs, setInputs } = useNodeCrud<EndNodeType>(id, payload)
const handleOutputTypeChange = useCallback((type: EndVarType) => {
const newInputs = produce(inputs, (draft: any) => {
draft.outputs.type = type