impaktapps-ui-builder 0.0.409-k → 0.0.409-m

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.
@@ -1,9 +1,11 @@
1
1
  import { handlersProps } from "./interface";
2
- export declare const executeEvents: (params: handlersProps) => Promise<any>;
3
- export declare function executeRefreshHandler(params: handlersProps): Promise<void>;
4
- export declare function buildApiPayload(compConfig: any, body: any, headers: any, store: any, dynamicData: any, userValue: any, service: any): Promise<{
2
+ export declare const executeEvents: (params: handlersProps) => any;
3
+ export declare function getRefreshElements(eventConfig: any, eventGropus: any): string[];
4
+ export declare function executeRefreshHandler(params: handlersProps): Promise<any[][]>;
5
+ export declare function executeApiRequest(params: any): any;
6
+ export declare function shouldEventExecute(params: handlersProps): any;
7
+ export declare function buildApiPayload(compConfig: any, body: any, headers: any, store: any, dynamicData: any, userValue: any, service: any): {
5
8
  body: any;
6
9
  headers: any;
7
- }>;
8
- export declare function getRefreshElements(eventConfig: any, eventGropus: any): string[];
10
+ };
9
11
  export declare function asyncOperation(): Promise<unknown>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "impaktapps-ui-builder",
3
- "version": "0.0.409k",
3
+ "version": "0.0.409m",
4
4
  "scripts": {
5
5
  "dev": "vite",
6
6
  "build": "tsc && vite build",
@@ -3,13 +3,6 @@ import _ from "lodash";
3
3
  export default (FormData: any) => {
4
4
  const formData = _.cloneDeep(FormData)
5
5
  let component: any = {};
6
- // if (formData?.layout) {
7
- // component.layout = createData(FormData?.layout, "layout");
8
- // delete formData.layout
9
- // }
10
- // if(!formData.type ){
11
- // component.type = "page";
12
- // }
13
6
  if (formData.pageName) {
14
7
  delete formData.pageName
15
8
  }
@@ -56,7 +56,7 @@ export const refreshPage = (type: string, store: any) => {
56
56
 
57
57
  }
58
58
  const elements = sectionLabels[type]?.map(e => sectionUiSchema[e]);
59
- UiSchema.elements[1].config.main.tabLabels = sectionLabels[type] || ["Core", "style", "Event", "Validation"];
59
+ UiSchema.elements[1].config.main.tabLabels = sectionLabels[type] || ["Core", "Style", "Event", "Validation"];
60
60
  UiSchema.elements[1].elements = elements || [CoreSection, StyleSection, EventSection, ValidationSection];
61
61
 
62
62
  }
@@ -1,102 +1,150 @@
1
1
  import _, { cloneDeep } from "lodash";
2
2
  import { handlersProps } from "./interface";
3
3
 
4
-
5
- export const executeEvents = async (
6
- params: handlersProps
7
- ) => {
4
+ export const executeEvents = (params: handlersProps) => {
8
5
  let nextEvent = [];
9
6
  let finalResponse = null;
7
+
8
+ if (params.config.isSync !== "Yes") {
9
+
10
+ return shouldEventExecute(params)
11
+ .then((shouldExecute) => {
12
+ if (!shouldExecute) {
13
+ return { response: undefined, events: undefined };
14
+ }
15
+ return executeEventsHandler(params);
16
+ })
17
+ .then((response) => {
18
+ finalResponse = response;
19
+ const SuccessEvent = params.config?.events.filter(e => e.eventType === "Success");
20
+ nextEvent = SuccessEvent;
21
+ })
22
+ .catch((err) => {
23
+ const FailEvent = params.config?.events?.filter(e => e.eventType === "Fail");
24
+ const setEvent = FailEvent?.length > 0 ? FailEvent : [];
25
+ nextEvent = setEvent;
26
+ })
27
+ .then(() => {
28
+ if (nextEvent?.length > 0) {
29
+ return nextEvent.reduce((chain, actionConfig) => {
30
+ return chain.then(() => executeEvents({ ...params, config: actionConfig, parentEventOutput: finalResponse }));
31
+ }, Promise.resolve());
32
+ }
33
+ })
34
+ .then(() => finalResponse)
35
+ }
36
+ const shouldExecute = shouldEventExecute(params);
37
+ if (!shouldExecute) {
38
+ return { response: undefined, events: undefined };
39
+ }
10
40
  try {
11
- const shouldExecute = await shouldEventExecute(params)
12
- if (!shouldExecute) {
13
- return { response: undefined, events: undefined };
14
- }
15
- const response = await executeEventsHandler(params)
16
- finalResponse = response;
41
+ const eventsResponse = executeEventsHandler(params);
42
+ finalResponse = eventsResponse;
17
43
  const SuccessEvent = params.config?.events.filter(e => e.eventType === "Success");
18
44
  nextEvent = SuccessEvent;
19
- } catch (err) {
20
- const FailEvent = params.config?.events?.filter(e => e.eventType === "Fail")
21
- const setEvent = FailEvent?.length > 0 ? FailEvent : []
45
+ } catch {
46
+ const FailEvent = params.config?.events?.filter(e => e.eventType === "Fail");
47
+ const setEvent = FailEvent?.length > 0 ? FailEvent : [];
22
48
  nextEvent = setEvent;
23
49
  }
24
50
  if (nextEvent?.length > 0) {
25
51
  for (const actionConfig of nextEvent) {
26
- await executeEvents({ ...params, config: actionConfig, parentEventOutput: finalResponse })
52
+ executeEvents({ ...params, config: actionConfig, parentEventOutput: finalResponse })
27
53
  }
28
54
  }
29
55
  return finalResponse;
30
56
  }
31
-
32
- async function executeEventsHandler(params: handlersProps) {
57
+ function executeEventsHandler(params: handlersProps) {
33
58
  if (params.config.Handler === "api") {
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()
59
+ return executeApiRequest(params);
60
+ } else if (params.config.Handler === "inBuiltFunction") {
61
+ return executeInBuiltFunctionHandler(params);
62
+ } else if (params.config.Handler === "custom") {
63
+ return executeCustomHandler(params);
64
+ } else if (params.config.Handler === "refresh") {
65
+ return executeRefreshHandler(params);
66
+ } else if (params.config.Handler === "mergeFormdata") {
67
+ return mergeFormdata(
68
+ params.parentEventOutput,
69
+ params.componentName,
70
+ params.config,
71
+ params.store,
72
+ params.service
73
+ );
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();
58
80
  }
59
81
  }
60
- export async function executeRefreshHandler(params: handlersProps) {
61
- const compToRefresh: string[] = getRefreshElements(params.config, params.eventGroups)
62
- for (const componentName of compToRefresh) {
63
- for (const compEventConfig of params.eventGroups.onLoad[componentName]) {
64
- await executeEvents({ ...params, config: compEventConfig, componentName });
82
+
83
+ export function getRefreshElements(eventConfig: any, eventGropus: any) {
84
+ let result: string[] = [];
85
+ if (eventConfig?.refreshElements?.length > 0) {
86
+ result = eventConfig.refreshElements.map((e) => {
87
+ return e.value
88
+ })
89
+
90
+ } else {
91
+ if (eventGropus?.onLoad) {
92
+ result = Object.keys(eventGropus?.onLoad)
93
+ result.push(result[0]);
65
94
  }
66
95
  }
96
+ console.log(result);
97
+ return result;
67
98
  }
68
- async function executeApiEventHandler(params: handlersProps) {
99
+ export function executeRefreshHandler(params: handlersProps) {
100
+ const compToRefresh: string[] = getRefreshElements(params.config, params.eventGroups);
101
+
102
+ return Promise.all(compToRefresh.map(componentName => {
103
+ return Promise.all(params.eventGroups.onLoad[componentName].map(compEventConfig => {
104
+ return executeEvents({ ...params, config: compEventConfig, componentName });
105
+ }));
106
+ }))
107
+ };
108
+ export function executeApiRequest(params: any) {
69
109
  const initialBody = { ...params.userValue?.payload };
70
110
  const initialHeaders = {
71
111
  "X-Requested-With": "XMLHttpRequest",
72
112
  "Access-Control-Allow-Origin": "*"
73
113
  };
74
- const { body, headers } = await buildApiPayload(params.config, initialBody, initialHeaders, params.store, params.dynamicData, params.userValue, params.service)
75
114
 
76
- const response = await params.service[params.config.method](
115
+ const payloadApi = buildApiPayload(params.config, initialBody, initialHeaders, params.store, params.dynamicData, params.userValue, params.service)
116
+ return params.service[params.config.method](
77
117
  params.config.path,
78
- body,
79
- headers && { headers: headers }
80
- );
81
- return response;
82
- }
118
+ payloadApi.body,
119
+ { headers: payloadApi.headers }
120
+ ).then((response) => {
121
+ return response;
122
+ });
123
+ };
83
124
 
84
- async function executeInBuiltFunctionHandler(params: handlersProps) {
125
+ function executeInBuiltFunctionHandler(params: handlersProps) {
85
126
  let parameter = {};
86
127
  if (params.config.funcParametersCode) {
87
128
  const makeFunc = eval(params.config.funcParametersCode)
88
129
  parameter = makeFunc(params.store, params.dynamicData, params.userValue, params.parentEventOutput, params.service);
130
+ params.serviceHolder[params.config.inBuiltFunctionType](parameter, params.service)
131
+ } else {
132
+ params.serviceHolder[params.config.inBuiltFunctionType](params.store, params.dynamicData, params.userValue, params.parentEventOutput, params.service)
89
133
  }
90
- params.serviceHolder[params.config.inBuiltFunctionType](parameter)
91
134
  }
92
135
 
93
- async function executeCustomHandler(params: handlersProps) {
136
+ function executeCustomHandler(params: handlersProps) {
94
137
  const makeFunc = eval(params.config.eventCode)
95
- const response = await makeFunc(params.store, params.dynamicData, params.userValue, params.parentEventOutput, params.service, params.componentName);
96
- return response;
138
+ if (params.config.isSync !== "Yes") {
139
+ return makeFunc(params.store, params.dynamicData, params.userValue, params.parentEventOutput, params.service, params.componentName).then((res) => res)
140
+ } else {
141
+ const response = makeFunc(params.store, params.dynamicData, params.userValue, params.parentEventOutput, params.service, params.componentName)
142
+ return response;
143
+ }
144
+
97
145
  }
98
146
 
99
- async function mergeFormdata(handlerResponse: any, componentName: string, eventConfig: any, store: any, service: any) {
147
+ function mergeFormdata(handlerResponse: any, componentName: string, eventConfig: any, store: any, service: any) {
100
148
  if (eventConfig.type === "Select" && !(_.isEmpty(handlerResponse?.data) && handlerResponse?.data)) {
101
149
  store.setSchema((pre) => {
102
150
  return {
@@ -131,14 +179,13 @@ async function mergeFormdata(handlerResponse: any, componentName: string, eventC
131
179
  }
132
180
  else {
133
181
  if (handlerResponse) {
134
- store.setFormdata((pre) => { return { ...pre, [componentName]: eventConfig.lazyLoading ? handlerResponse.data.data : handlerResponse.data } });
135
- const demoData = await asyncOperation();
182
+ store.setFormdata((pre) => { return { ...pre, [componentName]: eventConfig.lazyLoading ? handlerResponse?.data?.data : handlerResponse.data } });
136
183
  }
137
184
  }
138
185
  }
139
186
 
140
187
  const buildBodyFormat = (body: any[], formData: any, userValue: any) => {
141
- const finalBody = { ...userValue?.payload };
188
+ let finalBody = { ...userValue?.payload };
142
189
  body.map((elem) => {
143
190
  if (typeof elem?.value !== "string") {
144
191
  finalBody[elem.key] = elem.value;
@@ -150,7 +197,12 @@ const buildBodyFormat = (body: any[], formData: any, userValue: any) => {
150
197
  else if (elem?.value?.startsWith("$")) {
151
198
  const finalpath = elem.value.substring(1);
152
199
  finalBody[elem.key] = _.get(formData, finalpath);;
153
- } else {
200
+ } else if (elem?.value === "*" && elem?.key === "*") {
201
+ finalBody = { ...finalBody, ...formData };
202
+ } else if (elem?.value === "*") {
203
+ finalBody[elem.key] = formData;
204
+ }
205
+ else {
154
206
  finalBody[elem.key] = elem.value;
155
207
  }
156
208
  }
@@ -169,50 +221,45 @@ const buildHeadersFormat = (headers: any[]) => {
169
221
  return headerObj;
170
222
  }
171
223
 
172
- async function shouldEventExecute(params: handlersProps) {
224
+ export function shouldEventExecute(params: handlersProps) {
173
225
  const startEvent = params.config?.events?.filter(e => e.eventType === "onStart");
226
+
174
227
  if (startEvent?.length > 0) {
175
- const response = await executeEventsHandler({ ...params, config: startEvent[0] });
176
- return response;
228
+ if (startEvent[0]?.isSync !== "Yes") {
229
+ return executeEventsHandler({ ...params, config: startEvent[0] }).then((response) => {
230
+ return response;
231
+ });
232
+ } else {
233
+ return executeEventsHandler({ ...params, config: startEvent[0] })
234
+ }
177
235
  } else {
178
- return true
236
+ if (params.config.isSync !== "Yes") {
237
+ return Promise.resolve(true)
238
+ } else {
239
+ return true
240
+ }
179
241
  }
180
242
  }
181
243
 
182
- export async function buildApiPayload(compConfig: any, body: any, headers: any, store: any, dynamicData: any, userValue: any, service) {
183
- if (compConfig?.headers) {
184
- headers = buildHeadersFormat(compConfig.headers)
185
244
 
245
+ export function buildApiPayload(compConfig: any, body: any, headers: any, store: any, dynamicData: any, userValue: any, service) {
246
+ if (compConfig?.headers) {
247
+ headers = buildHeadersFormat(compConfig.headers);
186
248
  }
249
+
187
250
  if (compConfig.body) {
188
251
  body = { ...buildBodyFormat(compConfig.body, store.newData || store?.ctx?.core?.data || store.formData, userValue) };
189
252
  }
190
- if (compConfig.apiBody) {
191
- const makeFunc = eval(compConfig.apiBody);
192
- const data = await makeFunc(store, dynamicData, userValue, body);
193
- body = data
194
- }
195
- return { body, headers };
196
- }
197
253
 
198
- export function getRefreshElements(eventConfig: any, eventGropus: any) {
199
- let result: string[] = [];
200
- if (eventConfig?.refreshElements?.length > 0) {
201
- result = eventConfig.refreshElements.map((e) => {
202
- return e.value
203
- })
254
+ const promiseChain = { body, headers };
204
255
 
205
- } else {
206
- if (eventGropus?.onLoad) {
207
- result = Object.keys(eventGropus?.onLoad)
208
- result.push(result[0]);
209
- }
256
+
257
+ if (compConfig.apiBody) {
258
+ const makeFunc = eval(compConfig.apiBody);
259
+ return { body: makeFunc(store, dynamicData, userValue, promiseChain.body), headers: promiseChain.headers };
210
260
  }
211
- console.log(result);
212
- return result;
261
+ return promiseChain;
213
262
  }
214
-
215
-
216
263
  export function asyncOperation() {
217
264
  return new Promise((resolve, reject) => {
218
265
  setTimeout(() => {
@@ -223,4 +270,4 @@ export function asyncOperation() {
223
270
  }
224
271
  }, 50);
225
272
  });
226
- }
273
+ }