@nocobase/plugin-workflow 0.9.1-alpha.1 → 0.9.2-alpha.1

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.
Files changed (132) hide show
  1. package/lib/client/AddButton.js +50 -86
  2. package/lib/client/Branch.js +0 -13
  3. package/lib/client/ExecutionCanvas.js +16 -63
  4. package/lib/client/ExecutionLink.js +3 -21
  5. package/lib/client/ExecutionPage.js +1 -19
  6. package/lib/client/ExecutionResourceProvider.js +6 -23
  7. package/lib/client/FlowContext.js +0 -8
  8. package/lib/client/WorkflowCanvas.js +57 -129
  9. package/lib/client/WorkflowLink.js +3 -21
  10. package/lib/client/WorkflowPage.js +1 -19
  11. package/lib/client/WorkflowProvider.js +24 -47
  12. package/lib/client/WorkflowShortcut.js +0 -16
  13. package/lib/client/components/CollectionBlockInitializer.js +12 -22
  14. package/lib/client/components/CollectionFieldInitializers.js +5 -24
  15. package/lib/client/components/CollectionFieldset.js +33 -85
  16. package/lib/client/components/Duration.js +0 -14
  17. package/lib/client/components/DynamicExpression.d.ts +4 -0
  18. package/lib/client/components/DynamicExpression.js +102 -0
  19. package/lib/client/components/FieldsSelect.d.ts +2 -0
  20. package/lib/client/components/FieldsSelect.js +66 -0
  21. package/lib/client/components/FilterDynamicComponent.js +1 -10
  22. package/lib/client/components/NullRender.js +0 -1
  23. package/lib/client/components/OpenDrawer.js +10 -35
  24. package/lib/client/components/RadioWithTooltip.js +5 -27
  25. package/lib/client/components/renderEngineReference.d.ts +1 -0
  26. package/lib/client/components/renderEngineReference.js +55 -0
  27. package/lib/client/constants.js +0 -9
  28. package/lib/client/index.js +0 -6
  29. package/lib/client/interfaces/expression.d.ts +3 -0
  30. package/lib/client/interfaces/expression.js +37 -0
  31. package/lib/client/locale/index.js +5 -15
  32. package/lib/client/locale/pt-BR.d.ts +130 -0
  33. package/lib/client/locale/pt-BR.js +136 -0
  34. package/lib/client/locale/zh-CN.d.ts +16 -1
  35. package/lib/client/locale/zh-CN.js +17 -2
  36. package/lib/client/nodes/calculation.d.ts +56 -7
  37. package/lib/client/nodes/calculation.js +141 -74
  38. package/lib/client/nodes/condition.d.ts +5 -9
  39. package/lib/client/nodes/condition.js +30 -93
  40. package/lib/client/nodes/create.d.ts +36 -12
  41. package/lib/client/nodes/create.js +14 -28
  42. package/lib/client/nodes/delay.d.ts +3 -7
  43. package/lib/client/nodes/delay.js +5 -14
  44. package/lib/client/nodes/destroy.d.ts +3 -11
  45. package/lib/client/nodes/destroy.js +14 -12
  46. package/lib/client/nodes/index.d.ts +2 -2
  47. package/lib/client/nodes/index.js +181 -222
  48. package/lib/client/nodes/manual/AssigneesSelect.js +8 -18
  49. package/lib/client/nodes/manual/ModeConfig.js +0 -27
  50. package/lib/client/nodes/manual/SchemaConfig.js +87 -449
  51. package/lib/client/nodes/manual/WorkflowTodo.js +99 -163
  52. package/lib/client/nodes/manual/WorkflowTodoBlockInitializer.js +4 -20
  53. package/lib/client/nodes/manual/forms/customForm.d.ts +40 -0
  54. package/lib/client/nodes/manual/forms/customForm.js +411 -0
  55. package/lib/client/nodes/manual/index.d.ts +15 -6
  56. package/lib/client/nodes/manual/index.js +58 -54
  57. package/lib/client/nodes/parallel.d.ts +1 -2
  58. package/lib/client/nodes/parallel.js +16 -45
  59. package/lib/client/nodes/query.d.ts +30 -12
  60. package/lib/client/nodes/query.js +17 -25
  61. package/lib/client/nodes/request.d.ts +9 -17
  62. package/lib/client/nodes/request.js +13 -37
  63. package/lib/client/nodes/update.d.ts +27 -28
  64. package/lib/client/nodes/update.js +17 -18
  65. package/lib/client/schemas/collection.d.ts +20 -7
  66. package/lib/client/schemas/collection.js +27 -28
  67. package/lib/client/schemas/executions.js +3 -18
  68. package/lib/client/schemas/workflows.js +10 -33
  69. package/lib/client/style.js +75 -26
  70. package/lib/client/triggers/collection.d.ts +47 -18
  71. package/lib/client/triggers/collection.js +65 -123
  72. package/lib/client/triggers/index.d.ts +3 -6
  73. package/lib/client/triggers/index.js +146 -146
  74. package/lib/client/triggers/schedule/DateFieldsSelect.js +7 -32
  75. package/lib/client/triggers/schedule/EndsByField.js +1 -18
  76. package/lib/client/triggers/schedule/OnField.js +10 -38
  77. package/lib/client/triggers/schedule/RepeatField.js +4 -32
  78. package/lib/client/triggers/schedule/ScheduleConfig.js +25 -68
  79. package/lib/client/triggers/schedule/index.d.ts +21 -1
  80. package/lib/client/triggers/schedule/index.js +22 -24
  81. package/lib/client/triggers/schedule/locale/Cron.zh-CN.js +8 -4
  82. package/lib/client/utils.d.ts +1 -0
  83. package/lib/client/utils.js +31 -10
  84. package/lib/client/variable.d.ts +7 -6
  85. package/lib/client/variable.js +132 -71
  86. package/lib/index.js +0 -2
  87. package/lib/server/Plugin.d.ts +7 -7
  88. package/lib/server/Plugin.js +76 -111
  89. package/lib/server/Processor.d.ts +2 -0
  90. package/lib/server/Processor.js +62 -125
  91. package/lib/server/actions/index.js +3 -10
  92. package/lib/server/actions/nodes.js +34 -87
  93. package/lib/server/actions/workflows.js +46 -96
  94. package/lib/server/collections/executions.js +1 -1
  95. package/lib/server/collections/flow_nodes.js +7 -4
  96. package/lib/server/collections/jobs.js +1 -1
  97. package/lib/server/collections/workflows.js +3 -4
  98. package/lib/server/fields/expression-field.d.ts +8 -0
  99. package/lib/server/fields/expression-field.js +26 -0
  100. package/lib/server/fields/index.d.ts +1 -0
  101. package/lib/server/fields/index.js +12 -0
  102. package/lib/server/functions/index.js +3 -14
  103. package/lib/server/index.js +0 -6
  104. package/lib/server/instructions/calculation.js +22 -17
  105. package/lib/server/instructions/condition.js +8 -52
  106. package/lib/server/instructions/create.js +31 -15
  107. package/lib/server/instructions/delay.js +4 -32
  108. package/lib/server/instructions/destroy.js +6 -12
  109. package/lib/server/instructions/index.js +6 -23
  110. package/lib/server/instructions/manual/actions.js +22 -31
  111. package/lib/server/instructions/manual/collecions/users_jobs.js +1 -1
  112. package/lib/server/instructions/manual/index.d.ts +13 -12
  113. package/lib/server/instructions/manual/index.js +9 -47
  114. package/lib/server/instructions/parallel.js +9 -36
  115. package/lib/server/instructions/query.js +17 -15
  116. package/lib/server/instructions/request.js +7 -30
  117. package/lib/server/instructions/update.js +8 -14
  118. package/lib/server/migrations/20221129153547-calculation-variables.js +3 -27
  119. package/lib/server/migrations/20230221032941-change-request-body-type.js +3 -26
  120. package/lib/server/migrations/20230221071831-calculation-expression.js +1 -33
  121. package/lib/server/migrations/20230221121203-condition-calculation.js +5 -28
  122. package/lib/server/migrations/20230221162902-jsonb-to-json.js +3 -18
  123. package/lib/server/migrations/20230411034722-manual-multi-form.d.ts +4 -0
  124. package/lib/server/migrations/20230411034722-manual-multi-form.js +303 -0
  125. package/lib/server/models/Execution.js +0 -5
  126. package/lib/server/models/FlowNode.js +0 -5
  127. package/lib/server/models/Job.js +0 -5
  128. package/lib/server/models/Workflow.js +0 -5
  129. package/lib/server/triggers/collection.js +39 -61
  130. package/lib/server/triggers/index.js +3 -22
  131. package/lib/server/triggers/schedule.js +72 -194
  132. package/package.json +14 -11
@@ -11,143 +11,100 @@ exports.RemoveButton = RemoveButton;
11
11
  exports.instructions = void 0;
12
12
  exports.useAvailableUpstreams = useAvailableUpstreams;
13
13
  exports.useNodeContext = useNodeContext;
14
-
15
14
  function _react() {
16
15
  const data = _interopRequireWildcard(require("react"));
17
-
18
16
  _react = function _react() {
19
17
  return data;
20
18
  };
21
-
22
19
  return data;
23
20
  }
24
-
25
21
  function _icons() {
26
22
  const data = require("@ant-design/icons");
27
-
28
23
  _icons = function _icons() {
29
24
  return data;
30
25
  };
31
-
32
26
  return data;
33
27
  }
34
-
35
28
  function _css() {
36
29
  const data = require("@emotion/css");
37
-
38
30
  _css = function _css() {
39
31
  return data;
40
32
  };
41
-
42
33
  return data;
43
34
  }
44
-
45
35
  function _react2() {
46
36
  const data = require("@formily/react");
47
-
48
37
  _react2 = function _react2() {
49
38
  return data;
50
39
  };
51
-
52
40
  return data;
53
41
  }
54
-
55
42
  function _antd() {
56
43
  const data = require("antd");
57
-
58
44
  _antd = function _antd() {
59
45
  return data;
60
46
  };
61
-
62
47
  return data;
63
48
  }
64
-
65
49
  function _reactI18next() {
66
50
  const data = require("react-i18next");
67
-
68
51
  _reactI18next = function _reactI18next() {
69
52
  return data;
70
53
  };
71
-
72
54
  return data;
73
55
  }
74
-
75
56
  function _jsonTemplates() {
76
57
  const data = _interopRequireDefault(require("json-templates"));
77
-
78
58
  _jsonTemplates = function _jsonTemplates() {
79
59
  return data;
80
60
  };
81
-
82
61
  return data;
83
62
  }
84
-
85
63
  function _client() {
86
64
  const data = require("@nocobase/utils/client");
87
-
88
65
  _client = function _client() {
89
66
  return data;
90
67
  };
91
-
92
68
  return data;
93
69
  }
94
-
95
70
  function _client2() {
96
71
  const data = require("@nocobase/client");
97
-
98
72
  _client2 = function _client2() {
99
73
  return data;
100
74
  };
101
-
102
75
  return data;
103
76
  }
104
-
105
77
  var _style = require("../style");
106
-
107
78
  var _AddButton = require("../AddButton");
108
-
109
79
  var _FlowContext = require("../FlowContext");
110
-
111
80
  var _calculation = _interopRequireDefault(require("./calculation"));
112
-
113
81
  var _condition = _interopRequireDefault(require("./condition"));
114
-
115
82
  var _parallel = _interopRequireDefault(require("./parallel"));
116
-
117
83
  var _delay = _interopRequireDefault(require("./delay"));
118
-
119
84
  var _manual = _interopRequireDefault(require("./manual"));
120
-
121
85
  var _query = _interopRequireDefault(require("./query"));
122
-
123
86
  var _create = _interopRequireDefault(require("./create"));
124
-
125
87
  var _update = _interopRequireDefault(require("./update"));
126
-
127
88
  var _destroy = _interopRequireDefault(require("./destroy"));
128
-
129
89
  var _constants = require("../constants");
130
-
131
90
  var _locale = require("../locale");
132
-
133
91
  var _request = _interopRequireDefault(require("./request"));
134
-
135
92
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
136
-
137
93
  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); }
138
-
139
94
  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; }
140
-
141
95
  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; }
142
-
143
96
  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; }
144
-
145
- function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
146
-
97
+ function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
98
+ function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return typeof key === "symbol" ? key : String(key); }
99
+ function _toPrimitive(input, hint) { if (typeof input !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (typeof res !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
100
+ function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
101
+ function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
102
+ function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
103
+ function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
104
+ function _iterableToArrayLimit(arr, i) { var _i = null == arr ? null : "undefined" != typeof Symbol && arr[Symbol.iterator] || arr["@@iterator"]; if (null != _i) { var _s, _e, _x, _r, _arr = [], _n = !0, _d = !1; try { if (_x = (_i = _i.call(arr)).next, 0 === i) { if (Object(_i) !== _i) return; _n = !1; } else for (; !(_n = (_s = _x.call(_i)).done) && (_arr.push(_s.value), _arr.length !== i); _n = !0); } catch (err) { _d = !0, _e = err; } finally { try { if (!_n && null != _i.return && (_r = _i.return(), Object(_r) !== _r)) return; } finally { if (_d) throw _e; } } return _arr; } }
105
+ function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
147
106
  function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
148
-
149
107
  function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
150
-
151
108
  ;
152
109
  const instructions = new (_client().Registry)();
153
110
  exports.instructions = instructions;
@@ -161,73 +118,52 @@ instructions.register('create', _create.default);
161
118
  instructions.register('update', _update.default);
162
119
  instructions.register('destroy', _destroy.default);
163
120
  instructions.register('request', _request.default);
164
-
165
121
  function useUpdateAction() {
166
122
  const form = (0, _react2().useForm)();
167
123
  const api = (0, _client2().useAPIClient)();
168
124
  const ctx = (0, _client2().useActionContext)();
169
-
170
125
  const _useResourceActionCon = (0, _client2().useResourceActionContext)(),
171
- refresh = _useResourceActionCon.refresh;
172
-
126
+ refresh = _useResourceActionCon.refresh;
173
127
  const data = useNodeContext();
174
-
175
128
  const _useFlowContext = (0, _FlowContext.useFlowContext)(),
176
- workflow = _useFlowContext.workflow;
177
-
129
+ workflow = _useFlowContext.workflow;
178
130
  return {
179
131
  run() {
180
132
  return _asyncToGenerator(function* () {
181
133
  var _api$resource$update, _api$resource;
182
-
183
134
  if (workflow.executed) {
184
135
  _antd().message.error((0, _locale.lang)('Node in executed workflow cannot be modified'));
185
-
186
- return;
187
- } // TODO: how to do validation separately for each field? especially disabled for dynamic fields?
188
-
189
-
190
- try {
191
- yield form.submit();
192
- } catch (err) {
193
136
  return;
194
137
  }
195
-
138
+ yield form.submit();
196
139
  yield (_api$resource$update = (_api$resource = api.resource('flow_nodes', data.id)).update) === null || _api$resource$update === void 0 ? void 0 : _api$resource$update.call(_api$resource, {
197
140
  filterByTk: data.id,
198
141
  values: {
199
- title: form.values.title,
200
- config: form.values.config
142
+ config: form.values
201
143
  }
202
144
  });
203
145
  ctx.setVisible(false);
204
146
  refresh();
205
147
  })();
206
148
  }
207
-
208
149
  };
209
150
  }
210
-
211
151
  ;
212
-
213
152
  const NodeContext = _react().default.createContext({});
214
-
215
153
  exports.NodeContext = NodeContext;
216
-
217
154
  function useNodeContext() {
218
155
  return (0, _react().useContext)(NodeContext);
219
156
  }
220
-
221
157
  function useAvailableUpstreams(node) {
222
158
  const stack = [];
223
-
159
+ if (!node) {
160
+ return [];
161
+ }
224
162
  for (let current = node.upstream; current; current = current.upstream) {
225
163
  stack.push(current);
226
164
  }
227
-
228
165
  return stack;
229
166
  }
230
-
231
167
  function Node({
232
168
  data
233
169
  }) {
@@ -259,64 +195,48 @@ function Node({
259
195
  `
260
196
  }, _react().default.createElement(_icons().CloseOutlined, null))));
261
197
  }
262
-
263
198
  function RemoveButton() {
264
199
  var _useFlowContext2;
265
-
266
200
  const _useTranslation = (0, _reactI18next().useTranslation)(),
267
- t = _useTranslation.t;
268
-
201
+ t = _useTranslation.t;
269
202
  const api = (0, _client2().useAPIClient)();
270
-
271
203
  const _ref = (_useFlowContext2 = (0, _FlowContext.useFlowContext)()) !== null && _useFlowContext2 !== void 0 ? _useFlowContext2 : {},
272
- workflow = _ref.workflow,
273
- nodes = _ref.nodes,
274
- onNodeRemoved = _ref.onNodeRemoved;
275
-
204
+ workflow = _ref.workflow,
205
+ nodes = _ref.nodes,
206
+ refresh = _ref.refresh;
276
207
  const current = useNodeContext();
277
-
278
208
  if (!workflow) {
279
209
  return null;
280
210
  }
281
-
282
211
  const resource = api.resource('workflows.nodes', workflow.id);
283
-
284
212
  function onRemove() {
285
213
  return _onRemove.apply(this, arguments);
286
214
  }
287
-
288
215
  function _onRemove() {
289
216
  _onRemove = _asyncToGenerator(function* () {
290
217
  function onOk() {
291
218
  return _onOk.apply(this, arguments);
292
219
  }
293
-
294
220
  function _onOk() {
295
221
  _onOk = _asyncToGenerator(function* () {
296
222
  var _resource$destroy;
297
-
298
- const _yield$resource$destr = yield (_resource$destroy = resource.destroy) === null || _resource$destroy === void 0 ? void 0 : _resource$destroy.call(resource, {
223
+ yield (_resource$destroy = resource.destroy) === null || _resource$destroy === void 0 ? void 0 : _resource$destroy.call(resource, {
299
224
  filterByTk: current.id
300
- }),
301
- node = _yield$resource$destr.data.data;
302
-
303
- onNodeRemoved(node);
225
+ });
226
+ refresh();
304
227
  });
305
228
  return _onOk.apply(this, arguments);
306
229
  }
307
-
308
230
  const usingNodes = nodes.filter(node => {
309
231
  if (node === current) {
310
232
  return false;
311
233
  }
312
-
313
234
  const template = (0, _jsonTemplates().default)(node.config);
314
235
  const refs = template.parameters.filter(({
315
236
  key
316
237
  }) => key.startsWith(`$jobsMapByNodeId.${current.id}.`) || key === `$jobsMapByNodeId.${current.id}`);
317
238
  return refs.length;
318
239
  });
319
-
320
240
  if (usingNodes.length) {
321
241
  _antd().Modal.error({
322
242
  title: (0, _locale.lang)('Can not delete'),
@@ -324,13 +244,10 @@ function RemoveButton() {
324
244
  nodes: usingNodes.map(item => `#${item.id}`).join(', ')
325
245
  })
326
246
  });
327
-
328
247
  return;
329
248
  }
330
-
331
249
  const hasBranches = !nodes.find(item => item.upstream === current && item.branchIndex != null);
332
250
  const message = hasBranches ? t('Are you sure you want to delete it?') : (0, _locale.lang)('This node contains branches, deleting will also be preformed to them, are you sure?');
333
-
334
251
  _antd().Modal.confirm({
335
252
  title: t('Delete'),
336
253
  content: message,
@@ -339,7 +256,6 @@ function RemoveButton() {
339
256
  });
340
257
  return _onRemove.apply(this, arguments);
341
258
  }
342
-
343
259
  return workflow.executed ? null : _react().default.createElement(_antd().Button, {
344
260
  type: "text",
345
261
  shape: "circle",
@@ -348,39 +264,33 @@ function RemoveButton() {
348
264
  className: "workflow-node-remove-button"
349
265
  });
350
266
  }
351
-
352
267
  function JobButton() {
353
268
  var _useNodeContext;
354
-
355
269
  const compile = (0, _client2().useCompile)();
356
-
357
270
  const _useFlowContext3 = (0, _FlowContext.useFlowContext)(),
358
- execution = _useFlowContext3.execution;
359
-
271
+ execution = _useFlowContext3.execution;
360
272
  const _ref2 = (_useNodeContext = useNodeContext()) !== null && _useNodeContext !== void 0 ? _useNodeContext : {},
361
- id = _ref2.id,
362
- type = _ref2.type,
363
- title = _ref2.title,
364
- job = _ref2.job;
365
-
273
+ id = _ref2.id,
274
+ type = _ref2.type,
275
+ title = _ref2.title,
276
+ job = _ref2.job;
366
277
  if (!execution) {
367
278
  return null;
368
279
  }
369
-
370
280
  if (!job) {
371
281
  return _react().default.createElement("span", {
372
282
  className: (0, _css().cx)('workflow-node-job-button', (0, _css().css)`
373
283
  border: 2px solid #d9d9d9;
374
284
  border-radius: 50%;
285
+ cursor: not-allowed;
375
286
  `)
376
287
  });
377
288
  }
378
-
379
289
  const instruction = instructions.get(type);
380
290
  const _JobStatusOptionsMap$ = _constants.JobStatusOptionsMap[job.status],
381
- value = _JobStatusOptionsMap$.value,
382
- icon = _JobStatusOptionsMap$.icon,
383
- color = _JobStatusOptionsMap$.color;
291
+ value = _JobStatusOptionsMap$.value,
292
+ icon = _JobStatusOptionsMap$.icon,
293
+ color = _JobStatusOptionsMap$.color;
384
294
  return _react().default.createElement(_client2().SchemaComponent, {
385
295
  schema: {
386
296
  type: 'void',
@@ -456,36 +366,84 @@ function JobButton() {
456
366
  }
457
367
  });
458
368
  }
459
-
460
369
  function NodeDefaultView(props) {
461
- var _useFlowContext4;
462
-
370
+ var _useFlowContext4, _data$title;
371
+ const data = props.data,
372
+ children = props.children;
463
373
  const compile = (0, _client2().useCompile)();
464
-
374
+ const api = (0, _client2().useAPIClient)();
465
375
  const _ref3 = (_useFlowContext4 = (0, _FlowContext.useFlowContext)()) !== null && _useFlowContext4 !== void 0 ? _useFlowContext4 : {},
466
- workflow = _ref3.workflow;
467
-
468
- if (!workflow) {
469
- return null;
470
- }
471
-
472
- const data = props.data,
473
- children = props.children;
376
+ workflow = _ref3.workflow,
377
+ refresh = _ref3.refresh;
474
378
  const instruction = instructions.get(data.type);
475
379
  const detailText = workflow.executed ? '{{t("View")}}' : '{{t("Configure")}}';
380
+ const typeTitle = compile(instruction.title);
381
+ const _useState = (0, _react().useState)((_data$title = data.title) !== null && _data$title !== void 0 ? _data$title : typeTitle),
382
+ _useState2 = _slicedToArray(_useState, 2),
383
+ editingTitle = _useState2[0],
384
+ setEditingTitle = _useState2[1];
385
+ const _useState3 = (0, _react().useState)(false),
386
+ _useState4 = _slicedToArray(_useState3, 2),
387
+ editingConfig = _useState4[0],
388
+ setEditingConfig = _useState4[1];
389
+ function onChangeTitle(_x2) {
390
+ return _onChangeTitle.apply(this, arguments);
391
+ }
392
+ function _onChangeTitle() {
393
+ _onChangeTitle = _asyncToGenerator(function* (next) {
394
+ var _api$resource$update2, _api$resource2;
395
+ const title = next || typeTitle;
396
+ setEditingTitle(title);
397
+ if (title === data.title) {
398
+ return;
399
+ }
400
+ yield (_api$resource$update2 = (_api$resource2 = api.resource('flow_nodes')).update) === null || _api$resource$update2 === void 0 ? void 0 : _api$resource$update2.call(_api$resource2, {
401
+ filterByTk: data.id,
402
+ values: {
403
+ title
404
+ }
405
+ });
406
+ refresh();
407
+ });
408
+ return _onChangeTitle.apply(this, arguments);
409
+ }
410
+ function onOpenDrawer(ev) {
411
+ if (ev.target === ev.currentTarget) {
412
+ setEditingConfig(true);
413
+ return;
414
+ }
415
+ const whiteSet = new Set(['workflow-node-meta', 'workflow-node-config-button', 'ant-input-disabled']);
416
+ for (let el = ev.target; el && el !== ev.currentTarget; el = el.parentNode) {
417
+ if (Array.from(el.classList).some(name => whiteSet.has(name))) {
418
+ setEditingConfig(true);
419
+ ev.stopPropagation();
420
+ return;
421
+ }
422
+ }
423
+ }
476
424
  return _react().default.createElement("div", {
477
425
  className: (0, _css().cx)(_style.nodeClass, `workflow-node-type-${data.type}`)
478
426
  }, _react().default.createElement("div", {
479
- className: (0, _css().cx)(_style.nodeCardClass)
480
- }, _react().default.createElement("div", {
481
- className: (0, _css().cx)(_style.nodeHeaderClass)
427
+ className: (0, _css().cx)(_style.nodeCardClass, {
428
+ configuring: editingConfig
429
+ }),
430
+ onClick: onOpenDrawer
482
431
  }, _react().default.createElement("div", {
483
- className: (0, _css().cx)(_style.nodeMetaClass)
484
- }, _react().default.createElement(_antd().Tag, null, compile(instruction.title))), _react().default.createElement("h4", {
485
- className: (0, _css().cx)(_style.nodeTitleClass)
486
- }, _react().default.createElement("strong", null, data.title), _react().default.createElement("span", {
432
+ className: (0, _css().cx)(_style.nodeMetaClass, 'workflow-node-meta')
433
+ }, _react().default.createElement(_antd().Tag, null, typeTitle), _react().default.createElement("span", {
487
434
  className: "workflow-node-id"
488
- }, "#", data.id)), _react().default.createElement(RemoveButton, null), _react().default.createElement(JobButton, null)), _react().default.createElement(_client2().SchemaComponent, {
435
+ }, data.id)), _react().default.createElement("div", null, _react().default.createElement(_antd().Input.TextArea, {
436
+ disabled: workflow.executed,
437
+ value: editingTitle,
438
+ onChange: ev => setEditingTitle(ev.target.value),
439
+ onBlur: ev => onChangeTitle(ev.target.value),
440
+ autoSize: true
441
+ })), _react().default.createElement(RemoveButton, null), _react().default.createElement(JobButton, null), _react().default.createElement(_client2().ActionContext.Provider, {
442
+ value: {
443
+ visible: editingConfig,
444
+ setVisible: setEditingConfig
445
+ }
446
+ }, _react().default.createElement(_client2().SchemaComponent, {
489
447
  scope: instruction.scope,
490
448
  components: instruction.components,
491
449
  schema: {
@@ -493,99 +451,100 @@ function NodeDefaultView(props) {
493
451
  properties: _objectSpread(_objectSpread({}, instruction.view ? {
494
452
  view: instruction.view
495
453
  } : {}), {}, {
496
- config: {
454
+ button: {
497
455
  type: 'void',
498
- title: detailText,
499
- 'x-component': 'Action.Link',
456
+ 'x-content': detailText,
457
+ 'x-component': _antd().Button,
500
458
  'x-component-props': {
501
- type: 'primary'
459
+ type: 'link',
460
+ className: 'workflow-node-config-button'
461
+ }
462
+ },
463
+ [`${instruction.type}_${data.id}`]: {
464
+ type: 'void',
465
+ title: instruction.title,
466
+ 'x-component': 'Action.Drawer',
467
+ 'x-decorator': 'Form',
468
+ 'x-decorator-props': {
469
+ disabled: workflow.executed,
470
+ useValues(options) {
471
+ const _useNodeContext2 = useNodeContext(),
472
+ config = _useNodeContext2.config;
473
+ return (0, _client2().useRequest)(() => {
474
+ return Promise.resolve({
475
+ data: config
476
+ });
477
+ }, options);
478
+ }
502
479
  },
503
- properties: {
504
- [`${instruction.type}_${data.id}`]: {
480
+ properties: _objectSpread(_objectSpread({}, workflow.executed ? {
481
+ alert: {
505
482
  type: 'void',
506
- title: instruction.title,
507
- 'x-component': 'Action.Drawer',
508
- 'x-decorator': 'Form',
509
- 'x-decorator-props': {
510
- disabled: workflow.executed,
511
-
512
- useValues(options) {
513
- const d = useNodeContext();
514
- return (0, _client2().useRequest)(() => {
515
- return Promise.resolve({
516
- data: d
517
- });
518
- }, options);
519
- }
520
-
483
+ 'x-component': _antd().Alert,
484
+ 'x-component-props': {
485
+ type: 'warning',
486
+ showIcon: true,
487
+ message: `{{t("Node in executed workflow cannot be modified", { ns: "${_locale.NAMESPACE}" })}}`,
488
+ className: (0, _css().css)`
489
+ width: 100%;
490
+ font-size: 85%;
491
+ margin-bottom: 2em;
492
+ `
493
+ }
494
+ }
495
+ } : {}), {}, {
496
+ fieldset: {
497
+ type: 'void',
498
+ 'x-component': 'fieldset',
499
+ 'x-component-props': {
500
+ className: (0, _css().css)`
501
+ .ant-select,
502
+ .ant-cascader-picker,
503
+ .ant-picker,
504
+ .ant-input-number,
505
+ .ant-input-affix-wrapper{
506
+ &:not(.full-width){
507
+ width: auto;
508
+ min-width: 6em;
509
+ }
510
+ }
511
+
512
+ .ant-input-affix-wrapper{
513
+ &:not(.full-width){
514
+ .ant-input{
515
+ width: auto;
516
+ min-width: 6em;
517
+ }
518
+ }
519
+ }
520
+ `
521
521
  },
522
- properties: _objectSpread(_objectSpread({}, workflow.executed ? {
523
- alert: {
524
- 'x-component': _antd().Alert,
522
+ properties: instruction.fieldset
523
+ },
524
+ actions: workflow.executed ? null : {
525
+ type: 'void',
526
+ 'x-component': 'Action.Drawer.Footer',
527
+ properties: {
528
+ cancel: {
529
+ title: '{{t("Cancel")}}',
530
+ 'x-component': 'Action',
525
531
  'x-component-props': {
526
- type: 'warning',
527
- showIcon: true,
528
- message: `{{t("Node in executed workflow cannot be modified", { ns: "${_locale.NAMESPACE}" })}}`,
529
- className: (0, _css().css)`
530
- width: 100%;
531
- font-size: 85%;
532
- margin-bottom: 2em;
533
- `
532
+ useAction: '{{ cm.useCancelAction }}'
534
533
  }
535
- }
536
- } : {}), {}, {
537
- title: {
538
- type: 'string',
539
- name: 'title',
540
- title: '{{t("Name")}}',
541
- 'x-decorator': 'FormItem',
542
- 'x-component': 'Input'
543
534
  },
544
- config: {
545
- type: 'void',
546
- name: 'config',
547
- 'x-component': 'fieldset',
535
+ submit: {
536
+ title: '{{t("Submit")}}',
537
+ 'x-component': 'Action',
548
538
  'x-component-props': {
549
- className: (0, _css().css)`
550
- .ant-input,
551
- .ant-select,
552
- .ant-cascader-picker,
553
- .ant-picker,
554
- .ant-input-number,
555
- .ant-input-affix-wrapper{
556
- width: auto;
557
- min-width: 6em;
558
- }
559
- `
560
- },
561
- properties: instruction.fieldset
562
- },
563
- actions: workflow.executed ? null : {
564
- type: 'void',
565
- 'x-component': 'Action.Drawer.Footer',
566
- properties: {
567
- cancel: {
568
- title: '{{t("Cancel")}}',
569
- 'x-component': 'Action',
570
- 'x-component-props': {
571
- useAction: '{{ cm.useCancelAction }}'
572
- }
573
- },
574
- submit: {
575
- title: '{{t("Submit")}}',
576
- 'x-component': 'Action',
577
- 'x-component-props': {
578
- type: 'primary',
579
- useAction: useUpdateAction
580
- }
581
- }
539
+ type: 'primary',
540
+ useAction: useUpdateAction
582
541
  }
583
542
  }
584
- })
543
+ }
585
544
  }
586
- }
545
+ })
587
546
  }
588
547
  })
589
548
  }
590
- })), children);
549
+ }))), children);
591
550
  }