@tachybase/plugin-workflow-approval 1.5.1 → 1.6.0

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.
@@ -0,0 +1,7 @@
1
+ import '../../style/style.css';
2
+ interface ApprovalsSummaryProps {
3
+ value: any;
4
+ collectionName?: string;
5
+ }
6
+ export declare const ApprovalsSummary: (props: ApprovalsSummaryProps) => import("react/jsx-runtime").JSX.Element;
7
+ export {};
@@ -0,0 +1,14 @@
1
+ interface SummaryItem {
2
+ label: string;
3
+ value: string | number | null | undefined;
4
+ }
5
+ /**
6
+ * 处理 summary 数据,兼容新旧两种格式
7
+ * @param summary - 可能是旧格式的对象或新格式的数组
8
+ * @param collectionName - 集合名称
9
+ * @param cm - CollectionManager 实例
10
+ * @param compile - 编译函数
11
+ * @returns 统一格式的 summary 数组
12
+ */
13
+ export declare function processSummary(summary: any, collectionName: string, cm: any, compile: (value: any) => string): SummaryItem[];
14
+ export {};
@@ -1,2 +1,2 @@
1
1
  export declare const TabApprovalItem: import("react").MemoExoticComponent<import("@tachybase/schema").ReactFC<unknown>>;
2
- export declare const changeWorkflowNoticeService: (api: any, t: any, cm: any, compile: any, input: any, setData: any, params: any, filter: any, user: any) => void;
2
+ export declare const changeWorkflowNoticeService: (api: any, t: any, cm: any, compile: any, input: any, setData: any, params: any, filter: any, user: any, page: any, setTotal: any) => void;
@@ -5,3 +5,9 @@ export declare const COLLECTION_WORKFLOWS_NAME = "workflows";
5
5
  export declare const NAMESPACE = "workflow-approval";
6
6
  export declare const PLUGIN_NAME_APPROVAL = "approval";
7
7
  export declare const INSTRUCTION_TYPE_NAME_APPROVAL = "approval";
8
+ export declare const SUMMARY_TYPE: {
9
+ readonly LITERAL: "literal";
10
+ readonly TABLE: "table";
11
+ readonly DATE: "date";
12
+ readonly ARRAY: "array";
13
+ };
@@ -23,7 +23,8 @@ __export(constants_exports, {
23
23
  INSTRUCTION_TYPE_NAME_APPROVAL: () => INSTRUCTION_TYPE_NAME_APPROVAL,
24
24
  NAMESPACE: () => NAMESPACE,
25
25
  NOTICE_INSTRUCTION_NAMESPACE: () => NOTICE_INSTRUCTION_NAMESPACE,
26
- PLUGIN_NAME_APPROVAL: () => PLUGIN_NAME_APPROVAL
26
+ PLUGIN_NAME_APPROVAL: () => PLUGIN_NAME_APPROVAL,
27
+ SUMMARY_TYPE: () => SUMMARY_TYPE
27
28
  });
28
29
  module.exports = __toCommonJS(constants_exports);
29
30
  const NOTICE_INSTRUCTION_NAMESPACE = "notice";
@@ -33,6 +34,16 @@ const COLLECTION_WORKFLOWS_NAME = "workflows";
33
34
  const NAMESPACE = "workflow-approval";
34
35
  const PLUGIN_NAME_APPROVAL = "approval";
35
36
  const INSTRUCTION_TYPE_NAME_APPROVAL = "approval";
37
+ const SUMMARY_TYPE = {
38
+ LITERAL: "literal",
39
+ // 单个值
40
+ TABLE: "table",
41
+ // 表格
42
+ DATE: "date",
43
+ // 日期
44
+ ARRAY: "array"
45
+ // 数组
46
+ };
36
47
  // Annotate the CommonJS export names for ESM import in node:
37
48
  0 && (module.exports = {
38
49
  COLLECTION_NAME_APPROVAL_CARBON_COPY,
@@ -41,5 +52,6 @@ const INSTRUCTION_TYPE_NAME_APPROVAL = "approval";
41
52
  INSTRUCTION_TYPE_NAME_APPROVAL,
42
53
  NAMESPACE,
43
54
  NOTICE_INSTRUCTION_NAMESPACE,
44
- PLUGIN_NAME_APPROVAL
55
+ PLUGIN_NAME_APPROVAL,
56
+ SUMMARY_TYPE
45
57
  });
@@ -0,0 +1,15 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __copyProps = (to, from, except, desc) => {
6
+ if (from && typeof from === "object" || typeof from === "function") {
7
+ for (let key of __getOwnPropNames(from))
8
+ if (!__hasOwnProp.call(to, key) && key !== except)
9
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
10
+ }
11
+ return to;
12
+ };
13
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
14
+ var interface_d_exports = {};
15
+ module.exports = __toCommonJS(interface_d_exports);
@@ -0,0 +1,2 @@
1
+ export declare function isUTCString(str?: string): boolean;
2
+ export declare function isDateType(value: any): boolean;
@@ -0,0 +1,46 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __export = (target, all) => {
6
+ for (var name in all)
7
+ __defProp(target, name, { get: all[name], enumerable: true });
8
+ };
9
+ var __copyProps = (to, from, except, desc) => {
10
+ if (from && typeof from === "object" || typeof from === "function") {
11
+ for (let key of __getOwnPropNames(from))
12
+ if (!__hasOwnProp.call(to, key) && key !== except)
13
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
+ }
15
+ return to;
16
+ };
17
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
+ var utils_exports = {};
19
+ __export(utils_exports, {
20
+ isDateType: () => isDateType,
21
+ isUTCString: () => isUTCString
22
+ });
23
+ module.exports = __toCommonJS(utils_exports);
24
+ const utcRegex = /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}\.\d{3}Z$/;
25
+ function isUTCString(str = "") {
26
+ return utcRegex.test(str);
27
+ }
28
+ function isDateType(value) {
29
+ if (typeof value !== "string") {
30
+ return false;
31
+ }
32
+ if (isUTCString(value)) {
33
+ return true;
34
+ }
35
+ const dateRegex = /^\d{4}-\d{2}-\d{2}/;
36
+ if (dateRegex.test(value)) {
37
+ const date = new Date(value);
38
+ return !isNaN(date.getTime());
39
+ }
40
+ return false;
41
+ }
42
+ // Annotate the CommonJS export names for ESM import in node:
43
+ 0 && (module.exports = {
44
+ isDateType,
45
+ isUTCString
46
+ });
@@ -1,16 +1,17 @@
1
1
  module.exports = {
2
- "@tachybase/client": "1.5.1",
3
- "@tachybase/module-workflow": "1.5.1",
2
+ "@tachybase/client": "1.6.0",
4
3
  "@tego/server": "1.3.52",
4
+ "@tachybase/module-workflow": "1.6.0",
5
5
  "lodash": "4.17.21",
6
6
  "react": "18.3.1",
7
7
  "@tachybase/schema": "1.3.52",
8
8
  "antd": "5.22.5",
9
- "@tachybase/module-ui-schema": "1.5.1",
9
+ "@tachybase/module-ui-schema": "1.6.0",
10
10
  "sequelize": "6.37.5",
11
11
  "@tego/client": "1.3.52",
12
+ "react-i18next": "16.2.1",
13
+ "react-router-dom": "6.28.1",
12
14
  "@ant-design/icons": "5.6.1",
13
15
  "dayjs": "1.11.13",
14
- "ahooks": "3.9.0",
15
- "react-router-dom": "6.28.1"
16
+ "ahooks": "3.9.0"
16
17
  };
@@ -183,6 +183,7 @@
183
183
  "Negotiation": "Negotiation",
184
184
  "Negotiation mode": "Negotiation mode",
185
185
  "New Initiate Request": "New Initiate Request",
186
+ "No data yet": "No data yet",
186
187
  "No end": "No end",
187
188
  "No limit": "No limit",
188
189
  "No repeat": "No repeat",
@@ -96,7 +96,9 @@ const approvals = {
96
96
  data: {
97
97
  ...instance,
98
98
  ...data
99
- }
99
+ },
100
+ collection,
101
+ app: context.app
100
102
  });
101
103
  Object.keys(model.associations).forEach((key) => {
102
104
  delete instance[key];
@@ -126,7 +128,9 @@ const approvals = {
126
128
  });
127
129
  const summary = (0, import_tools.getSummary)({
128
130
  summaryConfig,
129
- data
131
+ data,
132
+ collection,
133
+ app: context.app
130
134
  });
131
135
  context.action.mergeParams({
132
136
  values: {
@@ -1,11 +1,8 @@
1
- interface ParamsType {
2
- summaryConfig: Array<string>;
3
- data: object;
4
- }
5
- export declare function getSummary(params: ParamsType): object;
6
- export declare function parsePerson({ node, processor, keyName }: {
1
+ import { type ParamsType } from '../common/interface';
2
+ declare function parsePerson({ node, processor, keyName }: {
7
3
  node: any;
8
4
  processor: any;
9
5
  keyName: any;
10
6
  }): Promise<unknown[]>;
11
- export {};
7
+ declare function getSummary(params: ParamsType): object;
8
+ export { getSummary, parsePerson };
@@ -32,18 +32,8 @@ __export(tools_exports, {
32
32
  });
33
33
  module.exports = __toCommonJS(tools_exports);
34
34
  var import_lodash = __toESM(require("lodash"));
35
- function getSummary(params) {
36
- const { summaryConfig = [], data } = params;
37
- const result = summaryConfig.reduce((summary, key) => {
38
- const value = import_lodash.default.get(data, key);
39
- const realValue = Object.prototype.toString.call(value) === "[object Object]" ? value == null ? void 0 : value["name"] : value;
40
- return {
41
- ...summary,
42
- [key]: realValue
43
- };
44
- }, {});
45
- return result;
46
- }
35
+ var import_constants = require("../common/constants");
36
+ var import_utils = require("../common/utils");
47
37
  async function parsePerson({ node, processor, keyName }) {
48
38
  var _a;
49
39
  const configPerson = processor.getParsedValue(((_a = node.config) == null ? void 0 : _a[keyName]) ?? [], node.id).flat().filter(Boolean);
@@ -63,6 +53,257 @@ async function parsePerson({ node, processor, keyName }) {
63
53
  }
64
54
  return [...targetPerson];
65
55
  }
56
+ function getSummary(params) {
57
+ const { summaryConfig = [], data, collection, app } = params;
58
+ const summaryDataSource = getSummaryDataSource({ summaryConfig, data, collection, app });
59
+ return summaryDataSource;
60
+ }
61
+ function getAssociationTitleFieldValue(value, fieldName, collection, app) {
62
+ if (!collection && !app || typeof value !== "object" || value === null || Array.isArray(value)) {
63
+ return void 0;
64
+ }
65
+ let field;
66
+ let dataSource;
67
+ let targetCollection;
68
+ if (collection) {
69
+ field = collection.getField(fieldName);
70
+ if (!field || !field.target) {
71
+ return void 0;
72
+ }
73
+ const db = collection.db;
74
+ if (db) {
75
+ targetCollection = db.getCollection(field.target);
76
+ } else if (app && app.dataSourceManager) {
77
+ const collectionDataSource = collection.dataSource;
78
+ if (collectionDataSource) {
79
+ dataSource = app.dataSourceManager.dataSources.get(collectionDataSource);
80
+ } else {
81
+ dataSource = app.dataSourceManager.dataSources.get("main");
82
+ }
83
+ if (dataSource) {
84
+ targetCollection = dataSource.collectionManager.getCollection(field.target);
85
+ }
86
+ } else {
87
+ try {
88
+ const cm = collection.collectionManager;
89
+ if (cm) {
90
+ dataSource = cm.dataSource;
91
+ targetCollection = dataSource.collectionManager.getCollection(field.target);
92
+ }
93
+ } catch (e) {
94
+ }
95
+ }
96
+ } else if (app) {
97
+ return void 0;
98
+ }
99
+ if (!targetCollection) {
100
+ return void 0;
101
+ }
102
+ const titleField = targetCollection.titleField || targetCollection.getPrimaryKey() || "id";
103
+ const titleValue = value[titleField];
104
+ return titleValue !== void 0 && titleValue !== null ? String(titleValue) : void 0;
105
+ }
106
+ function getFieldLabel(key, collection) {
107
+ var _a;
108
+ if (!collection) {
109
+ return key;
110
+ }
111
+ const field = collection.getField(key);
112
+ if (field) {
113
+ const uiSchema = (_a = field.options) == null ? void 0 : _a.uiSchema;
114
+ if (uiSchema == null ? void 0 : uiSchema.title) {
115
+ return uiSchema.title;
116
+ }
117
+ if (field.title) {
118
+ return field.title;
119
+ }
120
+ }
121
+ return key;
122
+ }
123
+ function processValue(value, fieldName, collection, app) {
124
+ if (value === void 0 || value === null) {
125
+ return "";
126
+ }
127
+ if (value instanceof Date || typeof value.toDate === "function" && value.toDate() instanceof Date) {
128
+ const dateObj = value instanceof Date ? value : value.toDate();
129
+ return dateObj.toISOString();
130
+ }
131
+ if (typeof value === "object" && !Array.isArray(value)) {
132
+ const titleFieldValue = getAssociationTitleFieldValue(value, fieldName, collection, app);
133
+ if (titleFieldValue !== void 0) {
134
+ return titleFieldValue;
135
+ }
136
+ if (value.name !== void 0) {
137
+ return String(value.name);
138
+ }
139
+ return JSON.stringify(value);
140
+ }
141
+ if (typeof value === "number") {
142
+ return value;
143
+ }
144
+ return String(value);
145
+ }
146
+ function getSummaryItem(key, data, collection, app) {
147
+ const value = import_lodash.default.get(data, key);
148
+ const label = getFieldLabel(key, collection);
149
+ if (value === void 0 || value === null) {
150
+ return {
151
+ key,
152
+ label,
153
+ type: import_constants.SUMMARY_TYPE.LITERAL,
154
+ value: ""
155
+ };
156
+ }
157
+ if (Array.isArray(value)) {
158
+ const processedArray = [];
159
+ for (const item of value) {
160
+ const processedValue2 = processValue(item, key, collection, app);
161
+ processedArray.push(processedValue2);
162
+ }
163
+ return {
164
+ key,
165
+ label,
166
+ type: import_constants.SUMMARY_TYPE.ARRAY,
167
+ value: processedArray
168
+ };
169
+ }
170
+ if (value instanceof Date || typeof value.toDate === "function" && value.toDate() instanceof Date) {
171
+ const dateObj = value instanceof Date ? value : value.toDate();
172
+ return {
173
+ key,
174
+ label,
175
+ type: import_constants.SUMMARY_TYPE.DATE,
176
+ value: dateObj.toISOString()
177
+ };
178
+ }
179
+ const processedValue = processValue(value, key, collection, app);
180
+ const valueStr = String(processedValue);
181
+ const finalType = (0, import_utils.isDateType)(valueStr) ? import_constants.SUMMARY_TYPE.DATE : import_constants.SUMMARY_TYPE.LITERAL;
182
+ return {
183
+ key,
184
+ label,
185
+ type: finalType,
186
+ value: processedValue
187
+ };
188
+ }
189
+ function getTargetCollection(mainKey, collection, app) {
190
+ if (!collection) {
191
+ return void 0;
192
+ }
193
+ const field = collection.getField(mainKey);
194
+ if (!field || !field.target) {
195
+ return void 0;
196
+ }
197
+ let targetCollection;
198
+ const db = collection.db;
199
+ if (db) {
200
+ targetCollection = db.getCollection(field.target);
201
+ } else if (app && app.dataSourceManager) {
202
+ const collectionDataSource = collection.dataSource;
203
+ let dataSource;
204
+ if (collectionDataSource) {
205
+ dataSource = app.dataSourceManager.dataSources.get(collectionDataSource);
206
+ } else {
207
+ dataSource = app.dataSourceManager.dataSources.get("main");
208
+ }
209
+ if (dataSource) {
210
+ targetCollection = dataSource.collectionManager.getCollection(field.target);
211
+ }
212
+ }
213
+ return targetCollection;
214
+ }
215
+ function isManyToManyField(mainKey, collection) {
216
+ if (!collection) {
217
+ return false;
218
+ }
219
+ const field = collection.getField(mainKey);
220
+ if (!field) {
221
+ return false;
222
+ }
223
+ return field.type === "belongsToMany" || field.type === "hasMany";
224
+ }
225
+ function getSummaryDataSource({ summaryConfig = [], data, collection, app }) {
226
+ const mainPathKeys = [];
227
+ const subPathKeys = [];
228
+ for (const key of summaryConfig) {
229
+ if (key.includes(".")) {
230
+ subPathKeys.push(key);
231
+ } else {
232
+ mainPathKeys.push(key);
233
+ }
234
+ }
235
+ const summaryDataSource = [];
236
+ for (const mainKey of mainPathKeys) {
237
+ const parentValue = import_lodash.default.get(data, mainKey);
238
+ const label = getFieldLabel(mainKey, collection);
239
+ const isManyToMany = isManyToManyField(mainKey, collection);
240
+ if (isManyToMany && Array.isArray(parentValue) && parentValue.length > 0) {
241
+ const mainKeyPrefix = `${mainKey}.`;
242
+ const relevantSubKeys = subPathKeys.filter((subKey) => subKey.startsWith(mainKeyPrefix));
243
+ if (relevantSubKeys.length === 0) {
244
+ summaryDataSource.push(getSummaryItem(mainKey, data, collection, app));
245
+ } else {
246
+ const fieldPathMap = /* @__PURE__ */ new Map();
247
+ for (const subKey of relevantSubKeys) {
248
+ const relativePath = subKey.slice(mainKeyPrefix.length);
249
+ const fieldName = relativePath.split(".")[0];
250
+ if (!fieldPathMap.has(fieldName)) {
251
+ fieldPathMap.set(fieldName, relativePath);
252
+ } else {
253
+ const existingPath = fieldPathMap.get(fieldName);
254
+ if (relativePath.length > existingPath.length) {
255
+ fieldPathMap.set(fieldName, relativePath);
256
+ }
257
+ }
258
+ }
259
+ const targetFields = Array.from(fieldPathMap.keys());
260
+ const childValues = [];
261
+ let isValidTable = true;
262
+ let rowCount = 0;
263
+ for (const fieldName of targetFields) {
264
+ const relativePath = fieldPathMap.get(fieldName);
265
+ const fullSubKey = `${mainKey}.${fieldName}`;
266
+ const childArray = [];
267
+ for (let i = 0; i < parentValue.length; i++) {
268
+ const item = parentValue[i];
269
+ const childValue = import_lodash.default.get(item, relativePath);
270
+ const processedValue = processValue(childValue, fullSubKey, collection, app);
271
+ childArray.push(processedValue);
272
+ }
273
+ childValues.push(childArray);
274
+ if (rowCount === 0) {
275
+ rowCount = childArray.length;
276
+ } else if (rowCount !== childArray.length) {
277
+ isValidTable = false;
278
+ }
279
+ }
280
+ if (isValidTable && rowCount > 0) {
281
+ const targetCollection = getTargetCollection(mainKey, collection, app);
282
+ const tableFields = targetFields.map((fieldName, idx) => {
283
+ const childLabel = targetCollection ? getFieldLabel(fieldName, targetCollection) : fieldName;
284
+ return {
285
+ key: fieldName,
286
+ label: childLabel,
287
+ type: import_constants.SUMMARY_TYPE.ARRAY,
288
+ value: childValues[idx]
289
+ };
290
+ });
291
+ summaryDataSource.push({
292
+ key: mainKey,
293
+ label,
294
+ type: import_constants.SUMMARY_TYPE.TABLE,
295
+ value: tableFields
296
+ });
297
+ } else {
298
+ summaryDataSource.push(getSummaryItem(mainKey, data, collection, app));
299
+ }
300
+ }
301
+ } else {
302
+ summaryDataSource.push(getSummaryItem(mainKey, data, collection, app));
303
+ }
304
+ }
305
+ return summaryDataSource;
306
+ }
66
307
  // Annotate the CommonJS export names for ESM import in node:
67
308
  0 && (module.exports = {
68
309
  getSummary,
@@ -58,7 +58,9 @@ const _ApprovalTrigger = class _ApprovalTrigger extends import_module_workflow.T
58
58
  return;
59
59
  }
60
60
  const [dataSourceName, collectionName] = (0, import_server.parseCollectionName)(approval.collectionName);
61
- const { repository } = this.workflow.app.dataSourceManager.dataSources.get(dataSourceName).collectionManager.getCollection(collectionName);
61
+ const dataSource = this.workflow.app.dataSourceManager.dataSources.get(dataSourceName);
62
+ const collection = dataSource.collectionManager.getCollection(collectionName);
63
+ const { repository } = collection;
62
64
  const data = await repository.findOne({
63
65
  filterByTk: approval.get("dataKey"),
64
66
  appends: workflow.config.appends,
@@ -72,7 +74,10 @@ const _ApprovalTrigger = class _ApprovalTrigger extends import_module_workflow.T
72
74
  applicantRoleName: approval.applicantRoleName,
73
75
  summary: (0, import_tools.getSummary)({
74
76
  summaryConfig: workflow.config.summary,
75
- data
77
+ data,
78
+ collection,
79
+ // Fix: type assertion to bypass typing error
80
+ app: this.workflow.app
76
81
  }),
77
82
  collectionName: approval.collectionName
78
83
  },
@@ -239,7 +244,10 @@ const _ApprovalTrigger = class _ApprovalTrigger extends import_module_workflow.T
239
244
  workflowKey: workflow.key,
240
245
  summary: (0, import_tools.getSummary)({
241
246
  summaryConfig: workflow.config.summary,
242
- data
247
+ data,
248
+ collection: collecton,
249
+ // Fix: type assertion to bypass typing error
250
+ app: this.workflow.app
243
251
  })
244
252
  },
245
253
  context
@@ -302,7 +310,9 @@ const _ApprovalTrigger = class _ApprovalTrigger extends import_module_workflow.T
302
310
  applicantRoleName: context.state.currentRole,
303
311
  summary: (0, import_tools.getSummary)({
304
312
  summaryConfig: workflow.config.summary,
305
- data: dataCurrent
313
+ data: dataCurrent,
314
+ collection,
315
+ app: context.app
306
316
  })
307
317
  },
308
318
  context
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@tachybase/plugin-workflow-approval",
3
3
  "displayName": "Approval",
4
- "version": "1.5.1",
4
+ "version": "1.6.0",
5
5
  "description": "Approval base in Workflow",
6
6
  "keywords": [
7
7
  "Approval",
@@ -27,9 +27,9 @@
27
27
  "react-i18next": "16.2.1",
28
28
  "react-router-dom": "6.28.1",
29
29
  "sequelize": "6.37.5",
30
- "@tachybase/module-ui-schema": "1.5.1",
31
- "@tachybase/module-workflow": "1.5.1",
32
- "@tachybase/client": "1.5.1"
30
+ "@tachybase/client": "1.6.0",
31
+ "@tachybase/module-workflow": "1.6.0",
32
+ "@tachybase/module-ui-schema": "1.6.0"
33
33
  },
34
34
  "description.zh-CN": "审批系统是一个强大的BPM工具,为业务流程自动化提供基础支持,同时具备高度灵活性和可扩展性,确保审批流程的效率和合规性,助力企业释放创新潜力。",
35
35
  "displayName.zh-CN": "审批"