@nestledjs/data-browser 1.0.9 → 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.
@@ -106,6 +106,7 @@ function extractInitialValues(model, item) {
106
106
  if (!item) {
107
107
  return initialValues;
108
108
  }
109
+ console.log(`[DataBrowser] Extracting initial values for ${model.name}:`, item);
109
110
  const idField = model.fields.find((f) => f.isId);
110
111
  if (idField) {
111
112
  initialValues[idField.name] = item[idField.name];
@@ -129,10 +130,29 @@ function extractInitialValues(model, item) {
129
130
  } else {
130
131
  value = sanitizeFieldValue(value, field);
131
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
+ }
132
142
  initialValues[field.name] = value;
143
+ if (value !== null && typeof value === "string" && fieldTypeLower !== "string" && fieldTypeLower !== "datetime" && fieldTypeLower !== "date") {
144
+ console.log(`[DataBrowser] Enum field detected - "${field.name}":`, {
145
+ type: field.type,
146
+ kind: field.kind,
147
+ isList: field.isList,
148
+ extractedValue: value,
149
+ rawValue: item[field.name]
150
+ });
151
+ }
133
152
  }
134
153
  });
135
154
  performFinalSafetyChecks(initialValues, model);
155
+ console.log(`[DataBrowser] Final initial values for ${model.name}:`, initialValues);
136
156
  return initialValues;
137
157
  }
138
158
  const validateId = (id) => {
@@ -483,6 +503,7 @@ function AdminDataEditPageContent({ model, id, basePath, formTheme, displayField
483
503
  });
484
504
  const initialValues = extractInitialValues(model, item);
485
505
  const handleSubmit = async (formData) => {
506
+ console.log(`[DataBrowser] Form submission for ${model.name}:`, formData);
486
507
  setSubmissionState({ status: "loading" });
487
508
  const result = await executeUpdateMutation(updateMutation, formData, model, id, idVariableName);
488
509
  setSubmissionState({
@@ -491,7 +512,9 @@ function AdminDataEditPageContent({ model, id, basePath, formTheme, displayField
491
512
  });
492
513
  window.scrollTo({ top: 0, behavior: "smooth" });
493
514
  if (result.success) {
494
- await refetch();
515
+ console.log(`[DataBrowser] Update successful, refetching data for ${model.name}...`);
516
+ const refetchResult = await refetch();
517
+ console.log(`[DataBrowser] Refetch complete for ${model.name}:`, refetchResult.data);
495
518
  }
496
519
  };
497
520
  const handleDelete = async () => {
@@ -191,14 +191,43 @@ function buildFormFields(sdk, model, operation, options = {}) {
191
191
  default: {
192
192
  const enumValues = getEnumValues(sdk, field.type);
193
193
  if (enumValues) {
194
+ console.log(`[DataBrowser] Building enum field "${field.name}":`, {
195
+ enumType: field.type,
196
+ availableValues: enumValues,
197
+ currentValue: initialValue,
198
+ operation,
199
+ isList: field.isList
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
+ }
194
225
  const selectOptions = enumValues.map((value) => ({
195
226
  value,
196
227
  label: value.replace(/_/g, " ").toLowerCase().replace(/^./, (str) => str.toUpperCase())
197
228
  }));
198
- formField = FormFieldClass.select(field.name, {
199
- ...options2,
200
- options: selectOptions
201
- });
229
+ const enumOptions = operation === "update" ? { label: options2.label, required: options2.required, options: selectOptions } : { ...options2, options: selectOptions };
230
+ formField = FormFieldClass.select(field.name, enumOptions);
202
231
  break;
203
232
  }
204
233
  if (field.relationName && !field.isList) {
@@ -431,7 +460,8 @@ function processNestedObject(value, model) {
431
460
  return Object.keys(cleanedNested).length > 0 ? cleanedNested : null;
432
461
  }
433
462
  function cleanFormInput(input, model) {
434
- var _a, _b, _c, _d, _e;
463
+ var _a, _b, _c, _d, _e, _f, _g;
464
+ console.log(`[DataBrowser] Cleaning form input for ${model == null ? void 0 : model.name}:`, input);
435
465
  const cleaned = {};
436
466
  const booleanFields = new Set(
437
467
  ((_b = (_a = model == null ? void 0 : model.fields) == null ? void 0 : _a.filter((field) => field.type.toLowerCase() === "boolean")) == null ? void 0 : _b.map((field) => field.name)) || []
@@ -439,11 +469,31 @@ function cleanFormInput(input, model) {
439
469
  const requiredArrayFields = new Set(
440
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)) || []
441
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
+ );
442
475
  for (const [key, value] of Object.entries(input)) {
443
476
  if (booleanFields.has(key) && value === void 0) {
444
477
  cleaned[key] = false;
445
478
  continue;
446
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
+ }
447
497
  if (requiredArrayFields.has(key) && (value === void 0 || value === null || value === "")) {
448
498
  cleaned[key] = [];
449
499
  continue;
@@ -452,7 +502,7 @@ function cleanFormInput(input, model) {
452
502
  continue;
453
503
  }
454
504
  if (typeof value === "string") {
455
- 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);
456
506
  const convertedValue = convertStringValue(value, field);
457
507
  cleaned[key] = convertedValue;
458
508
  continue;
@@ -471,6 +521,7 @@ function cleanFormInput(input, model) {
471
521
  }
472
522
  cleaned[key] = value;
473
523
  }
524
+ console.log(`[DataBrowser] Cleaned form input for ${model == null ? void 0 : model.name}:`, cleaned);
474
525
  return cleaned;
475
526
  }
476
527
  export {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nestledjs/data-browser",
3
- "version": "1.0.9",
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.9",
41
+ "@nestledjs/shared-components": "^1.0.12",
42
42
  "react": "^19.0.0",
43
43
  "react-router": "^7.0.0"
44
44
  },