@nocobase/plugin-workflow-action-trigger 0.20.0-alpha.6

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 (41) hide show
  1. package/LICENSE +661 -0
  2. package/README.md +9 -0
  3. package/README.zh-CN.md +9 -0
  4. package/client.d.ts +2 -0
  5. package/client.js +1 -0
  6. package/dist/client/ActionTrigger.d.ts +54 -0
  7. package/dist/client/index.d.ts +4 -0
  8. package/dist/client/index.js +1 -0
  9. package/dist/externalVersion.js +13 -0
  10. package/dist/index.d.ts +2 -0
  11. package/dist/index.js +39 -0
  12. package/dist/locale/en-US.json +9 -0
  13. package/dist/locale/index.d.ts +3 -0
  14. package/dist/locale/index.js +39 -0
  15. package/dist/locale/ko_KR.json +9 -0
  16. package/dist/locale/zh-CN.json +10 -0
  17. package/dist/server/ActionTrigger.d.ts +9 -0
  18. package/dist/server/ActionTrigger.js +130 -0
  19. package/dist/server/Plugin.d.ts +4 -0
  20. package/dist/server/Plugin.js +41 -0
  21. package/dist/server/index.d.ts +1 -0
  22. package/dist/server/index.js +33 -0
  23. package/dist/server/migrations/20240227172623-change-name.d.ts +6 -0
  24. package/dist/server/migrations/20240227172623-change-name.js +42 -0
  25. package/package.json +28 -0
  26. package/server.d.ts +2 -0
  27. package/server.js +1 -0
  28. package/src/client/ActionTrigger.tsx +132 -0
  29. package/src/client/__e2e__/configuration.test.ts +661 -0
  30. package/src/client/__e2e__/workflowCRUD.test.ts +178 -0
  31. package/src/client/index.ts +100 -0
  32. package/src/index.ts +2 -0
  33. package/src/locale/en-US.json +9 -0
  34. package/src/locale/index.ts +12 -0
  35. package/src/locale/ko_KR.json +9 -0
  36. package/src/locale/zh-CN.json +10 -0
  37. package/src/server/ActionTrigger.ts +132 -0
  38. package/src/server/Plugin.ts +11 -0
  39. package/src/server/__tests__/trigger.test.ts +503 -0
  40. package/src/server/index.ts +1 -0
  41. package/src/server/migrations/20240227172623-change-name.ts +22 -0
@@ -0,0 +1,132 @@
1
+ import { useForm } from '@formily/react';
2
+
3
+ import {
4
+ SchemaInitializerItemType,
5
+ useCollectionDataSource,
6
+ useCollectionManager_deprecated,
7
+ useCompile,
8
+ } from '@nocobase/client';
9
+ import { Trigger, CollectionBlockInitializer, getCollectionFieldOptions } from '@nocobase/plugin-workflow/client';
10
+ import { NAMESPACE, useLang } from '../locale';
11
+
12
+ export default class extends Trigger {
13
+ title = `{{t("Action event", { ns: "${NAMESPACE}" })}}`;
14
+ description = `{{t("Triggers after specific operations on data are submitted, such as create, update, delete, etc., or directly submitting a record to the workflow.", { ns: "${NAMESPACE}" })}}`;
15
+ fieldset = {
16
+ collection: {
17
+ type: 'string',
18
+ required: true,
19
+ 'x-decorator': 'FormItem',
20
+ 'x-component': 'CollectionSelect',
21
+ 'x-component-props': {
22
+ className: 'auto-width',
23
+ },
24
+ title: `{{t("Collection", { ns: "${NAMESPACE}" })}}`,
25
+ description: `{{t("Which collection record belongs to.", { ns: "${NAMESPACE}" })}}`,
26
+ 'x-reactions': [
27
+ {
28
+ target: 'appends',
29
+ effects: ['onFieldValueChange'],
30
+ fulfill: {
31
+ state: {
32
+ value: [],
33
+ },
34
+ },
35
+ },
36
+ ],
37
+ },
38
+ appends: {
39
+ type: 'array',
40
+ title: `{{t("Associations to use", { ns: "${NAMESPACE}" })}}`,
41
+ description: `{{t("Please select the associated fields that need to be accessed in subsequent nodes. With more than two levels of to-many associations may cause performance issue, please use with caution.", { ns: "workflow" })}}`,
42
+ 'x-decorator': 'FormItem',
43
+ 'x-component': 'AppendsTreeSelect',
44
+ 'x-component-props': {
45
+ title: 'Preload associations',
46
+ multiple: true,
47
+ useCollection() {
48
+ const { values } = useForm();
49
+ return values?.collection;
50
+ },
51
+ },
52
+ 'x-reactions': [
53
+ {
54
+ dependencies: ['collection'],
55
+ fulfill: {
56
+ state: {
57
+ visible: '{{!!$deps[0]}}',
58
+ },
59
+ },
60
+ },
61
+ ],
62
+ },
63
+ };
64
+ scope = {
65
+ useCollectionDataSource,
66
+ };
67
+ isActionTriggerable = (config, context) => {
68
+ return ['create', 'update', 'customize:update', 'customize:triggerWorkflows'].includes(context.action);
69
+ };
70
+ useVariables(config, options) {
71
+ // eslint-disable-next-line react-hooks/rules-of-hooks
72
+ const compile = useCompile();
73
+ // eslint-disable-next-line react-hooks/rules-of-hooks
74
+ const { getCollectionFields } = useCollectionManager_deprecated();
75
+ // eslint-disable-next-line react-hooks/rules-of-hooks
76
+ const langTriggerData = useLang('Trigger data');
77
+ // eslint-disable-next-line react-hooks/rules-of-hooks
78
+ const langUserSubmittedForm = useLang('User submitted action');
79
+ // eslint-disable-next-line react-hooks/rules-of-hooks
80
+ const langRoleSubmittedForm = useLang('Role of user submitted action');
81
+ const rootFields = [
82
+ {
83
+ collectionName: config.collection,
84
+ name: 'data',
85
+ type: 'hasOne',
86
+ target: config.collection,
87
+ uiSchema: {
88
+ title: langTriggerData,
89
+ },
90
+ },
91
+ {
92
+ collectionName: 'users',
93
+ name: 'user',
94
+ type: 'hasOne',
95
+ target: 'users',
96
+ uiSchema: {
97
+ title: langUserSubmittedForm,
98
+ },
99
+ },
100
+ {
101
+ name: 'roleName',
102
+ uiSchema: {
103
+ title: langRoleSubmittedForm,
104
+ },
105
+ },
106
+ ];
107
+ const result = getCollectionFieldOptions({
108
+ // depth,
109
+ appends: ['data', 'user', ...(config.appends?.map((item) => `data.${item}`) || [])],
110
+ ...options,
111
+ fields: rootFields,
112
+ compile,
113
+ getCollectionFields,
114
+ });
115
+ return result;
116
+ }
117
+ useInitializers(config): SchemaInitializerItemType | null {
118
+ if (!config.collection) {
119
+ return null;
120
+ }
121
+
122
+ return {
123
+ name: 'triggerData',
124
+ type: 'item',
125
+ key: 'triggerData',
126
+ title: `{{t("Trigger data", { ns: "${NAMESPACE}" })}}`,
127
+ Component: CollectionBlockInitializer,
128
+ collection: config.collection,
129
+ dataSource: '{{$context.data}}',
130
+ };
131
+ }
132
+ }