-
Notifications
You must be signed in to change notification settings - Fork 324
[elsa] feat: add reply node #324
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
reeeborn33
wants to merge
2
commits into
ModelEngine-Group:main
Choose a base branch
from
reeeborn33:elsa-feature-repy-node
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
86 changes: 86 additions & 0 deletions
86
framework/elsa/fit-elsa-react/src/components/replyNode/ReplyWrapper.jsx
This file contains hidden or 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,86 @@ | ||
import React from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import {JadeInputForm} from '../common/JadeInputForm.jsx'; | ||
import {useDispatch, useShapeContext} from '@/components/DefaultRoot.jsx'; | ||
import {TemplatePanel} from "@/components/common/TemplatePanel.jsx"; | ||
import {Trans, useTranslation} from "react-i18next"; | ||
|
||
ReplyWrapper.propTypes = { | ||
data: PropTypes.object.isRequired, | ||
shapeStatus: PropTypes.object, | ||
}; | ||
|
||
export default function ReplyWrapper({data, shapeStatus}) { | ||
const dispatch = useDispatch(); | ||
const shape = useShapeContext(); | ||
const {t} = useTranslation(); | ||
const template = data.inputParams.find(item => item.name === 'template'); | ||
|
||
/** | ||
* 初始化数据 | ||
* | ||
* @return {*} | ||
*/ | ||
const initItems = () => { | ||
return data.inputParams.find(item => item.name === "variables").value | ||
}; | ||
|
||
/** | ||
* 添加输入的变量 | ||
* | ||
* @param id id 数据id | ||
*/ | ||
const addItem = (id) => { | ||
// 代码节点入参最大数量为20 | ||
if (data.inputParams.find(item => item.name === 'variables').value.length < 20) { | ||
dispatch({type: 'addInputParam', id: id}); | ||
} | ||
}; | ||
|
||
/** | ||
* 更新入参变量属性名或者类型 | ||
* | ||
* @param id 数据id | ||
* @param value 新值 | ||
*/ | ||
const updateItem = (id, value) => { | ||
dispatch({type: 'editInputParam', id: id, newValue: value}); | ||
}; | ||
|
||
/** | ||
* 删除input | ||
* | ||
* @param id 需要删除的数据id | ||
*/ | ||
const deleteItem = (id) => { | ||
dispatch({type: 'deleteInputParam', id: id}); | ||
}; | ||
|
||
return ( | ||
<div> | ||
<JadeInputForm | ||
shapeStatus={shapeStatus} | ||
items={initItems()} | ||
addItem={addItem} | ||
updateItem={updateItem} | ||
deleteItem={deleteItem} | ||
content={ | ||
(<div className={'jade-font-size'} style={{lineHeight: '1.2'}}> | ||
<Trans i18nKey='templateInputPopover' components={{p: <p/>}}/> | ||
</div>)} | ||
maxInputLength={1000} | ||
/> | ||
<TemplatePanel | ||
disabled={shapeStatus.disabled} | ||
template={template} | ||
title={t("replyTextLabel")} | ||
placeHolder={t("promptPlaceHolder")} | ||
name={"reply"} | ||
onChange={(templateText) => { | ||
dispatch({type: 'changeTemplate', id: template.id, value: templateText}); | ||
}} | ||
labelName={t("replyTextLabel")} | ||
/> | ||
</div> | ||
); | ||
} |
191 changes: 191 additions & 0 deletions
191
framework/elsa/fit-elsa-react/src/components/replyNode/reducers/reducer.js
This file contains hidden or 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,191 @@ | ||
/*--------------------------------------------------------------------------------------------- | ||
* Copyright (c) 2025 Huawei Technologies Co., Ltd. All rights reserved. | ||
* This file is a part of the ModelEngine Project. | ||
* Licensed under the MIT License. See License.txt in the project root for license information. | ||
*--------------------------------------------------------------------------------------------*/ | ||
|
||
/** | ||
* changeTemplate 事件处理器. | ||
* | ||
* @return {{}} 处理器对象. | ||
* @constructor | ||
*/ | ||
export const ChangeTemplateReducer = () => { | ||
const self = {}; | ||
self.type = 'changeTemplate'; | ||
|
||
/** | ||
* 处理方法. | ||
* | ||
* @param config 配置数据. | ||
* @param action 事件对象. | ||
* @return {*} 处理之后的数据. | ||
*/ | ||
self.reduce = (config, action) => { | ||
const newConfig = {}; | ||
Object.entries(config).forEach(([key, value]) => { | ||
if (key === 'inputParams') { | ||
newConfig[key] = value.map(item => { | ||
if (item.id === action.id) { | ||
return { | ||
...item, value: action.value, | ||
}; | ||
} else { | ||
return item; | ||
} | ||
}); | ||
} else { | ||
newConfig[key] = value; | ||
} | ||
}); | ||
return newConfig; | ||
}; | ||
|
||
return self; | ||
}; | ||
|
||
/** | ||
* addInputParam 事件处理器. | ||
* | ||
* @return {{}} 处理器对象. | ||
* @constructor | ||
*/ | ||
export const AddInputParamReducer = () => { | ||
const self = {}; | ||
self.type = 'addInputParam'; | ||
|
||
/** | ||
* 处理方法. | ||
* | ||
* @param config 配置数据. | ||
* @param action 事件对象. | ||
* @return {*} 处理之后的数据. | ||
*/ | ||
self.reduce = (config, action) => { | ||
const newConfig = {}; | ||
Object.entries(config).forEach(([key, value]) => { | ||
if (key === 'inputParams') { | ||
newConfig[key] = value.map(item => { | ||
if (item.name === 'variables') { | ||
return { | ||
...item, | ||
value: [ | ||
...item.value, | ||
{ | ||
id: action.id, | ||
name: undefined, | ||
type: 'String', | ||
from: 'Reference', | ||
value: '', | ||
reeeborn33 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
referenceNode: '', | ||
referenceId: '', | ||
referenceKey: '', | ||
} | ||
] | ||
}; | ||
} else { | ||
return item; | ||
} | ||
}); | ||
} else { | ||
newConfig[key] = value; | ||
} | ||
}); | ||
return newConfig; | ||
}; | ||
|
||
|
||
return self; | ||
}; | ||
|
||
/** | ||
* deleteInputParam 事件处理器. | ||
* | ||
* @return {{}} 处理器对象. | ||
* @constructor | ||
*/ | ||
export const DeleteInputParamReducer = () => { | ||
const self = {}; | ||
self.type = 'deleteInputParam'; | ||
|
||
/** | ||
* 处理方法. | ||
* | ||
* @param config 配置数据. | ||
* @param action 事件对象. | ||
* @return {*} 处理之后的数据. | ||
*/ | ||
self.reduce = (config, action) => { | ||
const newConfig = {}; | ||
Object.entries(config).forEach(([key, value]) => { | ||
if (key === 'inputParams') { | ||
newConfig[key] = value.map(item => { | ||
if (item.name === 'variables') { | ||
return { | ||
...item, | ||
value: item.value.filter((item) => item.id !== action.id), | ||
}; | ||
} else { | ||
return item; | ||
} | ||
}); | ||
} else { | ||
newConfig[key] = value; | ||
} | ||
}); | ||
return newConfig; | ||
}; | ||
|
||
return self; | ||
}; | ||
|
||
/** | ||
* deleteInputParam 事件处理器. | ||
* | ||
* @return {{}} 处理器对象. | ||
* @constructor | ||
*/ | ||
export const EditInputParamReducer = () => { | ||
const self = {}; | ||
self.type = 'editInputParam'; | ||
|
||
/** | ||
* 处理方法. | ||
* | ||
* @param config 配置数据. | ||
* @param action 事件对象. | ||
* @return {*} 处理之后的数据. | ||
*/ | ||
self.reduce = (config, action) => { | ||
const newConfig = {}; | ||
Object.entries(config).forEach(([key, value]) => { | ||
if (key === 'inputParams') { | ||
newConfig[key] = value.map(item => { | ||
if (item.name === 'variables') { | ||
return { | ||
...item, | ||
value: item.value.map(inputItem => { | ||
if (inputItem.id === action.id) { | ||
let updatedInputItem = {...inputItem}; | ||
action.newValue.map((param) => { | ||
updatedInputItem[param.key] = param.value; | ||
}); | ||
return updatedInputItem; | ||
} else { | ||
return inputItem; | ||
} | ||
}), | ||
}; | ||
} else { | ||
return item; | ||
} | ||
}); | ||
} else { | ||
newConfig[key] = value; | ||
} | ||
}); | ||
return newConfig; | ||
}; | ||
|
||
return self; | ||
} |
85 changes: 85 additions & 0 deletions
85
framework/elsa/fit-elsa-react/src/components/replyNode/replyNodeComponent.jsx
This file contains hidden or 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,85 @@ | ||
/*--------------------------------------------------------------------------------------------- | ||
* Copyright (c) 2025 Huawei Technologies Co., Ltd. All rights reserved. | ||
* This file is a part of the ModelEngine Project. | ||
* Licensed under the MIT License. See License.txt in the project root for license information. | ||
*--------------------------------------------------------------------------------------------*/ | ||
|
||
import ReplyWrapper from './ReplyWrapper.jsx'; | ||
import {v4 as uuidv4} from 'uuid'; | ||
import {defaultComponent} from '@/components/defaultComponent.js'; | ||
import { | ||
AddInputParamReducer, | ||
ChangeTemplateReducer, | ||
DeleteInputParamReducer, | ||
EditInputParamReducer | ||
} from "@/components/replyNode/reducers/reducer.js"; | ||
|
||
/** | ||
* 直接回复节点组件 | ||
* | ||
* @param jadeConfig | ||
* @param shape 图形对象. | ||
*/ | ||
export const replyNodeComponent = (jadeConfig, shape) => { | ||
const self = defaultComponent(jadeConfig); | ||
const addReducer = (map, reducer) => map.set(reducer.type, reducer); | ||
const builtInReducers = new Map(); | ||
addReducer(builtInReducers, AddInputParamReducer()); | ||
addReducer(builtInReducers, EditInputParamReducer()); | ||
addReducer(builtInReducers, ChangeTemplateReducer()); | ||
addReducer(builtInReducers, DeleteInputParamReducer()); | ||
|
||
/** | ||
* 必须. | ||
*/ | ||
self.getJadeConfig = () => { | ||
return jadeConfig ? jadeConfig : { | ||
inputParams: [ | ||
{ | ||
id: uuidv4(), name: 'variables', type: 'Object', from: 'Expand', value: [ | ||
{ | ||
id: uuidv4(), | ||
name: undefined, | ||
type: 'String', | ||
from: 'Reference', | ||
value: '', | ||
referenceNode: '', | ||
referenceId: '', | ||
referenceKey: '', | ||
} | ||
], | ||
}, | ||
{ | ||
id: uuidv4(), | ||
name: 'template', | ||
type: 'String', | ||
from: 'Input', | ||
value: '' | ||
}, | ||
], | ||
outputParams: [], | ||
tempReference: {}, | ||
}; | ||
}; | ||
|
||
/** | ||
* 必须. | ||
* | ||
* @param shapeStatus 图形状态集合. | ||
* @param data 数据. | ||
*/ | ||
self.getReactComponents = (shapeStatus, data) => { | ||
return (<><ReplyWrapper shapeStatus={shapeStatus} data={data}/></>); | ||
}; | ||
|
||
/** | ||
* 必须. | ||
*/ | ||
const reducers = self.reducers; | ||
self.reducers = (data, action) => { | ||
const reducer = builtInReducers.get(action.type); | ||
return reducer ? reducer.reduce(data, action) : reducers.apply(self, [data, action]); | ||
}; | ||
|
||
return self; | ||
}; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.