Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions packages/flow-approval-presenter/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,19 @@
# @coding-flow/flow-approval-presenter

## 0.2.21

### Patch Changes

- 0b9b8d6: fix: 退回候选节点改为后端按执行历史下发(issue #270)

- 详情响应新增 `backNodes`:只包含当前记录真实执行过的历史节点,按“最近优先”排序(例如停留在 C 节点时为 B、A),`nodes` 仍保留流程定义全量节点不受影响。
- PC / 移动端退回弹框改用 `backNodes`(`buildReturnNodeOptions`),不再从流程定义节点中截取,避免列出未走过、甚至位于当前节点之后的节点;`backNodes` 为空时不展示退回入口。
- 兼容旧版后端:缺少 `backNodes` 字段时回退到原有按定义顺序截取的逻辑。

- Updated dependencies [0b9b8d6]
- @coding-flow/flow-types@0.2.21
- @coding-flow/flow-core@0.2.21

## 0.2.20

### Patch Changes
Expand Down
2 changes: 1 addition & 1 deletion packages/flow-approval-presenter/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@coding-flow/flow-approval-presenter",
"version": "0.2.20",
"version": "0.2.21",
"description": "flow-engine approval presenter framework ",
"type": "module",
"sideEffects": [
Expand Down
1 change: 1 addition & 0 deletions packages/flow-approval-presenter/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@ export * from '@/hooks';
export * from '@/interceptor';
export * from '@/utils/operator-count';
export * from '@/utils/active-form';
export * from '@/utils/return-nodes';
export { FlowActionPresenter } from '@/presenters/action';
47 changes: 47 additions & 0 deletions packages/flow-approval-presenter/src/utils/return-nodes.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import { FlowContent } from "@coding-flow/flow-types";

/**
* 退回节点下拉选项
*/
export interface ReturnNodeOption {
label: string;
value: string;
}

/**
* 构建退回候选节点。
*
* <p>优先使用后端 `backNodes`:它只包含当前记录真实执行过的历史节点,并已按“最近优先”排序
* (例如停留在 C 节点时为 B、A),避免从流程定义的全量节点 `nodes` 中截取时把未走过、
* 甚至位于当前节点之后的节点也列出来(issue #270)。</p>
*
* <p>`backNodes` 为空数组表示明确没有可退回节点(如开始节点),此时不再回退;
* 只有旧版后端完全不下发该字段时才回退到原有“按定义顺序截取到当前节点”的兼容逻辑。</p>
*
* @param flow 流程详情内容
* @returns 退回候选节点选项,最近优先
*/
export const buildReturnNodeOptions = (flow?: FlowContent): ReturnNodeOption[] => {
if (!flow) {
return [];
}
if (flow.backNodes) {
return flow.backNodes.map(node => ({
label: node.name,
value: node.id,
}));
}
const options: ReturnNodeOption[] = [];
for (const node of flow.nodes || []) {
if (node.id === flow.nodeId) {
break;
}
if (node.display) {
options.push({
label: node.name,
value: node.id,
});
}
}
return options;
};
55 changes: 55 additions & 0 deletions packages/flow-approval-presenter/tests/return-nodes.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import { describe, expect, it } from "@rstest/core";
import { FlowContent, NodeOption } from "@coding-flow/flow-types";
import { buildReturnNodeOptions } from "@/utils/return-nodes";

/** 构造最小可用的节点选项 */
const buildNode = (id: string, name: string, display = true): NodeOption => ({
id,
name,
type: 'APPROVAL',
display,
} as NodeOption);

/** 构造仅包含退回相关字段的流程详情 */
const buildFlow = (data: Partial<FlowContent>): FlowContent => ({
nodeId: 'C',
nodes: [buildNode('A', '开始节点'), buildNode('B', 'B审批'), buildNode('C', 'C审批'), buildNode('D', '结束节点')],
...data,
} as FlowContent);

describe('buildReturnNodeOptions(退回候选节点)', () => {
it('优先使用后端 backNodes,并按最近优先顺序输出', () => {
const flow = buildFlow({
backNodes: [buildNode('B', 'B审批'), buildNode('A', '开始节点')],
});
expect(buildReturnNodeOptions(flow)).toEqual([
{label: 'B审批', value: 'B'},
{label: '开始节点', value: 'A'},
]);
});

it('backNodes 为空数组时表示没有可退回节点,不再按 nodes 截取', () => {
const flow = buildFlow({backNodes: []});
expect(buildReturnNodeOptions(flow)).toEqual([]);
});

it('旧版后端缺失 backNodes 时回退到按定义顺序截取到当前节点', () => {
const flow = buildFlow({});
expect(buildReturnNodeOptions(flow)).toEqual([
{label: '开始节点', value: 'A'},
{label: 'B审批', value: 'B'},
]);
});

it('回退逻辑仍会跳过硬编码 display=false 的节点', () => {
const flow = buildFlow({
nodes: [buildNode('A', '开始节点'), buildNode('X', '隐藏节点', false), buildNode('C', 'C审批')],
nodeId: 'C',
});
expect(buildReturnNodeOptions(flow)).toEqual([{label: '开始节点', value: 'A'}]);
});

it('流程内容为空时返回空列表', () => {
expect(buildReturnNodeOptions(undefined)).toEqual([]);
});
});
2 changes: 2 additions & 0 deletions packages/flow-core/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# @coding-flow/flow-core

## 0.2.21

## 0.2.20

### Patch Changes
Expand Down
2 changes: 1 addition & 1 deletion packages/flow-core/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@coding-flow/flow-core",
"version": "0.2.20",
"version": "0.2.21",
"description": "flow-engine core lib framework ",
"type": "module",
"sideEffects": [
Expand Down
10 changes: 10 additions & 0 deletions packages/flow-design/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
# @coding-flow/flow-design

## 0.2.21

### Patch Changes

- Updated dependencies [0b9b8d6]
- @coding-flow/flow-types@0.2.21
- @coding-flow/flow-core@0.2.21
- @coding-flow/flow-icons@0.2.21
- @coding-flow/flow-pc-ui@0.2.21

## 0.2.20

### Patch Changes
Expand Down
2 changes: 1 addition & 1 deletion packages/flow-design/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@coding-flow/flow-design",
"version": "0.2.20",
"version": "0.2.21",
"description": "flow-engine design components ",
"type": "module",
"sideEffects": [
Expand Down
6 changes: 6 additions & 0 deletions packages/flow-icons/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# @coding-flow/flow-icons

## 0.2.21

### Patch Changes

- @coding-flow/flow-core@0.2.21

## 0.2.20

### Patch Changes
Expand Down
2 changes: 1 addition & 1 deletion packages/flow-icons/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@coding-flow/flow-icons",
"version": "0.2.20",
"version": "0.2.21",
"description": "flow-engine icons ",
"type": "module",
"sideEffects": [
Expand Down
18 changes: 18 additions & 0 deletions packages/flow-mobile/flow-mobile-approval/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,23 @@
# @coding-flow/flow-mobile-approval

## 0.2.21

### Patch Changes

- 0b9b8d6: fix: 退回候选节点改为后端按执行历史下发(issue #270)

- 详情响应新增 `backNodes`:只包含当前记录真实执行过的历史节点,按“最近优先”排序(例如停留在 C 节点时为 B、A),`nodes` 仍保留流程定义全量节点不受影响。
- PC / 移动端退回弹框改用 `backNodes`(`buildReturnNodeOptions`),不再从流程定义节点中截取,避免列出未走过、甚至位于当前节点之后的节点;`backNodes` 为空时不展示退回入口。
- 兼容旧版后端:缺少 `backNodes` 字段时回退到原有按定义顺序截取的逻辑。

- Updated dependencies [0b9b8d6]
- @coding-flow/flow-approval-presenter@0.2.21
- @coding-flow/flow-types@0.2.21
- @coding-flow/flow-mobile-form@0.2.21
- @coding-flow/flow-core@0.2.21
- @coding-flow/flow-icons@0.2.21
- @coding-flow/flow-mobile-ui@0.2.21

## 0.2.20

### Patch Changes
Expand Down
2 changes: 1 addition & 1 deletion packages/flow-mobile/flow-mobile-approval/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@coding-flow/flow-mobile-approval",
"version": "0.2.20",
"version": "0.2.21",
"description": "flow-engine pc mobile approval components",
"type": "module",
"sideEffects": [
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
import React from "react";
import {ReturnViewPlugin, ReturnViewPluginKey} from "@coding-flow/flow-approval-presenter";
import {
buildReturnNodeOptions,
ReturnViewPlugin,
ReturnViewPluginKey
} from "@coding-flow/flow-approval-presenter";
import {ViewBindPlugin} from "@coding-flow/flow-core";
import {Selector} from "antd-mobile";
import {useApprovalContext} from "@coding-flow/flow-approval-presenter";
Expand All @@ -20,23 +24,10 @@ export const ReturnView: React.FC<ReturnViewPlugin> = (props) => {
return [];
},[props.value]);

/** 候选节点由后端按执行历史下发(最近优先),不在前端从流程定义节点中截取 */
const nodeOptions = React.useMemo(() => {
const nodes = state.flow?.nodes || [];
const currentId = state.flow?.nodeId || '';
const options:any[] = [];
for (const node of nodes) {
if (currentId === node.id) {
break;
}
if(node.display) {
options.push({
label: node.name,
value: node.id,
})
}
}
return options;
}, [state.flow?.nodes])
return buildReturnNodeOptions(state.flow);
}, [state.flow?.backNodes, state.flow?.nodes, state.flow?.nodeId])


if (ReturnViewComponent) {
Expand All @@ -58,4 +49,4 @@ export const ReturnView: React.FC<ReturnViewPlugin> = (props) => {
options={nodeOptions}
/>
)
}
}
8 changes: 8 additions & 0 deletions packages/flow-mobile/flow-mobile-form/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
# @coding-flow/flow-mobile-form

## 0.2.21

### Patch Changes

- Updated dependencies [0b9b8d6]
- @coding-flow/flow-types@0.2.21
- @coding-flow/flow-core@0.2.21

## 0.2.20

### Patch Changes
Expand Down
2 changes: 1 addition & 1 deletion packages/flow-mobile/flow-mobile-form/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@coding-flow/flow-mobile-form",
"version": "0.2.20",
"version": "0.2.21",
"description": "flow-engine mobile form engine",
"type": "module",
"sideEffects": [
Expand Down
6 changes: 6 additions & 0 deletions packages/flow-mobile/flow-mobile-ui/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# @coding-flow/flow-mobile-ui

## 0.2.21

### Patch Changes

- @coding-flow/flow-core@0.2.21

## 0.2.20

### Patch Changes
Expand Down
2 changes: 1 addition & 1 deletion packages/flow-mobile/flow-mobile-ui/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@coding-flow/flow-mobile-ui",
"version": "0.2.20",
"version": "0.2.21",
"description": "flow-engine mobile ui components",
"type": "module",
"sideEffects": [
Expand Down
18 changes: 18 additions & 0 deletions packages/flow-pc/flow-pc-approval/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,23 @@
# @coding-flow/flow-pc-approval

## 0.2.21

### Patch Changes

- 0b9b8d6: fix: 退回候选节点改为后端按执行历史下发(issue #270)

- 详情响应新增 `backNodes`:只包含当前记录真实执行过的历史节点,按“最近优先”排序(例如停留在 C 节点时为 B、A),`nodes` 仍保留流程定义全量节点不受影响。
- PC / 移动端退回弹框改用 `backNodes`(`buildReturnNodeOptions`),不再从流程定义节点中截取,避免列出未走过、甚至位于当前节点之后的节点;`backNodes` 为空时不展示退回入口。
- 兼容旧版后端:缺少 `backNodes` 字段时回退到原有按定义顺序截取的逻辑。

- Updated dependencies [0b9b8d6]
- @coding-flow/flow-approval-presenter@0.2.21
- @coding-flow/flow-types@0.2.21
- @coding-flow/flow-pc-form@0.2.21
- @coding-flow/flow-core@0.2.21
- @coding-flow/flow-icons@0.2.21
- @coding-flow/flow-pc-ui@0.2.21

## 0.2.20

### Patch Changes
Expand Down
2 changes: 1 addition & 1 deletion packages/flow-pc/flow-pc-approval/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@coding-flow/flow-pc-approval",
"version": "0.2.20",
"version": "0.2.21",
"description": "flow-engine pc form approval components",
"type": "module",
"sideEffects": [
Expand Down
27 changes: 9 additions & 18 deletions packages/flow-pc/flow-pc-approval/src/plugins/view/return-view.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
import React from "react";
import {ReturnViewPlugin, ReturnViewPluginKey} from "@coding-flow/flow-approval-presenter";
import {
buildReturnNodeOptions,
ReturnViewPlugin,
ReturnViewPluginKey
} from "@coding-flow/flow-approval-presenter";
import {ViewBindPlugin} from "@coding-flow/flow-core";
import {Select} from "antd";
import {useApprovalContext} from "@coding-flow/flow-approval-presenter";
Expand All @@ -9,23 +13,10 @@ export const ReturnView: React.FC<ReturnViewPlugin> = (props) => {

const {state} = useApprovalContext();

/** 候选节点由后端按执行历史下发(最近优先),不在前端从流程定义节点中截取 */
const nodeOptions = React.useMemo(() => {
const nodes = state.flow?.nodes || [];
const currentId = state.flow?.nodeId || '';
const options:any[] = [];
for (const node of nodes) {
if (currentId === node.id) {
break;
}
if(node.display) {
options.push({
label: node.name,
value: node.id,
})
}
}
return options;
}, [state.flow?.nodes])
return buildReturnNodeOptions(state.flow);
}, [state.flow?.backNodes, state.flow?.nodes, state.flow?.nodeId])


if (ReturnViewComponent) {
Expand All @@ -48,4 +39,4 @@ export const ReturnView: React.FC<ReturnViewPlugin> = (props) => {
options={nodeOptions}
/>
)
}
}
Loading
Loading