impaktapps-ui-builder 0.0.283 → 0.0.285

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.
Files changed (23) hide show
  1. package/dist/impaktapps-ui-builder.es.js +225 -292
  2. package/dist/impaktapps-ui-builder.es.js.map +1 -1
  3. package/dist/impaktapps-ui-builder.umd.js +12 -12
  4. package/dist/impaktapps-ui-builder.umd.js.map +1 -1
  5. package/dist/src/impaktapps-ui-builder/builder/build/uischema/buildPropertiesSection.d.ts +4 -4
  6. package/dist/src/impaktapps-ui-builder/builder/build/uischema/selectInputField.d.ts +1 -0
  7. package/dist/src/impaktapps-ui-builder/runtime/services/events.d.ts +2 -1
  8. package/dist/src/impaktapps-ui-builder/runtime/services/interface.d.ts +11 -0
  9. package/dist/src/impaktapps-ui-builder/runtime/services/service.d.ts +1 -1
  10. package/package.json +1 -1
  11. package/src/impaktapps-ui-builder/builder/build/buildMultiSelect.ts +18 -16
  12. package/src/impaktapps-ui-builder/builder/build/buildSelect.ts +17 -14
  13. package/src/impaktapps-ui-builder/builder/build/buildTable.ts +9 -0
  14. package/src/impaktapps-ui-builder/builder/build/uischema/buildPropertiesSection.ts +33 -19
  15. package/src/impaktapps-ui-builder/builder/build/uischema/selectInputField.ts +1 -1
  16. package/src/impaktapps-ui-builder/builder/elements/UiSchema/Component/uiSchema.ts +36 -36
  17. package/src/impaktapps-ui-builder/builder/elements/UiSchema/PageMaster/uiSchema.ts +1 -1
  18. package/src/impaktapps-ui-builder/builder/elements/UiSchema/event/uiSchema.ts +10 -10
  19. package/src/impaktapps-ui-builder/builder/services/component.ts +2 -2
  20. package/src/impaktapps-ui-builder/builder/services/event.ts +2 -2
  21. package/src/impaktapps-ui-builder/runtime/services/events.ts +70 -137
  22. package/src/impaktapps-ui-builder/runtime/services/interface.ts +11 -0
  23. package/src/impaktapps-ui-builder/runtime/services/service.ts +54 -31
@@ -1,171 +1,112 @@
1
1
  import _, { cloneDeep } from "lodash";
2
+ import { handlersProps } from "./interface";
2
3
 
3
4
 
4
5
  export const executeEvents = async (
5
- config: any, componentName: string,
6
- store: any, dynamicData: any, userValue: any,
7
- service: any, serviceHolder: any, eventGroups?: any, parentEventOutput?: any
6
+ params:handlersProps
8
7
  ) => {
9
8
  let nextEvent = [];
10
9
  let LoadResponse = null;
11
- if (config.eventType === "onLoad") {
12
- const { response, events } = await executetOnLoadEvent(config, componentName,
13
- store, dynamicData, userValue,
14
- service, serviceHolder, eventGroups, parentEventOutput)
15
- if (config.returnResponse) {
16
- return response;
17
- }
18
- LoadResponse = response;
19
- nextEvent = events;
20
- }
21
- else {
22
- if (!shouldEventExecute(config, componentName,
23
- store, dynamicData, userValue,
24
- service, serviceHolder, eventGroups)) {
10
+ try{
11
+ if (!shouldEventExecute(params)) {
25
12
  return { response: undefined, events: undefined };
26
13
  }
27
- const { response, events } = await executeEventsHandler(config, componentName,
28
- store, dynamicData, userValue,
29
- service, serviceHolder, eventGroups, parentEventOutput)
14
+ const response = await executeEventsHandler(params)
30
15
  LoadResponse = response;
31
- nextEvent = events;
16
+ const SuccessEvent = params.config?.events.filter(e => e.eventType === "Success");
17
+ if(params.config.returnNeeded){
18
+ return LoadResponse
19
+ }
20
+ nextEvent = SuccessEvent;
21
+ } catch (err) {
22
+ const FailEvent = params.config?.events?.filter(e => e.eventType === "Fail")
23
+ const setEvent = FailEvent?.length > 0 ? FailEvent : []
24
+ nextEvent = setEvent;
32
25
  }
33
26
  if (nextEvent?.length > 0) {
34
27
  for (const actionConfig of nextEvent) {
35
- await executeEvents(actionConfig, componentName, store, dynamicData, userValue, service, serviceHolder, eventGroups, LoadResponse)
28
+ await executeEvents({...params,config:actionConfig,parentEventOutput:LoadResponse})
36
29
  }
37
30
  }
31
+ return LoadResponse;
38
32
  }
39
- const executetOnLoadEvent = async (
40
- config: any, componentName: string,
41
- store: any, dynamicData: any, userValue: any,
42
- service: any, serviceHolder: any, eventGroups?: any, parentEventOutput?: any
43
- ) => {
44
33
 
45
- try {
46
- if (!shouldEventExecute(config, componentName,
47
- store, dynamicData, userValue,
48
- service, serviceHolder, eventGroups)) {
49
- return { response: undefined, events: undefined };
50
- }
51
- const { response } = await executeEventsHandler(config, componentName,
52
- store, dynamicData, userValue,
53
- service, serviceHolder, eventGroups, parentEventOutput)
54
- if(config.returnResponse){
55
- return {response}
56
- }
57
- const SuccessEvent = config?.events.filter(e => e.eventType === "Success")
58
- const setEvent = SuccessEvent.length > 0 ? SuccessEvent : [{ Handler: "mergeFormdata", eventType: "Success", type: config.type }]
59
- return { response, events: setEvent };
60
- } catch (err) {
61
- const FailEvent = config?.events.filter(e => e.eventType === "Fail")
62
- const setEvent = FailEvent.length > 0 ? FailEvent : []
63
- return { response: undefined, events: setEvent };
34
+ async function executeEventsHandler(params:handlersProps) {
35
+ if (params.config.Handler === "api") {
36
+ return await executeApiEventHandler(params)
64
37
  }
65
-
66
- }
67
-
68
- async function executeEventsHandler(
69
- config: any, componentName: string,
70
- store: any, dynamicData: any, userValue: any,
71
- service: any, serviceHolder: any, eventGroups?: any, parentEventOutput?: any
72
- ) {
73
- if (config.Handler === "api") {
74
- return await executeApiEventHandler(
75
- config, componentName,
76
- store, dynamicData, userValue,
77
- service, serviceHolder, parentEventOutput
78
- )
79
- }
80
- else if (config.Handler === "inBuiltFunction") {
81
- return await executeInBuiltFunctionHandler(
82
- config, componentName,
83
- store, dynamicData, userValue,
84
- service, serviceHolder, parentEventOutput
85
- )
38
+ else if (params.config.Handler === "inBuiltFunction") {
39
+ return await executeInBuiltFunctionHandler(params)
86
40
  }
87
- else if (config.Handler === "custom") {
88
- return await executeCustomHandler(
89
- config, componentName,
90
- store, dynamicData, userValue,
91
- service, serviceHolder, parentEventOutput
92
- )
41
+ else if (params.config.Handler === "custom") {
42
+ return await executeCustomHandler(params)
93
43
  }
94
- else if (config.Handler === "refresh") {
95
- return await executeRefreshHandler(
96
- config, componentName,
97
- store, dynamicData, userValue,
98
- service, serviceHolder, parentEventOutput, eventGroups
99
- )
44
+ else if (params.config.Handler === "refresh") {
45
+ return await executeRefreshHandler(params)
100
46
  }
101
- else if (config.Handler === "mergeFormdata") {
102
- return await mergeFormdata(parentEventOutput, componentName, config, store)
47
+ else if (params.config.Handler === "mergeFormdata") {
48
+ return await mergeFormdata(
49
+ params.parentEventOutput, params.componentName, params.config, params.store)
103
50
  }
104
51
  }
105
- async function executeRefreshHandler(
106
- refreshConfig: any, componentName: string,
107
- store: any, dynamicData: any, userValue: any,
108
- service: any, serviceHolder: any, parentEventOutput?: any, eventGroups?: any
109
- ) {
110
- const compToRefresh: string[] = getRefreshElements(refreshConfig, eventGroups)
52
+ async function executeRefreshHandler(params:handlersProps) {
53
+ const compToRefresh: string[] = getRefreshElements(params.config, params.eventGroups)
111
54
  for (const componentName of compToRefresh) {
112
- for (const compEventConfig of eventGroups.onLoad[componentName]) {
113
- await executeEvents(compEventConfig, componentName, store, dynamicData, userValue, service, serviceHolder);
55
+ for (const compEventConfig of params.eventGroups.onLoad[componentName]) {
56
+ await executeEvents({...params,config:compEventConfig});
114
57
  }
115
58
  }
116
- return { response: undefined, events: undefined }
117
59
  }
118
- async function executeApiEventHandler(apiHandlerConfig: any, componentName: string,
119
- store: any, dynamicData: any, userValue: any,
120
- service: any, serviceHolder: any, parentEventOutput?: any) {
121
- const initialBody = { ...userValue?.payload };
60
+ async function executeApiEventHandler(params:handlersProps) {
61
+ const initialBody = { ...params.userValue?.payload };
122
62
  const initialHeaders = {
123
63
  "X-Requested-With": "XMLHttpRequest",
124
64
  "Access-Control-Allow-Origin": "*"
125
65
  };
126
- const { body, headers } = await buildApiPayload(apiHandlerConfig, initialBody, initialHeaders, store, dynamicData, userValue, service)
66
+ const { body, headers } = await buildApiPayload(params.config, initialBody, initialHeaders, params.store, params.dynamicData, params.userValue, params.service)
127
67
  let response: any;
128
- response = await service[apiHandlerConfig.method](
129
- apiHandlerConfig.path,
130
- body,
131
- headers && { headers: headers }
132
- );
133
- if(apiHandlerConfig.returnResponse){
134
- return {response}
135
- }
136
- return { response, events: apiHandlerConfig?.events };;
68
+ const dataJSON = await fetch(params.config.path, {
69
+ method: "POST",
70
+ headers: {
71
+ 'Content-Type': 'application/json',
72
+ },
73
+ body: JSON.stringify(body)
74
+ })
75
+ response = await dataJSON.json();
76
+ // if(params.config.returnResponse){
77
+ // return {response}
78
+ // }
79
+ // return response;
80
+ // response = await params.service[params.config.method](
81
+ // params.config.path,
82
+ // body,
83
+ // headers && { headers: headers }
84
+ // );
85
+ return response;
137
86
  }
138
87
 
139
- async function executeInBuiltFunctionHandler(refreshHandlerConfig: any, componentName: string,
140
- store: any, dynamicData: any, userValue: any,
141
- service: any, serviceHolder: any, parentEventOutput?: any) {
88
+ async function executeInBuiltFunctionHandler(params:handlersProps) {
142
89
  let parameter = {};
143
- if (refreshHandlerConfig.funcParametersCode) {
144
- const makeFunc = eval(refreshHandlerConfig.funcParametersCode)
145
- parameter = makeFunc(store, dynamicData, userValue, parentEventOutput, service);
90
+ if (params.config.funcParametersCode) {
91
+ const makeFunc = eval(params.config.funcParametersCode)
92
+ parameter = makeFunc(params.store, params.dynamicData, params.userValue, params.parentEventOutput, params.service);
146
93
  }
147
- serviceHolder[refreshHandlerConfig.inBuiltFunctionType](parameter)
148
- return { response: undefined, events: refreshHandlerConfig?.events };;
94
+ params.serviceHolder[params.config.inBuiltFunctionType](parameter)
149
95
  }
150
96
 
151
- async function executeCustomHandler(customHandlerConfig: any, componentName: string,
152
- store: any, dynamicData: any, userValue: any,
153
- service: any, serviceHolder: any, parentEventOutput?: any) {
154
- console.log(service)
155
- const makeFunc = eval(customHandlerConfig.eventCode)
156
- const response = await makeFunc(store, dynamicData, userValue, parentEventOutput, service, componentName);
157
- return { response: response, events: customHandlerConfig?.events };
97
+ async function executeCustomHandler(params:handlersProps) {
98
+ const makeFunc = eval(params.config.eventCode)
99
+ const response = await makeFunc(params.store, params.dynamicData, params.userValue, params.parentEventOutput, params.service, params.componentName);
100
+ return response;
158
101
  }
159
102
 
160
103
  async function mergeFormdata(handlerResponse: any, componentName: string, eventConfig: any, store: any) {
161
-
162
104
  if (eventConfig.type === "Select" && !(_.isEmpty(handlerResponse) && handlerResponse)) {
163
105
  store.setSchema((pre) => {
164
106
  return {
165
107
  ...pre, properties: {
166
108
  ...pre.properties, [componentName]: {
167
- // ...pre?.properties?. [componentName],
168
- oneOf: handlerResponse.data
109
+ enum: handlerResponse.data
169
110
  }
170
111
  }
171
112
  }
@@ -175,16 +116,12 @@ async function mergeFormdata(handlerResponse: any, componentName: string, eventC
175
116
  store.setFormdata((pre: any) => { return { ...pre, ...handlerResponse?.data } })
176
117
  }
177
118
  else {
178
- handlerResponse &&
179
- store.setFormdata((pre) => { return { ...pre, [componentName]: handlerResponse.data } });
119
+ if (handlerResponse) {
120
+ store.setFormdata((pre) => { return { ...pre, [componentName]: handlerResponse } });
121
+ }
180
122
  }
181
-
182
- return { response: undefined, events: undefined }
183
123
  }
184
124
 
185
-
186
-
187
-
188
125
  const buildBodyFormat = (body: any[], formData: any, userValue: any) => {
189
126
  const finalBody = { ...userValue?.payload };
190
127
  body.map((elem) => {
@@ -217,17 +154,14 @@ const buildHeadersFormat = (headers: any[]) => {
217
154
  return headerObj;
218
155
  }
219
156
 
220
- async function shouldEventExecute(config, componentName,
221
- store, dynamicData, userValue,
222
- service, serviceHolder, eventGroups) {
223
- const startEvent = config?.events?.filter(e => e.eventType === "onStart");
157
+ async function shouldEventExecute(params:handlersProps) {
158
+ const startEvent = params.config?.events?.filter(e => e.eventType === "onStart");
224
159
  if (startEvent?.length > 0) {
225
- const { response } = await executeEventsHandler(startEvent[0], componentName,
226
- store, dynamicData, userValue,
227
- service, serviceHolder, eventGroups);
160
+ const { response } = await executeEventsHandler(params);
228
161
  return response
229
162
  }
230
163
  }
164
+
231
165
  export async function buildApiPayload(compConfig: any, body: any, headers: any, store: any, dynamicData: any, userValue: any, service) {
232
166
  if (compConfig?.headers) {
233
167
  headers = buildHeadersFormat(compConfig.headers)
@@ -244,7 +178,6 @@ export async function buildApiPayload(compConfig: any, body: any, headers: any,
244
178
  return { body, headers };
245
179
  }
246
180
 
247
-
248
181
  export function getRefreshElements(eventConfig: any, eventGropus: any) {
249
182
  let result: string[] = [];
250
183
  if (eventConfig?.refreshElements?.length > 0) {
@@ -0,0 +1,11 @@
1
+ export interface handlersProps {
2
+ config: any,
3
+ componentName: string,
4
+ store: any,
5
+ dynamicData: any,
6
+ userValue: any,
7
+ service: any,
8
+ serviceHolder: any,
9
+ eventGroups?: any,
10
+ parentEventOutput?: any
11
+ }
@@ -1,6 +1,7 @@
1
1
  import _ from "lodash";
2
2
  import { downloadFile } from "./downloadFile";
3
3
  import { executeEvents } from "./events";
4
+ import { handlersProps } from "./interface";
4
5
  let compType: string;
5
6
  let eventGroups: any = {};
6
7
  const notifyUiSchema = {
@@ -25,10 +26,17 @@ export const extractEvents = (eventConfig: any) => {
25
26
  if (!eventGroups[event.eventType][eventConfigObj.name]) {
26
27
  eventGroups[event.eventType][eventConfigObj.name] = [];
27
28
  }
28
- eventGroups[event.eventType][eventConfigObj.name].push({ ...event, type: compType });
29
+ 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 })
34
+ }
35
+ eventGroups[event.eventType][eventConfigObj.name].push({ ...event, type: compType })
29
36
  });
30
37
  }
31
38
  }
39
+
32
40
  extractsConfigEvents(eventConfig)
33
41
  if (eventConfig?.elements) {
34
42
  eventConfig.elements.forEach(extractEvents);
@@ -46,17 +54,29 @@ interface funcParamsProps {
46
54
  userValue: any,
47
55
  }
48
56
  export default (funcParams: funcParamsProps) => {
57
+ eventGroups = {}
58
+ eventGroups = extractEvents(funcParams.config)
59
+ let executeEventsParameters: handlersProps = {
60
+ config: {}, componentName: "",
61
+ store: funcParams.store, dynamicData: funcParams.dynamicData, userValue: funcParams.userValue, service: funcParams.service,
62
+ serviceHolder: this, eventGroups
63
+ };
49
64
  return {
50
65
  setPage: async function () {
51
66
  funcParams.store.setFormdata({});
52
- eventGroups = {}
53
- eventGroups = extractEvents(funcParams.config)
54
- await executeEvents(
55
- { Handler: "refresh", eventType: "onPageRefresh" }, "all",
56
- funcParams.store, funcParams.dynamicData, funcParams.userValue, funcParams.service,
57
- this, eventGroups)
67
+ executeEventsParameters = {
68
+ config: {}, componentName: "",
69
+ store: funcParams.store, dynamicData: funcParams.dynamicData, userValue: funcParams.userValue, service: funcParams.service,
70
+ serviceHolder: this, eventGroups
71
+ }
72
+ await executeEvents({
73
+ ...executeEventsParameters,
74
+ config: { Handler: "refresh", eventType: "onPageRefresh" },
75
+ componentName: "all"
76
+ })
77
+
58
78
  funcParams.store.setSchema(
59
- (pre:any) => {
79
+ (pre: any) => {
60
80
  return {
61
81
  ...funcParams.schema, properties:
62
82
  { ...funcParams.schema.properties, ...pre.properties, }
@@ -68,36 +88,38 @@ export default (funcParams: funcParamsProps) => {
68
88
  onClick: async function () {
69
89
  const path = funcParams.dynamicData?.tableButtonPath || funcParams.dynamicData.path.split(".")[0];
70
90
  for (const eventConfig of eventGroups?.onClick[path]) {
71
-
72
- await executeEvents(
73
- eventConfig, path,
74
- funcParams.store, funcParams.dynamicData, funcParams.userValue, funcParams.service,
75
- this, eventGroups)
91
+ await executeEvents({
92
+ ...executeEventsParameters,
93
+ config: eventConfig,
94
+ componentName: path
95
+ })
76
96
  }
77
97
  },
78
98
  onPaginationChange: async (paginationValues) => {
79
99
  for (const eventConfig of eventGroups?.onLoad[paginationValues.path]) {
80
- ;
81
100
  const bodyValues = [
82
- {key: "size",value: paginationValues.pagination.pageSize},
83
- {key: "start",value: paginationValues.pagination.pageIndex * paginationValues.pagination.pageSize},
84
- {key:"filters",value: paginationValues.columnFilters || []},
85
- {key:"globalFilter",value: paginationValues.globalFilter ?? ''}
101
+ { key: "size", value: paginationValues.pagination.pageSize },
102
+ { key: "start", value: paginationValues.pagination.pageIndex * paginationValues.pagination.pageSize },
103
+ { key: "sorting", value: paginationValues.sorting || [] },
104
+ { key: "filters", value: paginationValues.columnFilters || [] },
105
+ { key: "globalFilter", value: paginationValues.globalFilter ?? '' }
86
106
  ]
87
107
  if (eventConfig.body) {
88
- eventConfig.returnResponse = true
89
108
  eventConfig.body = [
90
109
  ...eventConfig.body,
91
110
  ...bodyValues
92
111
  ]
93
- } else {
94
- eventConfig.returnResponse = true
95
- eventConfig.body = bodyValues;
96
- };
97
- await executeEvents(
98
- eventConfig, paginationValues.path,
99
- funcParams.store, funcParams.dynamicData, funcParams.userValue, funcParams.service,
100
- this, eventGroups)
112
+ } else { eventConfig.body = bodyValues; };
113
+ const responseEvent = eventConfig?.events?.filter((elem) => {
114
+ return elem.Handler !== "mergeFormdata"
115
+ })
116
+ eventConfig.events = responseEvent??[]
117
+ const data = await executeEvents({
118
+ ...executeEventsParameters,
119
+ config: eventConfig,
120
+ componentName: paginationValues.path
121
+ })
122
+ return data;
101
123
  }
102
124
  },
103
125
  onChange: async function () {
@@ -109,10 +131,11 @@ export default (funcParams: funcParamsProps) => {
109
131
  funcParams.store?.newData[componentName] !== undefined
110
132
  ) {
111
133
  for (const eventConfig of eventGroups.onChange[componentName]) {
112
- await executeEvents(
113
- eventConfig, componentName,
114
- funcParams.store, funcParams.dynamicData, funcParams.userValue, funcParams.service,
115
- this, eventGroups)
134
+ await executeEvents({
135
+ ...executeEventsParameters,
136
+ config: eventConfig,
137
+ componentName
138
+ })
116
139
  }
117
140
  }
118
141
  }))