impaktapps-ui-builder 0.0.409-h → 0.0.409-k

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,148 +1,102 @@
1
- import _ from "lodash";
1
+ import _, { cloneDeep } from "lodash";
2
2
  import { handlersProps } from "./interface";
3
3
 
4
- export const executeEvents = (params: handlersProps) => {
4
+
5
+ export const executeEvents = async (
6
+ params: handlersProps
7
+ ) => {
5
8
  let nextEvent = [];
6
9
  let finalResponse = null;
7
-
8
- if (params.config.isSync !== "Yes") {
9
- return shouldEventExecute(params)
10
- .then((shouldExecute) => {
11
- if (!shouldExecute) {
12
- return { response: undefined, events: undefined };
13
- }
14
- return executeEventsHandler(params);
15
- })
16
- .then((response) => {
17
- finalResponse = response;
18
- const SuccessEvent = params.config?.events.filter(e => e.eventType === "Success");
19
- nextEvent = SuccessEvent;
20
- })
21
- .catch((err) => {
22
- const FailEvent = params.config?.events?.filter(e => e.eventType === "Fail");
23
- const setEvent = FailEvent?.length > 0 ? FailEvent : [];
24
- nextEvent = setEvent;
25
- })
26
- .then(() => {
27
- if (nextEvent?.length > 0) {
28
- return nextEvent.reduce((chain, actionConfig) => {
29
- return chain.then(() => executeEvents({ ...params, config: actionConfig, parentEventOutput: finalResponse }));
30
- }, Promise.resolve());
31
- }
32
- })
33
- .then(() => finalResponse)
34
- }
35
- const shouldExecute = shouldEventExecute(params);
36
- if (!shouldExecute) {
37
- return { response: undefined, events: undefined };
38
- }
39
10
  try {
40
- const eventsResponse = executeEventsHandler(params);
41
- finalResponse = eventsResponse;
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;
42
17
  const SuccessEvent = params.config?.events.filter(e => e.eventType === "Success");
43
18
  nextEvent = SuccessEvent;
44
- } catch {
45
- const FailEvent = params.config?.events?.filter(e => e.eventType === "Fail");
46
- const setEvent = FailEvent?.length > 0 ? FailEvent : [];
19
+ } catch (err) {
20
+ const FailEvent = params.config?.events?.filter(e => e.eventType === "Fail")
21
+ const setEvent = FailEvent?.length > 0 ? FailEvent : []
47
22
  nextEvent = setEvent;
48
23
  }
49
24
  if (nextEvent?.length > 0) {
50
25
  for (const actionConfig of nextEvent) {
51
- executeEvents({ ...params, config: actionConfig, parentEventOutput: finalResponse })
26
+ await executeEvents({ ...params, config: actionConfig, parentEventOutput: finalResponse })
52
27
  }
53
28
  }
54
29
  return finalResponse;
55
30
  }
56
- function executeEventsHandler(params: handlersProps) {
31
+
32
+ async function executeEventsHandler(params: handlersProps) {
57
33
  if (params.config.Handler === "api") {
58
- return executeApiRequest(params);
59
- } else if (params.config.Handler === "inBuiltFunction") {
60
- return executeInBuiltFunctionHandler(params);
61
- } else if (params.config.Handler === "custom") {
62
- return executeCustomHandler(params);
63
- } else if (params.config.Handler === "refresh") {
64
- return executeRefreshHandler(params);
65
- } else if (params.config.Handler === "mergeFormdata") {
66
- return mergeFormdata(
67
- params.parentEventOutput,
68
- params.componentName,
69
- params.config,
70
- params.store,
71
- params.service
72
- );
73
- } else if (params.config.Handler === "onBackHandler") {
74
- return params.store.functionParameters?.handleBack();
75
- } else if (params.config.Handler === "onNextHandler") {
76
- return params.store.functionParameters?.handleNext();
77
- } else if (params.config.Handler === "onResetHandler") {
78
- 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()
79
58
  }
80
59
  }
81
-
82
- export function getRefreshElements(eventConfig: any, eventGropus: any) {
83
- let result: string[] = [];
84
- if (eventConfig?.refreshElements?.length > 0) {
85
- result = eventConfig.refreshElements.map((e) => {
86
- return e.value
87
- })
88
-
89
- } else {
90
- if (eventGropus?.onLoad) {
91
- result = Object.keys(eventGropus?.onLoad)
92
- result.push(result[0]);
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 });
93
65
  }
94
66
  }
95
- return result;
96
67
  }
97
- export function executeRefreshHandler(params: handlersProps) {
98
- const compToRefresh: string[] = getRefreshElements(params.config, params.eventGroups);
99
-
100
- return Promise.all(compToRefresh.map(componentName => {
101
- return Promise.all(params.eventGroups.onLoad[componentName].map(compEventConfig => {
102
- return executeEvents({ ...params, config: compEventConfig, componentName });
103
- }));
104
- }))
105
- };
106
- export function executeApiRequest(params: any) {
68
+ async function executeApiEventHandler(params: handlersProps) {
107
69
  const initialBody = { ...params.userValue?.payload };
108
70
  const initialHeaders = {
109
71
  "X-Requested-With": "XMLHttpRequest",
110
72
  "Access-Control-Allow-Origin": "*"
111
73
  };
74
+ const { body, headers } = await buildApiPayload(params.config, initialBody, initialHeaders, params.store, params.dynamicData, params.userValue, params.service)
112
75
 
113
- const payloadApi = buildApiPayload(params.config, initialBody, initialHeaders, params.store, params.dynamicData, params.userValue, params.service)
114
- return params.service[params.config.method](
76
+ const response = await params.service[params.config.method](
115
77
  params.config.path,
116
- payloadApi.body,
117
- { headers: payloadApi.headers }
118
- ).then((response) => {
119
- return response;
120
- });
121
- };
78
+ body,
79
+ headers && { headers: headers }
80
+ );
81
+ return response;
82
+ }
122
83
 
123
- function executeInBuiltFunctionHandler(params: handlersProps) {
84
+ async function executeInBuiltFunctionHandler(params: handlersProps) {
124
85
  let parameter = {};
125
86
  if (params.config.funcParametersCode) {
126
87
  const makeFunc = eval(params.config.funcParametersCode)
127
88
  parameter = makeFunc(params.store, params.dynamicData, params.userValue, params.parentEventOutput, params.service);
128
- params.serviceHolder[params.config.inBuiltFunctionType](parameter, params.service)
129
- } else {
130
- params.serviceHolder[params.config.inBuiltFunctionType](params.store, params.dynamicData, params.userValue, params.parentEventOutput, params.service)
131
89
  }
90
+ params.serviceHolder[params.config.inBuiltFunctionType](parameter)
132
91
  }
133
92
 
134
- function executeCustomHandler(params: handlersProps) {
93
+ async function executeCustomHandler(params: handlersProps) {
135
94
  const makeFunc = eval(params.config.eventCode)
136
- if (params.config.isSync !== "Yes") {
137
- makeFunc(params.store, params.dynamicData, params.userValue, params.parentEventOutput, params.service, params.componentName).then((res) => res)
138
- } else {
139
- const response = makeFunc(params.store, params.dynamicData, params.userValue, params.parentEventOutput, params.service, params.componentName)
140
- return response;
141
- }
142
-
95
+ const response = await makeFunc(params.store, params.dynamicData, params.userValue, params.parentEventOutput, params.service, params.componentName);
96
+ return response;
143
97
  }
144
98
 
145
- function mergeFormdata(handlerResponse: any, componentName: string, eventConfig: any, store: any, service: any) {
99
+ async function mergeFormdata(handlerResponse: any, componentName: string, eventConfig: any, store: any, service: any) {
146
100
  if (eventConfig.type === "Select" && !(_.isEmpty(handlerResponse?.data) && handlerResponse?.data)) {
147
101
  store.setSchema((pre) => {
148
102
  return {
@@ -177,13 +131,14 @@ function mergeFormdata(handlerResponse: any, componentName: string, eventConfig:
177
131
  }
178
132
  else {
179
133
  if (handlerResponse) {
180
- store.setFormdata((pre) => { return { ...pre, [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();
181
136
  }
182
137
  }
183
138
  }
184
139
 
185
140
  const buildBodyFormat = (body: any[], formData: any, userValue: any) => {
186
- let finalBody = { ...userValue?.payload };
141
+ const finalBody = { ...userValue?.payload };
187
142
  body.map((elem) => {
188
143
  if (typeof elem?.value !== "string") {
189
144
  finalBody[elem.key] = elem.value;
@@ -195,12 +150,7 @@ const buildBodyFormat = (body: any[], formData: any, userValue: any) => {
195
150
  else if (elem?.value?.startsWith("$")) {
196
151
  const finalpath = elem.value.substring(1);
197
152
  finalBody[elem.key] = _.get(formData, finalpath);;
198
- } else if (elem?.value === "*" && elem?.key === "*") {
199
- finalBody = { ...finalBody, ...formData };
200
- } else if (elem?.value === "*") {
201
- finalBody[elem.key] = formData;
202
- }
203
- else {
153
+ } else {
204
154
  finalBody[elem.key] = elem.value;
205
155
  }
206
156
  }
@@ -219,40 +169,58 @@ const buildHeadersFormat = (headers: any[]) => {
219
169
  return headerObj;
220
170
  }
221
171
 
222
- export function shouldEventExecute(params: handlersProps) {
172
+ async function shouldEventExecute(params: handlersProps) {
223
173
  const startEvent = params.config?.events?.filter(e => e.eventType === "onStart");
224
-
225
174
  if (startEvent?.length > 0) {
226
- return executeEventsHandler({ ...params, config: startEvent[0] }).then((response) => {
227
- return response;
228
- });
175
+ const response = await executeEventsHandler({ ...params, config: startEvent[0] });
176
+ return response;
229
177
  } else {
230
- if (params.config.isSync !== "Yes") {
231
- return Promise.resolve(true)
232
- } else {
233
- return true
234
- }
178
+ return true
235
179
  }
236
180
  }
237
181
 
238
-
239
- export function buildApiPayload(compConfig: any, body: any, headers: any, store: any, dynamicData: any, userValue: any, service) {
182
+ export async function buildApiPayload(compConfig: any, body: any, headers: any, store: any, dynamicData: any, userValue: any, service) {
240
183
  if (compConfig?.headers) {
241
- headers = buildHeadersFormat(compConfig.headers);
242
- }
184
+ headers = buildHeadersFormat(compConfig.headers)
243
185
 
186
+ }
244
187
  if (compConfig.body) {
245
188
  body = { ...buildBodyFormat(compConfig.body, store.newData || store?.ctx?.core?.data || store.formData, userValue) };
246
189
  }
247
-
248
- const promiseChain = { body, headers };
249
-
250
-
251
190
  if (compConfig.apiBody) {
252
191
  const makeFunc = eval(compConfig.apiBody);
253
- return { body: makeFunc(store, dynamicData, userValue, promiseChain.body), headers: promiseChain.headers };
254
- // return result;
192
+ const data = await makeFunc(store, dynamicData, userValue, body);
193
+ body = data
194
+ }
195
+ return { body, headers };
196
+ }
197
+
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
+ })
255
204
 
205
+ } else {
206
+ if (eventGropus?.onLoad) {
207
+ result = Object.keys(eventGropus?.onLoad)
208
+ result.push(result[0]);
209
+ }
256
210
  }
257
- return promiseChain;
211
+ console.log(result);
212
+ return result;
213
+ }
214
+
215
+
216
+ export function asyncOperation() {
217
+ return new Promise((resolve, reject) => {
218
+ setTimeout(() => {
219
+ const success = true;
220
+ if (success) {
221
+ resolve("Operation completed successfully!");
222
+ reject(new Error("Operation failed!"));
223
+ }
224
+ }, 50);
225
+ });
258
226
  }
@@ -1,6 +1,6 @@
1
1
  import _, { isEmpty } from "lodash";
2
2
  import { doDownload, downloadFile } from "./downloadFile";
3
- import { executeEvents, executeRefreshHandler } from "./events";
3
+ import { asyncOperation, executeEvents, executeRefreshHandler } from "./events";
4
4
  import { handlersProps } from "./interface";
5
5
  let compType: string;
6
6
  let eventGroups: any = {};
@@ -13,14 +13,6 @@ const notifyUiSchema = {
13
13
  layout: 6,
14
14
  };
15
15
 
16
- interface funcParamsProps {
17
- store: any,
18
- dynamicData: any,
19
- service: any,
20
- userValue: any,
21
- functionsProvider?: Record<string, any>
22
- }
23
-
24
16
  export const extractEvents = (eventConfig: any) => {
25
17
  function extractsConfigEvents(eventConfigObj: any) {
26
18
  if (eventConfigObj.events) {
@@ -54,53 +46,41 @@ export const extractEvents = (eventConfig: any) => {
54
46
  }
55
47
  return eventGroups;
56
48
  };
49
+
50
+ interface funcParamsProps {
51
+ store: any,
52
+ dynamicData: any,
53
+ config: any,
54
+ uiSchema: any,
55
+ schema: any,
56
+ service: any,
57
+ userValue: any,
58
+ }
57
59
  export default (funcParams: funcParamsProps) => {
60
+ eventGroups = {}
61
+ eventGroups = extractEvents(funcParams.config)
58
62
  let executeEventsParameters: handlersProps = {
59
63
  config: {}, componentName: "",
60
64
  store: funcParams.store, dynamicData: funcParams.dynamicData, userValue: funcParams.userValue, service: funcParams.service,
61
- serviceHolder: { downloadFile, download: doDownload, ...funcParams.functionsProvider }, eventGroups,
62
- functionsProvider: funcParams.functionsProvider,
65
+ serviceHolder: { downloadFile, download: doDownload }, eventGroups
63
66
  };
64
67
  return {
65
68
  setPage: async function () {
66
- funcParams.store.setFormdata({})
67
- const data = JSON.stringify({
68
- pageName: funcParams.store.pageName
69
- });
70
- let pageData;
71
- const pageBasicDetailString = localStorage.getItem("pagemasterMetaData")
72
- if (pageBasicDetailString) {
73
- pageData = JSON.parse(pageBasicDetailString)
74
- } else {
75
- const pageId = await funcParams.service
76
- .post("/page/getByName", data, {
77
- headers: {
78
- "Content-Type": "application/json",
79
- },
80
- });
81
- const response = await funcParams.service.get(
82
- `/page/getById?id=${pageId?.data?.id}`,
83
- {
84
- headers: {
85
- "Content-Type": "application/json",
86
- },
69
+ funcParams.store.setFormdata({});
70
+ funcParams.store.setSchema(
71
+ (pre: any) => {
72
+ return {
73
+ ...funcParams.schema, properties:
74
+ { ...funcParams.schema.properties, ...pre.properties, }
87
75
  }
88
- );
89
- pageData = response.data;
90
- localStorage.setItem("pagemasterMetaData", JSON.stringify({
91
- schema: pageData?.schema,
92
- uiSchema: pageData?.uiSchema, config: pageData?.config
93
- }))
94
- }
95
- const config = pageData?.config;
96
- const uiSchema = pageData?.uiSchema;
97
- const schema = pageData?.schema ?? { type: "object", properties: {} };
98
- eventGroups = {}
99
- eventGroups = extractEvents(config);
76
+ }
77
+ )
78
+ funcParams.uiSchema.elements.push(notifyUiSchema);
79
+ funcParams.store.setUiSchema(funcParams.uiSchema);
80
+ await asyncOperation()
100
81
  executeEventsParameters = {
101
82
  config: {}, componentName: "",
102
83
  store: funcParams.store, dynamicData: funcParams.dynamicData, userValue: funcParams.userValue, service: funcParams.service,
103
- functionsProvider: funcParams.functionsProvider,
104
84
  serviceHolder: this, eventGroups
105
85
  }
106
86
  await executeRefreshHandler({
@@ -108,47 +88,15 @@ export default (funcParams: funcParamsProps) => {
108
88
  store: funcParams.store, dynamicData: funcParams.dynamicData, userValue: funcParams.userValue, service: funcParams.service,
109
89
  serviceHolder: this, eventGroups
110
90
  })
111
- funcParams.store.setSchema(
112
- (pre: any) => {
113
- return {
114
- ...schema, properties:
115
- { ...schema.properties, ...pre.properties, }
116
- }
117
- }
118
- )
119
- uiSchema.elements.push(notifyUiSchema);
120
- funcParams.store.setUiSchema(uiSchema);
121
-
122
- },
123
- onCellRenderer: (cellParams) => {
124
- let finalResponse = {};
125
- cellParams.spanRef.current.style.color = "yellow";
126
- const path = funcParams.dynamicData?.tableButtonPath || funcParams.dynamicData.path.split(".")[0];
127
- for (const eventConfig of eventGroups?.onCellRenderer[path]) {
128
- executeEventsParameters.store.functionParameters = cellParams
129
- finalResponse = executeEvents({
130
- ...executeEventsParameters,
131
- config: eventConfig,
132
- componentName: path
133
- })
134
- }
135
- console.log("finalResponse >> >> >> ", finalResponse)
136
- return finalResponse
137
- },
138
- onClick: function () {
139
- this.callHandler("onClick")
140
91
  },
141
- onMount: function () {
142
- this.callHandler("onMount")
92
+ onClick: async function () {
93
+ await this.callHandler("onClick")
143
94
  },
144
- onFileDownload: function () {
145
- this.callHandler("onDownload")
95
+ onFileDownload: async function () {
96
+ await this.callHandler("onDownload")
146
97
  },
147
- onFileUpload: function () {
148
- this.callHandler("onUpload")
149
- },
150
- backHandler: function () {
151
- funcParams.store.navigate(-1)
98
+ onFileUpload: async function () {
99
+ await this.callHandler("onUpload")
152
100
  },
153
101
  onPaginationChange: async function (paginationValues) {
154
102
  const apiBody = [
@@ -167,8 +115,7 @@ export default (funcParams: funcParamsProps) => {
167
115
  { key: "searchValue", value: param.serachValue },
168
116
  { key: "currentValue", value: param.currentValue }
169
117
  ]
170
- const response = await this.updateConfigApiBody(param, apiBody);
171
- return response?.data;
118
+ return await this.updateConfigApiBody(param, apiBody)
172
119
  }
173
120
  },
174
121
  onChange: async function () {
@@ -237,7 +184,7 @@ export default (funcParams: funcParamsProps) => {
237
184
  if (eventGroups?.[eventType]?.[path] !== undefined) {
238
185
  for (const eventConfig of eventGroups?.[eventType]?.[path]) {
239
186
  executeEventsParameters.store.functionParameters = functionParameters
240
- executeEvents({
187
+ await executeEvents({
241
188
  ...executeEventsParameters,
242
189
  config: eventConfig,
243
190
  componentName: path
@@ -245,10 +192,8 @@ export default (funcParams: funcParamsProps) => {
245
192
  }
246
193
  }
247
194
  },
248
-
249
195
  downloadFile: downloadFile,
250
196
  download: doDownload,
251
- ...funcParams.functionsProvider
252
197
  };
253
198
  };
254
199
 
@@ -256,3 +201,9 @@ export default (funcParams: funcParamsProps) => {
256
201
 
257
202
 
258
203
 
204
+
205
+
206
+
207
+
208
+
209
+