@visns-studio/visns-components 5.10.1 → 5.10.3

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.
@@ -162,8 +162,18 @@ function Field({
162
162
  let filter = {};
163
163
 
164
164
  if (settings.where?.length > 0) {
165
+ const processedWhere = settings.where.map((whereItem) => {
166
+ if (whereItem.getKey && formData[whereItem.getKey]) {
167
+ return {
168
+ ...whereItem,
169
+ value: formData[whereItem.getKey],
170
+ };
171
+ }
172
+ return whereItem;
173
+ });
174
+
165
175
  filter = {
166
- where: settings.where,
176
+ where: processedWhere,
167
177
  };
168
178
  }
169
179
 
@@ -247,7 +257,7 @@ function Field({
247
257
  );
248
258
  setCanvasUrl(canvasType.url);
249
259
  }
250
- }, [settings, counter]);
260
+ }, [settings, counter, formData]);
251
261
 
252
262
  const fetchChildDropdownData = (s, v) => {
253
263
  let filter = {};
@@ -265,7 +275,9 @@ function Field({
265
275
  {
266
276
  id: s.id,
267
277
  value: _inputValue,
268
- ...(a.whereHas && { whereHas: a.whereHas }),
278
+ ...(a.whereHas && {
279
+ whereHas: a.whereHas,
280
+ }),
269
281
  },
270
282
  ],
271
283
  };
@@ -0,0 +1,123 @@
1
+ import React, { useEffect, useRef, useState } from 'react';
2
+ import { Tooltip } from 'react-tooltip';
3
+ import moment from 'moment';
4
+ import numeral from 'numeral';
5
+
6
+ // Utility function to check if text content is truncated
7
+ const isTextTruncated = (element) => {
8
+ if (!element) return false;
9
+ return (
10
+ element.scrollWidth > element.clientWidth ||
11
+ element.scrollHeight > element.clientHeight
12
+ );
13
+ };
14
+
15
+ // Utility function to format cell value for tooltip display
16
+ const formatCellValueForTooltip = (value, columnType) => {
17
+ if (value === null || value === undefined || value === '') {
18
+ return '';
19
+ }
20
+
21
+ switch (columnType) {
22
+ case 'date':
23
+ case 'datetime':
24
+ if (
25
+ moment(value).isValid() &&
26
+ moment(value).format('YYYY-MM-DD') !== '1970-01-01'
27
+ ) {
28
+ return moment(value).format('DD-MM-YYYY HH:mm');
29
+ }
30
+ return String(value);
31
+ case 'currency':
32
+ return numeral(value).format('$0,0.00');
33
+ case 'number':
34
+ return numeral(value).format('0,0');
35
+ case 'boolean':
36
+ return value ? 'Yes' : 'No';
37
+ case 'richtext':
38
+ // Strip HTML tags for tooltip
39
+ const tempDiv = document.createElement('div');
40
+ tempDiv.innerHTML = value;
41
+ return tempDiv.textContent || tempDiv.innerText || '';
42
+ default:
43
+ return String(value);
44
+ }
45
+ };
46
+
47
+ // Component to wrap cell content with tooltip functionality
48
+ const CellWithTooltip = ({
49
+ children,
50
+ value,
51
+ columnType = 'text',
52
+ className = '',
53
+ }) => {
54
+ const cellRef = useRef(null);
55
+ const [showTooltip, setShowTooltip] = useState(false);
56
+ const [tooltipId] = useState(
57
+ () => `cell-tooltip-${Math.random().toString(36).substr(2, 9)}`
58
+ );
59
+
60
+ useEffect(() => {
61
+ const checkTruncation = () => {
62
+ if (cellRef.current) {
63
+ const isTruncated = isTextTruncated(cellRef.current);
64
+ setShowTooltip(isTruncated);
65
+ }
66
+ };
67
+
68
+ // Check truncation on mount and when content changes
69
+ checkTruncation();
70
+
71
+ // Also check on window resize
72
+ const handleResize = () => checkTruncation();
73
+ window.addEventListener('resize', handleResize);
74
+
75
+ return () => {
76
+ window.removeEventListener('resize', handleResize);
77
+ };
78
+ }, [children, value]);
79
+
80
+ const tooltipContent = formatCellValueForTooltip(value, columnType);
81
+
82
+ // Only show tooltip if content is truncated and we have meaningful content
83
+ const shouldShowTooltip =
84
+ showTooltip && tooltipContent && tooltipContent.trim() !== '';
85
+
86
+ return (
87
+ <div
88
+ ref={cellRef}
89
+ className={className}
90
+ style={{
91
+ overflow: 'hidden',
92
+ textOverflow: 'ellipsis',
93
+ whiteSpace: 'nowrap',
94
+ width: '100%',
95
+ }}
96
+ {...(shouldShowTooltip && {
97
+ 'data-tooltip-id': tooltipId,
98
+ 'data-tooltip-html': tooltipContent,
99
+ })}
100
+ >
101
+ {children}
102
+ {shouldShowTooltip && (
103
+ <Tooltip
104
+ id={tooltipId}
105
+ style={{
106
+ backgroundColor: 'rgba(0, 0, 0, 0.9)',
107
+ color: 'white',
108
+ borderRadius: '6px',
109
+ padding: '8px 12px',
110
+ fontSize: '13px',
111
+ maxWidth: '500px',
112
+ wordWrap: 'break-word',
113
+ zIndex: 1000,
114
+ }}
115
+ place="top"
116
+ offset={5}
117
+ />
118
+ )}
119
+ </div>
120
+ );
121
+ };
122
+
123
+ export default CellWithTooltip;