impaktapps-ui-builder 1.0.114-test.1 → 1.0.116

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,4 +1,4 @@
1
- import _ from "lodash";
1
+ import _, { isObject, mapKeys } from "lodash";
2
2
  import { handlersProps } from "./interface";
3
3
  export const executeEvents = (params: handlersProps) => {
4
4
  let nextEvent = [];
@@ -68,8 +68,7 @@ function executeEventsHandler(params: handlersProps) {
68
68
  params.componentName,
69
69
  params.config,
70
70
  params.store,
71
- params.service,
72
- params.formDataHolder
71
+ params.formDataHolder,
73
72
  );
74
73
  } else if (params.config.Handler === "onBackHandler") {
75
74
  return params.store.functionParameters?.handleBack();
@@ -144,8 +143,7 @@ function executeCustomHandler(params: handlersProps) {
144
143
  }
145
144
 
146
145
  }
147
-
148
- function mergeFormdata(handlerResponse: any, componentName: string, eventConfig: any, store: any, service: any, formDataHolder: any) {
146
+ function mergeFormdata(handlerResponse: any, componentName: string, eventConfig: any, store: any, formDataHolder: any) {
149
147
  if (eventConfig.type === "Select" && handlerResponse?.data) {
150
148
  if (!_.isEmpty(handlerResponse?.data)) {
151
149
  store.setSchema((pre) => {
@@ -178,28 +176,30 @@ function mergeFormdata(handlerResponse: any, componentName: string, eventConfig:
178
176
  }
179
177
  }
180
178
  else if (eventConfig.type === "page") {
181
- if (!(_.isEmpty(handlerResponse?.data) && handlerResponse?.data)) {
179
+ if (!(_.isEmpty(handlerResponse?.data) && handlerResponse?.data && isObject(handlerResponse.data))) {
182
180
  store.newData = {
183
181
  ...store.newData,
184
182
  ...handlerResponse?.data
185
183
  }
186
- store.setFormdata((pre: any) => { return { ...pre, ...handlerResponse?.data } })
184
+ const keys = Object.keys(handlerResponse.data)
185
+ keys.map((e) => {
186
+ formDataHolder[e] = handlerResponse.data[e]
187
+ })
188
+
187
189
  }
188
190
  }
189
191
  else if (eventConfig.type === "Table" && eventConfig.lazyLoading) {
190
192
  if (handlerResponse && handlerResponse?.data) {
191
193
  formDataHolder[componentName] = handlerResponse.data?.data
192
194
  formDataHolder[`${componentName}_RowCount`] = handlerResponse.data?.meta?.totalRowCount
193
- store.setFormdata((pre) => { return { ...pre, ...formDataHolder } });
194
195
  }
195
196
  }
196
197
  else {
197
198
  if (handlerResponse) {
198
199
  formDataHolder[componentName] = handlerResponse.data
199
- store.setFormdata((pre) => { return { ...pre, ...formDataHolder } });
200
200
  }
201
201
  }
202
- }
202
+ };
203
203
 
204
204
  const buildBodyFormat = (body: any[], formData: any, userValue: any, store: any) => {
205
205
  let finalBody = { ...userValue?.payload };
@@ -1,5 +1,5 @@
1
1
  import _, { isEmpty } from "lodash";
2
- import { doDownload, downloadFile } from "./downloadFile";
2
+ import { downloadFileFromUrl, downloadFile } from "./downloadFile";
3
3
  import { executeEvents, executeRefreshHandler } from "./events";
4
4
  import { handlersProps } from "./interface";
5
5
  let compType: string;
@@ -62,20 +62,17 @@ export const extractEvents = (eventConfig: any) => {
62
62
  return eventGroups;
63
63
  };
64
64
  export default (funcParams: funcParamsProps) => {
65
- const formDataHolder = {}
65
+ const formDataHolder = {};
66
66
  let executeEventsParameters: handlersProps = {
67
67
  config: {}, componentName: "",
68
68
  store: funcParams.store, dynamicData: funcParams.dynamicData, userValue: funcParams.userValue, service: funcParams.service,
69
- serviceHolder: { downloadFile, download: doDownload, ...funcParams.functionsProvider }, eventGroups,
69
+ serviceHolder: { downloadFile, download: downloadFileFromUrl, ...funcParams.functionsProvider }, eventGroups,
70
70
  functionsProvider: funcParams.functionsProvider, formDataHolder
71
71
  };
72
72
  return {
73
73
  setPage: async function () {
74
74
  funcParams.store.setAdditionalErrors([]);
75
- funcParams.store.setFormdata((pre) => ({
76
- ...pre,
77
- ...(funcParams?.initFormData()),
78
- }));
75
+ funcParams.store.setFormdata(funcParams?.initFormData() || {});
79
76
  funcParams.store.setSchema({ type: "object", properties: {} });
80
77
  funcParams.store.newData = {};
81
78
  eventGroups = {};
@@ -93,7 +90,7 @@ export default (funcParams: funcParamsProps) => {
93
90
  config: {}, componentName: "",
94
91
  store: funcParams.store, dynamicData: funcParams.dynamicData, userValue: funcParams.userValue, service: funcParams.service,
95
92
  functionsProvider: funcParams.functionsProvider,
96
- serviceHolder: this, eventGroups, formDataHolder
93
+ serviceHolder: this, eventGroups, formDataHolder,
97
94
  }
98
95
 
99
96
  funcParams.store.setSchema(
@@ -104,29 +101,32 @@ export default (funcParams: funcParamsProps) => {
104
101
  }
105
102
  }
106
103
  )
107
- await executeRefreshHandler({
104
+ executeRefreshHandler({
108
105
  config: {}, componentName: "",
109
106
  store: funcParams.store, dynamicData: funcParams.dynamicData, userValue: funcParams.userValue, service: funcParams.service,
110
- serviceHolder: this, eventGroups, formDataHolder: {}
111
- })
112
-
113
- uiSchema.elements.push(notifyUiSchema);
114
- funcParams.store.setUiSchema(uiSchema);
107
+ serviceHolder: this, eventGroups, formDataHolder: formDataHolder
108
+ }).then((e) => {
109
+ funcParams.store.setFormdata((pre) => ({ ...pre, ...formDataHolder }))
110
+ uiSchema.elements.push(notifyUiSchema);
111
+ funcParams.store.setUiSchema(uiSchema);
112
+ });
115
113
  },
116
114
  onCellRenderer: (cellParams) => {
117
- if (eventGroups.onCellRenderer) {
115
+ const cloneEventGroup = _.cloneDeep(eventGroups)
116
+ if (cloneEventGroup.onCellRenderer) {
118
117
  let finalResponse = {};
119
118
  const path = funcParams.dynamicData?.tableButtonPath || funcParams?.dynamicData?.path?.split(".")[0];
120
-
121
- for (const eventConfig of eventGroups?.onCellRenderer?.[path]) {
122
- executeEventsParameters.store.functionParameters = cellParams
123
- finalResponse = executeEvents({
124
- ...executeEventsParameters,
125
- config: eventConfig,
126
- componentName: path
127
- })
119
+ if (cloneEventGroup?.onCellRenderer?.[path]) {
120
+ for (const eventConfig of cloneEventGroup?.onCellRenderer?.[path]) {
121
+ executeEventsParameters.store.functionParameters = cellParams
122
+ finalResponse = executeEvents({
123
+ ...executeEventsParameters,
124
+ config: eventConfig,
125
+ componentName: path
126
+ })
127
+ }
128
+ return finalResponse
128
129
  }
129
- return finalResponse
130
130
  }
131
131
  return {}
132
132
  },
@@ -168,7 +168,7 @@ export default (funcParams: funcParamsProps) => {
168
168
  { key: "sorting", value: paginationValues.sorting || [] },
169
169
  { key: "filters", value: paginationValues.tableColumnConfig || [] },
170
170
  { key: "globalFilter", value: paginationValues.globalFilter ?? '' },
171
- { key: "expandedRowIds", value: paginationValues.expandedRowIds ?? []}
171
+ { key: "expandedRowIds", value: paginationValues.expandedRowIds ?? [] }
172
172
  ]
173
173
  const response = await this.callExecuteEvents(paginationValues, apiBody, "onLoad");
174
174
  return response?.data;
@@ -195,8 +195,12 @@ export default (funcParams: funcParamsProps) => {
195
195
  await executeEvents({
196
196
  ...executeEventsParameters,
197
197
  config: eventConfig,
198
- componentName
198
+ componentName,
199
+ formDataHolder
199
200
  })
201
+ if (eventConfig.Handler === "refresh") {
202
+ funcParams.store.setFormdata((pre) => ({ ...pre, ...formDataHolder }));
203
+ }
200
204
  }
201
205
  }
202
206
  }))
@@ -226,40 +230,51 @@ export default (funcParams: funcParamsProps) => {
226
230
  },
227
231
  onBack: async function (functionParameters) {
228
232
  const path = funcParams.dynamicData?.tableButtonPath || funcParams.dynamicData.path.split(".")[0];
229
- await this.callHandler("onBack", functionParameters)
233
+ this.callHandler("onBack", functionParameters)
230
234
  if (eventGroups?.["onBack"]?.[path] === undefined) {
231
235
  functionParameters?.handleBack()
232
236
  }
233
237
  },
234
238
  onNext: async function (functionParameters) {
235
239
  const path = funcParams.dynamicData?.tableButtonPath || funcParams.dynamicData.path.split(".")[0];
236
- await this.callHandler("onNext", functionParameters)
240
+ this.callHandler("onNext", functionParameters)
237
241
  if (eventGroups?.["onNext"]?.[path] === undefined) {
238
242
  functionParameters?.handleNext()
239
243
  }
240
244
  },
241
245
  onReset: async function (functionParameters) {
242
246
  const path = funcParams.dynamicData?.tableButtonPath || funcParams.dynamicData.path.split(".")[0];
243
- await this.callHandler("onReset", functionParameters)
247
+ this.callHandler("onReset", functionParameters)
244
248
  if (eventGroups?.["onReset"]?.[path] === undefined) {
245
249
  functionParameters?.handleReset()
246
250
  }
247
251
  },
248
- callHandler: async function (eventType: string, functionParameters?: any) {
252
+ callHandler: function (eventType: string, functionParameters?: any) {
249
253
  const path = funcParams.dynamicData?.tableButtonPath || funcParams.dynamicData.path.split(".")[funcParams.dynamicData.path.split(".").length - 1];
250
254
  if (eventGroups?.[eventType]?.[path] !== undefined) {
251
- Promise.all(eventGroups?.[eventType]?.[path].map((eventConfig) => {
255
+ (eventGroups?.[eventType]?.[path].map((eventConfig) => {
252
256
  executeEventsParameters.store.functionParameters = functionParameters
253
- executeEvents({
254
- ...executeEventsParameters,
255
- config: eventConfig,
256
- componentName: path
257
- })
257
+ if (eventConfig.Handler === "refresh") {
258
+ executeEvents({
259
+ ...executeEventsParameters,
260
+ config: eventConfig,
261
+ componentName: path,
262
+ formDataHolder: formDataHolder
263
+ }).then((res) => {
264
+ funcParams.store.setFormdata((pre) => ({ ...pre, ...formDataHolder }));
265
+ });
266
+ } else {
267
+ executeEvents({
268
+ ...executeEventsParameters,
269
+ config: eventConfig,
270
+ componentName: path
271
+ })
272
+ }
258
273
  }))
259
274
  }
260
275
  },
261
276
  downloadFile: downloadFile,
262
- download: doDownload,
277
+ downloadFileFromUrl: downloadFileFromUrl,
263
278
  ...funcParams.functionsProvider
264
279
  };
265
280
  };