impaktapps-ui-builder 0.0.382-alpha.335 → 0.0.382-alpha.336

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