@visns-studio/visns-components 5.13.17 → 5.13.18

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/package.json CHANGED
@@ -88,7 +88,7 @@
88
88
  "react-dom": "^17.0.0 || ^18.0.0"
89
89
  },
90
90
  "name": "@visns-studio/visns-components",
91
- "version": "5.13.17",
91
+ "version": "5.13.18",
92
92
  "description": "Various packages to assist in the development of our Custom Applications.",
93
93
  "main": "src/index.js",
94
94
  "files": [
@@ -375,6 +375,14 @@ const GenericEditableTable = ({
375
375
  setSelectedRows(new Set());
376
376
  }, [dataSets, activeDatasetIndex, hasMarginRow, rows.marginRow]);
377
377
 
378
+ // Initialize newEntry with default values when columns change
379
+ useEffect(() => {
380
+ const defaultValues = getDefaultRowValues();
381
+ if (!hasCategory) {
382
+ setNewEntry(defaultValues);
383
+ }
384
+ }, [columns, hasCategory]);
385
+
378
386
  // Helper to sort by sort_order
379
387
  const sortBySortOrder = (dataArray) =>
380
388
  [...dataArray].sort((a, b) => a.sort_order - b.sort_order);
@@ -416,6 +424,73 @@ const GenericEditableTable = ({
416
424
  return undefined;
417
425
  };
418
426
 
427
+ // Helper function to get default values for new row
428
+ const getDefaultRowValues = () => {
429
+ const defaultValues = {};
430
+ columns.forEach((column) => {
431
+ switch (column.type) {
432
+ case 'dropdown':
433
+ if (column.options && column.options.length > 0) {
434
+ defaultValues[column.id] = column.options[0].id;
435
+ }
436
+ break;
437
+ case 'dropdown-ajax':
438
+ // Reset to empty for ajax dropdowns
439
+ defaultValues[column.id] = '';
440
+ break;
441
+ case 'currency':
442
+ case 'number':
443
+ case 'text':
444
+ case 'date':
445
+ case 'html5_date':
446
+ // Reset to empty string for input fields
447
+ defaultValues[column.id] = '';
448
+ break;
449
+ case 'multi-dropdown-ajax':
450
+ // Reset to empty for multi-select
451
+ defaultValues[column.id] = '';
452
+ break;
453
+ case 'total':
454
+ // Don't reset total fields as they are calculated
455
+ break;
456
+ case 'colour':
457
+ // Reset colour fields
458
+ defaultValues[column.id] = '';
459
+ break;
460
+ default:
461
+ // Reset any other field types to empty string
462
+ defaultValues[column.id] = '';
463
+ break;
464
+ }
465
+ });
466
+ return defaultValues;
467
+ };
468
+
469
+ // Helper function to get add row background color (same logic as getRowBackground)
470
+ const getAddRowBackground = (newRowData, groupId = null) => {
471
+ if (!newRowData) newRowData = {};
472
+
473
+ // Ensure default status values are applied for color calculation
474
+ const enrichedRowData = { ...newRowData };
475
+ columns.forEach((column) => {
476
+ if (column.type === 'dropdown' && column.options && column.options.length > 0) {
477
+ if (!enrichedRowData[column.id]) {
478
+ enrichedRowData[column.id] = column.options[0].id;
479
+ }
480
+ }
481
+ });
482
+
483
+ // Check if there's a colour picked from the colours column
484
+ const coloursValue = enrichedRowData.colours || enrichedRowData.row_colour;
485
+ if (coloursValue) {
486
+ return `${coloursValue}40`; // Add 40% opacity
487
+ }
488
+
489
+ // Check for status color if no manual color is set
490
+ const statusColor = getStatusColor(enrichedRowData);
491
+ return statusColor ? `${statusColor}40` : undefined; // Add 40% opacity
492
+ };
493
+
419
494
  // Calculate total project cost (sum of all entries excluding margin row)
420
495
  const calculateTotalProjectCost = (dataEntries) => {
421
496
  const totalColIndex = columns.findIndex((c) => c.type === 'total');
@@ -674,11 +749,12 @@ const GenericEditableTable = ({
674
749
  setDataSets(updatedDataSets);
675
750
  debouncedUpdate(updatedDataSets);
676
751
 
677
- // Reset new-entry state
752
+ // Reset new-entry state with default values
753
+ const defaultValues = getDefaultRowValues();
678
754
  if (hasCategory) {
679
- setNewEntries((prev) => ({ ...prev, [groupId]: {} }));
755
+ setNewEntries((prev) => ({ ...prev, [groupId]: defaultValues }));
680
756
  } else {
681
- setNewEntry({});
757
+ setNewEntry(defaultValues);
682
758
  }
683
759
  toast.success('Row added');
684
760
  };
@@ -1117,10 +1193,11 @@ const GenericEditableTable = ({
1117
1193
  case 'currency':
1118
1194
  return (
1119
1195
  <CurrencyInput
1196
+ key={`new-currency-${column.id}-${groupId || 'default'}-${value || 'empty'}`}
1120
1197
  id={`new-currency-${column.id}-${groupId || 'default'}`}
1121
1198
  name={column.id}
1122
1199
  placeholder="$0.00"
1123
- defaultValue={value || ''}
1200
+ value={value || ''}
1124
1201
  decimalsLimit={2}
1125
1202
  prefix="$"
1126
1203
  decimalSeparator="."
@@ -1181,9 +1258,10 @@ const GenericEditableTable = ({
1181
1258
  />
1182
1259
  );
1183
1260
  case 'dropdown':
1261
+ const defaultValue = value || (column.options && column.options.length > 0 ? column.options[0].id : '');
1184
1262
  return (
1185
1263
  <select
1186
- value={value || ''}
1264
+ value={defaultValue}
1187
1265
  onChange={(e) =>
1188
1266
  handleNewFieldChange(
1189
1267
  e.target.value,
@@ -1429,7 +1507,12 @@ const GenericEditableTable = ({
1429
1507
  const renderNewRowForm = (groupId = null) => {
1430
1508
  const newRowData = hasCategory ? newEntries[groupId] || {} : newEntry;
1431
1509
  return (
1432
- <tr className={styles.newRow}>
1510
+ <tr
1511
+ className={styles.newRow}
1512
+ style={{
1513
+ background: getAddRowBackground(newRowData, groupId),
1514
+ }}
1515
+ >
1433
1516
  <td className={styles.checkboxColumn}></td>
1434
1517
  {columns.map((column) => (
1435
1518
  <td