impaktapps-ui-builder 0.0.409-k → 0.0.409-l

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,10 @@
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[];
9
- export declare function asyncOperation(): Promise<unknown>;
10
+ };
@@ -1,18 +1,19 @@
1
- export declare const extractEvents: (eventConfig: any) => any;
2
1
  interface funcParamsProps {
3
2
  store: any;
4
3
  dynamicData: any;
5
- config: any;
6
- uiSchema: any;
7
- schema: any;
8
4
  service: any;
9
5
  userValue: any;
6
+ functionsProvider?: Record<string, any>;
10
7
  }
8
+ export declare const extractEvents: (eventConfig: any) => any;
11
9
  declare const _default: (funcParams: funcParamsProps) => {
12
10
  setPage: () => Promise<void>;
13
- onClick: () => Promise<void>;
14
- onFileDownload: () => Promise<void>;
15
- onFileUpload: () => Promise<void>;
11
+ onCellRenderer: (cellParams: any) => {};
12
+ onClick: () => void;
13
+ onMount: () => void;
14
+ onFileDownload: () => void;
15
+ onFileUpload: () => void;
16
+ backHandler: () => void;
16
17
  onPaginationChange: (paginationValues: any) => Promise<any>;
17
18
  getSelectOptions: (param: any) => Promise<any>;
18
19
  onChange: () => Promise<void>;
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.409l",
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
  }
@@ -1,102 +1,149 @@
1
- import _, { cloneDeep } from "lodash";
2
- import { handlersProps } from "./interface";
3
1
 
2
+ import _ from "lodash";
3
+ import { handlersProps } from "./interface";
4
4
 
5
- export const executeEvents = async (
6
- params: handlersProps
7
- ) => {
5
+ export const executeEvents = (params: handlersProps) => {
8
6
  let nextEvent = [];
9
7
  let finalResponse = null;
8
+
9
+ if (params.config.isSync !== "Yes") {
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
+ return result;
67
97
  }
68
- async function executeApiEventHandler(params: handlersProps) {
98
+ export function executeRefreshHandler(params: handlersProps) {
99
+ const compToRefresh: string[] = getRefreshElements(params.config, params.eventGroups);
100
+
101
+ return Promise.all(compToRefresh.map(componentName => {
102
+ return Promise.all(params.eventGroups.onLoad[componentName].map(compEventConfig => {
103
+ return executeEvents({ ...params, config: compEventConfig, componentName });
104
+ }));
105
+ }))
106
+ };
107
+ export function executeApiRequest(params: any) {
69
108
  const initialBody = { ...params.userValue?.payload };
70
109
  const initialHeaders = {
71
110
  "X-Requested-With": "XMLHttpRequest",
72
111
  "Access-Control-Allow-Origin": "*"
73
112
  };
74
- const { body, headers } = await buildApiPayload(params.config, initialBody, initialHeaders, params.store, params.dynamicData, params.userValue, params.service)
75
113
 
76
- const response = await params.service[params.config.method](
114
+ const payloadApi = buildApiPayload(params.config, initialBody, initialHeaders, params.store, params.dynamicData, params.userValue, params.service)
115
+ return params.service[params.config.method](
77
116
  params.config.path,
78
- body,
79
- headers && { headers: headers }
80
- );
81
- return response;
82
- }
117
+ payloadApi.body,
118
+ { headers: payloadApi.headers }
119
+ ).then((response) => {
120
+ return response;
121
+ });
122
+ };
83
123
 
84
- async function executeInBuiltFunctionHandler(params: handlersProps) {
124
+ function executeInBuiltFunctionHandler(params: handlersProps) {
85
125
  let parameter = {};
86
126
  if (params.config.funcParametersCode) {
87
127
  const makeFunc = eval(params.config.funcParametersCode)
88
128
  parameter = makeFunc(params.store, params.dynamicData, params.userValue, params.parentEventOutput, params.service);
129
+ params.serviceHolder[params.config.inBuiltFunctionType](parameter, params.service)
130
+ } else {
131
+ params.serviceHolder[params.config.inBuiltFunctionType](params.store, params.dynamicData, params.userValue, params.parentEventOutput, params.service)
89
132
  }
90
- params.serviceHolder[params.config.inBuiltFunctionType](parameter)
91
133
  }
92
134
 
93
- async function executeCustomHandler(params: handlersProps) {
135
+ function executeCustomHandler(params: handlersProps) {
94
136
  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;
137
+ if (params.config.isSync !== "Yes") {
138
+ return makeFunc(params.store, params.dynamicData, params.userValue, params.parentEventOutput, params.service, params.componentName).then((res) => res)
139
+ } else {
140
+ const response = makeFunc(params.store, params.dynamicData, params.userValue, params.parentEventOutput, params.service, params.componentName)
141
+ return response;
142
+ }
143
+
97
144
  }
98
145
 
99
- async function mergeFormdata(handlerResponse: any, componentName: string, eventConfig: any, store: any, service: any) {
146
+ function mergeFormdata(handlerResponse: any, componentName: string, eventConfig: any, store: any, service: any) {
100
147
  if (eventConfig.type === "Select" && !(_.isEmpty(handlerResponse?.data) && handlerResponse?.data)) {
101
148
  store.setSchema((pre) => {
102
149
  return {
@@ -131,14 +178,13 @@ async function mergeFormdata(handlerResponse: any, componentName: string, eventC
131
178
  }
132
179
  else {
133
180
  if (handlerResponse) {
134
- store.setFormdata((pre) => { return { ...pre, [componentName]: eventConfig.lazyLoading ? handlerResponse.data.data : handlerResponse.data } });
135
- const demoData = await asyncOperation();
181
+ store.setFormdata((pre) => { return { ...pre, [componentName]: eventConfig.lazyLoading ? handlerResponse?.data?.data : handlerResponse.data } });
136
182
  }
137
183
  }
138
184
  }
139
185
 
140
186
  const buildBodyFormat = (body: any[], formData: any, userValue: any) => {
141
- const finalBody = { ...userValue?.payload };
187
+ let finalBody = { ...userValue?.payload };
142
188
  body.map((elem) => {
143
189
  if (typeof elem?.value !== "string") {
144
190
  finalBody[elem.key] = elem.value;
@@ -150,7 +196,12 @@ const buildBodyFormat = (body: any[], formData: any, userValue: any) => {
150
196
  else if (elem?.value?.startsWith("$")) {
151
197
  const finalpath = elem.value.substring(1);
152
198
  finalBody[elem.key] = _.get(formData, finalpath);;
153
- } else {
199
+ } else if (elem?.value === "*" && elem?.key === "*") {
200
+ finalBody = { ...finalBody, ...formData };
201
+ } else if (elem?.value === "*") {
202
+ finalBody[elem.key] = formData;
203
+ }
204
+ else {
154
205
  finalBody[elem.key] = elem.value;
155
206
  }
156
207
  }
@@ -169,58 +220,40 @@ const buildHeadersFormat = (headers: any[]) => {
169
220
  return headerObj;
170
221
  }
171
222
 
172
- async function shouldEventExecute(params: handlersProps) {
223
+ export function shouldEventExecute(params: handlersProps) {
173
224
  const startEvent = params.config?.events?.filter(e => e.eventType === "onStart");
225
+
174
226
  if (startEvent?.length > 0) {
175
- const response = await executeEventsHandler({ ...params, config: startEvent[0] });
176
- return response;
227
+ return executeEventsHandler({ ...params, config: startEvent[0] }).then((response) => {
228
+ return response;
229
+ });
177
230
  } else {
178
- return true
231
+ if (params.config.isSync !== "Yes") {
232
+ return Promise.resolve(true)
233
+ } else {
234
+ return true
235
+ }
179
236
  }
180
237
  }
181
238
 
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
239
 
240
+ export function buildApiPayload(compConfig: any, body: any, headers: any, store: any, dynamicData: any, userValue: any, service) {
241
+ if (compConfig?.headers) {
242
+ headers = buildHeadersFormat(compConfig.headers);
186
243
  }
244
+
187
245
  if (compConfig.body) {
188
246
  body = { ...buildBodyFormat(compConfig.body, store.newData || store?.ctx?.core?.data || store.formData, userValue) };
189
247
  }
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
248
 
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
- })
249
+ const promiseChain = { body, headers };
204
250
 
205
- } else {
206
- if (eventGropus?.onLoad) {
207
- result = Object.keys(eventGropus?.onLoad)
208
- result.push(result[0]);
209
- }
210
- }
211
- console.log(result);
212
- return result;
213
- }
214
251
 
252
+ if (compConfig.apiBody) {
253
+ const makeFunc = eval(compConfig.apiBody);
254
+ return { body: makeFunc(store, dynamicData, userValue, promiseChain.body), headers: promiseChain.headers };
255
+ // return result;
215
256
 
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
- });
257
+ }
258
+ return promiseChain;
226
259
  }
@@ -1,6 +1,6 @@
1
1
  import _, { isEmpty } from "lodash";
2
2
  import { doDownload, downloadFile } from "./downloadFile";
3
- import { asyncOperation, executeEvents, executeRefreshHandler } from "./events";
3
+ import { executeEvents, executeRefreshHandler } from "./events";
4
4
  import { handlersProps } from "./interface";
5
5
  let compType: string;
6
6
  let eventGroups: any = {};
@@ -13,6 +13,14 @@ 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
+
16
24
  export const extractEvents = (eventConfig: any) => {
17
25
  function extractsConfigEvents(eventConfigObj: any) {
18
26
  if (eventConfigObj.events) {
@@ -46,41 +54,53 @@ export const extractEvents = (eventConfig: any) => {
46
54
  }
47
55
  return eventGroups;
48
56
  };
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
- }
59
57
  export default (funcParams: funcParamsProps) => {
60
- eventGroups = {}
61
- eventGroups = extractEvents(funcParams.config)
62
58
  let executeEventsParameters: handlersProps = {
63
59
  config: {}, componentName: "",
64
60
  store: funcParams.store, dynamicData: funcParams.dynamicData, userValue: funcParams.userValue, service: funcParams.service,
65
- serviceHolder: { downloadFile, download: doDownload }, eventGroups
61
+ serviceHolder: { downloadFile, download: doDownload, ...funcParams.functionsProvider }, eventGroups,
62
+ functionsProvider: funcParams.functionsProvider,
66
63
  };
67
64
  return {
68
65
  setPage: async function () {
69
- funcParams.store.setFormdata({});
70
- funcParams.store.setSchema(
71
- (pre: any) => {
72
- return {
73
- ...funcParams.schema, properties:
74
- { ...funcParams.schema.properties, ...pre.properties, }
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
+ },
75
87
  }
76
- }
77
- )
78
- funcParams.uiSchema.elements.push(notifyUiSchema);
79
- funcParams.store.setUiSchema(funcParams.uiSchema);
80
- await asyncOperation()
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);
81
100
  executeEventsParameters = {
82
101
  config: {}, componentName: "",
83
102
  store: funcParams.store, dynamicData: funcParams.dynamicData, userValue: funcParams.userValue, service: funcParams.service,
103
+ functionsProvider: funcParams.functionsProvider,
84
104
  serviceHolder: this, eventGroups
85
105
  }
86
106
  await executeRefreshHandler({
@@ -88,15 +108,47 @@ export default (funcParams: funcParamsProps) => {
88
108
  store: funcParams.store, dynamicData: funcParams.dynamicData, userValue: funcParams.userValue, service: funcParams.service,
89
109
  serviceHolder: this, eventGroups
90
110
  })
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
+ },
141
+ onMount: function () {
142
+ this.callHandler("onMount")
91
143
  },
92
- onClick: async function () {
93
- await this.callHandler("onClick")
144
+ onFileDownload: function () {
145
+ this.callHandler("onDownload")
94
146
  },
95
- onFileDownload: async function () {
96
- await this.callHandler("onDownload")
147
+ onFileUpload: function () {
148
+ this.callHandler("onUpload")
97
149
  },
98
- onFileUpload: async function () {
99
- await this.callHandler("onUpload")
150
+ backHandler: function () {
151
+ funcParams.store.navigate(-1)
100
152
  },
101
153
  onPaginationChange: async function (paginationValues) {
102
154
  const apiBody = [
@@ -115,7 +167,8 @@ export default (funcParams: funcParamsProps) => {
115
167
  { key: "searchValue", value: param.serachValue },
116
168
  { key: "currentValue", value: param.currentValue }
117
169
  ]
118
- return await this.updateConfigApiBody(param, apiBody)
170
+ const response = await this.updateConfigApiBody(param, apiBody);
171
+ return response?.data;
119
172
  }
120
173
  },
121
174
  onChange: async function () {
@@ -184,7 +237,7 @@ export default (funcParams: funcParamsProps) => {
184
237
  if (eventGroups?.[eventType]?.[path] !== undefined) {
185
238
  for (const eventConfig of eventGroups?.[eventType]?.[path]) {
186
239
  executeEventsParameters.store.functionParameters = functionParameters
187
- await executeEvents({
240
+ executeEvents({
188
241
  ...executeEventsParameters,
189
242
  config: eventConfig,
190
243
  componentName: path
@@ -192,18 +245,9 @@ export default (funcParams: funcParamsProps) => {
192
245
  }
193
246
  }
194
247
  },
248
+
195
249
  downloadFile: downloadFile,
196
250
  download: doDownload,
251
+ ...funcParams.functionsProvider
197
252
  };
198
253
  };
199
-
200
-
201
-
202
-
203
-
204
-
205
-
206
-
207
-
208
-
209
-