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.
- package/.env +8 -0
- package/.vscode/settings.json +13 -0
- package/dist/components/index.js +43 -43
- package/dist/utils/index.js +34 -34
- package/package.json +1 -1
- package/src/@daf/core/components/EditForm/storyConfig1.js +155 -249
- package/src/@daf/core/components/EditForm/storyConfig2.js +127 -21
- package/src/helpers/Forms.js +522 -443
package/src/helpers/Forms.js
CHANGED
|
@@ -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
|
|
6
|
-
import customParseFormat from
|
|
7
|
-
import utc from
|
|
8
|
-
import localizedFormat from
|
|
9
|
-
import
|
|
10
|
-
import
|
|
11
|
-
import
|
|
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
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
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
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
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
|
-
|
|
184
|
-
|
|
185
|
-
|
|
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
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
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
|
-
|
|
254
|
+
const years = [];
|
|
220
255
|
|
|
221
|
-
|
|
222
|
-
|
|
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
|
-
|
|
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
|
-
|
|
276
|
+
const numbers = [];
|
|
238
277
|
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
278
|
+
for (let j = 0; j < i; j++) {
|
|
279
|
+
numbers.push(j + 1);
|
|
280
|
+
}
|
|
242
281
|
|
|
243
|
-
|
|
282
|
+
return numbers;
|
|
244
283
|
};
|
|
245
284
|
|
|
246
285
|
export const tooltipInputs = [
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
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
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
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
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
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(
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
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
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
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
|
-
|
|
402
|
-
|
|
457
|
+
if (label && typeof label === "object") {
|
|
458
|
+
let toReturn = label;
|
|
403
459
|
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
{ showIf: k },
|
|
407
|
-
allData
|
|
408
|
-
)
|
|
460
|
+
Object.keys(label).forEach((k) => {
|
|
461
|
+
const show = showHideInput({ showIf: k }, allData);
|
|
409
462
|
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
463
|
+
if (show) {
|
|
464
|
+
toReturn = label[k];
|
|
465
|
+
}
|
|
466
|
+
});
|
|
414
467
|
|
|
415
|
-
|
|
416
|
-
|
|
468
|
+
return toReturn;
|
|
469
|
+
}
|
|
417
470
|
|
|
418
|
-
|
|
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) =>
|
|
428
|
-
|
|
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
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
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
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
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
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
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 = [
|
|
646
|
+
export const noActionsInputs = ["groupExpandable", "groupCheckbox", "smartHelp"];
|
|
579
647
|
|
|
580
648
|
const isObjectEmpty = (obj) => {
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
649
|
+
if (obj === null || typeof obj !== "object") {
|
|
650
|
+
return false;
|
|
651
|
+
}
|
|
584
652
|
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
653
|
+
if (Object.keys(obj).length === 0) {
|
|
654
|
+
return true;
|
|
655
|
+
}
|
|
588
656
|
|
|
589
|
-
|
|
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
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
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
|
-
|
|
625
|
-
|
|
692
|
+
key,
|
|
693
|
+
type,
|
|
694
|
+
value,
|
|
695
|
+
otherValues = {},
|
|
696
|
+
setInputsMeta,
|
|
697
|
+
editValues,
|
|
698
|
+
MainForm,
|
|
699
|
+
setData,
|
|
700
|
+
onValuesChange,
|
|
626
701
|
}) => {
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
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 =
|
|
681
|
-
|
|
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
|
-
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
|
|
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
|
-
|
|
803
|
+
if (typeof labelObj !== "object" || !formScope) return labelObj;
|
|
725
804
|
|
|
726
|
-
|
|
727
|
-
|
|
805
|
+
const matchKey = Object.keys(labelObj).find((k) => k.includes(`scope is ${formScope}`));
|
|
806
|
+
if (matchKey) return labelObj[matchKey];
|
|
728
807
|
|
|
729
|
-
|
|
730
|
-
|
|
808
|
+
const fallbackKey = Object.keys(labelObj).find((k) => k.startsWith("scope not"));
|
|
809
|
+
if (fallbackKey) return labelObj[fallbackKey];
|
|
731
810
|
|
|
732
|
-
|
|
811
|
+
return "";
|
|
733
812
|
};
|