@nestledjs/data-browser 1.0.10 → 1.0.13

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.
@@ -125,7 +125,18 @@ function extractInitialValues(model, item) {
125
125
  initialValues[relationFieldName] = processRelationFieldValue(field, item);
126
126
  } else {
127
127
  const fieldTypeLower = field.type.toLowerCase();
128
- if (fieldTypeLower === "datetime" || fieldTypeLower === "date") {
128
+ if (field.kind === "enum" && field.isList) {
129
+ if (!Array.isArray(value)) {
130
+ value = [];
131
+ }
132
+ const arrayValue = value;
133
+ value = value.join(",");
134
+ console.log(`[DataBrowser] Enum array field detected - "${field.name}":`, {
135
+ type: field.type,
136
+ arrayValue,
137
+ convertedValue: value
138
+ });
139
+ } else if (fieldTypeLower === "datetime" || fieldTypeLower === "date") {
129
140
  value = processDateFieldValue(field, value);
130
141
  } else {
131
142
  value = sanitizeFieldValue(value, field);
@@ -134,6 +145,8 @@ function extractInitialValues(model, item) {
134
145
  if (value !== null && typeof value === "string" && fieldTypeLower !== "string" && fieldTypeLower !== "datetime" && fieldTypeLower !== "date") {
135
146
  console.log(`[DataBrowser] Enum field detected - "${field.name}":`, {
136
147
  type: field.type,
148
+ kind: field.kind,
149
+ isList: field.isList,
137
150
  extractedValue: value,
138
151
  rawValue: item[field.name]
139
152
  });
@@ -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.13",
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.13",
42
42
  "react": "^19.0.0",
43
43
  "react-router": "^7.0.0"
44
44
  },