@nocobase/plugin-workflow 0.11.1-alpha.3 → 0.11.1-alpha.5

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,4 +1,3 @@
1
1
  import React from 'react';
2
- export declare function useCollectionUIFields(collection: any): import("@nocobase/client").CollectionFieldOptions[];
3
2
  declare const CollectionFieldSet: React.MemoExoticComponent<import("@formily/react").ReactFC<Omit<any, "ref">>>;
4
3
  export default CollectionFieldSet;
@@ -4,7 +4,6 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.default = void 0;
7
- exports.useCollectionUIFields = useCollectionUIFields;
8
7
  function _icons() {
9
8
  const data = require("@ant-design/icons");
10
9
  _icons = function _icons() {
@@ -79,11 +78,6 @@ function AssociationInput(props) {
79
78
  onChange: onChange
80
79
  }));
81
80
  }
82
- function useCollectionUIFields(collection) {
83
- const _useCollectionManager2 = (0, _client().useCollectionManager)(),
84
- getCollectionFields = _useCollectionManager2.getCollectionFields;
85
- return getCollectionFields(collection).filter(field => !field.hidden && (field.uiSchema ? !field.uiSchema['x-read-pretty'] : false));
86
- }
87
81
  // NOTE: observer for watching useProps
88
82
  const CollectionFieldSet = (0, _react().observer)(({
89
83
  value,
@@ -97,12 +91,13 @@ const CollectionFieldSet = (0, _react().observer)(({
97
91
  t = _useTranslation.t;
98
92
  const compile = (0, _client().useCompile)();
99
93
  const form = (0, _react().useForm)();
100
- const _useCollectionManager3 = (0, _client().useCollectionManager)(),
101
- getCollection = _useCollectionManager3.getCollection;
94
+ const _useCollectionManager2 = (0, _client().useCollectionManager)(),
95
+ getCollection = _useCollectionManager2.getCollection,
96
+ getCollectionFields = _useCollectionManager2.getCollectionFields;
102
97
  const scope = (0, _variable.useWorkflowVariableOptions)();
103
98
  const config = form.values;
104
99
  const collectionName = config === null || config === void 0 ? void 0 : config.collection;
105
- const collectionFields = useCollectionUIFields(collectionName);
100
+ const collectionFields = getCollectionFields(collectionName);
106
101
  const fields = filter ? collectionFields.filter(filter.bind(config)) : collectionFields;
107
102
  const unassignedFields = (0, _react2().useMemo)(() => fields.filter(field => !value || !(field.name in value)), [fields, value]);
108
103
  const mergedDisabled = disabled || form.disabled;
@@ -5,14 +5,14 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.default = void 0;
7
7
  function _react() {
8
- const data = _interopRequireDefault(require("react"));
8
+ const data = require("@formily/react");
9
9
  _react = function _react() {
10
10
  return data;
11
11
  };
12
12
  return data;
13
13
  }
14
14
  function _react2() {
15
- const data = require("@formily/react");
15
+ const data = _interopRequireDefault(require("react"));
16
16
  _react2 = function _react2() {
17
17
  return data;
18
18
  };
@@ -25,15 +25,13 @@ function _client() {
25
25
  };
26
26
  return data;
27
27
  }
28
+ var _CollectionFieldset = _interopRequireDefault(require("../components/CollectionFieldset"));
28
29
  var _FilterDynamicComponent = require("../components/FilterDynamicComponent");
29
- var _CollectionFieldset = _interopRequireWildcard(require("../components/CollectionFieldset"));
30
- var _utils = require("../utils");
30
+ var _RadioWithTooltip = require("../components/RadioWithTooltip");
31
31
  var _locale = require("../locale");
32
32
  var _collection = require("../schemas/collection");
33
- var _RadioWithTooltip = require("../components/RadioWithTooltip");
33
+ var _utils = require("../utils");
34
34
  const _excluded = ["onChange"];
35
- function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
36
- function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
37
35
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
38
36
  function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
39
37
  function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
@@ -45,10 +43,12 @@ function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) r
45
43
  function IndividualHooksRadioWithTooltip(_ref) {
46
44
  let onChange = _ref.onChange,
47
45
  props = _objectWithoutProperties(_ref, _excluded);
48
- const form = (0, _react2().useForm)();
46
+ const _useCollectionManager = (0, _client().useCollectionManager)(),
47
+ getCollectionFields = _useCollectionManager.getCollectionFields;
48
+ const form = (0, _react().useForm)();
49
49
  const collection = form.values.collection;
50
- const fields = (0, _CollectionFieldset.useCollectionUIFields)(collection);
51
- const field = (0, _react2().useField)();
50
+ const fields = getCollectionFields(collection);
51
+ const field = (0, _react().useField)();
52
52
  function onValueChange({
53
53
  target
54
54
  }) {
@@ -65,7 +65,7 @@ function IndividualHooksRadioWithTooltip(_ref) {
65
65
  form.setValuesIn('params.values', filteredValues);
66
66
  onChange(target.value);
67
67
  }
68
- return _react().default.createElement(_RadioWithTooltip.RadioWithTooltip, _objectSpread(_objectSpread({}, props), {}, {
68
+ return _react2().default.createElement(_RadioWithTooltip.RadioWithTooltip, _objectSpread(_objectSpread({}, props), {}, {
69
69
  onChange: onValueChange
70
70
  }));
71
71
  }
@@ -25,10 +25,10 @@ const calculators = new (_utils().Registry)();
25
25
  // built-in functions
26
26
  exports.calculators = calculators;
27
27
  function equal(a, b) {
28
- return a === b;
28
+ return a == b;
29
29
  }
30
30
  function notEqual(a, b) {
31
- return a !== b;
31
+ return a != b;
32
32
  }
33
33
  function gt(a, b) {
34
34
  return a > b;
@@ -48,8 +48,8 @@ calculators.register('gt', gt);
48
48
  calculators.register('gte', gte);
49
49
  calculators.register('lt', lt);
50
50
  calculators.register('lte', lte);
51
- calculators.register('===', equal);
52
- calculators.register('!==', notEqual);
51
+ calculators.register('==', equal);
52
+ calculators.register('!=', notEqual);
53
53
  calculators.register('>', gt);
54
54
  calculators.register('>=', gte);
55
55
  calculators.register('<', lt);
package/package.json CHANGED
@@ -4,7 +4,7 @@
4
4
  "displayName.zh-CN": "工作流",
5
5
  "description": "A powerful workflow plugin designed to support business process management and automation.",
6
6
  "description.zh-CN": "工作流插件,为业务流程管理和自动化提供支持。",
7
- "version": "0.11.1-alpha.3",
7
+ "version": "0.11.1-alpha.5",
8
8
  "license": "AGPL-3.0",
9
9
  "main": "./lib/server/index.js",
10
10
  "files": [
@@ -27,9 +27,9 @@
27
27
  },
28
28
  "peerDependencies": {
29
29
  "@ant-design/icons": "^5.1.4",
30
- "@formily/antd-v5": "1.1.0-beta.4",
31
- "@formily/core": "2.2.26",
32
- "@formily/react": "2.2.26",
30
+ "@formily/antd-v5": "^1.1.0",
31
+ "@formily/core": "^2.2.27",
32
+ "@formily/react": "^2.2.27",
33
33
  "@nocobase/actions": "0.11.0-alpha.1",
34
34
  "@nocobase/client": "0.11.0-alpha.1",
35
35
  "@nocobase/database": "0.11.0-alpha.1",
@@ -48,8 +48,8 @@
48
48
  "winston": "^3.8.2"
49
49
  },
50
50
  "devDependencies": {
51
- "@nocobase/test": "0.11.1-alpha.3",
51
+ "@nocobase/test": "0.11.1-alpha.5",
52
52
  "@types/ejs": "^3.1.1"
53
53
  },
54
- "gitHead": "5ed3bd7d5b16bd38d268961b34875d5cd45799ef"
54
+ "gitHead": "1dcfd15a7d95a40b0a2f60e1de19ec574066fb20"
55
55
  }
@@ -32,14 +32,6 @@ function AssociationInput(props) {
32
32
  return <Input {...props} value={value} onChange={onChange} />;
33
33
  }
34
34
 
35
- export function useCollectionUIFields(collection) {
36
- const { getCollectionFields } = useCollectionManager();
37
-
38
- return getCollectionFields(collection).filter(
39
- (field) => !field.hidden && (field.uiSchema ? !field.uiSchema['x-read-pretty'] : false),
40
- );
41
- }
42
-
43
35
  // NOTE: observer for watching useProps
44
36
  const CollectionFieldSet = observer(
45
37
  ({ value, disabled, onChange, filter }: any) => {
@@ -47,11 +39,11 @@ const CollectionFieldSet = observer(
47
39
  const { t } = useTranslation();
48
40
  const compile = useCompile();
49
41
  const form = useForm();
50
- const { getCollection } = useCollectionManager();
42
+ const { getCollection, getCollectionFields } = useCollectionManager();
51
43
  const scope = useWorkflowVariableOptions();
52
44
  const { values: config } = form;
53
45
  const collectionName = config?.collection;
54
- const collectionFields = useCollectionUIFields(collectionName);
46
+ const collectionFields = getCollectionFields(collectionName);
55
47
  const fields = filter ? collectionFields.filter(filter.bind(config)) : collectionFields;
56
48
 
57
49
  const unassignedFields = useMemo(() => fields.filter((field) => !value || !(field.name in value)), [fields, value]);
@@ -1,20 +1,21 @@
1
+ import { useField, useForm } from '@formily/react';
1
2
  import React from 'react';
2
- import { useForm, useField } from '@formily/react';
3
3
 
4
- import { useCollectionDataSource } from '@nocobase/client';
4
+ import { useCollectionDataSource, useCollectionManager } from '@nocobase/client';
5
5
 
6
+ import CollectionFieldset from '../components/CollectionFieldset';
6
7
  import { FilterDynamicComponent } from '../components/FilterDynamicComponent';
7
- import CollectionFieldset, { useCollectionUIFields } from '../components/CollectionFieldset';
8
8
 
9
- import { isValidFilter } from '../utils';
9
+ import { RadioWithTooltip } from '../components/RadioWithTooltip';
10
10
  import { NAMESPACE, lang } from '../locale';
11
11
  import { collection, filter, values } from '../schemas/collection';
12
- import { RadioWithTooltip } from '../components/RadioWithTooltip';
12
+ import { isValidFilter } from '../utils';
13
13
 
14
14
  function IndividualHooksRadioWithTooltip({ onChange, ...props }) {
15
+ const { getCollectionFields } = useCollectionManager();
15
16
  const form = useForm();
16
17
  const { collection } = form.values;
17
- const fields = useCollectionUIFields(collection);
18
+ const fields = getCollectionFields(collection);
18
19
  const field = useField<any>();
19
20
 
20
21
  function onValueChange({ target }) {
@@ -1,7 +1,7 @@
1
- import { Application } from '@nocobase/server';
2
1
  import Database from '@nocobase/database';
2
+ import { Application } from '@nocobase/server';
3
3
  import { getApp, sleep } from '..';
4
- import { EXECUTION_STATUS, BRANCH_INDEX } from '../../constants';
4
+ import { BRANCH_INDEX, EXECUTION_STATUS } from '../../constants';
5
5
 
6
6
  describe('workflow > instructions > condition', () => {
7
7
  let app: Application;
@@ -243,51 +243,150 @@ describe('workflow > instructions > condition', () => {
243
243
  });
244
244
 
245
245
  describe('engines', () => {
246
- it('default as basic', async () => {
247
- const n1 = await workflow.createNode({
248
- title: 'condition',
249
- type: 'condition',
250
- config: {
251
- calculation: {
252
- calculator: 'equal',
253
- operands: [1, '{{$context.data.read}}'],
246
+ describe('basic', () => {
247
+ it('default as basic', async () => {
248
+ const n1 = await workflow.createNode({
249
+ title: 'condition',
250
+ type: 'condition',
251
+ config: {
252
+ calculation: {
253
+ calculator: 'equal',
254
+ operands: [1, '{{$context.data.read}}'],
255
+ },
254
256
  },
255
- },
257
+ });
258
+
259
+ const post = await PostRepo.create({ values: { read: 1 } });
260
+
261
+ await sleep(500);
262
+
263
+ const [execution] = await workflow.getExecutions();
264
+ expect(execution.status).toEqual(EXECUTION_STATUS.RESOLVED);
265
+
266
+ const [job] = await execution.getJobs();
267
+ expect(job.result).toEqual(true);
256
268
  });
257
269
 
258
- const post = await PostRepo.create({ values: { read: 1 } });
270
+ it('equal: 0 != null', async () => {
271
+ const n1 = await workflow.createNode({
272
+ title: 'condition',
273
+ type: 'condition',
274
+ config: {
275
+ engine: 'basic',
276
+ calculation: {
277
+ calculator: 'equal',
278
+ operands: [0, '{{$context.data.title}}'],
279
+ },
280
+ rejectOnFalse: false,
281
+ },
282
+ });
283
+
284
+ const post = await PostRepo.create({ values: {} });
259
285
 
260
- await sleep(500);
286
+ await sleep(500);
261
287
 
262
- const [execution] = await workflow.getExecutions();
263
- expect(execution.status).toEqual(EXECUTION_STATUS.RESOLVED);
288
+ const [execution] = await workflow.getExecutions();
289
+ expect(execution.status).toEqual(EXECUTION_STATUS.RESOLVED);
264
290
 
265
- const [job] = await execution.getJobs();
266
- expect(job.result).toEqual(true);
267
- });
291
+ const [job] = await execution.getJobs();
292
+ expect(job.result).toEqual(false);
293
+ });
268
294
 
269
- it('basic engine', async () => {
270
- const n1 = await workflow.createNode({
271
- title: 'condition',
272
- type: 'condition',
273
- config: {
274
- engine: 'basic',
275
- calculation: {
276
- calculator: 'equal',
277
- operands: [1, '{{$context.data.read}}'],
295
+ it('equal: 0 == false', async () => {
296
+ const n1 = await workflow.createNode({
297
+ title: 'condition',
298
+ type: 'condition',
299
+ config: {
300
+ engine: 'basic',
301
+ calculation: {
302
+ calculator: 'equal',
303
+ operands: [false, '{{$context.data.read}}'],
304
+ },
278
305
  },
279
- },
306
+ });
307
+
308
+ const post = await PostRepo.create({ values: {} });
309
+
310
+ await sleep(500);
311
+
312
+ const [execution] = await workflow.getExecutions();
313
+ expect(execution.status).toEqual(EXECUTION_STATUS.RESOLVED);
314
+
315
+ const [job] = await execution.getJobs();
316
+ expect(job.result).toEqual(true);
280
317
  });
281
318
 
282
- const post = await PostRepo.create({ values: { read: 1 } });
319
+ it('equal: number == number', async () => {
320
+ const n1 = await workflow.createNode({
321
+ title: 'condition',
322
+ type: 'condition',
323
+ config: {
324
+ engine: 'basic',
325
+ calculation: {
326
+ calculator: 'equal',
327
+ operands: [1, '{{$context.data.read}}'],
328
+ },
329
+ },
330
+ });
283
331
 
284
- await sleep(500);
332
+ const post = await PostRepo.create({ values: { read: 1 } });
285
333
 
286
- const [execution] = await workflow.getExecutions();
287
- expect(execution.status).toEqual(EXECUTION_STATUS.RESOLVED);
334
+ await sleep(500);
288
335
 
289
- const [job] = await execution.getJobs();
290
- expect(job.result).toEqual(true);
336
+ const [execution] = await workflow.getExecutions();
337
+ expect(execution.status).toEqual(EXECUTION_STATUS.RESOLVED);
338
+
339
+ const [job] = await execution.getJobs();
340
+ expect(job.result).toEqual(true);
341
+ });
342
+
343
+ it('equal: string == number', async () => {
344
+ const n1 = await workflow.createNode({
345
+ title: 'condition',
346
+ type: 'condition',
347
+ config: {
348
+ engine: 'basic',
349
+ calculation: {
350
+ calculator: 'equal',
351
+ operands: ['1', '{{$context.data.read}}'],
352
+ },
353
+ },
354
+ });
355
+
356
+ const post = await PostRepo.create({ values: { read: 1 } });
357
+
358
+ await sleep(500);
359
+
360
+ const [execution] = await workflow.getExecutions();
361
+ expect(execution.status).toEqual(EXECUTION_STATUS.RESOLVED);
362
+
363
+ const [job] = await execution.getJobs();
364
+ expect(job.result).toEqual(true);
365
+ });
366
+
367
+ it('equal: undefined == null', async () => {
368
+ const n1 = await workflow.createNode({
369
+ title: 'condition',
370
+ type: 'condition',
371
+ config: {
372
+ engine: 'basic',
373
+ calculation: {
374
+ calculator: 'equal',
375
+ operands: ['{{$context.data.category.id}}', null],
376
+ },
377
+ },
378
+ });
379
+
380
+ const post = await PostRepo.create({ values: {} });
381
+
382
+ await sleep(500);
383
+
384
+ const [execution] = await workflow.getExecutions();
385
+ expect(execution.status).toEqual(EXECUTION_STATUS.RESOLVED);
386
+
387
+ const [job] = await execution.getJobs();
388
+ expect(job.result).toEqual(true);
389
+ });
291
390
  });
292
391
 
293
392
  it('math.js', async () => {
@@ -11,11 +11,11 @@ export const calculators = new Registry<Comparer>();
11
11
 
12
12
  // built-in functions
13
13
  function equal(a, b) {
14
- return a === b;
14
+ return a == b;
15
15
  }
16
16
 
17
17
  function notEqual(a, b) {
18
- return a !== b;
18
+ return a != b;
19
19
  }
20
20
 
21
21
  function gt(a, b) {
@@ -41,8 +41,8 @@ calculators.register('gte', gte);
41
41
  calculators.register('lt', lt);
42
42
  calculators.register('lte', lte);
43
43
 
44
- calculators.register('===', equal);
45
- calculators.register('!==', notEqual);
44
+ calculators.register('==', equal);
45
+ calculators.register('!=', notEqual);
46
46
  calculators.register('>', gt);
47
47
  calculators.register('>=', gte);
48
48
  calculators.register('<', lt);