Skip to content

Commit

Permalink
fix:条件节点数据格式更改
Browse files Browse the repository at this point in the history
  • Loading branch information
昔梦 committed Jan 6, 2025
1 parent 7c30cb2 commit 587606e
Show file tree
Hide file tree
Showing 9 changed files with 34 additions and 34 deletions.
6 changes: 3 additions & 3 deletions docs/xflow/demo/layout/LR/setting.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ export const nodes = [
data: {
list: [
{
_conditionId: 'iawoyh5niyi6zjob',
_id: 'iawoyh5niyi6zjob',
},
],
},
Expand Down Expand Up @@ -259,8 +259,8 @@ export const edges = [
{
type: 'buttonedge',
source: 'b6zsd6w5ah2b209t',
sourceHandle: 'condition_else',
sourceHandle: 'id_else',
target: '4',
id: 'xy-edge__b6zsd6w5ah2b209tcondition_else-4',
id: 'xy-edge__b6zsd6w5ah2b209tid_else-4',
},
];
6 changes: 3 additions & 3 deletions docs/xflow/demo/layout/TB/setting.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ export const nodes = [
data: {
list: [
{
_conditionId: 'iawoyh5niyi6zjob',
_id: 'iawoyh5niyi6zjob',
},
],
},
Expand Down Expand Up @@ -273,8 +273,8 @@ export const edges = [
{
type: 'buttonedge',
source: 'b6zsd6w5ah2b209t',
sourceHandle: 'condition_else',
sourceHandle: 'id_else',
target: '4',
id: 'xy-edge__b6zsd6w5ah2b209tcondition_else-4',
id: 'xy-edge__b6zsd6w5ah2b209tid_else-4',
},
];
6 changes: 3 additions & 3 deletions docs/xflow/demo/nodeSetting/data.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ export const nodes = [
data: {
list: [
{
_conditionId: 'iawoyh5niyi6zjob',
_id: 'iawoyh5niyi6zjob',
},
],
},
Expand Down Expand Up @@ -224,8 +224,8 @@ export const edges = [
{
type: 'buttonedge',
source: 'b6zsd6w5ah2b209t',
sourceHandle: 'condition_else',
sourceHandle: 'id_else',
target: '4',
id: 'xy-edge__b6zsd6w5ah2b209tcondition_else-4',
id: 'xy-edge__b6zsd6w5ah2b209tid_else-4',
},
];
14 changes: 7 additions & 7 deletions docs/xflow/demo/switchNode/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,16 @@ export default () => {
data: {
list: [
{
_conditionId: 'condition_1nmzbhnbtv1se6sd', // 对应的 sourceHandle: 'condition_1nmzbhnbtv1se6sd'的边
_id: 'id_1nmzbhnbtv1se6sd', // 对应的 sourceHandle: 'id_1nmzbhnbtv1se6sd'的边
value: '条件1',
},
{
value: '条件2',
_conditionId: 'condition_enxhwfca1ebn55td', // 对应sourceHandle: 'condition_enxhwfca1ebn55td'的边
_id: 'id_enxhwfca1ebn55td', // 对应sourceHandle: 'id_enxhwfca1ebn55td'的边
},
{
value: '条件3',
_conditionId: 'condition_z1f7b93zwbx1xycu',// 对应sourceHandle: 'condition_z1f7b93zwbx1xycu'的边
_id: 'id_z1f7b93zwbx1xycu',// 对应sourceHandle: 'id_z1f7b93zwbx1xycu'的边
},
],
desc: '',
Expand Down Expand Up @@ -97,25 +97,25 @@ export default () => {
id: '5s6af77jbcqvzfod',
source: 'kshd2hp4vqm8ww19',// switch节点的边
target: 'ql61j2tdli4xage0',
sourceHandle: 'condition_1nmzbhnbtv1se6sd', // 对应 _conditionId为'condition_1nmzbhnbtv1se6sd'的条件
sourceHandle: 'id_1nmzbhnbtv1se6sd', // 对应 _id为'id_1nmzbhnbtv1se6sd'的条件
},
{
id: '6tw709qgc3mtazrv',
source: 'kshd2hp4vqm8ww19',// switch节点的边
target: 'fab1j735q8iow6u3',
sourceHandle: 'condition_enxhwfca1ebn55td', // 对应 _conditionId为'condition_enxhwfca1ebn55td'的条件
sourceHandle: 'id_enxhwfca1ebn55td', // 对应 _id为'id_enxhwfca1ebn55td'的条件
},
{
id: 'vzlvdo69ljcqegc8',
source: 'kshd2hp4vqm8ww19',// switch节点的边
target: '9mc5i628mfrxdow0',
sourceHandle: 'condition_z1f7b93zwbx1xycu',// 对应 _conditionId为'condition_z1f7b93zwbx1xycu'的条件
sourceHandle: 'id_z1f7b93zwbx1xycu',// 对应 _id为'id_z1f7b93zwbx1xycu'的条件
},
{
id: 'j8p8fnr5au9k25pb',
source: 'kshd2hp4vqm8ww19',// switch节点的边
target: 'anmv2kcadqxj4k63',
sourceHandle: 'condition_else',// condition_else 对应默认路径ELSE
sourceHandle: 'id_else',// id_else 对应默认路径ELSE
},
{
id: '0qfpkc9vcjdb31qp',
Expand Down
6 changes: 3 additions & 3 deletions docs/xflow/nodeBuildIn.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@ group:
## 条件内置节点
内置条件节点,可以直接设置type为`Switch`使用。

条件节点的数据格式为`data:{list:[{value:"条件1",_conditionId:"condition_${随机数}"}]}``_conditionId`为边数据的`sourceHandle`,以便条件和边一一对应。
有条件参数value(可以通过自定义条件节点配置面板更改配置参数)的放入list数组里面作为`IF或者ELIF`渲染,没有条件参数的,为默认执行路径`ELSE`,`ELSE`路径的固定`_conditionId``condition_else`,即边数据的`sourceHandle`必须为`condition_else`才能链接`ELSE`链接头,比如:
条件节点的数据格式为`data:{list:[{value:"条件1",_id:"id_${随机数}"}]}``_id`为边数据的`sourceHandle`,以便条件和边一一对应。
有条件参数value(可以通过自定义条件节点配置面板更改配置参数)的放入list数组里面作为`IF或者ELIF`渲染,没有条件参数的,为默认执行路径`ELSE`,`ELSE`路径的固定`_id``id_else`,即边数据的`sourceHandle`必须为`id_else`才能链接`ELSE`链接头,比如:
```js
{
id: 'j8p8fnr5au9k25pb',
source: 'kshd2hp4vqm8ww19',
target: 'anmv2kcadqxj4k63',
sourceHandle: 'condition_else', // else路径的边
sourceHandle: 'id_else', // else路径的边
}
```

Expand Down
6 changes: 3 additions & 3 deletions packages/x-flow/src/components/CustomNode/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -146,15 +146,15 @@ export default memo((props: any) => {
key: 'paste-' + i,
index: i,
id: id,
sourcehandle: r._conditionId,
sourcehandle: r._id,
};
} else {
return {
label: `粘贴到第${i + 1}个出口`,
key: 'paste-' + i,
id: id,
index: i,
sourcehandle: r._conditionId,
sourcehandle: r._id,
};
}
});
Expand All @@ -166,7 +166,7 @@ export default memo((props: any) => {
key: 'paste-' + (list.length + 1),
id: id,
index: list.length + 1,
sourcehandle: 'condition_else',
sourcehandle: 'id_else',
},
];
}
Expand Down
8 changes: 4 additions & 4 deletions packages/x-flow/src/components/NodeEditor/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -71,19 +71,19 @@ const NodeEditor: FC<INodeEditorProps> = (props: any) => {
// 更新节点的 data
if (node?.data?._nodeType === 'Switch' && data?.list?.length) {
data['list'] = (data?.list || [])?.map((item, index) => {
if (item?._conditionId) {
if (item?._id) {
return item;
} else {
if (
node?.data?.list?.length &&
node?.data?.list[index]?._conditionId
node?.data?.list[index]?._id
) {
return {
...item,
_conditionId: node?.data?.list[index]?._conditionId,
_id: node?.data?.list[index]?._id,
};
} else {
return { ...item, _conditionId: `condition_${uuid()}` };
return { ...item, _id: `id_${uuid()}` };
}
}
});
Expand Down
2 changes: 1 addition & 1 deletion packages/x-flow/src/components/NodesPopover/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ export default forwardRef((props: any, popoverRef) => {

const handCreateNode = useCallback<any>(({ type }) => {
if (type === 'Switch') {
addNode({ _nodeType: type, list: [{ '_conditionId':`${uuid()}`}] });
addNode({ _nodeType: type, list: [{ '_id':`${uuid()}`}] });
} else if (type === 'Parallel') {
addNode({ _nodeType: type, list: [{ _id: `id_${uuid()}` }, { _id: `id_${uuid()}` }] });
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,15 +36,15 @@ export default memo((props: any) => {
position={position}
isConnectable={
(edges || [])?.filter(
flow => flow?.sourceHandle === item?._conditionId
flow => flow?.sourceHandle === item?._id
)?.length === 0
}
selected={selected}
isHovered={isHovered}
handleAddNode={data => {
handleAddNode(data, item?._conditionId);
handleAddNode(data, item?._id);
}}
id={item?._conditionId}
id={item?._id}
className="item-handle"
/>
</div>
Expand Down Expand Up @@ -89,7 +89,7 @@ export default memo((props: any) => {
})}
size={5}
>
{(data?.list || [{ _conditionId: `condition_${uuid()}` }])?.map(
{(data?.list || [{ _id: `id_${uuid()}` }])?.map(
(item, index) => (
<div
className={classNames('node-switch-widget-item', {
Expand Down Expand Up @@ -122,16 +122,16 @@ export default memo((props: any) => {
position={position}
isConnectable={
(edges || [])?.filter(
flow => flow?.sourceHandle === 'condition_else'
flow => flow?.sourceHandle === 'id_else'
)?.length === 0
}
selected={selected}
isHovered={isHovered}
handleAddNode={data => {
handleAddNode(data, 'condition_else');
handleAddNode(data, 'id_else');
}}
className="item-handle"
id={'condition_else'}
id={'id_else'}
/>
</div>
</div>
Expand Down

0 comments on commit 587606e

Please sign in to comment.