impaktapps-ui-builder 0.0.382-alpha.334 → 0.0.382-alpha.335
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.
- package/dist/impaktapps-ui-builder.es.js +49 -76
- package/dist/impaktapps-ui-builder.es.js.map +1 -1
- package/dist/impaktapps-ui-builder.umd.js +11 -11
- package/dist/impaktapps-ui-builder.umd.js.map +1 -1
- package/dist/src/impaktapps-ui-builder/runtime/services/events.d.ts +2 -5
- package/package.json +1 -1
- package/src/impaktapps-ui-builder/runtime/services/events.ts +110 -90
|
@@ -1,11 +1,8 @@
|
|
|
1
1
|
import { handlersProps } from "./interface";
|
|
2
|
-
export declare const executeEvents: (params: handlersProps) => Promise<
|
|
3
|
-
response: any;
|
|
4
|
-
events: any;
|
|
5
|
-
}>;
|
|
2
|
+
export declare const executeEvents: (params: handlersProps) => Promise<any>;
|
|
6
3
|
export declare function executeRefreshHandler(params: handlersProps): Promise<void>;
|
|
7
4
|
export declare function buildApiPayload(compConfig: any, body: any, headers: any, store: any, dynamicData: any, userValue: any, service: any): Promise<{
|
|
8
5
|
body: any;
|
|
9
6
|
headers: any;
|
|
10
7
|
}>;
|
|
11
|
-
export declare function getRefreshElements(eventConfig: any,
|
|
8
|
+
export declare function getRefreshElements(eventConfig: any, eventGroups: any): string[];
|
package/package.json
CHANGED
|
@@ -1,85 +1,103 @@
|
|
|
1
1
|
import _, { cloneDeep } from "lodash";
|
|
2
2
|
import { handlersProps } from "./interface";
|
|
3
3
|
|
|
4
|
-
|
|
4
|
+
// Main function to execute events
|
|
5
5
|
export const executeEvents = async (
|
|
6
6
|
params: handlersProps
|
|
7
7
|
) => {
|
|
8
8
|
let nextEvent = [];
|
|
9
9
|
let finalResponse = null;
|
|
10
|
+
let accumulatedData = {}; // Accumulated data variable
|
|
11
|
+
|
|
10
12
|
try {
|
|
11
|
-
const shouldExecute = await shouldEventExecute(params)
|
|
13
|
+
const shouldExecute = await shouldEventExecute(params);
|
|
12
14
|
if (!shouldExecute) {
|
|
13
15
|
return { response: undefined, events: undefined };
|
|
14
16
|
}
|
|
15
|
-
|
|
17
|
+
|
|
18
|
+
// Execute the event handler and get the response
|
|
19
|
+
const response = await executeEventsHandler(params);
|
|
16
20
|
finalResponse = response;
|
|
21
|
+
|
|
22
|
+
// Check if we need to accumulate data from mergeFormdata handler
|
|
23
|
+
if (params.config.Handler === "mergeFormdata") {
|
|
24
|
+
const data = await mergeFormdata(
|
|
25
|
+
params.parentEventOutput,
|
|
26
|
+
params.componentName,
|
|
27
|
+
params.config,
|
|
28
|
+
params.store,
|
|
29
|
+
params.service
|
|
30
|
+
);
|
|
31
|
+
accumulatedData = { ...accumulatedData, ...data };
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
// Filter events to execute based on success
|
|
17
35
|
const SuccessEvent = params.config?.events.filter(e => e.eventType === "Success");
|
|
18
36
|
nextEvent = SuccessEvent;
|
|
19
37
|
} catch (err) {
|
|
20
|
-
|
|
21
|
-
const
|
|
38
|
+
// Handle failure events
|
|
39
|
+
const FailEvent = params.config?.events?.filter(e => e.eventType === "Fail");
|
|
40
|
+
const setEvent = FailEvent?.length > 0 ? FailEvent : [];
|
|
22
41
|
nextEvent = setEvent;
|
|
23
42
|
}
|
|
43
|
+
|
|
44
|
+
// Execute the next events
|
|
24
45
|
if (nextEvent?.length > 0) {
|
|
25
46
|
for (const actionConfig of nextEvent) {
|
|
26
|
-
await executeEvents({ ...params, config: actionConfig, parentEventOutput: finalResponse })
|
|
47
|
+
const result = await executeEvents({ ...params, config: actionConfig, parentEventOutput: finalResponse });
|
|
48
|
+
accumulatedData = { ...accumulatedData, ...result };
|
|
27
49
|
}
|
|
28
50
|
}
|
|
29
|
-
|
|
51
|
+
|
|
52
|
+
// After all events are processed, update the store with accumulated data
|
|
53
|
+
params.store.setFormdata((pre: any) => ({ ...pre, ...accumulatedData }));
|
|
54
|
+
|
|
55
|
+
return finalResponse;
|
|
30
56
|
}
|
|
31
57
|
|
|
58
|
+
// Handler function execution
|
|
32
59
|
async function executeEventsHandler(params: handlersProps) {
|
|
33
60
|
if (params.config.Handler === "api") {
|
|
34
|
-
const res = await executeApiEventHandler(params)
|
|
35
|
-
const demoData = await asyncOperation();
|
|
61
|
+
const res = await executeApiEventHandler(params);
|
|
36
62
|
return res;
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
else if (params.config.Handler === "custom") {
|
|
42
|
-
const res = await executeCustomHandler(params)
|
|
43
|
-
const demoData = await asyncOperation();
|
|
63
|
+
} else if (params.config.Handler === "inBuiltFunction") {
|
|
64
|
+
return await executeInBuiltFunctionHandler(params);
|
|
65
|
+
} else if (params.config.Handler === "custom") {
|
|
66
|
+
const res = await executeCustomHandler(params);
|
|
44
67
|
return res;
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
const res = await executeRefreshHandler(params)
|
|
48
|
-
const demoData = await asyncOperation();
|
|
49
|
-
return res;
|
|
50
|
-
}
|
|
51
|
-
else if (params.config.Handler === "mergeFormdata") {
|
|
52
|
-
const result = await mergeFormdata(
|
|
53
|
-
params.parentEventOutput, params.componentName, params.config, params.store, params.service)
|
|
54
|
-
const res = result;
|
|
55
|
-
const demoData = await asyncOperation();
|
|
68
|
+
} else if (params.config.Handler === "refresh") {
|
|
69
|
+
const res = await executeRefreshHandler(params);
|
|
56
70
|
return res;
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
return params.
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
else if (params.config.Handler === "onResetHandler") {
|
|
65
|
-
return params.store.functionParameters?.handleReset()
|
|
71
|
+
} else if (params.config.Handler === "mergeFormdata") {
|
|
72
|
+
// Don't call mergeFormdata here. It's already handled in executeEvents.
|
|
73
|
+
return params.parentEventOutput;
|
|
74
|
+
} else if (params.config.Handler === "onBackHandler") {
|
|
75
|
+
return params.store.functionParameters?.handleBack();
|
|
76
|
+
} else if (params.config.Handler === "onNextHandler") {
|
|
77
|
+
return params.store.functionParameters?.handleNext();
|
|
78
|
+
} else if (params.config.Handler === "onResetHandler") {
|
|
79
|
+
return params.store.functionParameters?.handleReset();
|
|
66
80
|
}
|
|
67
81
|
}
|
|
82
|
+
|
|
83
|
+
// Refresh handler function
|
|
68
84
|
export async function executeRefreshHandler(params: handlersProps) {
|
|
69
|
-
const compToRefresh: string[] = getRefreshElements(params.config, params.eventGroups)
|
|
85
|
+
const compToRefresh: string[] = getRefreshElements(params.config, params.eventGroups);
|
|
70
86
|
for (const componentName of compToRefresh) {
|
|
71
87
|
for (const compEventConfig of params.eventGroups.onLoad[componentName]) {
|
|
72
88
|
await executeEvents({ ...params, config: compEventConfig, componentName });
|
|
73
89
|
}
|
|
74
90
|
}
|
|
75
91
|
}
|
|
92
|
+
|
|
93
|
+
// API event handler function
|
|
76
94
|
async function executeApiEventHandler(params: handlersProps) {
|
|
77
95
|
const initialBody = { ...params.userValue?.payload };
|
|
78
96
|
const initialHeaders = {
|
|
79
97
|
"X-Requested-With": "XMLHttpRequest",
|
|
80
98
|
"Access-Control-Allow-Origin": "*"
|
|
81
99
|
};
|
|
82
|
-
const { body, headers } = await buildApiPayload(params.config, initialBody, initialHeaders, params.store, params.dynamicData, params.userValue, params.service)
|
|
100
|
+
const { body, headers } = await buildApiPayload(params.config, initialBody, initialHeaders, params.store, params.dynamicData, params.userValue, params.service);
|
|
83
101
|
|
|
84
102
|
const response = await params.service[params.config.method](
|
|
85
103
|
params.config.path,
|
|
@@ -89,63 +107,65 @@ async function executeApiEventHandler(params: handlersProps) {
|
|
|
89
107
|
return response;
|
|
90
108
|
}
|
|
91
109
|
|
|
110
|
+
// Built-in function event handler
|
|
92
111
|
async function executeInBuiltFunctionHandler(params: handlersProps) {
|
|
93
112
|
let parameter = {};
|
|
94
113
|
if (params.config.funcParametersCode) {
|
|
95
|
-
const makeFunc = eval(params.config.funcParametersCode)
|
|
114
|
+
const makeFunc = eval(params.config.funcParametersCode);
|
|
96
115
|
parameter = makeFunc(params.store, params.dynamicData, params.userValue, params.parentEventOutput, params.service);
|
|
97
116
|
}
|
|
98
|
-
params.serviceHolder[params.config.inBuiltFunctionType](parameter)
|
|
117
|
+
params.serviceHolder[params.config.inBuiltFunctionType](parameter);
|
|
99
118
|
}
|
|
100
119
|
|
|
120
|
+
// Custom handler function
|
|
101
121
|
async function executeCustomHandler(params: handlersProps) {
|
|
102
|
-
const makeFunc = eval(params.config.eventCode)
|
|
122
|
+
const makeFunc = eval(params.config.eventCode);
|
|
103
123
|
const response = await makeFunc(params.store, params.dynamicData, params.userValue, params.parentEventOutput, params.service, params.componentName);
|
|
104
124
|
return response;
|
|
105
125
|
}
|
|
106
126
|
|
|
107
|
-
|
|
127
|
+
// Function to merge form data
|
|
128
|
+
async function mergeFormdata(
|
|
129
|
+
handlerResponse: any,
|
|
130
|
+
componentName: string,
|
|
131
|
+
eventConfig: any,
|
|
132
|
+
store: any,
|
|
133
|
+
service: any
|
|
134
|
+
) {
|
|
135
|
+
let accumulatedData = {};
|
|
136
|
+
|
|
108
137
|
if (eventConfig.type === "Select" && !(_.isEmpty(handlerResponse?.data) && handlerResponse?.data)) {
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
...
|
|
112
|
-
|
|
113
|
-
...pre.properties?.[componentName],
|
|
114
|
-
oneOf: handlerResponse.data
|
|
115
|
-
}
|
|
116
|
-
}
|
|
138
|
+
accumulatedData = {
|
|
139
|
+
[componentName]: {
|
|
140
|
+
...store.schema.properties?.[componentName],
|
|
141
|
+
oneOf: handlerResponse.data
|
|
117
142
|
}
|
|
118
|
-
}
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
type: "array",
|
|
127
|
-
items: {
|
|
128
|
-
oneOf: handlerResponse?.data
|
|
129
|
-
}
|
|
130
|
-
}
|
|
143
|
+
};
|
|
144
|
+
} else if (eventConfig.type === "MultipleSelect" && !(_.isEmpty(handlerResponse?.data) && handlerResponse?.data)) {
|
|
145
|
+
accumulatedData = {
|
|
146
|
+
[componentName]: {
|
|
147
|
+
...store.schema.properties?.[componentName],
|
|
148
|
+
type: "array",
|
|
149
|
+
items: {
|
|
150
|
+
oneOf: handlerResponse?.data
|
|
131
151
|
}
|
|
132
152
|
}
|
|
133
|
-
}
|
|
134
|
-
}
|
|
135
|
-
else if (eventConfig.type === "page") {
|
|
153
|
+
};
|
|
154
|
+
} else if (eventConfig.type === "page") {
|
|
136
155
|
if (!(_.isEmpty(handlerResponse?.data) && handlerResponse?.data)) {
|
|
137
|
-
|
|
138
|
-
const demoData = await asyncOperation();
|
|
156
|
+
accumulatedData = { ...handlerResponse?.data };
|
|
139
157
|
}
|
|
140
|
-
}
|
|
141
|
-
else {
|
|
158
|
+
} else {
|
|
142
159
|
if (handlerResponse) {
|
|
143
|
-
|
|
144
|
-
const demoData = await asyncOperation();
|
|
160
|
+
accumulatedData = { [componentName]: eventConfig.lazyLoading ? handlerResponse.data.data : handlerResponse.data };
|
|
145
161
|
}
|
|
146
162
|
}
|
|
163
|
+
|
|
164
|
+
// Return accumulated data
|
|
165
|
+
return accumulatedData;
|
|
147
166
|
}
|
|
148
167
|
|
|
168
|
+
// Helper functions for building API payloads
|
|
149
169
|
const buildBodyFormat = (body: any[], formData: any, userValue: any) => {
|
|
150
170
|
const finalBody = { ...userValue?.payload };
|
|
151
171
|
body.map((elem) => {
|
|
@@ -154,16 +174,16 @@ const buildBodyFormat = (body: any[], formData: any, userValue: any) => {
|
|
|
154
174
|
} else {
|
|
155
175
|
if (elem?.value?.startsWith("$userValue")) {
|
|
156
176
|
const finalpath = elem.value.substring(11);
|
|
157
|
-
finalBody[elem.key] = _.get(userValue, finalpath)
|
|
177
|
+
finalBody[elem.key] = _.get(userValue, finalpath);
|
|
158
178
|
}
|
|
159
179
|
else if (elem?.value?.startsWith("$")) {
|
|
160
180
|
const finalpath = elem.value.substring(1);
|
|
161
|
-
finalBody[elem.key] = _.get(formData, finalpath)
|
|
181
|
+
finalBody[elem.key] = _.get(formData, finalpath);
|
|
162
182
|
} else {
|
|
163
183
|
finalBody[elem.key] = elem.value;
|
|
164
184
|
}
|
|
165
185
|
}
|
|
166
|
-
})
|
|
186
|
+
});
|
|
167
187
|
return finalBody;
|
|
168
188
|
}
|
|
169
189
|
|
|
@@ -171,27 +191,28 @@ const buildHeadersFormat = (headers: any[]) => {
|
|
|
171
191
|
const headerObj = {
|
|
172
192
|
// "Content-Type": "application/json",
|
|
173
193
|
"X-Requested-With": "XMLHttpRequest"
|
|
174
|
-
}
|
|
194
|
+
};
|
|
175
195
|
headers.map((elem) => {
|
|
176
196
|
headerObj[elem.key] = elem.value;
|
|
177
|
-
})
|
|
197
|
+
});
|
|
178
198
|
return headerObj;
|
|
179
199
|
}
|
|
180
200
|
|
|
201
|
+
// Function to determine if an event should execute
|
|
181
202
|
async function shouldEventExecute(params: handlersProps) {
|
|
182
203
|
const startEvent = params.config?.events?.filter(e => e.eventType === "onStart");
|
|
183
204
|
if (startEvent?.length > 0) {
|
|
184
205
|
const response = await executeEventsHandler({ ...params, config: startEvent[0] });
|
|
185
206
|
return response;
|
|
186
207
|
} else {
|
|
187
|
-
return true
|
|
208
|
+
return true;
|
|
188
209
|
}
|
|
189
210
|
}
|
|
190
211
|
|
|
212
|
+
// Function to build API payload
|
|
191
213
|
export async function buildApiPayload(compConfig: any, body: any, headers: any, store: any, dynamicData: any, userValue: any, service) {
|
|
192
214
|
if (compConfig?.headers) {
|
|
193
|
-
headers = buildHeadersFormat(compConfig.headers)
|
|
194
|
-
|
|
215
|
+
headers = buildHeadersFormat(compConfig.headers);
|
|
195
216
|
}
|
|
196
217
|
if (compConfig.body) {
|
|
197
218
|
body = { ...buildBodyFormat(compConfig.body, store.newData || store?.ctx?.core?.data || store.formData, userValue) };
|
|
@@ -199,21 +220,19 @@ export async function buildApiPayload(compConfig: any, body: any, headers: any,
|
|
|
199
220
|
if (compConfig.apiBody) {
|
|
200
221
|
const makeFunc = eval(compConfig.apiBody);
|
|
201
222
|
const data = await makeFunc(store, dynamicData, userValue, body);
|
|
202
|
-
body = data
|
|
223
|
+
body = data;
|
|
203
224
|
}
|
|
204
225
|
return { body, headers };
|
|
205
226
|
}
|
|
206
227
|
|
|
207
|
-
|
|
228
|
+
// Function to get elements that need refreshing
|
|
229
|
+
export function getRefreshElements(eventConfig: any, eventGroups: any) {
|
|
208
230
|
let result: string[] = [];
|
|
209
231
|
if (eventConfig?.refreshElements?.length > 0) {
|
|
210
|
-
result = eventConfig.refreshElements.map((e) =>
|
|
211
|
-
return e.value
|
|
212
|
-
})
|
|
213
|
-
|
|
232
|
+
result = eventConfig.refreshElements.map((e) => e.value);
|
|
214
233
|
} else {
|
|
215
|
-
if (
|
|
216
|
-
result = Object.keys(
|
|
234
|
+
if (eventGroups?.onLoad) {
|
|
235
|
+
result = Object.keys(eventGroups?.onLoad);
|
|
217
236
|
result.push(result[0]);
|
|
218
237
|
}
|
|
219
238
|
}
|
|
@@ -221,15 +240,16 @@ export function getRefreshElements(eventConfig: any, eventGropus: any) {
|
|
|
221
240
|
return result;
|
|
222
241
|
}
|
|
223
242
|
|
|
224
|
-
|
|
243
|
+
// Mock asynchronous operation
|
|
225
244
|
function asyncOperation() {
|
|
226
245
|
return new Promise((resolve, reject) => {
|
|
227
246
|
setTimeout(() => {
|
|
228
247
|
const success = true;
|
|
229
248
|
if (success) {
|
|
230
249
|
resolve("Operation completed successfully!");
|
|
250
|
+
} else {
|
|
231
251
|
reject(new Error("Operation failed!"));
|
|
232
252
|
}
|
|
233
253
|
}, 50);
|
|
234
254
|
});
|
|
235
|
-
}
|
|
255
|
+
}
|