@nestledjs/data-browser 1.0.10 → 1.0.12

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.
@@ -130,10 +130,21 @@ function extractInitialValues(model, item) {
130
130
  } else {
131
131
  value = sanitizeFieldValue(value, field);
132
132
  }
133
+ if (field.kind === "enum" && field.isList && Array.isArray(value)) {
134
+ const arrayValue = value;
135
+ value = value.join(",");
136
+ console.log(`[DataBrowser] Enum array field detected - "${field.name}":`, {
137
+ type: field.type,
138
+ arrayValue,
139
+ convertedValue: value
140
+ });
141
+ }
133
142
  initialValues[field.name] = value;
134
143
  if (value !== null && typeof value === "string" && fieldTypeLower !== "string" && fieldTypeLower !== "datetime" && fieldTypeLower !== "date") {
135
144
  console.log(`[DataBrowser] Enum field detected - "${field.name}":`, {
136
145
  type: field.type,
146
+ kind: field.kind,
147
+ isList: field.isList,
137
148
  extractedValue: value,
138
149
  rawValue: item[field.name]
139
150
  });
@@ -195,8 +195,33 @@ function buildFormFields(sdk, model, operation, options = {}) {
195
195
  enumType: field.type,
196
196
  availableValues: enumValues,
197
197
  currentValue: initialValue,
198
- operation
198
+ operation,
199
+ isList: field.isList
199
200
  });
201
+ if (field.isList) {
202
+ let defaultValue = "";
203
+ if (Array.isArray(initialValue) && initialValue.length > 0) {
204
+ defaultValue = initialValue.join(",");
205
+ }
206
+ console.log(`[DataBrowser] Array enum field "${field.name}" converted:`, {
207
+ arrayValue: initialValue,
208
+ stringValue: defaultValue
209
+ });
210
+ const checkboxOptions = enumValues.map((value) => ({
211
+ key: value,
212
+ value,
213
+ label: value.replaceAll("_", " ").toLowerCase().replace(/^./, (str) => str.toUpperCase())
214
+ }));
215
+ formField = FormFieldClass.checkboxGroup(field.name, {
216
+ label: options2.label,
217
+ required: options2.required,
218
+ checkboxOptions,
219
+ checkboxDirection: "column",
220
+ // Don't set value in field options for update operations
221
+ ...operation !== "update" && defaultValue && { defaultValue }
222
+ });
223
+ break;
224
+ }
200
225
  const selectOptions = enumValues.map((value) => ({
201
226
  value,
202
227
  label: value.replace(/_/g, " ").toLowerCase().replace(/^./, (str) => str.toUpperCase())
@@ -435,7 +460,7 @@ function processNestedObject(value, model) {
435
460
  return Object.keys(cleanedNested).length > 0 ? cleanedNested : null;
436
461
  }
437
462
  function cleanFormInput(input, model) {
438
- var _a, _b, _c, _d, _e;
463
+ var _a, _b, _c, _d, _e, _f, _g;
439
464
  console.log(`[DataBrowser] Cleaning form input for ${model == null ? void 0 : model.name}:`, input);
440
465
  const cleaned = {};
441
466
  const booleanFields = new Set(
@@ -444,11 +469,31 @@ function cleanFormInput(input, model) {
444
469
  const requiredArrayFields = new Set(
445
470
  ((_d = (_c = model == null ? void 0 : model.fields) == null ? void 0 : _c.filter((field) => field.isList && !field.isOptional && !field.relationName)) == null ? void 0 : _d.map((field) => field.name)) || []
446
471
  );
472
+ const enumArrayFields = new Set(
473
+ ((_f = (_e = model == null ? void 0 : model.fields) == null ? void 0 : _e.filter((field) => field.isList && field.kind === "enum")) == null ? void 0 : _f.map((field) => field.name)) || []
474
+ );
447
475
  for (const [key, value] of Object.entries(input)) {
448
476
  if (booleanFields.has(key) && value === void 0) {
449
477
  cleaned[key] = false;
450
478
  continue;
451
479
  }
480
+ if (enumArrayFields.has(key)) {
481
+ if (typeof value === "string") {
482
+ const arrayValue = value.split(",").filter((v) => v.trim() !== "");
483
+ console.log(`[DataBrowser] Converting enum array "${key}":`, {
484
+ stringValue: value,
485
+ arrayValue
486
+ });
487
+ cleaned[key] = arrayValue;
488
+ continue;
489
+ } else if (Array.isArray(value)) {
490
+ cleaned[key] = value;
491
+ continue;
492
+ } else if (value === void 0 || value === null || value === "") {
493
+ cleaned[key] = [];
494
+ continue;
495
+ }
496
+ }
452
497
  if (requiredArrayFields.has(key) && (value === void 0 || value === null || value === "")) {
453
498
  cleaned[key] = [];
454
499
  continue;
@@ -457,7 +502,7 @@ function cleanFormInput(input, model) {
457
502
  continue;
458
503
  }
459
504
  if (typeof value === "string") {
460
- const field = (_e = model == null ? void 0 : model.fields) == null ? void 0 : _e.find((f) => f.name === key);
505
+ const field = (_g = model == null ? void 0 : model.fields) == null ? void 0 : _g.find((f) => f.name === key);
461
506
  const convertedValue = convertStringValue(value, field);
462
507
  cleaned[key] = convertedValue;
463
508
  continue;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nestledjs/data-browser",
3
- "version": "1.0.10",
3
+ "version": "1.0.12",
4
4
  "description": "Universal admin data browser for Nestled framework projects with full CRUD operations",
5
5
  "main": "./index.js",
6
6
  "module": "./index.js",
@@ -38,7 +38,7 @@
38
38
  "@apollo/client": "^4.0.0",
39
39
  "@heroicons/react": "^2.0.0",
40
40
  "@nestledjs/forms": "^0.6.3",
41
- "@nestledjs/shared-components": "^1.0.10",
41
+ "@nestledjs/shared-components": "^1.0.12",
42
42
  "react": "^19.0.0",
43
43
  "react-router": "^7.0.0"
44
44
  },