Skip to content

Commit 918d14d

Browse files
committed
update groovy script
1 parent 0abec0f commit 918d14d

12 files changed

Lines changed: 227 additions & 150 deletions

File tree

frontend/packages/flow-core/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@
1414
],
1515
"scripts": {
1616
"build": "rslib build",
17-
"dev": "rslib build --watch"
17+
"dev": "rslib build --watch",
18+
"test": "rstest"
1819
},
1920
"peerDependencies": {
2021
"react": ">=18",
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import {pluginReact} from '@rsbuild/plugin-react';
2+
import {defineConfig} from '@rstest/core';
3+
import {pluginSass} from "@rsbuild/plugin-sass";
4+
import * as path from "path";
5+
6+
export default defineConfig({
7+
testEnvironment: 'jsdom',
8+
setupFiles: ['./rstest.setup.ts'],
9+
plugins: [pluginReact(), pluginSass()],
10+
resolve: {
11+
alias: {
12+
"@/": path.resolve(__dirname, "src"),
13+
}
14+
}
15+
});
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
import { expect } from '@rstest/core';
2+
import * as jestDomMatchers from '@testing-library/jest-dom/matchers';
3+
4+
expect.extend(jestDomMatchers);

frontend/packages/flow-core/src/groovy.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -415,7 +415,7 @@ export class GroovyScriptConvertorUtil {
415415
*/
416416
public static updateScriptMeta(script: string, meta: string): string {
417417
const metaComment = `// ${SCRIPT_META} ${meta}`;
418-
if (GroovyScriptConvertorUtil.getScriptTitle(script)) {
418+
if (GroovyScriptConvertorUtil.getScriptMeta(script)) {
419419
return script.replace(new RegExp(`//\\s*${SCRIPT_META}\\s*.+`), metaComment);
420420
} else {
421421
return `${metaComment}\n${script}`;

frontend/packages/flow-pc/flow-pc-design/tests/script/utils/convertor-utils.test.ts renamed to frontend/packages/flow-core/tests/groovy.test.ts

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import {describe, expect, it} from '@rstest/core';
2-
import {GroovyScriptConvertorUtil} from "@/components/script/utils/convertor";
2+
import {GroovyScriptConvertorUtil} from "@/groovy";
33

44
describe('GroovyScriptUtil', () => {
55

@@ -54,7 +54,7 @@ def run(request){
5454
});
5555

5656

57-
describe('getScriptMeta', () => {
57+
describe('getScriptMeta1', () => {
5858
it('get groovy script meta', () => {
5959
const script = `
6060
// @SCRIPT_TITLE 这是一个实例的标题
@@ -67,8 +67,21 @@ def run(request){
6767
});
6868
});
6969

70+
describe('getScriptMeta2', () => {
71+
it('get groovy script meta', () => {
72+
const script = `
73+
// @CUSTOM_SCRIPT 自定义脚本,返回的数据为动作类型
74+
// @SCRIPT_META {"trigger":"PASS"}
75+
def run(request){
76+
return 'SAVE';
77+
}`
78+
const result = GroovyScriptConvertorUtil.getScriptMeta(script)
79+
expect(result).toEqual(`{"trigger":"PASS"}`);
80+
});
81+
});
7082

71-
describe('updateScriptMeta', () => {
83+
84+
describe('updateScriptMeta1', () => {
7285
it('update groovy script meta', () => {
7386
const script = `
7487
// @SCRIPT_TITLE 这是一个实例的标题
@@ -82,4 +95,19 @@ def run(request){
8295
expect(title).toEqual(`{name:"test"}`);
8396
});
8497
});
98+
99+
describe('updateScriptMeta2', () => {
100+
it('update groovy script meta', () => {
101+
const script = `
102+
// @CUSTOM_SCRIPT 自定义脚本,返回的数据为动作类型
103+
// @SCRIPT_META {"trigger":"PASS"}
104+
def run(request){
105+
return 'SAVE';
106+
}`
107+
const result = GroovyScriptConvertorUtil.updateScriptMeta(script,'{trigger:"SAVE"}');
108+
console.log(result);
109+
const title = GroovyScriptConvertorUtil.getScriptMeta(result)
110+
expect(title).toEqual(`{trigger:"SAVE"}`);
111+
});
112+
});
85113
});
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/// <reference types="@testing-library/jest-dom" />
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"extends": "../tsconfig.json",
3+
"include": [".", "../rstest.setup.ts"],
4+
"compilerOptions": {
5+
"baseUrl": ".",
6+
"paths": {
7+
"@/*": ["../src/*"]
8+
}
9+
}
10+
}

frontend/packages/flow-pc/flow-pc-design/src/components/design-editor/node-components/action/modal.tsx

Lines changed: 64 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -12,27 +12,85 @@ interface ActionModalProps {
1212
options: any[];
1313
}
1414

15-
export const ActionModal: React.FC<ActionModalProps> = (props) => {
16-
const custom = props.custom;
1715

16+
interface CustomScriptViewProps{
17+
options: any[];
18+
form: FormInstance<any>;
19+
}
20+
21+
const CustomScriptView:React.FC<CustomScriptViewProps> = (props)=>{
22+
23+
const trigger = props.form.getFieldValue("trigger") as string;
24+
25+
const [currentTrigger,setCurrentTrigger] = React.useState(trigger);
1826

1927
const handleChangeNodeType = (value: string) => {
2028
const script = props.form.getFieldValue('script') as string;
21-
const returnData = GroovyScriptConvertorUtil.getReturnScript(script).trim();
2229
let groovy;
23-
if (returnData) {
30+
if (script) {
31+
const returnData = GroovyScriptConvertorUtil.getReturnScript(script).trim();
2432
groovy = script.replace(returnData, `'${value}'`);
33+
groovy = GroovyScriptConvertorUtil.updateScriptMeta(groovy,`{"trigger":"${value}"}`);
2534
} else {
26-
groovy = `// 自定义脚本,返回的数据为动作类型
35+
groovy = `// @CUSTOM_SCRIPT 自定义脚本,返回的数据为动作类型
2736
// @SCRIPT_META {"trigger":"${value}"}
2837
def run(request){
2938
return '${value}';
3039
}
3140
`
3241
}
3342
props.form.setFieldValue("script", GroovyScriptConvertorUtil.formatScript(groovy));
43+
setCurrentTrigger(value);
3444
}
3545

46+
return (
47+
<Col span={24}>
48+
<Form.Item
49+
name={"script"}
50+
label={(
51+
<Space>
52+
自定义脚本
53+
<Space.Compact size={"small"}>
54+
<Space.Addon>触发动作:</Space.Addon>
55+
<Select
56+
style={{
57+
width: '100px'
58+
}}
59+
value={currentTrigger}
60+
placeholder={"请选择触发动作类型"}
61+
options={props.options}
62+
onChange={handleChangeNodeType}
63+
/>
64+
</Space.Compact>
65+
66+
67+
</Space>
68+
)}
69+
required={true}
70+
help={"请先设置触发动作类型"}
71+
72+
rules={[
73+
{
74+
required: true,
75+
message: '自定义脚本不能为空'
76+
}
77+
]}
78+
>
79+
<GroovyCodeEditor
80+
placeholder={"请输入自定义脚本"}
81+
options={{
82+
minHeight: 200
83+
}}
84+
/>
85+
</Form.Item>
86+
</Col>
87+
)
88+
}
89+
90+
export const ActionModal: React.FC<ActionModalProps> = (props) => {
91+
const custom = props.custom;
92+
93+
3694
return (
3795
<Modal
3896
width={"60%"}
@@ -91,51 +149,9 @@ export const ActionModal: React.FC<ActionModalProps> = (props) => {
91149
</Form.Item>
92150
</Col>
93151

94-
95152
{custom && (
96-
<>
97-
<Col span={24}>
98-
<Form.Item
99-
name={"script"}
100-
label={(
101-
<Space>
102-
自定义脚本
103-
<Space.Compact size={"small"}>
104-
<Space.Addon>触发动作:</Space.Addon>
105-
<Select
106-
style={{
107-
width: '100px'
108-
}}
109-
placeholder={"请选择触发动作类型"}
110-
options={props.options}
111-
onChange={handleChangeNodeType}
112-
/>
113-
</Space.Compact>
114-
115-
116-
</Space>
117-
)}
118-
required={true}
119-
help={"请先设置触发动作类型"}
120-
121-
rules={[
122-
{
123-
required: true,
124-
message: '自定义脚本不能为空'
125-
}
126-
]}
127-
>
128-
<GroovyCodeEditor
129-
placeholder={"请输入自定义脚本"}
130-
options={{
131-
minHeight: 200
132-
}}
133-
/>
134-
</Form.Item>
135-
</Col>
136-
</>
153+
<CustomScriptView options={props.options} form={props.form} />
137154
)}
138-
139155
</Row>
140156

141157
</Form>

frontend/packages/flow-pc/flow-pc-design/src/components/design-panel/layout/header.tsx

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
import React from "react";
2-
import {Button, Space, Tabs, message} from "antd";
2+
import {Button, message, Space, Tabs} from "antd";
33
import {LayoutHeaderHeight, TabPanelType} from "../types";
44
import {useDesignContext} from "../hooks/use-design-context";
5+
import {CloseOutlined, SaveOutlined } from "@ant-design/icons";
56

67
const Left = () => {
78
return (
@@ -17,18 +18,23 @@ const Right = () => {
1718
return (
1819
<Space style={{
1920
width: 150,
21+
marginRight:20
2022
}}>
2123
<Button
24+
icon={<SaveOutlined />}
2225
type="primary"
2326
onClick={() => {
2427
context.save().then(() => {
2528
message.success("流程已经保存.");
2629
});
2730
}}
2831
>保存</Button>
29-
<Button onClick={() => {
30-
context.close();
31-
}}>关闭</Button>
32+
<Button
33+
icon={<CloseOutlined />}
34+
onClick={() => {
35+
context.close();
36+
}}
37+
>关闭</Button>
3238
</Space>
3339
)
3440
}

0 commit comments

Comments
 (0)