datastake-daf 0.6.261 → 0.6.262

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.
@@ -2,20 +2,19 @@
2
2
  import moment from "moment";
3
3
  import { deepFind, propHasValue } from "./deepFind";
4
4
  import _ from "lodash";
5
- import dayjs from 'dayjs';
6
- import customParseFormat from 'dayjs/plugin/customParseFormat';
7
- import utc from 'dayjs/plugin/utc';
8
- import localizedFormat from 'dayjs/plugin/localizedFormat';
9
- import 'dayjs/locale/fr'; // import desired locales
10
- import 'dayjs/locale/es';
11
- import 'dayjs/locale/en';
5
+ import dayjs from "dayjs";
6
+ import customParseFormat from "dayjs/plugin/customParseFormat";
7
+ import utc from "dayjs/plugin/utc";
8
+ import localizedFormat from "dayjs/plugin/localizedFormat";
9
+ import "dayjs/locale/fr"; // import desired locales
10
+ import "dayjs/locale/es";
11
+ import "dayjs/locale/en";
12
12
 
13
13
  dayjs.extend(customParseFormat);
14
14
  dayjs.extend(utc);
15
15
  dayjs.extend(utc);
16
16
  dayjs.extend(localizedFormat);
17
17
 
18
-
19
18
  /**
20
19
  * @function _checkValue
21
20
  * @description Checks if a value matches a condition.
@@ -31,44 +30,59 @@ dayjs.extend(localizedFormat);
31
30
  * _checkValue('admin', 'notEmpty', { admin: ['user', 'moderator'] })
32
31
  */
33
32
  export function _checkValue(wantedValue, match, fieldValue) {
34
- match = match ? match.trim() : null
35
- if (!match) {
36
- return propHasValue(fieldValue) || (Array.isArray(fieldValue) && fieldValue.length > 0) ? true : false
37
- } else {
38
- const values = wantedValue.split(',');
39
- if (match === 'is') {
40
- if (values.length === 1) {
41
- return Array.isArray(fieldValue) ? (fieldValue.includes(values[0])) : String(fieldValue) === values[0];
42
- } else {
43
- return false
44
- }
45
- }
46
- if (match === 'includes') {
47
- if (values.length) {
48
- return Array.isArray(fieldValue) ? (values.filter(v => fieldValue.includes(v)).length > 0) : values.includes(String(fieldValue));
49
- } else {
50
- return false;
51
- }
52
- }
53
- if (match === 'not') {
54
- if (values.length && propHasValue(fieldValue)) {
55
- return Array.isArray(fieldValue) ? (values.filter(v => fieldValue.includes(v)).length === 0) : !values.includes(String(fieldValue));
56
- } else {
57
- return false;
58
- }
59
- }
60
- if (match === 'notOnly') {
61
- if (values.length) {
62
- return Array.isArray(fieldValue) ? (values.filter(v => fieldValue.includes(v)).length === 0) : !values.includes(String(fieldValue));
63
- } else {
64
- return false;
65
- }
66
- }
67
- if (match === 'notEmpty') {
68
- return fieldValue && Object.keys(fieldValue).includes(wantedValue) && (!Array.isArray(fieldValue[wantedValue]) || (Array.isArray(fieldValue[wantedValue]) && fieldValue[wantedValue].length > 0));
69
- }
70
- }
71
- return false;
33
+ match = match ? match.trim() : null;
34
+ if (!match) {
35
+ return propHasValue(fieldValue) || (Array.isArray(fieldValue) && fieldValue.length > 0)
36
+ ? true
37
+ : false;
38
+ } else {
39
+ const values = wantedValue.split(",");
40
+ if (match === "is") {
41
+ if (values.length === 1) {
42
+ return Array.isArray(fieldValue)
43
+ ? fieldValue.includes(values[0])
44
+ : String(fieldValue) === values[0];
45
+ } else {
46
+ return false;
47
+ }
48
+ }
49
+ if (match === "includes") {
50
+ if (values.length) {
51
+ return Array.isArray(fieldValue)
52
+ ? values.filter((v) => fieldValue.includes(v)).length > 0
53
+ : values.includes(String(fieldValue));
54
+ } else {
55
+ return false;
56
+ }
57
+ }
58
+ if (match === "not") {
59
+ if (values.length && propHasValue(fieldValue)) {
60
+ return Array.isArray(fieldValue)
61
+ ? values.filter((v) => fieldValue.includes(v)).length === 0
62
+ : !values.includes(String(fieldValue));
63
+ } else {
64
+ return false;
65
+ }
66
+ }
67
+ if (match === "notOnly") {
68
+ if (values.length) {
69
+ return Array.isArray(fieldValue)
70
+ ? values.filter((v) => fieldValue.includes(v)).length === 0
71
+ : !values.includes(String(fieldValue));
72
+ } else {
73
+ return false;
74
+ }
75
+ }
76
+ if (match === "notEmpty") {
77
+ return (
78
+ fieldValue &&
79
+ Object.keys(fieldValue).includes(wantedValue) &&
80
+ (!Array.isArray(fieldValue[wantedValue]) ||
81
+ (Array.isArray(fieldValue[wantedValue]) && fieldValue[wantedValue].length > 0))
82
+ );
83
+ }
84
+ }
85
+ return false;
72
86
  }
73
87
 
74
88
  /**
@@ -83,87 +97,94 @@ export function _checkValue(wantedValue, match, fieldValue) {
83
97
  * showHideInput(input, data, repeatIndex, repeatValues)
84
98
  */
85
99
  export function showHideInput(input, data, repeatIndex, repeatValues) {
86
- if (typeof input?.meta?.excludeFromEdit === 'boolean') {
87
- return !input?.meta?.excludeFromEdit;
88
- }
89
-
90
- const formsValue = { ...data };
91
-
92
- Object.keys(data?.meta?.inputs || {}).forEach((key) => {
93
- const input = data?.meta?.inputs[key];
94
-
95
- if (input?.notApplicable || input?.notAvailable) {
96
- formsValue[key] = undefined;
97
- delete formsValue[key];
98
- }
99
- });
100
-
101
- if (input.showIf) {
102
- const isOrCond = input.showIf.indexOf('OR') >= 0;
103
- const allParts = input.showIf.split(/( OR | && )/gmi).filter(c => !['OR', '&&'].includes(c.trim()));
104
- const parts = allParts.map(condition => {
105
- let [field, match, wantedValue] = condition.split(/( is | includes | not | notEmpty | notOnly | gte | gt | lte | lt )/gmi);
106
- match = match ? match.trim() : null;
107
- const isRepeatable = field.split('./').length > 1;
108
- const isNotEmpty = match === 'notEmpty';
109
- const formValue = isRepeatable ? repeatValues : formsValue;
110
- field = isRepeatable ? field.split('./')[1] : field;
111
- if (match && field.split('.').length > 1) {
112
- if (input.inputs) {
113
- const value = deepFind(formValue, field);
114
- const isShown = _checkValue(
115
- isNotEmpty ? field : wantedValue,
116
- match,
117
- isNotEmpty ? formValue : value
118
- );
119
- return isShown;
120
- } else {
121
- if ((isRepeatable ? !repeatValues : !formsValue)) {
122
- return false;
123
- } else {
124
- const value = deepFind(formValue, field);
125
- const isShown = _checkValue(
126
- isNotEmpty ? field : wantedValue,
127
- match,
128
- isNotEmpty ? formValue : value
129
- );
130
- return isShown;
131
- }
132
- }
133
- } else {
134
- const value = deepFind(formValue, field);
135
-
136
- if (match === 'gte') {
137
- return Number(formValue[field]) >= Number(wantedValue);
138
- }
139
-
140
- if (match === 'gt') {
141
- return Number(formValue[field]) > Number(wantedValue);
142
- }
143
-
144
- if (match === 'lte') {
145
- return Number(formValue[field]) <= Number(wantedValue);
146
- }
147
-
148
- if (match === 'lt') {
149
- return Number(formValue[field]) < Number(wantedValue);
150
- }
151
-
152
- const isShown = _checkValue(
153
- isNotEmpty ? field : wantedValue,
154
- match,
155
- isNotEmpty ? formValue : value
156
- );
157
- return isShown;
158
- }
159
- });
160
- const isShown = parts.length > 0 && ((isOrCond && parts.filter(p => p).length >= 1) || parts.filter(p => !p).length === 0);
161
- // if (!isShown && propHasValue(dot.pick(ref, formsValue)) && input.deleteDataOnHide !== false) {
162
- // dot.delete(ref, formsValue);
163
- // }
164
- return isShown;
165
- }
166
- return true;
100
+ if (typeof input?.meta?.excludeFromEdit === "boolean") {
101
+ return !input?.meta?.excludeFromEdit;
102
+ }
103
+
104
+ const formsValue = { ...data };
105
+
106
+ Object.keys(data?.meta?.inputs || {}).forEach((key) => {
107
+ const input = data?.meta?.inputs[key];
108
+
109
+ if (input?.notApplicable || input?.notAvailable) {
110
+ formsValue[key] = undefined;
111
+ delete formsValue[key];
112
+ }
113
+ });
114
+
115
+ if (input.showIf) {
116
+ const isOrCond = input.showIf.indexOf("OR") >= 0;
117
+ const allParts = input.showIf
118
+ .split(/( OR | && )/gim)
119
+ .filter((c) => !["OR", "&&"].includes(c.trim()));
120
+ const parts = allParts.map((condition) => {
121
+ let [field, match, wantedValue] = condition.split(
122
+ /( is | includes | not | notEmpty | notOnly | gte | gt | lte | lt )/gim,
123
+ );
124
+ match = match ? match.trim() : null;
125
+ const isRepeatable = field.split("./").length > 1;
126
+ const isNotEmpty = match === "notEmpty";
127
+ const formValue = isRepeatable ? repeatValues : formsValue;
128
+ field = isRepeatable ? field.split("./")[1] : field;
129
+ if (match && field.split(".").length > 1) {
130
+ if (input.inputs) {
131
+ const value = deepFind(formValue, field);
132
+ const isShown = _checkValue(
133
+ isNotEmpty ? field : wantedValue,
134
+ match,
135
+ isNotEmpty ? formValue : value,
136
+ );
137
+ return isShown;
138
+ } else {
139
+ if (isRepeatable ? !repeatValues : !formsValue) {
140
+ return false;
141
+ } else {
142
+ const value = deepFind(formValue, field);
143
+ const isShown = _checkValue(
144
+ isNotEmpty ? field : wantedValue,
145
+ match,
146
+ isNotEmpty ? formValue : value,
147
+ );
148
+ return isShown;
149
+ }
150
+ }
151
+ } else {
152
+ const value = deepFind(formValue, field);
153
+
154
+ if (match === "gte") {
155
+ return Number(formValue[field]) >= Number(wantedValue);
156
+ }
157
+
158
+ if (match === "gt") {
159
+ return Number(formValue[field]) > Number(wantedValue);
160
+ }
161
+
162
+ if (match === "lte") {
163
+ return Number(formValue[field]) <= Number(wantedValue);
164
+ }
165
+
166
+ if (match === "lt") {
167
+ return Number(formValue[field]) < Number(wantedValue);
168
+ }
169
+
170
+ const isShown = _checkValue(
171
+ isNotEmpty ? field : wantedValue,
172
+ match,
173
+ isNotEmpty ? formValue : value,
174
+ );
175
+ return isShown;
176
+ }
177
+ });
178
+ const isShown =
179
+ parts.length > 0 &&
180
+ ((isOrCond && parts.filter((p) => p).length >= 1) ||
181
+ parts.filter((p) => !p).length === 0);
182
+ // if (!isShown && propHasValue(dot.pick(ref, formsValue)) && input.deleteDataOnHide !== false) {
183
+ // dot.delete(ref, formsValue);
184
+ // }
185
+ return isShown;
186
+ }
187
+ return true;
167
188
  }
168
189
 
169
190
  /**
@@ -180,10 +201,22 @@ export function showHideInput(input, data, repeatIndex, repeatValues) {
180
201
  * filterString('h ll ', 'll') // true
181
202
  */
182
203
  export const filterString = (str1, str2) => {
183
- str1 = typeof str1 === 'string' ? str1.toLowerCase().normalize('NFD').replace(/[\u0300-\u036f]/g, "") : '';
184
- str2 = typeof str2 === 'string' ? str2.toLowerCase().normalize('NFD').replace(/[\u0300-\u036f]/g, "") : '';
185
- return str1.toLowerCase().indexOf(str2.toLowerCase()) >= 0;
186
- }
204
+ str1 =
205
+ typeof str1 === "string"
206
+ ? str1
207
+ .toLowerCase()
208
+ .normalize("NFD")
209
+ .replace(/[\u0300-\u036f]/g, "")
210
+ : "";
211
+ str2 =
212
+ typeof str2 === "string"
213
+ ? str2
214
+ .toLowerCase()
215
+ .normalize("NFD")
216
+ .replace(/[\u0300-\u036f]/g, "")
217
+ : "";
218
+ return str1.toLowerCase().indexOf(str2.toLowerCase()) >= 0;
219
+ };
187
220
 
188
221
  /**
189
222
  * @function filterSelectOptions
@@ -199,13 +232,15 @@ export const filterString = (str1, str2) => {
199
232
  * filterSelectOptions('hello', { label: 'goodbye world' }) // false
200
233
  */
201
234
  export const filterSelectOptions = (inputValue, option) => {
202
- return filterString(
203
- typeof option.children === 'string' ? option.children :
204
- (typeof option.label === 'string' ? option.label : '')
205
- , inputValue
206
- );
207
- }
208
-
235
+ return filterString(
236
+ typeof option.children === "string"
237
+ ? option.children
238
+ : typeof option.label === "string"
239
+ ? option.label
240
+ : "",
241
+ inputValue,
242
+ );
243
+ };
209
244
 
210
245
  /**
211
246
  * @function createYearArray
@@ -216,13 +251,17 @@ export const filterSelectOptions = (inputValue, option) => {
216
251
  * createYearArray(3) // ['2023', '2022', '2021']
217
252
  */
218
253
  export const createYearArray = (i) => {
219
- const years = [];
254
+ const years = [];
220
255
 
221
- for (let j = 0; j < i; j++) {
222
- years.push(moment().add(j * -1, 'years').format('YYYY'));
223
- }
256
+ for (let j = 0; j < i; j++) {
257
+ years.push(
258
+ moment()
259
+ .add(j * -1, "years")
260
+ .format("YYYY"),
261
+ );
262
+ }
224
263
 
225
- return years;
264
+ return years;
226
265
  };
227
266
 
228
267
  /**
@@ -234,31 +273,42 @@ export const createYearArray = (i) => {
234
273
  * createNumberArray(3) // [1, 2, 3]
235
274
  */
236
275
  export const createNumberArray = (i) => {
237
- const numbers = [];
276
+ const numbers = [];
238
277
 
239
- for (let j = 0; j < i; j++) {
240
- numbers.push(j + 1);
241
- }
278
+ for (let j = 0; j < i; j++) {
279
+ numbers.push(j + 1);
280
+ }
242
281
 
243
- return numbers;
282
+ return numbers;
244
283
  };
245
284
 
246
285
  export const tooltipInputs = [
247
- 'text', 'phoneNumber', 'textarea', 'percentage', 'number',
248
- 'select', 'ajaxSelect', 'switch', 'multiselect', 'radioGroup',
249
- 'date', 'year'
286
+ "text",
287
+ "phoneNumber",
288
+ "textarea",
289
+ "percentage",
290
+ "number",
291
+ "select",
292
+ "ajaxSelect",
293
+ "switch",
294
+ "multiselect",
295
+ "radioGroup",
296
+ "date",
297
+ "year",
250
298
  ];
251
299
 
252
300
  export const formPaths = {
253
- edit: (mod, getRedirectLink) => typeof getRedirectLink === 'function'
254
- ? getRedirectLink(`/app/edit/:namespace/:id/:group?/:subsection?/:subgroup?/:formid?`)
255
- : `/app/${mod}/edit/:namespace/:id/:group?/:subsection?/:subgroup?/:formid?`,
256
- view: (mod, getRedirectLink) => typeof getRedirectLink === 'function'
257
- ? getRedirectLink(`/app/view/:namespace/:id/:group?/:subsection?/:subgroup?/:formid?`)
258
- : `/app/${mod}/view/:namespace/:id/:group?/:subsection?/:subgroup?/:formid?`,
259
- viewDD: (mod) => `/app/${mod}/viewdd/:namespace/:id/:group?/:subsection?/:subgroup?/:formid?`,
260
- editDD: (mod) => `/app/${mod}/editdd/:namespace/:id/:group?/:subsection?/:subgroup?/:formid?`,
261
- }
301
+ edit: (mod, getRedirectLink) =>
302
+ typeof getRedirectLink === "function"
303
+ ? getRedirectLink(`/app/edit/:namespace/:id/:group?/:subsection?/:subgroup?/:formid?`)
304
+ : `/app/${mod}/edit/:namespace/:id/:group?/:subsection?/:subgroup?/:formid?`,
305
+ view: (mod, getRedirectLink) =>
306
+ typeof getRedirectLink === "function"
307
+ ? getRedirectLink(`/app/view/:namespace/:id/:group?/:subsection?/:subgroup?/:formid?`)
308
+ : `/app/${mod}/view/:namespace/:id/:group?/:subsection?/:subgroup?/:formid?`,
309
+ viewDD: (mod) => `/app/${mod}/viewdd/:namespace/:id/:group?/:subsection?/:subgroup?/:formid?`,
310
+ editDD: (mod) => `/app/${mod}/editdd/:namespace/:id/:group?/:subsection?/:subgroup?/:formid?`,
311
+ };
262
312
 
263
313
  export const CREATE_DRAWER_WIDTH = 480;
264
314
  export const CREATE_DRAWER_WIDTH_LARGE = 980;
@@ -273,7 +323,7 @@ export const MAX_TEXT_INPUT_LENGTH = 60;
273
323
  /************* ✨ Codeium Command ⭐ *************/
274
324
  /**
275
325
  * Returns a translated placeholder message based on the input metadata.
276
- *
326
+ *
277
327
  * @param {Object} inputMeta - Metadata about the input.
278
328
  * @param {Function} t - Translation function.
279
329
  * @returns {string|undefined} - Translated string indicating the input is not applicable or no information is available, or undefined if neither condition is met.
@@ -281,15 +331,15 @@ export const MAX_TEXT_INPUT_LENGTH = 60;
281
331
 
282
332
  /****** 8ec9ef5f-b701-4986-bbd5-34fbf3fbc2fb *******/
283
333
  export const getMetaPlaceholer = (inputMeta, t) =>
284
- inputMeta.notApplicable
285
- ? t('Not applicable')
286
- : inputMeta.notAvailable
287
- ? t('No available information')
288
- : undefined
334
+ inputMeta.notApplicable
335
+ ? t("Not applicable")
336
+ : inputMeta.notAvailable
337
+ ? t("No available information")
338
+ : undefined;
289
339
 
290
340
  /**
291
341
  * Filters select options based on the given filters. Used in filterOptions of ant select
292
- *
342
+ *
293
343
  * @param {Object[]} options - Options to filter.
294
344
  * @param {string[]} filters - Filters to apply.
295
345
  * @param {Object} [formsValue={}] - Form values.
@@ -297,70 +347,79 @@ export const getMetaPlaceholer = (inputMeta, t) =>
297
347
  * @param {string} [filterCond=null] - Filter condition.
298
348
  * @returns {Object[]} - Filtered options.
299
349
  */
300
- export function filterOptions(options, filters, formsValue = {}, repeatValues = {}, filterCond = null) {
301
- const isOrCond = filterCond !== 'and';
302
- const objFilter = {};
303
- filters.forEach(f => {
304
- const [name, p] = f.split('|');
305
- const [path, delimeter] = p.split(/( as )/gmi);
306
- let value;
307
- let isRepeatable = false;
308
- if (delimeter && delimeter.trim() === 'as') {
309
- value = path;
310
- } else {
311
- const pathInsideRepeatValues = path.split('./');
312
- isRepeatable = pathInsideRepeatValues.length > 1;
313
- value = deepFind(isRepeatable ? repeatValues : formsValue, pathInsideRepeatValues[pathInsideRepeatValues.length - 1]);
314
- }
315
- objFilter[name] = {
316
- value,
317
- isRepeatable
318
- };
319
- });
320
- options = options.filter(o => {
321
- if (!o.filters) {
322
- return true;
323
- } else {
324
- const opFilters = o.filters.filter(fi => objFilter[fi.name]);
325
- if (opFilters.length === 0) {
326
- return true;
327
- }
328
- const parts = opFilters.map(fi => {
329
- const filter = objFilter[fi.name];
330
- const value = Array.isArray(filter.value) ? filter.value : [filter.value];
331
- return _checkValue(
332
- value.join(','),
333
- fi.condition,
334
- fi.value
335
- );
336
- });
337
- return parts.length > 0 && ((isOrCond && parts.filter(p => p).length >= 1) || parts.filter(p => !p).length === 0);
338
- // if (!filter) {
339
- // return true;
340
- // } else {
341
- // if (Array.isArray(value)) {
342
- // switch (filter.condition) {
343
- // case 'includes':
344
- // return filter.value && Array.isArray(filter.value) && filter.value.filter(v => value.includes(v)).length > 0;
345
- // case 'and':
346
- // return filter.value && Array.isArray(filter.value) && filter.value.filter(v => v.filter(vv => value.includes(vv).length > 0)).length > 0;
347
- // default:
348
- // return value.includes(filter.value);
349
- // }
350
- // } else {
351
- // switch (filter.condition) {
352
- // case 'includes':
353
- // return filter.value && Array.isArray(filter.value) && filter.value.includes(value);
354
- // case 'and':
355
- // return filter.value && Array.isArray(filter.value) && filter.value.filter(v => v.includes(value)).length > 0;
356
- // default:
357
- // return filter.value === value;
358
- // }
359
- // }
360
- // }
361
- }
362
- })
363
- return options;
350
+ export function filterOptions(
351
+ options,
352
+ filters,
353
+ formsValue = {},
354
+ repeatValues = {},
355
+ filterCond = null,
356
+ ) {
357
+ const isOrCond = filterCond !== "and";
358
+ const objFilter = {};
359
+ filters.forEach((f) => {
360
+ const [name, p] = f.split("|");
361
+ const [path, delimeter] = p.split(/( as )/gim);
362
+ let value;
363
+ let isRepeatable = false;
364
+ if (delimeter && delimeter.trim() === "as") {
365
+ value = path;
366
+ } else {
367
+ const pathInsideRepeatValues = path.split("./");
368
+ isRepeatable = pathInsideRepeatValues.length > 1;
369
+ value = deepFind(
370
+ isRepeatable ? repeatValues : formsValue,
371
+ pathInsideRepeatValues[pathInsideRepeatValues.length - 1],
372
+ );
373
+ }
374
+ objFilter[name] = {
375
+ value,
376
+ isRepeatable,
377
+ };
378
+ });
379
+ options = options.filter((o) => {
380
+ if (!o.filters) {
381
+ return true;
382
+ } else {
383
+ const opFilters = o.filters.filter((fi) => objFilter[fi.name]);
384
+ if (opFilters.length === 0) {
385
+ return true;
386
+ }
387
+ const parts = opFilters.map((fi) => {
388
+ const filter = objFilter[fi.name];
389
+ const value = Array.isArray(filter.value) ? filter.value : [filter.value];
390
+ return _checkValue(value.join(","), fi.condition, fi.value);
391
+ });
392
+ return (
393
+ parts.length > 0 &&
394
+ ((isOrCond && parts.filter((p) => p).length >= 1) ||
395
+ parts.filter((p) => !p).length === 0)
396
+ );
397
+ // if (!filter) {
398
+ // return true;
399
+ // } else {
400
+ // if (Array.isArray(value)) {
401
+ // switch (filter.condition) {
402
+ // case 'includes':
403
+ // return filter.value && Array.isArray(filter.value) && filter.value.filter(v => value.includes(v)).length > 0;
404
+ // case 'and':
405
+ // return filter.value && Array.isArray(filter.value) && filter.value.filter(v => v.filter(vv => value.includes(vv).length > 0)).length > 0;
406
+ // default:
407
+ // return value.includes(filter.value);
408
+ // }
409
+ // } else {
410
+ // switch (filter.condition) {
411
+ // case 'includes':
412
+ // return filter.value && Array.isArray(filter.value) && filter.value.includes(value);
413
+ // case 'and':
414
+ // return filter.value && Array.isArray(filter.value) && filter.value.filter(v => v.includes(value)).length > 0;
415
+ // default:
416
+ // return filter.value === value;
417
+ // }
418
+ // }
419
+ // }
420
+ }
421
+ });
422
+ return options;
364
423
  }
365
424
 
366
425
  /**
@@ -377,17 +436,14 @@ export function filterOptions(options, filters, formsValue = {}, repeatValues =
377
436
  * const normalizedValue = getImageUploadEditValue(value); // ['http://example.com/image1.jpg', 'http://example.com/image2.jpg']
378
437
  */
379
438
  export const getImageUploadEditValue = (value) => {
380
- return (
381
- Array.isArray(value) ? value :
382
- (
383
- value &&
384
- typeof value === 'object' &&
385
- value.fileList &&
386
- Array.isArray(value.fileList) ?
387
- value.fileList.map(f => f.response).filter(f => f) : []
388
- )
389
- ) || [];
390
- }
439
+ return (
440
+ (Array.isArray(value)
441
+ ? value
442
+ : value && typeof value === "object" && value.fileList && Array.isArray(value.fileList)
443
+ ? value.fileList.map((f) => f.response).filter((f) => f)
444
+ : []) || []
445
+ );
446
+ };
391
447
 
392
448
  /**
393
449
  * @function getLabel
@@ -398,24 +454,21 @@ export const getImageUploadEditValue = (value) => {
398
454
  */
399
455
 
400
456
  export const getLabel = (label, allData) => {
401
- if (label && typeof label === 'object') {
402
- let toReturn = label;
457
+ if (label && typeof label === "object") {
458
+ let toReturn = label;
403
459
 
404
- Object.keys(label).forEach((k) => {
405
- const show = showHideInput(
406
- { showIf: k },
407
- allData
408
- )
460
+ Object.keys(label).forEach((k) => {
461
+ const show = showHideInput({ showIf: k }, allData);
409
462
 
410
- if (show) {
411
- toReturn = label[k];
412
- }
413
- })
463
+ if (show) {
464
+ toReturn = label[k];
465
+ }
466
+ });
414
467
 
415
- return toReturn;
416
- }
468
+ return toReturn;
469
+ }
417
470
 
418
- return label;
471
+ return label;
419
472
  };
420
473
 
421
474
  /**
@@ -424,17 +477,16 @@ export const getLabel = (label, allData) => {
424
477
  * @param {Array} arr - The array to check.
425
478
  * @returns {boolean} - True if the array contains only objects, false otherwise.
426
479
  */
427
- const isArrayOfObjects = (arr) => Array.isArray(arr) && arr
428
- .map(i => typeof i === 'object')
429
- .every(i => i);
480
+ const isArrayOfObjects = (arr) =>
481
+ Array.isArray(arr) && arr.map((i) => typeof i === "object").every((i) => i);
430
482
 
431
483
  /**
432
484
  * Determines if two sets of data have not changed. Used to show Save button disabled or not.
433
- *
485
+ *
434
486
  * @param {Object} old - The original data set.
435
487
  * @param {Object} newData - The new data set to compare against the original.
436
488
  * @returns {boolean} - True if the data sets have not changed, false otherwise.
437
- *
489
+ *
438
490
  * This function compares two objects by iterating over the union of their keys.
439
491
  * For each key, it checks the type of the value in newData:
440
492
  * - If undefined, it considers it unchanged.
@@ -446,87 +498,98 @@ const isArrayOfObjects = (arr) => Array.isArray(arr) && arr
446
498
  */
447
499
 
448
500
  export const hasNotChanged = (old, newData) => {
449
- return _.union(Object.keys(old), Object.keys(newData))
450
- .map(key => {
451
- switch (typeof newData[key]) {
452
- case undefined:
453
- return true;
454
- case 'object':
455
- try {
456
- if (moment.isMoment(newData[key])) {
457
- if (typeof newData[key].format === 'function') {
458
- return old[key] === newData[key].format('YYYY-MM-DD');
459
- }
460
- return old[key] === moment(newData[key]._d).format('YYYY-MM-DD');
461
- } else if (isArrayOfObjects(newData[key])) {
462
- return newData[key].length === (old[key] || []).length && newData[key].map((oKey, i) => hasNotChanged((old[key] || [])[i] || {}, oKey || {})).every(i => i);
463
- }
464
- } catch (e) {
465
- // console.log(e, data[key], key);
466
- }
467
- return _.isEqual(old[key], newData[key]);
468
- case 'number':
469
- case 'string':
470
- case 'boolean':
471
- return old[key] === newData[key];
472
- default:
473
- return false;
474
- }
475
- }).every(key => key);
476
- }
501
+ return _.union(Object.keys(old), Object.keys(newData))
502
+ .map((key) => {
503
+ switch (typeof newData[key]) {
504
+ case undefined:
505
+ return true;
506
+ case "object":
507
+ try {
508
+ if (moment.isMoment(newData[key])) {
509
+ if (typeof newData[key].format === "function") {
510
+ return old[key] === newData[key].format("YYYY-MM-DD");
511
+ }
512
+ return old[key] === moment(newData[key]._d).format("YYYY-MM-DD");
513
+ } else if (isArrayOfObjects(newData[key])) {
514
+ return (
515
+ newData[key].length === (old[key] || []).length &&
516
+ newData[key]
517
+ .map((oKey, i) =>
518
+ hasNotChanged((old[key] || [])[i] || {}, oKey || {}),
519
+ )
520
+ .every((i) => i)
521
+ );
522
+ }
523
+ } catch (e) {
524
+ // console.log(e, data[key], key);
525
+ }
526
+ return _.isEqual(old[key], newData[key]);
527
+ case "number":
528
+ case "string":
529
+ case "boolean":
530
+ return old[key] === newData[key];
531
+ default:
532
+ return false;
533
+ }
534
+ })
535
+ .every((key) => key);
536
+ };
477
537
 
478
538
  /**
479
539
  * Maps sub groups in the form data structure for submission. This is mainly created for ajaxSubGroup input type.
480
- *
540
+ *
481
541
  * This function takes a form data structure and maps its sub groups to
482
542
  * the format expected by the server. It does this by iterating over the
483
543
  * form definition and checking if any of the inputs have the type 'ajaxSubGroup'
484
544
  * with either yearRecords or checkboxRecords set. If they do, it aggregates
485
545
  * the data from the corresponding year-specific keys and sets it as an array
486
546
  * on the key specified in the form definition.
487
- *
547
+ *
488
548
  * @param {{ data: Object, form: Object }} - The form data structure.
489
549
  * @returns {Object} - The mapped form data structure.
490
550
  */
491
551
  export const mapSubGroupsInSubmit = ({ data, form }) => {
492
- const _data = { ...data };
493
- const ajaxSubGroupsWithPeridicity = [];
494
-
495
- Object.keys(form).forEach((k) => {
496
- Object.keys(form[k]).forEach((key) => {
497
- const input = form[k][key];
498
- if (input?.type === 'ajaxSubGroup'
499
- && (typeof input?.meta?.yearRecords === 'number' || typeof input?.meta?.checkboxRecords === 'string')) {
500
- ajaxSubGroupsWithPeridicity.push(key);
501
- }
502
- })
503
- })
504
-
505
- if (ajaxSubGroupsWithPeridicity.length) {
506
- ajaxSubGroupsWithPeridicity.forEach((key) => {
507
- const subGroupData = [];
508
-
509
- Object.keys(_data).forEach((dataKey) => {
510
- if (dataKey.includes(`-${key}`)) {
511
- const year = dataKey.split(`-${key}`)[0];
512
- subGroupData.push({
513
- ..._data[dataKey],
514
- meta: {
515
- ...(_data[dataKey]?.meta || {}),
516
- year: year,
517
- },
518
- })
519
-
520
- _data[dataKey] = null;
521
- delete _data[dataKey];
522
- }
523
- });
524
-
525
- _data[key] = subGroupData;
526
- });
527
- }
528
-
529
- return _data;
552
+ const _data = { ...data };
553
+ const ajaxSubGroupsWithPeridicity = [];
554
+
555
+ Object.keys(form).forEach((k) => {
556
+ Object.keys(form[k]).forEach((key) => {
557
+ const input = form[k][key];
558
+ if (
559
+ input?.type === "ajaxSubGroup" &&
560
+ (typeof input?.meta?.yearRecords === "number" ||
561
+ typeof input?.meta?.checkboxRecords === "string")
562
+ ) {
563
+ ajaxSubGroupsWithPeridicity.push(key);
564
+ }
565
+ });
566
+ });
567
+
568
+ if (ajaxSubGroupsWithPeridicity.length) {
569
+ ajaxSubGroupsWithPeridicity.forEach((key) => {
570
+ const subGroupData = [];
571
+
572
+ Object.keys(_data).forEach((dataKey) => {
573
+ if (dataKey.includes(`-${key}`)) {
574
+ const year = dataKey.split(`-${key}`)[0];
575
+ subGroupData.push({
576
+ ..._data[dataKey],
577
+ meta: {
578
+ ...(_data[dataKey]?.meta || {}),
579
+ year: year,
580
+ },
581
+ });
582
+
583
+ _data[dataKey] = null;
584
+ delete _data[dataKey];
585
+ }
586
+ });
587
+
588
+ _data[key] = subGroupData;
589
+ });
590
+ }
591
+
592
+ return _data;
530
593
  };
531
594
 
532
595
  /**
@@ -539,54 +602,59 @@ export const mapSubGroupsInSubmit = ({ data, form }) => {
539
602
  * @return {Object} the mapped data
540
603
  */
541
604
  export const mapSubGroupsInGet = ({ data, form }) => {
542
- const _data = { ...data };
543
- const ajaxSubGroupsWithPeridicity = [];
544
-
545
- Object.keys(form).forEach((k) => {
546
- if (form[k]?.type && form[k]?.dataId) {
547
- const input = form[k];
548
- if (input?.type === 'ajaxSubGroup'
549
- && (typeof input?.meta?.yearRecords === 'number' || typeof input?.meta?.checkboxRecords === 'string')) {
550
- ajaxSubGroupsWithPeridicity.push(k);
551
- }
552
- } else {
553
- Object.keys(form[k]).forEach((key) => {
554
- const input = form[k][key];
555
- if (input?.type === 'ajaxSubGroup'
556
- && (typeof input?.meta?.yearRecords === 'number' || typeof input?.meta?.checkboxRecords === 'string')) {
557
- ajaxSubGroupsWithPeridicity.push(key);
558
- }
559
- })
560
- }
561
- })
562
-
563
-
564
- if (ajaxSubGroupsWithPeridicity.length) {
565
- ajaxSubGroupsWithPeridicity.forEach((key) => {
566
- (_data[key] || []).forEach((period) => {
567
- _data[`${period?.meta?.year}-${key}`] = period;
568
- })
569
-
570
- _data[key] = null;
571
- delete _data[key];
572
- });
573
- }
574
-
575
- return _data;
605
+ const _data = { ...data };
606
+ const ajaxSubGroupsWithPeridicity = [];
607
+
608
+ Object.keys(form).forEach((k) => {
609
+ if (form[k]?.type && form[k]?.dataId) {
610
+ const input = form[k];
611
+ if (
612
+ input?.type === "ajaxSubGroup" &&
613
+ (typeof input?.meta?.yearRecords === "number" ||
614
+ typeof input?.meta?.checkboxRecords === "string")
615
+ ) {
616
+ ajaxSubGroupsWithPeridicity.push(k);
617
+ }
618
+ } else {
619
+ Object.keys(form[k]).forEach((key) => {
620
+ const input = form[k][key];
621
+ if (
622
+ input?.type === "ajaxSubGroup" &&
623
+ (typeof input?.meta?.yearRecords === "number" ||
624
+ typeof input?.meta?.checkboxRecords === "string")
625
+ ) {
626
+ ajaxSubGroupsWithPeridicity.push(key);
627
+ }
628
+ });
629
+ }
630
+ });
631
+
632
+ if (ajaxSubGroupsWithPeridicity.length) {
633
+ ajaxSubGroupsWithPeridicity.forEach((key) => {
634
+ (_data[key] || []).forEach((period) => {
635
+ _data[`${period?.meta?.year}-${key}`] = period;
636
+ });
637
+
638
+ _data[key] = null;
639
+ delete _data[key];
640
+ });
641
+ }
642
+
643
+ return _data;
576
644
  };
577
645
 
578
- export const noActionsInputs = ['groupExpandable', 'groupCheckbox'];
646
+ export const noActionsInputs = ["groupExpandable", "groupCheckbox", "smartHelp"];
579
647
 
580
648
  const isObjectEmpty = (obj) => {
581
- if (obj === null || typeof obj !== 'object') {
582
- return false;
583
- }
649
+ if (obj === null || typeof obj !== "object") {
650
+ return false;
651
+ }
584
652
 
585
- if (Object.keys(obj).length === 0) {
586
- return true;
587
- }
653
+ if (Object.keys(obj).length === 0) {
654
+ return true;
655
+ }
588
656
 
589
- return Object.values(obj).every(value => isObjectEmpty(value));
657
+ return Object.values(obj).every((value) => isObjectEmpty(value));
590
658
  };
591
659
 
592
660
  /**
@@ -600,10 +668,10 @@ const isObjectEmpty = (obj) => {
600
668
  */
601
669
 
602
670
  export const filterCreateData = (data) => {
603
- // eslint-disable-next-line no-unused-vars
604
- const { view, module, scope, form, meta, ...rest } = data;
605
- const _meta = isObjectEmpty(meta) ? undefined : meta;
606
- return { ...rest, meta: _meta };
671
+ // eslint-disable-next-line no-unused-vars
672
+ const { view, module, scope, form, meta, ...rest } = data;
673
+ const _meta = isObjectEmpty(meta) ? undefined : meta;
674
+ return { ...rest, meta: _meta };
607
675
  };
608
676
 
609
677
  /**
@@ -621,50 +689,61 @@ export const filterCreateData = (data) => {
621
689
  * @param {function} options.onValuesChange - The function to call when the values change.
622
690
  */
623
691
  export const changeInputMeta = ({
624
- key, type, value, otherValues = {},
625
- setInputsMeta, editValues, MainForm, setData, onValuesChange,
692
+ key,
693
+ type,
694
+ value,
695
+ otherValues = {},
696
+ setInputsMeta,
697
+ editValues,
698
+ MainForm,
699
+ setData,
700
+ onValuesChange,
626
701
  }) => {
627
- switch (type) {
628
- default:
629
- setInputsMeta((prev) => ({
630
- ...prev,
631
- [key]: value ? { ...(prev[key] || {}), ...value } : undefined,
632
- }));
633
-
634
- const _val = {
635
- meta: {
636
- ...editValues?.meta,
637
- inputs: {
638
- ...(editValues?.meta?.inputs || {}),
639
- [key]: value ? { ...((editValues?.meta || {})[key] || {}), ...value } : undefined,
640
- },
641
- },
642
- ...otherValues,
643
- };
644
-
645
- const _all = {
646
- ...editValues,
647
- ...otherValues,
648
- meta: {
649
- ...editValues.meta,
650
- inputs: {
651
- ...(editValues?.meta?.inputs || {}),
652
- [key]: value ? { ...((editValues.meta || {})[key] || {}), ...value } : undefined,
653
- },
654
- },
655
- };
656
-
657
- const _otherValuesKeys = Object.keys(otherValues);
658
-
659
- if (_otherValuesKeys.length) {
660
- _otherValuesKeys.forEach((k) => {
661
- MainForm.setFieldValue(k, otherValues[k]);
662
- });
663
- }
664
-
665
- setData(_all);
666
- onValuesChange(_val, _all);
667
- }
702
+ switch (type) {
703
+ default:
704
+ setInputsMeta((prev) => ({
705
+ ...prev,
706
+ [key]: value ? { ...(prev[key] || {}), ...value } : undefined,
707
+ }));
708
+
709
+ const _val = {
710
+ meta: {
711
+ ...editValues?.meta,
712
+ inputs: {
713
+ ...(editValues?.meta?.inputs || {}),
714
+ [key]: value
715
+ ? { ...((editValues?.meta || {})[key] || {}), ...value }
716
+ : undefined,
717
+ },
718
+ },
719
+ ...otherValues,
720
+ };
721
+
722
+ const _all = {
723
+ ...editValues,
724
+ ...otherValues,
725
+ meta: {
726
+ ...editValues.meta,
727
+ inputs: {
728
+ ...(editValues?.meta?.inputs || {}),
729
+ [key]: value
730
+ ? { ...((editValues.meta || {})[key] || {}), ...value }
731
+ : undefined,
732
+ },
733
+ },
734
+ };
735
+
736
+ const _otherValuesKeys = Object.keys(otherValues);
737
+
738
+ if (_otherValuesKeys.length) {
739
+ _otherValuesKeys.forEach((k) => {
740
+ MainForm.setFieldValue(k, otherValues[k]);
741
+ });
742
+ }
743
+
744
+ setData(_all);
745
+ onValuesChange(_val, _all);
746
+ }
668
747
  };
669
748
 
670
749
  /**
@@ -677,8 +756,8 @@ export const changeInputMeta = ({
677
756
  * @returns {string} - The formatted date string.
678
757
  */
679
758
 
680
- export const renderDateFormatted = (value, format = 'DD MMM YYYY', locale = 'en') => {
681
- return dayjs.utc(value, 'YYYY-MM-DD').locale(locale).format(format);
759
+ export const renderDateFormatted = (value, format = "DD MMM YYYY", locale = "en") => {
760
+ return dayjs.utc(value, "YYYY-MM-DD").locale(locale).format(format);
682
761
  };
683
762
  /**
684
763
  * Sorts a form object by its inputs' positions.
@@ -687,23 +766,23 @@ export const renderDateFormatted = (value, format = 'DD MMM YYYY', locale = 'en'
687
766
  * @returns {Object} - The sorted form object.
688
767
  */
689
768
  export const sortForm = ({ form }) => {
690
- const _form = Object.keys(form).reduce((all, key) => {
691
- const _this = Object.keys(form[key])
692
- .sort((a, b) => form[key][a].position - form[key][b].position)
693
- .reduce((all, k) => {
694
- if (k === 'scope') {
695
- return all;
696
- }
697
-
698
- all[k] = form[key][k];
699
- return all;
700
- }, {});
701
-
702
- all[key] = _this;
703
- return all;
704
- }, {});
705
-
706
- return _form;
769
+ const _form = Object.keys(form).reduce((all, key) => {
770
+ const _this = Object.keys(form[key])
771
+ .sort((a, b) => form[key][a].position - form[key][b].position)
772
+ .reduce((all, k) => {
773
+ if (k === "scope") {
774
+ return all;
775
+ }
776
+
777
+ all[k] = form[key][k];
778
+ return all;
779
+ }, {});
780
+
781
+ all[key] = _this;
782
+ return all;
783
+ }, {});
784
+
785
+ return _form;
707
786
  };
708
787
 
709
788
  /**
@@ -721,13 +800,13 @@ export const sortForm = ({ form }) => {
721
800
  */
722
801
 
723
802
  export const getLabelFromScopeForDataLink = (labelObj, formScope) => {
724
- if (typeof labelObj !== 'object' || !formScope) return labelObj;
803
+ if (typeof labelObj !== "object" || !formScope) return labelObj;
725
804
 
726
- const matchKey = Object.keys(labelObj).find(k => k.includes(`scope is ${formScope}`));
727
- if (matchKey) return labelObj[matchKey];
805
+ const matchKey = Object.keys(labelObj).find((k) => k.includes(`scope is ${formScope}`));
806
+ if (matchKey) return labelObj[matchKey];
728
807
 
729
- const fallbackKey = Object.keys(labelObj).find(k => k.startsWith("scope not"));
730
- if (fallbackKey) return labelObj[fallbackKey];
808
+ const fallbackKey = Object.keys(labelObj).find((k) => k.startsWith("scope not"));
809
+ if (fallbackKey) return labelObj[fallbackKey];
731
810
 
732
- return "";
811
+ return "";
733
812
  };