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

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] = { ...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(
@@ -107,26 +104,28 @@ export default (funcParams: funcParamsProps) => {
107
104
  await executeRefreshHandler({
108
105
  config: {}, componentName: "",
109
106
  store: funcParams.store, dynamicData: funcParams.dynamicData, userValue: funcParams.userValue, service: funcParams.service,
110
- serviceHolder: this, eventGroups, formDataHolder: {}
107
+ serviceHolder: this, eventGroups, formDataHolder: formDataHolder
111
108
  })
112
-
109
+ funcParams.store.setFormdata((pre) => ({ ...pre, ...formDataHolder }))
113
110
  uiSchema.elements.push(notifyUiSchema);
114
111
  funcParams.store.setUiSchema(uiSchema);
115
112
  },
116
113
  onCellRenderer: (cellParams) => {
117
- if (eventGroups.onCellRenderer) {
114
+ const cloneEventGroup = _.cloneDeep(eventGroups)
115
+ if (cloneEventGroup.onCellRenderer) {
118
116
  let finalResponse = {};
119
117
  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
- })
118
+ if (cloneEventGroup?.onCellRenderer?.[path]) {
119
+ for (const eventConfig of cloneEventGroup?.onCellRenderer?.[path]) {
120
+ executeEventsParameters.store.functionParameters = cellParams
121
+ finalResponse = executeEvents({
122
+ ...executeEventsParameters,
123
+ config: eventConfig,
124
+ componentName: path
125
+ })
126
+ }
127
+ return finalResponse
128
128
  }
129
- return finalResponse
130
129
  }
131
130
  return {}
132
131
  },
@@ -168,7 +167,7 @@ export default (funcParams: funcParamsProps) => {
168
167
  { key: "sorting", value: paginationValues.sorting || [] },
169
168
  { key: "filters", value: paginationValues.tableColumnConfig || [] },
170
169
  { key: "globalFilter", value: paginationValues.globalFilter ?? '' },
171
- { key: "expandedRowIds", value: paginationValues.expandedRowIds ?? []}
170
+ { key: "expandedRowIds", value: paginationValues.expandedRowIds ?? [] }
172
171
  ]
173
172
  const response = await this.callExecuteEvents(paginationValues, apiBody, "onLoad");
174
173
  return response?.data;
@@ -197,6 +196,9 @@ export default (funcParams: funcParamsProps) => {
197
196
  config: eventConfig,
198
197
  componentName
199
198
  })
199
+ if (eventConfig.Handler === "refresh") {
200
+ funcParams.store.setFormdata((pre) => ({ ...pre, ...formDataHolder }));
201
+ }
200
202
  }
201
203
  }
202
204
  }))
@@ -226,40 +228,51 @@ export default (funcParams: funcParamsProps) => {
226
228
  },
227
229
  onBack: async function (functionParameters) {
228
230
  const path = funcParams.dynamicData?.tableButtonPath || funcParams.dynamicData.path.split(".")[0];
229
- await this.callHandler("onBack", functionParameters)
231
+ this.callHandler("onBack", functionParameters)
230
232
  if (eventGroups?.["onBack"]?.[path] === undefined) {
231
233
  functionParameters?.handleBack()
232
234
  }
233
235
  },
234
236
  onNext: async function (functionParameters) {
235
237
  const path = funcParams.dynamicData?.tableButtonPath || funcParams.dynamicData.path.split(".")[0];
236
- await this.callHandler("onNext", functionParameters)
238
+ this.callHandler("onNext", functionParameters)
237
239
  if (eventGroups?.["onNext"]?.[path] === undefined) {
238
240
  functionParameters?.handleNext()
239
241
  }
240
242
  },
241
243
  onReset: async function (functionParameters) {
242
244
  const path = funcParams.dynamicData?.tableButtonPath || funcParams.dynamicData.path.split(".")[0];
243
- await this.callHandler("onReset", functionParameters)
245
+ this.callHandler("onReset", functionParameters)
244
246
  if (eventGroups?.["onReset"]?.[path] === undefined) {
245
247
  functionParameters?.handleReset()
246
248
  }
247
249
  },
248
- callHandler: async function (eventType: string, functionParameters?: any) {
250
+ callHandler: function (eventType: string, functionParameters?: any) {
249
251
  const path = funcParams.dynamicData?.tableButtonPath || funcParams.dynamicData.path.split(".")[funcParams.dynamicData.path.split(".").length - 1];
250
252
  if (eventGroups?.[eventType]?.[path] !== undefined) {
251
- Promise.all(eventGroups?.[eventType]?.[path].map((eventConfig) => {
253
+ (eventGroups?.[eventType]?.[path].map((eventConfig) => {
252
254
  executeEventsParameters.store.functionParameters = functionParameters
253
- executeEvents({
254
- ...executeEventsParameters,
255
- config: eventConfig,
256
- componentName: path
257
- })
255
+ if (eventConfig.Handler === "refresh") {
256
+ executeEvents({
257
+ ...executeEventsParameters,
258
+ config: eventConfig,
259
+ componentName: path,
260
+ formDataHolder: formDataHolder
261
+ }).then((res) => {
262
+ funcParams.store.setFormdata((pre) => ({ ...pre, ...formDataHolder }));
263
+ });
264
+ } else {
265
+ executeEvents({
266
+ ...executeEventsParameters,
267
+ config: eventConfig,
268
+ componentName: path
269
+ })
270
+ }
258
271
  }))
259
272
  }
260
273
  },
261
274
  downloadFile: downloadFile,
262
- download: doDownload,
275
+ downloadFileFromUrl: downloadFileFromUrl,
263
276
  ...funcParams.functionsProvider
264
277
  };
265
278
  };