impaktapps-ui-builder 1.0.105 → 1.0.107

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.
@@ -3,6 +3,11 @@ export declare let schema: {
3
3
  properties: {};
4
4
  required: any[];
5
5
  };
6
- export declare function buildSchema(config: any): any;
6
+ export declare function buildSchemaFromConfig(config: any, parentSchema: any): void;
7
+ export declare const buildSchema: (config: any) => {
8
+ type: string;
9
+ properties: {};
10
+ required: any[];
11
+ };
7
12
  declare const buildUiSchema: (config: any, store?: any) => any;
8
13
  export default buildUiSchema;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "impaktapps-ui-builder",
3
- "version": "1.0.105",
3
+ "version": "1.0.107",
4
4
  "scripts": {
5
5
  "dev": "vite",
6
6
  "build": "tsc && vite build",
@@ -51,111 +51,70 @@ function buildOneOf(values: any[]) {
51
51
  title: e.label
52
52
  }));
53
53
  }
54
- function applyValidations(
55
- schemaNode: any,
56
- validations: any[] = [],
57
- requiredArr?: string[],
58
- fieldName?: string
59
- ) {
60
- validations.forEach((rule) => {
61
- if (rule.validationType === "readOnly") {
62
- schemaNode.disabled = true
63
- }
64
- if (rule.validationType === "required") {
65
- if (requiredArr && fieldName) {
66
- requiredArr.push(fieldName);
67
- }
68
- } else {
69
- schemaNode.type = "string";
70
- schemaNode[rule.validationType] =
71
- isNaN(rule.validationValue)
72
- ? rule.validationValue
73
- : Number(rule.validationValue);
74
- }
75
- });
76
- }
77
-
78
- function buildNode(config: any): any {
79
- if (config.type === "Array") {
80
- const arraySchema: any = {
81
- type: "array",
82
- items: {
83
- type: "object",
84
- properties: {},
85
- required: []
86
- }
87
- };
88
-
89
- config.elements?.forEach((child: any) => {
90
- const childNode = buildNode(child);
91
- if (!childNode) return;
92
-
93
- arraySchema.items.properties[child.name] = childNode.schema;
94
-
95
- if (childNode.required?.length) {
96
- arraySchema.items.required.push(child.name);
97
- }
98
- });
54
+ export function buildSchemaFromConfig(config: any, parentSchema: any) {
55
+ if (config.elements) {
56
+ if (config.type === "Array") {
57
+ parentSchema.properties ??= {};
58
+ parentSchema.properties[config.name] ??= {
59
+ type: "array",
60
+ items: {
61
+ type: "object",
62
+ properties: {},
63
+ required: [],
64
+ },
65
+ };
99
66
 
100
- return { schema: arraySchema };
101
- }
67
+ const arrayItemSchema = parentSchema.properties[config.name].items;
102
68
 
103
- let fieldSchema: any = {};
104
- if (
105
- (config.type === "Select" || config.type === "MultipleSelect") &&
106
- config.value?.length > 0
107
- ) {
108
- if (config.type === "Select") {
109
- fieldSchema.oneOf = buildOneOf(config.value);
69
+ config.elements?.forEach((child: any) =>
70
+ buildSchemaFromConfig(child, arrayItemSchema)
71
+ );
72
+ return;
110
73
  } else {
111
- fieldSchema.type = "array";
112
- fieldSchema.items = {
113
- oneOf: buildOneOf(config.value)
114
- };
74
+ config.elements?.forEach((child: any) =>
75
+ buildSchemaFromConfig(child, parentSchema)
76
+ );
77
+ return;
115
78
  }
116
79
  }
117
-
118
- if (config.validation) {
119
- applyValidations(fieldSchema, config.validation);
120
- }
121
-
122
- const required =
123
- config.validation?.some(
124
- (v: any) => v.validationType === "required"
125
- )
126
- ? [config.name]
127
- : [];
128
-
129
- return {
130
- schema: fieldSchema,
131
- required
132
- };
133
- }
134
-
135
- export function buildSchema(config: any): any {
136
- const schema: any = {
137
- type: "object",
138
- properties: {},
139
- required: []
140
- };
141
-
142
- config.elements?.forEach((element: any) => {
143
- const node = buildNode(element);
144
- if (!node) return;
145
-
146
- schema.properties[element.name] = node.schema;
147
-
148
- if (node.required?.length) {
149
- schema.required.push(element.name);
80
+ parentSchema.properties ??= {};
81
+ parentSchema.properties[config.name] ??= {};
82
+ const fieldSchema = parentSchema.properties[config.name];
83
+ config.validation?.forEach((v: any) => {
84
+ if (v.validationType === "required") {
85
+ parentSchema.required ??= [];
86
+ parentSchema.required.push(config.name);
87
+ } else if (v.validationType === "readOnly") {
88
+ fieldSchema.type = "string";
89
+ fieldSchema.disabled = true;
90
+ } else {
91
+ fieldSchema.type = "string";
92
+ fieldSchema[v.validationType] = isNaN(v.validationValue)
93
+ ? v.validationValue
94
+ : Number(v.validationValue);
150
95
  }
151
96
  });
152
-
153
- if (schema.required.length === 0) {
154
- delete schema.required;
97
+ if (config.type === "Select" && config.value?.length) {
98
+ fieldSchema.oneOf = config.value.map((v: any) => ({
99
+ const: v.value,
100
+ title: v.label,
101
+ }));
102
+ }
103
+ if (config.type === "MultipleSelect" && config.value?.length) {
104
+ fieldSchema.type = "array";
105
+ fieldSchema.items = {
106
+ oneOf: config.value.map((v: any) => ({
107
+ const: v.value,
108
+ title: v.label,
109
+ })),
110
+ };
155
111
  }
112
+ }
156
113
 
114
+ export const buildSchema = (config) => {
115
+ buildSchemaFromConfig(config, schema)
157
116
  return schema;
158
- };
117
+ }
159
118
 
160
119
  const buildUiSchema = (config: any, store?: any) => {
161
120
  let elements: any = {};
@@ -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) => {
@@ -183,23 +181,21 @@ function mergeFormdata(handlerResponse: any, componentName: string, eventConfig:
183
181
  ...store.newData,
184
182
  ...handlerResponse?.data
185
183
  }
186
- store.setFormdata((pre: any) => { return { ...pre, ...handlerResponse?.data } })
184
+ formDataHolder = { ...formDataHolder, ...handlerResponse?.data }
187
185
  }
188
186
  }
189
187
  else if (eventConfig.type === "Table" && eventConfig.lazyLoading) {
190
188
  if (handlerResponse && handlerResponse?.data) {
191
189
  formDataHolder[componentName] = handlerResponse.data?.data
192
190
  formDataHolder[`${componentName}_RowCount`] = handlerResponse.data?.meta?.totalRowCount
193
- store.setFormdata((pre) => { return { ...pre, ...formDataHolder } });
194
191
  }
195
192
  }
196
193
  else {
197
194
  if (handlerResponse) {
198
195
  formDataHolder[componentName] = handlerResponse.data
199
- store.setFormdata((pre) => { return { ...pre, ...formDataHolder } });
200
196
  }
201
197
  }
202
- }
198
+ };
203
199
 
204
200
  const buildBodyFormat = (body: any[], formData: any, userValue: any, store: any) => {
205
201
  let finalBody = { ...userValue?.payload };
@@ -90,9 +90,9 @@ export default (funcParams: funcParamsProps) => {
90
90
  config: {}, componentName: "",
91
91
  store: funcParams.store, dynamicData: funcParams.dynamicData, userValue: funcParams.userValue, service: funcParams.service,
92
92
  functionsProvider: funcParams.functionsProvider,
93
- serviceHolder: this, eventGroups, formDataHolder
93
+ serviceHolder: this, eventGroups, formDataHolder,
94
94
  }
95
-
95
+
96
96
  funcParams.store.setSchema(
97
97
  (pre: any) => {
98
98
  return {
@@ -104,9 +104,9 @@ export default (funcParams: funcParamsProps) => {
104
104
  await executeRefreshHandler({
105
105
  config: {}, componentName: "",
106
106
  store: funcParams.store, dynamicData: funcParams.dynamicData, userValue: funcParams.userValue, service: funcParams.service,
107
- serviceHolder: this, eventGroups, formDataHolder: {}
107
+ serviceHolder: this, eventGroups, formDataHolder: formDataHolder
108
108
  })
109
-
109
+ funcParams.store.setFormdata((pre) => ({ ...pre, ...formDataHolder }))
110
110
  uiSchema.elements.push(notifyUiSchema);
111
111
  funcParams.store.setUiSchema(uiSchema);
112
112
  },
@@ -247,13 +247,23 @@ export default (funcParams: funcParamsProps) => {
247
247
  callHandler: async function (eventType: string, functionParameters?: any) {
248
248
  const path = funcParams.dynamicData?.tableButtonPath || funcParams.dynamicData.path.split(".")[funcParams.dynamicData.path.split(".").length - 1];
249
249
  if (eventGroups?.[eventType]?.[path] !== undefined) {
250
- Promise.all(eventGroups?.[eventType]?.[path].map((eventConfig) => {
250
+ await Promise.all(eventGroups?.[eventType]?.[path].map(async (eventConfig) => {
251
251
  executeEventsParameters.store.functionParameters = functionParameters
252
- executeEvents({
253
- ...executeEventsParameters,
254
- config: eventConfig,
255
- componentName: path
256
- })
252
+ if (eventConfig.Handler === "refresh") {
253
+ await executeRefreshHandler({
254
+ ...executeEventsParameters,
255
+ config: eventConfig,
256
+ componentName: path,
257
+ formDataHolder: formDataHolder
258
+ })
259
+ funcParams.store.setFormdata((pre) => ({ ...pre, ...formDataHolder }));
260
+ } else {
261
+ executeEvents({
262
+ ...executeEventsParameters,
263
+ config: eventConfig,
264
+ componentName: path
265
+ })
266
+ }
257
267
  }))
258
268
  }
259
269
  },