@nocobase/plugin-workflow-dynamic-calculation 1.0.0-alpha.2 → 1.0.0-alpha.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,3 +1,11 @@
1
+ /**
2
+ * This file is part of the NocoBase (R) project.
3
+ * Copyright (c) 2020-2024 NocoBase Co., Ltd.
4
+ * Authors: NocoBase Team.
5
+ *
6
+ * This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
7
+ * For more information, please refer to: https://www.nocobase.com/agreement.
8
+ */
1
9
  import React from 'react';
2
10
  import { SchemaInitializerItemType } from '@nocobase/client';
3
11
  import { Instruction, WorkflowVariableInput } from '@nocobase/plugin-workflow/client';
@@ -1,3 +1,11 @@
1
+ /**
2
+ * This file is part of the NocoBase (R) project.
3
+ * Copyright (c) 2020-2024 NocoBase Co., Ltd.
4
+ * Authors: NocoBase Team.
5
+ *
6
+ * This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
7
+ * For more information, please refer to: https://www.nocobase.com/agreement.
8
+ */
1
9
  import React from 'react';
2
10
  export declare const DynamicExpression: React.ForwardRefExoticComponent<Omit<Partial<Omit<{
3
11
  children?: React.ReactNode;
@@ -1,3 +1,11 @@
1
+ /**
2
+ * This file is part of the NocoBase (R) project.
3
+ * Copyright (c) 2020-2024 NocoBase Co., Ltd.
4
+ * Authors: NocoBase Team.
5
+ *
6
+ * This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
7
+ * For more information, please refer to: https://www.nocobase.com/agreement.
8
+ */
1
9
  import { CollectionFieldInterface } from '@nocobase/client';
2
10
  export declare class ExpressionFieldInterface extends CollectionFieldInterface {
3
11
  name: string;
@@ -1,3 +1,11 @@
1
+ /**
2
+ * This file is part of the NocoBase (R) project.
3
+ * Copyright (c) 2020-2024 NocoBase Co., Ltd.
4
+ * Authors: NocoBase Team.
5
+ *
6
+ * This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
7
+ * For more information, please refer to: https://www.nocobase.com/agreement.
8
+ */
1
9
  import { Plugin } from '@nocobase/client';
2
10
  export default class extends Plugin {
3
11
  afterAdd(): Promise<void>;
@@ -1 +1,10 @@
1
+ /**
2
+ * This file is part of the NocoBase (R) project.
3
+ * Copyright (c) 2020-2024 NocoBase Co., Ltd.
4
+ * Authors: NocoBase Team.
5
+ *
6
+ * This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
7
+ * For more information, please refer to: https://www.nocobase.com/agreement.
8
+ */
9
+
1
10
  (function(n,e){typeof exports=="object"&&typeof module!="undefined"?e(exports,require("@nocobase/client"),require("react/jsx-runtime"),require("@nocobase/plugin-workflow/client"),require("react-i18next"),require("@formily/core"),require("@formily/react"),require("antd"),require("react")):typeof define=="function"&&define.amd?define(["exports","@nocobase/client","react/jsx-runtime","@nocobase/plugin-workflow/client","react-i18next","@formily/core","@formily/react","antd","react"],e):(n=typeof globalThis!="undefined"?globalThis:n||self,e(n["@nocobase/plugin-workflow-dynamic-calculation"]={},n["@nocobase/client"],n.jsxRuntime,n["@nocobase/plugin-workflow"],n["react-i18next"],n["@formily/core"],n["@formily/react"],n.antd,n.react))})(this,function(n,e,o,r,m,y,p,x,u){"use strict";var W=Object.defineProperty,N=Object.defineProperties;var z=Object.getOwnPropertyDescriptors;var V=Object.getOwnPropertySymbols;var L=Object.prototype.hasOwnProperty,U=Object.prototype.propertyIsEnumerable;var F=(n,e,o)=>e in n?W(n,e,{enumerable:!0,configurable:!0,writable:!0,value:o}):n[e]=o,b=(n,e)=>{for(var o in e||(e={}))L.call(e,o)&&F(n,o,e[o]);if(V)for(var o of V(e))U.call(e,o)&&F(n,o,e[o]);return n},I=(n,e)=>N(n,z(e));var i=(n,e,o)=>(F(n,typeof e!="symbol"?e+"":e,o),o);var h=(n,e,o)=>new Promise((r,m)=>{var y=u=>{try{x(o.next(u))}catch(a){m(a)}},p=u=>{try{x(o.throw(u))}catch(a){m(a)}},x=u=>u.done?r(u.value):Promise.resolve(u.value).then(y,p);x((o=o.apply(n,e)).next())});const a="workflow-dynamic-calculation";function k(s,l={}){const{t}=T(l);return t(s)}function T(s){return m.useTranslation(a,s)}function E(s){var t;return["belongsTo","hasOne"].includes(s.type)?((t=this.getCollection(s.collectionName))==null?void 0:t.template)==="expression"?!0:this.getCollectionFields(s.target).some(c=>c.interface==="expression"):!1}function v({value:s,onChange:l}){const{getCollectionFields:t,getCollection:c}=e.useCollectionManager_deprecated(),f=r.useWorkflowVariableOptions({types:[E.bind({getCollectionFields:t,getCollection:c})]});return o.jsx(e.Variable.Input,{value:s,onChange:l,scope:f})}class P extends r.Instruction{constructor(){super(...arguments);i(this,"title",`{{t("Dynamic Calculation", { ns: "${a}" })}}`);i(this,"type","dynamic-calculation");i(this,"group","extended");i(this,"description",`{{t("Calculate an expression based on a calculation engine and obtain a value as the result. Variables in the upstream nodes can be used in the expression. The expression is dynamic one from an expression collections.", { ns: "${a}" })}}`);i(this,"fieldset",{expression:{type:"string",title:`{{t("Calculation expression", { ns: "${a}" })}}`,"x-decorator":"FormItem","x-component":"DynamicExpression",required:!0},scope:{type:"string",title:`{{t("Variable datasource", { ns: "${a}" })}}`,"x-decorator":"FormItem","x-component":"WorkflowVariableInput","x-component-props":{changeOnSelect:!0,variableOptions:{types:[{type:"reference",options:{collection:"*",entity:!0}}]}},"x-reactions":{dependencies:["expression"],fulfill:{state:{visible:"{{$deps[0]}}"}}}}});i(this,"components",{DynamicExpression:v,WorkflowVariableInput:r.WorkflowVariableInput,ValueBlock:r.ValueBlock})}useVariables({key:t,title:c},{types:f,fieldNames:d=r.defaultFieldNames}){return f&&!f.some(g=>g in r.BaseTypeSets||Object.values(r.BaseTypeSets).some(C=>C.has(g)))?null:{[d.value]:t,[d.label]:c}}useInitializers(t){var c;return{name:`#${t.id}`,type:"item",title:(c=t.title)!=null?c:`#${t.id}`,Component:r.ValueBlock.Initializer,node:t,resultTitle:k("Calculation result")}}}const q=p.observer(s=>{const{onChange:l}=s,t=p.useField(),c=p.useForm(),d=[...t.path.segments.slice(0,-1),"sourceCollection"].join("."),[g,C]=u.useState(c.getValuesIn(d)),A=e.useCompile(),{getCollectionFields:B}=e.useCollectionManager_deprecated();p.useFormEffects(()=>{y.onFormInitialValuesChange(w=>{C(w.getValuesIn(d))}),y.onFieldInputValueChange(d,w=>{C(w.value),l(null)})});const _=r.getCollectionFieldOptions({collection:g,compile:A,getCollectionFields:B});return o.jsx(e.Variable.TextArea,I(b({},s),{scope:_}))},{displayName:"InternalExpression"});function M(s){const{t:l}=m.useTranslation(),t=e.useRecord(),c=e.useCompile(),{getCollectionFields:f}=e.useCollectionManager_deprecated(),d=u.useMemo(()=>r.getCollectionFieldOptions({collection:t.sourceCollection,compile:c,getCollectionFields:f}),[t.sourceCollection,t.sourceCollection]);return s.value?o.jsx(e.Variable.TextArea,I(b({},s),{scope:d})):o.jsx(x.Tag,{children:l("Unconfigured",{ns:a})})}const S=p.connect(q,p.mapReadPretty(M)),{defaultProps:j}=e.interfacesProperties;class D extends e.CollectionFieldInterface{constructor(){super(...arguments);i(this,"name","expression");i(this,"type","string");i(this,"group","advanced");i(this,"order",1);i(this,"title",`{{t("Expression", { ns: "${a}" })}}`);i(this,"description",`{{t("Used to store expressions for use in workflows so that different expressions can be called for different data.", { ns: "${a}" })}}`);i(this,"sortable",!0);i(this,"default",{type:"text",uiSchema:{"x-component":"DynamicExpression"}});i(this,"properties",b({},j))}}class O extends e.Plugin{afterAdd(){return h(this,null,function*(){})}beforeLoad(){return h(this,null,function*(){})}load(){return h(this,null,function*(){this.app.dataSourceManager.addFieldInterfaces([D]),this.app.addComponents({DynamicExpression:S});const l=this.app.pm.get("workflow"),t=new P;l.instructions.register(t.type,t)})}}n.default=O,Object.defineProperties(n,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});
@@ -1,13 +1,22 @@
1
+ /**
2
+ * This file is part of the NocoBase (R) project.
3
+ * Copyright (c) 2020-2024 NocoBase Co., Ltd.
4
+ * Authors: NocoBase Team.
5
+ *
6
+ * This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
7
+ * For more information, please refer to: https://www.nocobase.com/agreement.
8
+ */
9
+
1
10
  module.exports = {
2
11
  "react": "18.2.0",
3
- "@nocobase/client": "1.0.0-alpha.2",
4
- "@nocobase/plugin-workflow": "1.0.0-alpha.2",
12
+ "@nocobase/client": "1.0.0-alpha.3",
13
+ "@nocobase/plugin-workflow": "1.0.0-alpha.3",
5
14
  "@formily/core": "2.3.0",
6
15
  "@formily/react": "2.3.0",
7
16
  "antd": "5.12.8",
8
17
  "react-i18next": "11.18.6",
9
- "@nocobase/utils": "1.0.0-alpha.2",
10
- "@nocobase/evaluators": "1.0.0-alpha.2",
11
- "@nocobase/server": "1.0.0-alpha.2",
12
- "@nocobase/database": "1.0.0-alpha.2"
18
+ "@nocobase/utils": "1.0.0-alpha.3",
19
+ "@nocobase/evaluators": "1.0.0-alpha.3",
20
+ "@nocobase/server": "1.0.0-alpha.3",
21
+ "@nocobase/database": "1.0.0-alpha.3"
13
22
  };
package/dist/index.d.ts CHANGED
@@ -1,2 +1,10 @@
1
+ /**
2
+ * This file is part of the NocoBase (R) project.
3
+ * Copyright (c) 2020-2024 NocoBase Co., Ltd.
4
+ * Authors: NocoBase Team.
5
+ *
6
+ * This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
7
+ * For more information, please refer to: https://www.nocobase.com/agreement.
8
+ */
1
9
  export * from './server';
2
10
  export { default } from './server';
package/dist/index.js CHANGED
@@ -1,3 +1,12 @@
1
+ /**
2
+ * This file is part of the NocoBase (R) project.
3
+ * Copyright (c) 2020-2024 NocoBase Co., Ltd.
4
+ * Authors: NocoBase Team.
5
+ *
6
+ * This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
7
+ * For more information, please refer to: https://www.nocobase.com/agreement.
8
+ */
9
+
1
10
  var __create = Object.create;
2
11
  var __defProp = Object.defineProperty;
3
12
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
@@ -1,3 +1,11 @@
1
+ /**
2
+ * This file is part of the NocoBase (R) project.
3
+ * Copyright (c) 2020-2024 NocoBase Co., Ltd.
4
+ * Authors: NocoBase Team.
5
+ *
6
+ * This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
7
+ * For more information, please refer to: https://www.nocobase.com/agreement.
8
+ */
1
9
  export declare const NAMESPACE = "workflow-dynamic-calculation";
2
10
  export declare function useLang(key: string, options?: {}): string;
3
11
  export declare function usePluginTranslation(options: any): import("react-i18next").UseTranslationResponse<"workflow-dynamic-calculation", undefined>;
@@ -1,3 +1,12 @@
1
+ /**
2
+ * This file is part of the NocoBase (R) project.
3
+ * Copyright (c) 2020-2024 NocoBase Co., Ltd.
4
+ * Authors: NocoBase Team.
5
+ *
6
+ * This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
7
+ * For more information, please refer to: https://www.nocobase.com/agreement.
8
+ */
9
+
1
10
  var __defProp = Object.defineProperty;
2
11
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
12
  var __getOwnPropNames = Object.getOwnPropertyNames;
@@ -1,3 +1,11 @@
1
+ /**
2
+ * This file is part of the NocoBase (R) project.
3
+ * Copyright (c) 2020-2024 NocoBase Co., Ltd.
4
+ * Authors: NocoBase Team.
5
+ *
6
+ * This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
7
+ * For more information, please refer to: https://www.nocobase.com/agreement.
8
+ */
1
9
  import { FlowNodeModel, Instruction, Processor } from '@nocobase/plugin-workflow';
2
10
  export declare class DynamicCalculation extends Instruction {
3
11
  run(node: FlowNodeModel, prevJob: any, processor: Processor): Promise<{
@@ -1,3 +1,12 @@
1
+ /**
2
+ * This file is part of the NocoBase (R) project.
3
+ * Copyright (c) 2020-2024 NocoBase Co., Ltd.
4
+ * Authors: NocoBase Team.
5
+ *
6
+ * This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
7
+ * For more information, please refer to: https://www.nocobase.com/agreement.
8
+ */
9
+
1
10
  var __create = Object.create;
2
11
  var __defProp = Object.defineProperty;
3
12
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
@@ -1,3 +1,11 @@
1
+ /**
2
+ * This file is part of the NocoBase (R) project.
3
+ * Copyright (c) 2020-2024 NocoBase Co., Ltd.
4
+ * Authors: NocoBase Team.
5
+ *
6
+ * This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
7
+ * For more information, please refer to: https://www.nocobase.com/agreement.
8
+ */
1
9
  import { Plugin } from '@nocobase/server';
2
10
  export default class extends Plugin {
3
11
  load(): Promise<void>;
@@ -1,3 +1,12 @@
1
+ /**
2
+ * This file is part of the NocoBase (R) project.
3
+ * Copyright (c) 2020-2024 NocoBase Co., Ltd.
4
+ * Authors: NocoBase Team.
5
+ *
6
+ * This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
7
+ * For more information, please refer to: https://www.nocobase.com/agreement.
8
+ */
9
+
1
10
  var __create = Object.create;
2
11
  var __defProp = Object.defineProperty;
3
12
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
@@ -1,3 +1,11 @@
1
+ /**
2
+ * This file is part of the NocoBase (R) project.
3
+ * Copyright (c) 2020-2024 NocoBase Co., Ltd.
4
+ * Authors: NocoBase Team.
5
+ *
6
+ * This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
7
+ * For more information, please refer to: https://www.nocobase.com/agreement.
8
+ */
1
9
  import { BaseFieldOptions, DataTypes, Field } from '@nocobase/database';
2
10
  export interface ExpressionFieldOptions extends BaseFieldOptions {
3
11
  type: 'expression';
@@ -1,3 +1,12 @@
1
+ /**
2
+ * This file is part of the NocoBase (R) project.
3
+ * Copyright (c) 2020-2024 NocoBase Co., Ltd.
4
+ * Authors: NocoBase Team.
5
+ *
6
+ * This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
7
+ * For more information, please refer to: https://www.nocobase.com/agreement.
8
+ */
9
+
1
10
  var __defProp = Object.defineProperty;
2
11
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
12
  var __getOwnPropNames = Object.getOwnPropertyNames;
@@ -1 +1,9 @@
1
+ /**
2
+ * This file is part of the NocoBase (R) project.
3
+ * Copyright (c) 2020-2024 NocoBase Co., Ltd.
4
+ * Authors: NocoBase Team.
5
+ *
6
+ * This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
7
+ * For more information, please refer to: https://www.nocobase.com/agreement.
8
+ */
1
9
  export { default } from './Plugin';
@@ -1,3 +1,12 @@
1
+ /**
2
+ * This file is part of the NocoBase (R) project.
3
+ * Copyright (c) 2020-2024 NocoBase Co., Ltd.
4
+ * Authors: NocoBase Team.
5
+ *
6
+ * This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
7
+ * For more information, please refer to: https://www.nocobase.com/agreement.
8
+ */
9
+
1
10
  var __create = Object.create;
2
11
  var __defProp = Object.defineProperty;
3
12
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
package/package.json CHANGED
@@ -4,7 +4,7 @@
4
4
  "displayName.zh-CN": "工作流:动态表达式计算节点",
5
5
  "description": "Useful plugin for doing dynamic calculation based on expression collection records in workflow.",
6
6
  "description.zh-CN": "用于在工作流中进行基于数据行的动态表达式计算。",
7
- "version": "1.0.0-alpha.2",
7
+ "version": "1.0.0-alpha.3",
8
8
  "license": "AGPL-3.0",
9
9
  "main": "./dist/server/index.js",
10
10
  "homepage": "https://docs.nocobase.com/handbook/workflow-dynamic-calculation",
@@ -30,7 +30,7 @@
30
30
  "@nocobase/test": "1.x",
31
31
  "@nocobase/utils": "1.x"
32
32
  },
33
- "gitHead": "f89dbc9e67d58404a2e484a5e124f739f340dcf8",
33
+ "gitHead": "7ccb137c7616cba5d238f87368239640e1d9ace1",
34
34
  "keywords": [
35
35
  "Workflow",
36
36
  "Collections"
@@ -1,98 +0,0 @@
1
- import React from 'react';
2
-
3
- import { SchemaInitializerItemType, Variable, useCollectionManager_deprecated } from '@nocobase/client';
4
- import {
5
- BaseTypeSets,
6
- Instruction,
7
- ValueBlock,
8
- WorkflowVariableInput,
9
- defaultFieldNames,
10
- useWorkflowVariableOptions,
11
- } from '@nocobase/plugin-workflow/client';
12
- import { NAMESPACE, useLang } from '../locale';
13
-
14
- function useDynamicExpressionCollectionFieldMatcher(field): boolean {
15
- if (!['belongsTo', 'hasOne'].includes(field.type)) {
16
- return false;
17
- }
18
-
19
- if (this.getCollection(field.collectionName)?.template === 'expression') {
20
- return true;
21
- }
22
-
23
- const fields = this.getCollectionFields(field.target);
24
- return fields.some((f) => f.interface === 'expression');
25
- }
26
-
27
- function DynamicExpression({ value, onChange }) {
28
- const { getCollectionFields, getCollection } = useCollectionManager_deprecated();
29
- const scope = useWorkflowVariableOptions({
30
- types: [useDynamicExpressionCollectionFieldMatcher.bind({ getCollectionFields, getCollection })],
31
- });
32
-
33
- return <Variable.Input value={value} onChange={onChange} scope={scope} />;
34
- }
35
-
36
- export default class extends Instruction {
37
- title = `{{t("Dynamic Calculation", { ns: "${NAMESPACE}" })}}`;
38
- type = 'dynamic-calculation';
39
- group = 'extended';
40
- description = `{{t("Calculate an expression based on a calculation engine and obtain a value as the result. Variables in the upstream nodes can be used in the expression. The expression is dynamic one from an expression collections.", { ns: "${NAMESPACE}" })}}`;
41
- fieldset = {
42
- expression: {
43
- type: 'string',
44
- title: `{{t("Calculation expression", { ns: "${NAMESPACE}" })}}`,
45
- 'x-decorator': 'FormItem',
46
- 'x-component': 'DynamicExpression',
47
- required: true,
48
- },
49
- scope: {
50
- type: 'string',
51
- title: `{{t("Variable datasource", { ns: "${NAMESPACE}" })}}`,
52
- 'x-decorator': 'FormItem',
53
- 'x-component': 'WorkflowVariableInput',
54
- 'x-component-props': {
55
- changeOnSelect: true,
56
- variableOptions: {
57
- types: [{ type: 'reference', options: { collection: '*', entity: true } }],
58
- },
59
- },
60
- 'x-reactions': {
61
- dependencies: ['expression'],
62
- fulfill: {
63
- state: {
64
- visible: '{{$deps[0]}}',
65
- },
66
- },
67
- },
68
- },
69
- };
70
- components = {
71
- DynamicExpression,
72
- WorkflowVariableInput,
73
- ValueBlock,
74
- };
75
- useVariables({ key, title }, { types, fieldNames = defaultFieldNames }) {
76
- if (
77
- types &&
78
- !types.some((type) => type in BaseTypeSets || Object.values(BaseTypeSets).some((set) => set.has(type)))
79
- ) {
80
- return null;
81
- }
82
- return {
83
- [fieldNames.value]: key,
84
- [fieldNames.label]: title,
85
- };
86
- }
87
- useInitializers(node): SchemaInitializerItemType {
88
- return {
89
- name: `#${node.id}`,
90
- type: 'item',
91
- title: node.title ?? `#${node.id}`,
92
- Component: ValueBlock.Initializer,
93
- node,
94
- // eslint-disable-next-line react-hooks/rules-of-hooks
95
- resultTitle: useLang('Calculation result'),
96
- };
97
- }
98
- }
@@ -1,57 +0,0 @@
1
- import { onFieldInputValueChange, onFormInitialValuesChange } from '@formily/core';
2
- import { connect, mapReadPretty, observer, useField, useForm, useFormEffects } from '@formily/react';
3
- import { Tag } from 'antd';
4
- import React, { useMemo, useState } from 'react';
5
- import { useTranslation } from 'react-i18next';
6
-
7
- import { useCollectionManager_deprecated, useCompile, useRecord, Variable } from '@nocobase/client';
8
- import { getCollectionFieldOptions } from '@nocobase/plugin-workflow/client';
9
-
10
- import { NAMESPACE } from '../locale';
11
-
12
- const InternalExpression = observer(
13
- (props: any) => {
14
- const { onChange } = props;
15
- const field = useField<any>();
16
- // TODO(refactor): better to provide another context like useFieldset()
17
- const form = useForm();
18
- const basePath = field.path.segments.slice(0, -1);
19
- const collectionPath = [...basePath, 'sourceCollection'].join('.');
20
- const [collection, setCollection] = useState(form.getValuesIn(collectionPath));
21
- const compile = useCompile();
22
- const { getCollectionFields } = useCollectionManager_deprecated();
23
-
24
- useFormEffects(() => {
25
- onFormInitialValuesChange((form) => {
26
- setCollection(form.getValuesIn(collectionPath));
27
- });
28
- onFieldInputValueChange(collectionPath, (f) => {
29
- setCollection(f.value);
30
- onChange(null);
31
- });
32
- });
33
-
34
- const options = getCollectionFieldOptions({ collection, compile, getCollectionFields });
35
-
36
- return <Variable.TextArea {...props} scope={options} />;
37
- },
38
- { displayName: 'InternalExpression' },
39
- );
40
-
41
- function Result(props) {
42
- const { t } = useTranslation();
43
- const values = useRecord();
44
- const compile = useCompile();
45
- const { getCollectionFields } = useCollectionManager_deprecated();
46
- const options = useMemo(
47
- () => getCollectionFieldOptions({ collection: values.sourceCollection, compile, getCollectionFields }),
48
- [values.sourceCollection, values.sourceCollection],
49
- );
50
- return props.value ? (
51
- <Variable.TextArea {...props} scope={options} />
52
- ) : (
53
- <Tag>{t('Unconfigured', { ns: NAMESPACE })}</Tag>
54
- );
55
- }
56
-
57
- export const DynamicExpression = connect(InternalExpression, mapReadPretty(Result));
@@ -1,24 +0,0 @@
1
- import { CollectionFieldInterface, interfacesProperties } from '@nocobase/client';
2
-
3
- import { NAMESPACE } from '../locale';
4
-
5
- const { defaultProps } = interfacesProperties;
6
-
7
- export class ExpressionFieldInterface extends CollectionFieldInterface {
8
- name = 'expression';
9
- type = 'string';
10
- group = 'advanced';
11
- order = 1;
12
- title = `{{t("Expression", { ns: "${NAMESPACE}" })}}`;
13
- description = `{{t("Used to store expressions for use in workflows so that different expressions can be called for different data.", { ns: "${NAMESPACE}" })}}`;
14
- sortable = true;
15
- default = {
16
- type: 'text',
17
- uiSchema: {
18
- 'x-component': 'DynamicExpression',
19
- },
20
- };
21
- properties = {
22
- ...defaultProps,
23
- };
24
- }
@@ -1,25 +0,0 @@
1
- import { Plugin } from '@nocobase/client';
2
- import WorkflowPlugin from '@nocobase/plugin-workflow/client';
3
-
4
- import DynamicCalculation from './DynamicCalculation';
5
- import { DynamicExpression } from './DynamicExpression';
6
- import { ExpressionFieldInterface } from './expression';
7
-
8
- export default class extends Plugin {
9
- async afterAdd() {
10
- // await this.app.pm.add()
11
- }
12
-
13
- async beforeLoad() {}
14
-
15
- // You can get and modify the app instance here
16
- async load() {
17
- this.app.dataSourceManager.addFieldInterfaces([ExpressionFieldInterface]);
18
- this.app.addComponents({
19
- DynamicExpression,
20
- });
21
- const workflow = this.app.pm.get('workflow') as WorkflowPlugin;
22
- const dynamicCalculation = new DynamicCalculation();
23
- workflow.instructions.register(dynamicCalculation.type, dynamicCalculation);
24
- }
25
- }
package/src/index.ts DELETED
@@ -1,2 +0,0 @@
1
- export * from './server';
2
- export { default } from './server';
@@ -1,11 +0,0 @@
1
- {
2
- "Dynamic Calculation": "Dynamic Calculation",
3
- "Calculate an expression based on a calculation engine and obtain a value as the result. Variables in the upstream nodes can be used in the expression. The expression is dynamic one from an expression collections.": "Calculate an expression based on a calculation engine and obtain a value as the result. Variables in the upstream nodes can be used in the expression. The expression is dynamic one from an expression collections.",
4
- "Select dynamic expression": "Select dynamic expression",
5
- "Select the dynamic expression queried from the upstream node. You need to query it from an expression collection.": "Select the dynamic expression queried from the upstream node. You need to query it from an expression collection.",
6
- "Variable datasource": "Variable datasource",
7
- "Dynamic expression": "Dynamic expression",
8
- "An expression for calculation in each rows": "An expression for calculation in each rows",
9
- "Unconfigured": "Unconfigured",
10
- "Calculation result": "Calculation result"
11
- }
@@ -1,12 +0,0 @@
1
- import { useTranslation } from 'react-i18next';
2
-
3
- export const NAMESPACE = 'workflow-dynamic-calculation';
4
-
5
- export function useLang(key: string, options = {}) {
6
- const { t } = usePluginTranslation(options);
7
- return t(key);
8
- }
9
-
10
- export function usePluginTranslation(options) {
11
- return useTranslation(NAMESPACE, options);
12
- }
@@ -1,13 +0,0 @@
1
- {
2
- "Dynamic Calculation": "동적 표현식 계산",
3
- "Calculate an expression based on a calculation engine and obtain a value as the result. Variables in the upstream nodes can be used in the expression. The expression is dynamic one from an expression collections.":
4
- "계산 엔진을 기반으로 한 식을 계산하고 결과값을 얻습니다. 상류 노드의 변수를 식에 사용할 수 있습니다. 식은 표현식 컬렉션에서 동적으로 가져온 것입니다.",
5
- "Select dynamic expression": "동적 표현식 선택",
6
- "Select the dynamic expression queried from the upstream node. You need to query it from an expression collection.":
7
- "상류 노드에서 조회한 동적 표현식을 선택하세요. 표현식 컬렉션에서 조회해야 합니다.",
8
- "Variable datasource": "변수 데이터 소스",
9
- "Dynamic expression": "동적 표현식",
10
- "An expression for calculation in each rows": "각 행의 계산을 위한 식",
11
- "Unconfigured": "구성되지 않음",
12
- "Calculation result": "계산 결과"
13
- }
@@ -1,12 +0,0 @@
1
- {
2
- "Expression": "表达式",
3
- "Dynamic Calculation": "动态表达式计算",
4
- "Calculate an expression based on a calculation engine and obtain a value as the result. Variables in the upstream nodes can be used in the expression. The expression is dynamic one from an expression collections.": "基于计算引擎计算表达式并获取值作为结果。可以在表达式中使用上游节点的变量。表达式是从表达式表中动态获取的。",
5
- "Select dynamic expression": "选择动态表达式",
6
- "Select the dynamic expression queried from the upstream node. You need to query it from an expression collection.": "从上游节点中选择查询出来的动态表达式。你需要从动态表达式类型的数据表中查询。",
7
- "Variable datasource": "变量数据源",
8
- "Dynamic expression": "动态表达式",
9
- "Used to store expressions for use in workflows so that different expressions can be called for different data.": "用于存储表达式,在工作流中使用,以便针对不同的数据调用不同的表达式。",
10
- "Unconfigured": "未配置",
11
- "Calculation result": "运算结果"
12
- }
@@ -1,29 +0,0 @@
1
- import { parse } from '@nocobase/utils';
2
- import { FlowNodeModel, Instruction, JOB_STATUS, Processor } from '@nocobase/plugin-workflow';
3
- import evaluators, { Evaluator } from '@nocobase/evaluators';
4
-
5
- export class DynamicCalculation extends Instruction {
6
- async run(node: FlowNodeModel, prevJob, processor: Processor) {
7
- let { engine = 'math.js', expression = '' } = node.config;
8
- let scope = processor.getScope(node.id);
9
- const parsed = parse(expression)(scope) ?? {};
10
- engine = parsed.engine;
11
- expression = parsed.expression;
12
- scope = parse(node.config.scope ?? '')(scope) ?? {};
13
-
14
- const evaluator = <Evaluator | undefined>evaluators.get(engine);
15
-
16
- try {
17
- const result = evaluator && expression ? evaluator(expression, scope) : null;
18
- return {
19
- result,
20
- status: JOB_STATUS.RESOLVED,
21
- };
22
- } catch (e) {
23
- return {
24
- result: e.toString(),
25
- status: JOB_STATUS.ERROR,
26
- };
27
- }
28
- }
29
- }
@@ -1,16 +0,0 @@
1
- import { Plugin } from '@nocobase/server';
2
- import WorkflowPlugin from '@nocobase/plugin-workflow';
3
-
4
- import { ExpressionField } from './expression-field';
5
- import { DynamicCalculation } from './DynamicCalculation';
6
-
7
- export default class extends Plugin {
8
- async load() {
9
- this.db.registerFieldTypes({
10
- expression: ExpressionField,
11
- });
12
-
13
- const workflowPlugin = this.app.getPlugin<WorkflowPlugin>(WorkflowPlugin);
14
- workflowPlugin.registerInstruction('dynamic-calculation', DynamicCalculation);
15
- }
16
- }
@@ -1,19 +0,0 @@
1
- import { extendCollection } from '@nocobase/database';
2
-
3
- export default extendCollection({
4
- name: 'categories',
5
- fields: [
6
- {
7
- type: 'string',
8
- name: 'engine',
9
- },
10
- {
11
- type: 'string',
12
- name: 'collection',
13
- },
14
- {
15
- type: 'text',
16
- name: 'expression',
17
- },
18
- ],
19
- });
@@ -1,115 +0,0 @@
1
- import path from 'path';
2
-
3
- import { MockDatabase } from '@nocobase/database';
4
- import { getApp, sleep } from '@nocobase/plugin-workflow-test';
5
- import { MockServer } from '@nocobase/test';
6
-
7
- import Plugin from '..';
8
-
9
- describe('workflow > instructions > calculation', () => {
10
- let app: MockServer;
11
- let db: MockDatabase;
12
- let PostRepo;
13
- let CategoryRepo;
14
- let WorkflowModel;
15
- let workflow;
16
-
17
- beforeEach(async () => {
18
- app = await getApp({
19
- plugins: [Plugin],
20
- collectionsPath: path.join(__dirname, 'collections'),
21
- });
22
-
23
- db = app.db;
24
- WorkflowModel = db.getCollection('workflows').model;
25
- PostRepo = db.getCollection('posts').repository;
26
- CategoryRepo = db.getCollection('categories').repository;
27
-
28
- workflow = await WorkflowModel.create({
29
- title: 'test workflow',
30
- enabled: true,
31
- type: 'collection',
32
- config: {
33
- mode: 1,
34
- collection: 'posts',
35
- },
36
- });
37
- });
38
-
39
- afterEach(() => app.destroy());
40
-
41
- describe('dynamic expression', () => {
42
- it('dynamic expression field in current table', async () => {
43
- const n1 = await workflow.createNode({
44
- type: 'dynamic-calculation',
45
- config: {
46
- expression: '{{$context.data.category}}',
47
- scope: '{{$context.data}}',
48
- },
49
- });
50
-
51
- const post = await PostRepo.create({
52
- values: {
53
- title: 't1',
54
- category: {
55
- engine: 'math.js',
56
- expression: '1 + {{read}}',
57
- },
58
- },
59
- });
60
-
61
- await sleep(500);
62
-
63
- const [execution] = await workflow.getExecutions();
64
- const [job] = await execution.getJobs();
65
- expect(job.result).toBe(1);
66
- });
67
-
68
- it('dynamic expression field in association table', async () => {
69
- const n1 = await workflow.createNode({
70
- type: 'query',
71
- config: {
72
- collection: 'categories',
73
- params: {
74
- filter: {
75
- $and: [{ id: '{{$context.data.categoryId}}' }],
76
- },
77
- },
78
- },
79
- });
80
-
81
- const n2 = await workflow.createNode({
82
- type: 'dynamic-calculation',
83
- config: {
84
- expression: `{{$jobsMapByNodeKey.${n1.key}}}`,
85
- scope: '{{$context.data}}',
86
- },
87
- upstreamId: n1.id,
88
- });
89
-
90
- await n1.setDownstream(n2);
91
-
92
- const category = await CategoryRepo.create({
93
- values: {
94
- title: 'c1',
95
- engine: 'math.js',
96
- expression: '1 + {{read}}',
97
- },
98
- });
99
-
100
- const post = await PostRepo.create({
101
- values: {
102
- title: 't1',
103
- categoryId: category.id,
104
- },
105
- });
106
-
107
- await sleep(500);
108
-
109
- const [execution] = await workflow.getExecutions();
110
- const jobs = await execution.getJobs({ order: [['id', 'ASC']] });
111
- expect(jobs.length).toBe(2);
112
- expect(jobs[1].result).toBe(1);
113
- });
114
- });
115
- });
@@ -1,11 +0,0 @@
1
- import { BaseFieldOptions, DataTypes, Field } from '@nocobase/database';
2
-
3
- export interface ExpressionFieldOptions extends BaseFieldOptions {
4
- type: 'expression';
5
- }
6
-
7
- export class ExpressionField extends Field {
8
- get dataType() {
9
- return DataTypes.TEXT;
10
- }
11
- }
@@ -1 +0,0 @@
1
- export { default } from './Plugin';