impaktapps-ui-builder 0.0.382-alpha.321 → 0.0.382-alpha.322

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "impaktapps-ui-builder",
3
- "version": "0.0.382-alpha.321",
3
+ "version": "0.0.382-alpha.322",
4
4
  "scripts": {
5
5
  "dev": "vite",
6
6
  "build": "tsc && vite build",
@@ -1,3 +1,4 @@
1
+ import React, { useState, useEffect } from "react";
1
2
  import _, { isEmpty } from "lodash";
2
3
  import { doDownload, downloadFile } from "./downloadFile";
3
4
  import { executeEvents, executeRefreshHandler } from "./events";
@@ -27,20 +28,41 @@ export const extractEvents = (eventConfig: any) => {
27
28
  eventGroups[event.eventType][eventConfigObj.name] = [];
28
29
  }
29
30
  const SuccessEvent = event?.events?.find((elem) => {
30
- return elem.eventType === "Success"
31
- })
32
- if (!(!!SuccessEvent) && event.eventType === "onLoad") {
33
- event.events.push({ Handler: "mergeFormdata", eventType: "Success", type: compType, lazyLoading: eventConfig.lazyLoading === "YES" ? true : false })
31
+ return elem.eventType === "Success";
32
+ });
33
+ if (
34
+ !SuccessEvent &&
35
+ event.eventType === "onLoad"
36
+ ) {
37
+ event.events.push({
38
+ Handler: "mergeFormdata",
39
+ eventType: "Success",
40
+ type: compType,
41
+ lazyLoading: eventConfig.lazyLoading === "YES" ? true : false,
42
+ });
34
43
  }
35
- if (!(!!SuccessEvent) && (event.eventType === "onBack" || event.eventType === "onNext"|| event.eventType === "onReset")) {
36
- event.events.push({ Handler: `${event.eventType}Handler`, eventType: "Success", type: compType, lazyLoading: eventConfig.lazyLoading === "YES" ? true : false })
44
+ if (
45
+ !SuccessEvent &&
46
+ (event.eventType === "onBack" ||
47
+ event.eventType === "onNext" ||
48
+ event.eventType === "onReset")
49
+ ) {
50
+ event.events.push({
51
+ Handler: `${event.eventType}Handler`,
52
+ eventType: "Success",
53
+ type: compType,
54
+ lazyLoading: eventConfig.lazyLoading === "YES" ? true : false,
55
+ });
37
56
  }
38
- eventGroups[event.eventType][eventConfigObj.name].push({ ...event, type: compType })
57
+ eventGroups[event.eventType][eventConfigObj.name].push({
58
+ ...event,
59
+ type: compType,
60
+ });
39
61
  });
40
62
  }
41
63
  }
42
64
 
43
- extractsConfigEvents(eventConfig)
65
+ extractsConfigEvents(eventConfig);
44
66
  if (eventConfig?.elements) {
45
67
  eventConfig.elements.forEach(extractEvents);
46
68
  }
@@ -48,14 +70,15 @@ export const extractEvents = (eventConfig: any) => {
48
70
  };
49
71
 
50
72
  interface funcParamsProps {
51
- store: any,
52
- dynamicData: any,
53
- config: any,
54
- uiSchema: any,
55
- schema: any,
56
- service: any,
57
- userValue: any,
73
+ store: any;
74
+ dynamicData: any;
75
+ config: any;
76
+ uiSchema: any;
77
+ schema: any;
78
+ service: any;
79
+ userValue: any;
58
80
  }
81
+
59
82
  export default (funcParams: funcParamsProps) => {
60
83
  eventGroups = {}
61
84
  eventGroups = extractEvents(funcParams.config)
@@ -64,47 +87,44 @@ export default (funcParams: funcParamsProps) => {
64
87
  store: funcParams.store, dynamicData: funcParams.dynamicData, userValue: funcParams.userValue, service: funcParams.service,
65
88
  serviceHolder: { downloadFile,download:doDownload }, eventGroups
66
89
  };
67
- return {
68
- setPage: async function () {
69
- funcParams.store.setFormdata({});
70
- executeEventsParameters = {
71
- config: {}, componentName: "",
72
- store: funcParams.store, dynamicData: funcParams.dynamicData, userValue: funcParams.userValue, service: funcParams.service,
73
- serviceHolder: this, eventGroups
74
- }
75
- console.log("11 ",funcParams.store.formData);
90
+ const [isReady, setIsReady] = useState(false);
91
+
92
+ useEffect(() => {
93
+ if (isReady) {
94
+ executeRefreshHandler({
95
+ config: {},
96
+ componentName: "",
97
+ store: funcParams.store,
98
+ dynamicData: funcParams.dynamicData,
99
+ userValue: funcParams.userValue,
100
+ service: funcParams.service,
101
+ serviceHolder: this,
102
+ eventGroups,
103
+ });
104
+ }
105
+ }, [funcParams.store.formData]);
76
106
 
77
- const res = await fetch("https://jsonplaceholder.typicode.com/todos");
78
- const resTo = await res.json();
107
+ const setPage = async function () {
108
+ funcParams.store.setFormdata({});
109
+
79
110
 
80
- console.log("22 ",funcParams.store.formData);
111
+ funcParams.store.setSchema(funcParams.schema);
81
112
 
82
- // funcParams.store.setSchema(
83
- // (pre: any) => {
84
- // return {
85
- // ...funcParams.schema, properties:
86
- // { ...funcParams.schema.properties, ...pre.properties, }
87
- // }
88
- // }
89
- // )
90
- funcParams.store.setSchema(funcParams.schema);
113
+ funcParams.uiSchema.elements.push(notifyUiSchema);
114
+ funcParams.store.setUiSchema(funcParams.uiSchema);
115
+ setIsReady(true);
116
+ };
91
117
 
92
- funcParams.uiSchema.elements.push(notifyUiSchema);
93
- funcParams.store.setUiSchema(funcParams.uiSchema);
94
- await executeRefreshHandler({
95
- config: {}, componentName: "",
96
- store: funcParams.store, dynamicData: funcParams.dynamicData, userValue: funcParams.userValue, service: funcParams.service,
97
- serviceHolder: this, eventGroups
98
- })
99
- },
118
+ return {
119
+ setPage,
100
120
  onClick: async function () {
101
- await this.callHandler("onClick")
121
+ await this.callHandler("onClick");
102
122
  },
103
123
  onFileDownload: async function () {
104
- await this.callHandler("onDownload")
124
+ await this.callHandler("onDownload");
105
125
  },
106
126
  onFileUpload: async function () {
107
- await this.callHandler("onUpload")
127
+ await this.callHandler("onUpload");
108
128
  },
109
129
  onPaginationChange: async function (paginationValues) {
110
130
  const apiBody = [
@@ -112,8 +132,8 @@ export default (funcParams: funcParamsProps) => {
112
132
  { key: "pageIndex", value: paginationValues.pagination.pageIndex },
113
133
  { key: "sorting", value: paginationValues.sorting || [] },
114
134
  { key: "filters", value: paginationValues.columnFilters || [] },
115
- { key: "globalFilter", value: paginationValues.globalFilter ?? '' }
116
- ]
135
+ { key: "globalFilter", value: paginationValues.globalFilter ?? "" },
136
+ ];
117
137
  const response = await this.updateConfigApiBody(paginationValues, apiBody);
118
138
  return response?.data;
119
139
  },
@@ -121,97 +141,96 @@ export default (funcParams: funcParamsProps) => {
121
141
  if (param.serachValue !== "" && param.serachValue !== undefined) {
122
142
  const apiBody = [
123
143
  { key: "searchValue", value: param.serachValue },
124
- { key: "currentValue", value: param.currentValue }
125
- ]
126
- return await this.updateConfigApiBody(param, apiBody)
144
+ { key: "currentValue", value: param.currentValue },
145
+ ];
146
+ return await this.updateConfigApiBody(param, apiBody);
127
147
  }
128
148
  },
129
149
  onChange: async function () {
130
150
  if (eventGroups.onChange) {
131
151
  const ChangeEventsKeysArray = Object.keys(eventGroups.onChange);
132
- Promise.all(ChangeEventsKeysArray.map(async (componentName: string) => {
133
- if (
134
- funcParams.store?.formData[componentName] !== funcParams.store.newData[componentName] &&
135
- funcParams.store?.newData[componentName] !== undefined
136
- ) {
137
- for (const eventConfig of eventGroups.onChange[componentName]) {
138
- await executeEvents({
139
- ...executeEventsParameters,
140
- config: eventConfig,
141
- componentName
142
- })
152
+ Promise.all(
153
+ ChangeEventsKeysArray.map(async (componentName: string) => {
154
+ if (
155
+ funcParams.store?.formData[componentName] !==
156
+ funcParams.store.newData[componentName] &&
157
+ funcParams.store?.newData[componentName] !== undefined
158
+ ) {
159
+ for (const eventConfig of eventGroups.onChange[componentName]) {
160
+ await executeEvents({
161
+ ...executeEventsParameters,
162
+ config: eventConfig,
163
+ componentName,
164
+ });
165
+ }
143
166
  }
144
- }
145
- }))
167
+ })
168
+ );
146
169
  }
147
170
  },
148
171
  updateConfigApiBody: async function (paramValue, apiBody) {
149
172
  let LastCallResponse = undefined;
150
173
  for (const eventConfig of eventGroups?.onLoad[paramValue.path]) {
151
174
  if (eventConfig.body) {
152
- eventConfig.body = [
153
- ...eventConfig.body,
154
- ...apiBody
155
- ]
156
- } else { eventConfig.body = apiBody; };
175
+ eventConfig.body = [...eventConfig.body, ...apiBody];
176
+ } else {
177
+ eventConfig.body = apiBody;
178
+ }
157
179
  const responseEvent = eventConfig?.events?.filter((elem) => {
158
- return elem.Handler !== "mergeFormdata"
159
- })
160
- eventConfig.events = responseEvent ?? []
180
+ return elem.Handler !== "mergeFormdata";
181
+ });
182
+ eventConfig.events = responseEvent ?? [];
161
183
  LastCallResponse = await executeEvents({
162
184
  ...executeEventsParameters,
163
185
  config: eventConfig,
164
- componentName: paramValue.path
165
- })
186
+ componentName: paramValue.path,
187
+ });
166
188
  }
167
- return LastCallResponse
189
+ return LastCallResponse;
168
190
  },
169
191
  onBack: async function (functionParameters) {
170
- const path = funcParams.dynamicData?.tableButtonPath || funcParams.dynamicData.path.split(".")[0];
171
- await this.callHandler("onBack", functionParameters)
192
+ const path =
193
+ funcParams.dynamicData?.tableButtonPath ||
194
+ funcParams.dynamicData.path.split(".")[0];
195
+ await this.callHandler("onBack", functionParameters);
172
196
  if (eventGroups?.["onBack"]?.[path] === undefined) {
173
- functionParameters?.handleBack()
197
+ functionParameters?.handleBack();
174
198
  }
175
199
  },
176
200
  onNext: async function (functionParameters) {
177
- const path = funcParams.dynamicData?.tableButtonPath || funcParams.dynamicData.path.split(".")[0];
178
- await this.callHandler("onNext", functionParameters)
201
+ const path =
202
+ funcParams.dynamicData?.tableButtonPath ||
203
+ funcParams.dynamicData.path.split(".")[0];
204
+ await this.callHandler("onNext", functionParameters);
179
205
  if (eventGroups?.["onNext"]?.[path] === undefined) {
180
- functionParameters?.handleNext()
206
+ functionParameters?.handleNext();
181
207
  }
182
208
  },
183
209
  onReset: async function (functionParameters) {
184
- const path = funcParams.dynamicData?.tableButtonPath || funcParams.dynamicData.path.split(".")[0];
185
- await this.callHandler("onReset", functionParameters)
210
+ const path =
211
+ funcParams.dynamicData?.tableButtonPath ||
212
+ funcParams.dynamicData.path.split(".")[0];
213
+ await this.callHandler("onReset", functionParameters);
186
214
  if (eventGroups?.["onReset"]?.[path] === undefined) {
187
- functionParameters?.handleReset()
215
+ functionParameters?.handleReset();
188
216
  }
189
217
  },
190
218
  callHandler: async function (eventType: string, functionParameters?: any) {
191
- const path = funcParams.dynamicData?.tableButtonPath || funcParams.dynamicData.path.split(".")[0];
219
+ const path =
220
+ funcParams.dynamicData?.tableButtonPath ||
221
+ funcParams.dynamicData.path.split(".")[0];
192
222
  if (eventGroups?.[eventType]?.[path] !== undefined) {
193
223
  for (const eventConfig of eventGroups?.[eventType]?.[path]) {
194
- executeEventsParameters.store.functionParameters = functionParameters
224
+ executeEventsParameters.store.functionParameters = functionParameters;
195
225
  await executeEvents({
196
226
  ...executeEventsParameters,
197
227
  config: eventConfig,
198
- componentName: path
199
- })
228
+ componentName: path,
229
+ });
200
230
  }
201
231
  }
202
232
  },
203
233
  downloadFile: downloadFile,
204
- download:doDownload,
234
+ download: doDownload,
205
235
  };
206
236
  };
207
-
208
-
209
-
210
-
211
-
212
-
213
-
214
-
215
-
216
-
217
-