@visns-studio/visns-components 5.13.4 → 5.13.6

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
@@ -87,7 +87,7 @@
87
87
  "react-dom": "^17.0.0 || ^18.0.0"
88
88
  },
89
89
  "name": "@visns-studio/visns-components",
90
- "version": "5.13.4",
90
+ "version": "5.13.6",
91
91
  "description": "Various packages to assist in the development of our Custom Applications.",
92
92
  "main": "src/index.js",
93
93
  "files": [
@@ -114,6 +114,7 @@ import {
114
114
  renderDateRangeColumn,
115
115
  renderStageCounterColumn,
116
116
  renderGalleryColumn,
117
+ renderTotalColumn,
117
118
  } from './columns/ColumnRenderers.jsx';
118
119
  import _ from 'lodash';
119
120
 
@@ -2720,6 +2721,11 @@ const DataGrid = forwardRef(
2720
2721
  setLocalInputValues,
2721
2722
  handleInputUpdate,
2722
2723
  });
2724
+ case 'total':
2725
+ return renderTotalColumn()({
2726
+ column,
2727
+ commonProps,
2728
+ });
2723
2729
  default:
2724
2730
  columnId = Array.isArray(column.id)
2725
2731
  ? column.id.join('-')
@@ -2472,3 +2472,52 @@ export const renderStageCounterColumn = ({ column, commonProps, navigate, onUpda
2472
2472
  },
2473
2473
  };
2474
2474
  };
2475
+
2476
+ // Calculate total for columns of type 'total'
2477
+ const calculateTotal = (entry, keys) => {
2478
+ let total = 0;
2479
+ if (Array.isArray(keys)) {
2480
+ total = keys.reduce(
2481
+ (sum, key) => sum + (parseFloat(entry[key]) || 0),
2482
+ 0
2483
+ );
2484
+ } else if (
2485
+ keys &&
2486
+ typeof keys === 'object' &&
2487
+ keys.price &&
2488
+ keys.unit
2489
+ ) {
2490
+ const { price: priceKeys, unit: unitKeys } = keys;
2491
+ if (unitKeys.length === 1) {
2492
+ const unitValue = parseFloat(entry[unitKeys[0]]) || 0;
2493
+ total = priceKeys.reduce(
2494
+ (sum, key) =>
2495
+ sum + (parseFloat(entry[key]) || 0) * unitValue,
2496
+ 0
2497
+ );
2498
+ } else if (priceKeys.length === unitKeys.length) {
2499
+ total = priceKeys.reduce(
2500
+ (sum, key, index) =>
2501
+ sum +
2502
+ (parseFloat(entry[key]) || 0) *
2503
+ (parseFloat(entry[unitKeys[index]]) || 0),
2504
+ 0
2505
+ );
2506
+ }
2507
+ }
2508
+ return total;
2509
+ };
2510
+
2511
+
2512
+ export const renderTotalColumn = () => {
2513
+ return {
2514
+ render: ({ data: rowData, column }) => {
2515
+ // For individual rows, calculate the total for that specific row
2516
+ const subtotal = calculateTotal(rowData, column.keys);
2517
+ return new Intl.NumberFormat('en-AU', {
2518
+ style: 'currency',
2519
+ currency: 'AUD',
2520
+ }).format(subtotal);
2521
+ },
2522
+ };
2523
+ };
@@ -419,6 +419,18 @@ const GenericEditableTable = ({
419
419
  return totalProjectCost * (percentage / 100);
420
420
  };
421
421
 
422
+ // Check if row matches where conditions
423
+ const matchesWhereConditions = (row, whereConditions) => {
424
+ if (!whereConditions || !Array.isArray(whereConditions)) {
425
+ return true;
426
+ }
427
+
428
+ return whereConditions.every(condition => {
429
+ const { id, value } = condition;
430
+ return row[id] === value;
431
+ });
432
+ };
433
+
422
434
  // Calculate total for columns of type 'total'
423
435
  const calculateTotal = (entry, keys) => {
424
436
  let total = 0;
@@ -454,6 +466,19 @@ const GenericEditableTable = ({
454
466
  return total;
455
467
  };
456
468
 
469
+ // Calculate total across all data with where clause filtering
470
+ const calculateTotalFromData = (data, keys, whereConditions) => {
471
+ if (!data || !Array.isArray(data)) {
472
+ return 0;
473
+ }
474
+
475
+ const filteredData = data.filter(row => matchesWhereConditions(row, whereConditions));
476
+
477
+ return filteredData.reduce((sum, entry) => {
478
+ return sum + calculateTotal(entry, keys);
479
+ }, 0);
480
+ };
481
+
457
482
  // Debounced update to save entire dataSets array
458
483
  const debouncedUpdate = useMemo(
459
484
  () =>
@@ -1594,18 +1619,19 @@ const GenericEditableTable = ({
1594
1619
  );
1595
1620
  }
1596
1621
  if (index === totalColIndex) {
1622
+ const totalColumn = columns[totalColIndex];
1597
1623
  const groupTotal =
1598
- group.entries.reduce(
1599
- (sum, entry) =>
1600
- sum +
1601
- calculateTotal(
1602
- entry,
1603
- columns[
1604
- totalColIndex
1605
- ].keys
1606
- ),
1607
- 0
1608
- );
1624
+ group.entries
1625
+ .filter(entry => matchesWhereConditions(entry, totalColumn.where))
1626
+ .reduce(
1627
+ (sum, entry) =>
1628
+ sum +
1629
+ calculateTotal(
1630
+ entry,
1631
+ totalColumn.keys
1632
+ ),
1633
+ 0
1634
+ );
1609
1635
  return (
1610
1636
  <td key={col.id}>
1611
1637
  {groupTotal.toLocaleString(
@@ -1749,17 +1775,18 @@ const GenericEditableTable = ({
1749
1775
  );
1750
1776
  }
1751
1777
  if (index === totalColIndex) {
1778
+ const totalColumn = columns[totalColIndex];
1752
1779
  const overallTotal =
1753
1780
  sortBySortOrder(
1754
1781
  localData
1755
- ).reduce(
1782
+ )
1783
+ .filter(entry => matchesWhereConditions(entry, totalColumn.where))
1784
+ .reduce(
1756
1785
  (sum, entry) =>
1757
1786
  sum +
1758
1787
  calculateTotal(
1759
1788
  entry,
1760
- columns[
1761
- totalColIndex
1762
- ].keys
1789
+ totalColumn.keys
1763
1790
  ),
1764
1791
  0
1765
1792
  );
@@ -62,9 +62,9 @@ div[role="tooltip"],
62
62
  text-overflow: unset !important; /* Disable text truncation */
63
63
  overflow: visible !important; /* Show wrapped content */
64
64
  height: auto !important; /* Allow cell to expand vertically */
65
- min-height: 40px !important; /* Increased minimum height for better spacing */
65
+ min-height: 20px !important; /* Minimal height for maximum compactness */
66
66
  line-height: 1.4 !important; /* Better line spacing for readability */
67
- padding: 10px 8px !important; /* Increased vertical padding for multi-line content */
67
+ padding: 1px 2px !important; /* Very light padding for minimal spacing */
68
68
  vertical-align: top !important; /* Align content to top for multi-line cells */
69
69
  display: flex !important; /* Use flexbox for better content alignment */
70
70
  align-items: flex-start !important; /* Align content to top */