Skip to content
Merged

Dev #51

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
43 changes: 43 additions & 0 deletions designs/groovy-script/DESiGN.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# Groovy Script 脚本设计规范

## 脚本的实例写法如下
```
def run(request){
return "Hello, ${request.name}!"
}
```

## 脚本规范
request对象,根据脚本的不同,起传递的request对象也不同。
return语句,return语句根据脚本的不同,起返回的对象也不同。

## 开发规范
为了让脚本可以更好的呈现和使用,脚本的配置分为两种模式,一种是可视化配置模式,一种是代码配置模式。

* 代码配置模式
代码配置模式的脚本中,将会通过注释的方式添加一行@CUSTOM_SCRIPT,来标识这是一个自定义脚本,这样在编辑器中就会以代码的形式展示出来。
```
// @CUSTOM_SCRIPT
def run(request){
return "Hello, ${request.name}!"
}
```

* 可视化配置模式
可视化配置模式的脚本中,没有@CUSTOM_SCRIPT的注释标识,这样在编辑器中就会以可视化的形式展示出来。
```
def run(request){
return "Hello, ${request.name}!"
}
```

## 脚本展示标题
为了让脚本在在展示时可以更好的展示脚本的作用,所以在脚本中支持通过@SCRIPT_TITLE的注释来标识脚本的展示标题,这样在编辑器中就会以这个标题来展示脚本。

```
// @SCRIPT_TITLE 这是一个示例脚本
def run(request){
return "Hello, ${request.name}!"
}
```
上述的脚本在编辑器中就会以“这是一个示例脚本”来展示,而不是以代码的方式来展示。
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,12 @@
@AllArgsConstructor
public class ConditionScript {

public static final String SCRIPT_DEFAULT = "def run(request){return true}";
public static final String SCRIPT_DEFAULT = """
// @SCRIPT_TITLE 默认条件(允许执行)
def run(request){
return true;
}
""";

@Getter
private final String script;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,19 @@
public class ErrorTriggerScript {


public static final String SCRIPT_NODE_DEFAULT = "def run(request){ return $bind.createErrorThrow(request.getStartNode()); }";

public static final String SCRIPT_OPERATOR_DEFAULT = "def run(request){ return $bind.createErrorThrow(request.getCreatedOperator()); }";
public static final String SCRIPT_NODE_DEFAULT = """
// @SCRIPT_TITLE 回退至开始节点
def run(request){
return $bind.createErrorThrow(request.getStartNode());
}
""";

public static final String SCRIPT_OPERATOR_DEFAULT = """
// @SCRIPT_TITLE 指定用户到流程发起者
def run(request){
return $bind.createErrorThrow(request.getCreatedOperator());
}
""";

@Getter
private final String script;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,12 @@
@AllArgsConstructor
public class NodeTitleScript {

public static final String SCRIPT_DEFAULT = "def run(request){return '你有一条待办'}";
public static final String SCRIPT_DEFAULT = """
// @SCRIPT_TITLE 你有一条待办
def run(request){
return '你有一条待办'
}
""";

@Getter
private final String script;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,12 @@
@AllArgsConstructor
public class OperatorLoadScript {

public static final String SCRIPT_CREATOR = "def run(request){return [request.getCreatedOperator()]}";
public static final String SCRIPT_CREATOR = """
// @SCRIPT_TITLE 流程创建者
def run(request){
return [request.getCreatedOperator()]
}
""";

@Getter
private final String script;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,12 @@
@AllArgsConstructor
public class OperatorMatchScript {

public static final String SCRIPT_ANY = "def run(operator){return true}";
public static final String SCRIPT_ANY = """
// @SCRIPT_TITLE 任意用户
def run(request){
return true
}
""";

@Getter
private final String script;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@
import lombok.Getter;

/**
* 异常触发脚本
* 路由触发脚本
*/
@AllArgsConstructor
public class RouterNodeScript {


public static final String SCRIPT_NODE_DEFAULT = """
// @SCRIPT_TITLE 发起节点
def run(request){
return request.getStartNode().getId();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,12 @@
@AllArgsConstructor
public class SubProcessScript {

public static final String SCRIPT_DEFAULT = "def run(session){ return session.toCreateRequest() }";
public static final String SCRIPT_DEFAULT = """
// @SCRIPT_TITLE 创建当前流程
def run(request){
return request.toCreateRequest()
}
""";

@Getter
private final String script;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,12 @@
@AllArgsConstructor
public class TriggerScript {

public static final String SCRIPT_DEFAULT = "def run(session){ print('hello trigger node.') }";
public static final String SCRIPT_DEFAULT = """
// @SCRIPT_TITLE 示例触发节点(打印触发日志)
def run(request){
print('hello trigger node.');
}
""";

@Getter
private final String script;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public abstract class BaseGroovyRequest {
/**
* 当前操作人ID
*/
protected Integer operatorId;
protected long operatorId;

/**
* 是否流程管理员
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@ public class OperatorLoadGroovyRequest extends BaseGroovyRequest {
*/
private IFlowOperator createdOperator;

/**
* 当前操作人(上一节点审批人)
*/
private IFlowOperator currentOperator;

/**
* 从FlowSession构建OperatorLoadGroovyRequest
* @param session 流程会话(不能为null)
Expand All @@ -29,5 +34,6 @@ public OperatorLoadGroovyRequest(FlowSession session) {
if (session.getWorkflow() != null && session.getWorkflow().getCreatedOperator() != null) {
this.createdOperator = session.getWorkflow().getCreatedOperator();
}
this.currentOperator = session.getCurrentOperator();
}
}
1 change: 0 additions & 1 deletion frontend/apps/app-pc/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
"@flow-engine/flow-types": "workspace:*",
"@flow-engine/flow-pc-design": "workspace:*",
"@flow-engine/flow-pc-ui": "workspace:*",
"@flow-engine/flow-pc-form": "workspace:*",
"@flow-engine/flow-pc-approval":"workspace:*",
"antd": "^6.2.1",
"dayjs": "^1.11.19",
Expand Down
4 changes: 0 additions & 4 deletions frontend/apps/app-pc/src/config/plugin-view.tsx

This file was deleted.

1 change: 0 additions & 1 deletion frontend/apps/app-pc/src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import zhCN from 'antd/locale/zh_CN';
import dayjs from 'dayjs';
import 'dayjs/locale/zh-cn';
import "./index.css";
import "./config/plugin-view";

dayjs.locale('zh');

Expand Down
1 change: 1 addition & 0 deletions frontend/packages/flow-pc/flow-pc-approval/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
"@flow-engine/flow-types": "workspace:*",
"@flow-engine/flow-pc-design": "workspace:*",
"@flow-engine/flow-pc-ui": "workspace:*",
"@flow-engine/flow-pc-form": "workspace:*",
"@reduxjs/toolkit": "^2.11.2",
"antd": "^6.2.1",
"immer": "^11.1.3",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@ import React from "react";
import {useApprovalContext} from "@/components/flow-approval/hooks/use-approval-context";
import {ViewBindPlugin} from "@flow-engine/flow-types";
import { Form } from "antd";
import {FlowFormView} from "@flow-engine/flow-pc-form";

interface FormViewComponentProps{
onValuesChange?:(values:any)=>void;
}

export const FormViewComponent: React.FC<FormViewComponentProps> = (props) => {
const {state, context} = useApprovalContext();
const ViewComponent = ViewBindPlugin.getInstance().get(state.flow?.view || 'default');
const ViewComponent = ViewBindPlugin.getInstance().get(state.flow?.view || 'default') || FlowFormView ;

const formMeta = state.flow?.form;

Expand Down
4 changes: 3 additions & 1 deletion frontend/packages/flow-pc/flow-pc-design/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,11 @@
},
"dependencies": {
"@ant-design/icons": "~6.1.0",
"@codemirror/lang-java": "^6.0.2",
"@codemirror/theme-one-dark": "^6.1.3",
"@flow-engine/flow-core": "workspace:*",
"@flow-engine/flow-types": "workspace:*",
"@flow-engine/flow-pc-ui": "workspace:*",
"@flow-engine/flow-types": "workspace:*",
"@flowgram.ai/export-plugin": "1.0.7",
"@flowgram.ai/fixed-layout-editor": "1.0.7",
"@flowgram.ai/fixed-semi-materials": "1.0.7",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import {type FlowNodeEntity, useClientContext} from '@flowgram.ai/fixed-layout-editor';
import React, {useCallback, useContext} from "react";
import {NodeRenderContext} from "@/components/design-editor/context";
import {NodePanel} from "@/components/design-editor/node-components/panel";
import {NodeHeader} from "@/components/design-editor/node-components/header";
import {Button} from "antd";
import {nodeFormPanelFactory} from "@/components/design-editor/components/sidebar";
Expand Down Expand Up @@ -54,13 +53,13 @@ export const BranchAdderRender: React.FC<BranchAdderProps> = (props) => {
const canAddBranch = playground.config.readonlyOrDisabled;

return (
<NodePanel>
<div>
<NodeHeader
iconEnable={true}
style={{
width: 120
}}/>
<Button type={'link'} disabled={canAddBranch} onClick={handleAddBranch}>{props.buttonText}</Button>
</NodePanel>
</div>
);
};
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
export { NodeRenderContext } from './node-render-context';
export { IsSidebarContext } from './sidebar-context';
export { IsSidebarContext } from './sidebar-context';
export { NodeFormContext } from './node-form-context';
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import React from 'react';
import {FlowNodeJSON} from "@/components/design-editor/typings";
import {FormRenderProps,} from '@flowgram.ai/fixed-layout-editor';

export const NodeFormContext = React.createContext<FormRenderProps<FlowNodeJSON['data']>>({} as any);

Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { useContext } from 'react';
import { NodeFormContext } from '../context';

export function useNodeFormContext() {
return useContext(NodeFormContext);
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { Field, FieldRenderProps } from "@flowgram.ai/fixed-layout-editor";
import { Form,Input } from "antd";
import {Field, FieldRenderProps} from "@flowgram.ai/fixed-layout-editor";
import {Button, Form, Space} from "antd";
import React from "react";
import {GroovyScriptPreview} from "@/components/script/components/groovy-script-preview";
import {EditOutlined} from "@ant-design/icons";

/**
* 条件配置
Expand All @@ -25,9 +27,20 @@ export const ConditionScript = ()=>{
<Field
name={"script"}
render={({ field: { value, onChange } }: FieldRenderProps<any>) => (
<>
<Input value={value} onChange={onChange} />
</>
<Space.Compact style={{width: '100%'}}>
<GroovyScriptPreview
script={value}
/>

<Button
icon={<EditOutlined/>}
onClick={() => {
}}
style={{borderRadius: '0 6px 6px 0'}}
>
编辑
</Button>
</Space.Compact>
)}
/>
</Form.Item>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import React from "react";
import {useNodeFormContext} from "@/components/design-editor/hooks/use-node-form";
import {GroovyScriptConvertorUtil} from "@/components/script/utils/convertor";

export const CurrentNodeOperator = () => {
const data = useNodeFormContext();
const script = data.form.getValueIn('OperatorLoadStrategy.script');
return (
<span>
{GroovyScriptConvertorUtil.getScriptTitle(script)}
</span>
)
}
Original file line number Diff line number Diff line change
@@ -1,16 +1,28 @@
import React, {useCallback, useContext, useMemo, useState} from "react";
import {Flex, theme} from "antd";
import {CloseCircleOutlined} from "@ant-design/icons";
import {NodeRenderContext} from "@/components/design-editor/context";
import {FlowNodeRegistry} from "@/components/design-editor/typings";
import {useClientContext} from "@flowgram.ai/fixed-layout-editor";
import {NodeFormContext, NodeRenderContext} from "@/components/design-editor/context";
import {FlowNodeJSON, FlowNodeRegistry} from "@/components/design-editor/typings";
import {FormRenderProps, useClientContext} from "@flowgram.ai/fixed-layout-editor";
import {useIsSidebar} from "@/components/design-editor/hooks";

interface NodePanelProps {
children?: React.ReactNode;
data: FormRenderProps<FlowNodeJSON['data']>;
}

export const NodePanel: React.FC<NodePanelProps> = (props) => {
return (
<NodeFormContext.Provider value={props.data}>
<$NodePanel
{...props}
/>
</NodeFormContext.Provider>
)
}


export const $NodePanel: React.FC<NodePanelProps> = (props) => {
const [isHovered, setIsHovered] = useState(false);
const {node, deleteNode} = useContext(NodeRenderContext);
const clientContext = useClientContext();
Expand Down Expand Up @@ -48,7 +60,7 @@ export const NodePanel: React.FC<NodePanelProps> = (props) => {
deleteNode();
}, [deleteNode]);

if(isSidebar || canDeleteNode){
if (isSidebar || canDeleteNode) {
return (
<div
style={{
Expand Down
Loading