@visns-studio/visns-components 4.4.2 → 4.4.3
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.
|
@@ -115,7 +115,7 @@ function GenericDetail({ extraUrlParam, setting, urlParam, userProfile }) {
|
|
|
115
115
|
setDataReload(randomNumber);
|
|
116
116
|
};
|
|
117
117
|
|
|
118
|
-
const getValueFromData = (data, path, id) => {
|
|
118
|
+
const getValueFromData = (data, path, id, type) => {
|
|
119
119
|
let value =
|
|
120
120
|
path.reduce((result, key) => (result ? result[key] : ''), data) ??
|
|
121
121
|
'';
|
|
@@ -128,7 +128,11 @@ function GenericDetail({ extraUrlParam, setting, urlParam, userProfile }) {
|
|
|
128
128
|
.join(', ');
|
|
129
129
|
} else {
|
|
130
130
|
if (Array.isArray(id)) {
|
|
131
|
-
|
|
131
|
+
if (type === 'checkbox') {
|
|
132
|
+
return value[id];
|
|
133
|
+
} else {
|
|
134
|
+
return id.map((key) => value[key]).join(' ');
|
|
135
|
+
}
|
|
132
136
|
} else {
|
|
133
137
|
return value[id];
|
|
134
138
|
}
|
|
@@ -166,8 +170,9 @@ function GenericDetail({ extraUrlParam, setting, urlParam, userProfile }) {
|
|
|
166
170
|
} = item;
|
|
167
171
|
const value =
|
|
168
172
|
relation && relation.length > 0 && type !== 'total'
|
|
169
|
-
? getValueFromData(data, [...relation], id)
|
|
170
|
-
: getValueFromData(data, [], id);
|
|
173
|
+
? getValueFromData(data, [...relation], id, type)
|
|
174
|
+
: getValueFromData(data, [], id, type);
|
|
175
|
+
|
|
171
176
|
const stringValue = String(value ?? ''); // Convert value to a string
|
|
172
177
|
|
|
173
178
|
// Conditionally truncate the value if the 'truncate' key is present
|
|
@@ -229,9 +234,45 @@ function GenericDetail({ extraUrlParam, setting, urlParam, userProfile }) {
|
|
|
229
234
|
|
|
230
235
|
const renderBoolean = () => (value ? 'Yes' : 'No');
|
|
231
236
|
|
|
232
|
-
const renderCheckbox = (
|
|
233
|
-
|
|
234
|
-
|
|
237
|
+
const renderCheckbox = () => {
|
|
238
|
+
if (!value || typeof value !== 'object') {
|
|
239
|
+
return '';
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
const formatKey = (key) => {
|
|
243
|
+
return key
|
|
244
|
+
.toLowerCase()
|
|
245
|
+
.split('_')
|
|
246
|
+
.map((word) => word.charAt(0).toUpperCase() + word.slice(1))
|
|
247
|
+
.join(' ');
|
|
248
|
+
};
|
|
249
|
+
|
|
250
|
+
const keys = Object.keys(value)
|
|
251
|
+
.filter((key) => value[key] && key !== 'notes')
|
|
252
|
+
.sort((a, b) => {
|
|
253
|
+
if (a === 'other') return 1;
|
|
254
|
+
if (b === 'other') return -1;
|
|
255
|
+
return a.localeCompare(b);
|
|
256
|
+
});
|
|
257
|
+
|
|
258
|
+
const formattedKeys = keys.map((key) => {
|
|
259
|
+
let formattedKey = formatKey(key);
|
|
260
|
+
if (key === 'other') {
|
|
261
|
+
const otherValue = getValueFromData(
|
|
262
|
+
data,
|
|
263
|
+
[...relation],
|
|
264
|
+
`${id}_other`,
|
|
265
|
+
type
|
|
266
|
+
);
|
|
267
|
+
|
|
268
|
+
if (otherValue) {
|
|
269
|
+
formattedKey += `: ${otherValue}`;
|
|
270
|
+
}
|
|
271
|
+
}
|
|
272
|
+
return formattedKey;
|
|
273
|
+
});
|
|
274
|
+
|
|
275
|
+
return formattedKeys.join(', ');
|
|
235
276
|
};
|
|
236
277
|
|
|
237
278
|
const renderDate = () => formatDateValue(value);
|
package/package.json
CHANGED