@visns-studio/visns-components 5.7.18 → 5.7.19
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 +1 -1
- package/src/components/crm/DataGrid.jsx +361 -14
package/package.json
CHANGED
|
@@ -82,7 +82,7 @@
|
|
|
82
82
|
"react-dom": "^17.0.0 || ^18.0.0"
|
|
83
83
|
},
|
|
84
84
|
"name": "@visns-studio/visns-components",
|
|
85
|
-
"version": "5.7.
|
|
85
|
+
"version": "5.7.19",
|
|
86
86
|
"description": "Various packages to assist in the development of our Custom Applications.",
|
|
87
87
|
"main": "src/index.js",
|
|
88
88
|
"files": [
|
|
@@ -32,6 +32,7 @@ import {
|
|
|
32
32
|
ArrowCounterClockwise,
|
|
33
33
|
ArrowCycle,
|
|
34
34
|
Backspace,
|
|
35
|
+
BookOpen,
|
|
35
36
|
Check,
|
|
36
37
|
CircleCheck,
|
|
37
38
|
CircleX,
|
|
@@ -1442,19 +1443,42 @@ const DataGrid = forwardRef(
|
|
|
1442
1443
|
const addIcon = (src, icon, alt, tooltipContent, key) => {
|
|
1443
1444
|
if (src && src !== '') {
|
|
1444
1445
|
icons.push(
|
|
1445
|
-
<
|
|
1446
|
-
src={`${assetPath}${src}`}
|
|
1447
|
-
alt={alt}
|
|
1448
|
-
data-tooltip-id="system-tooltip"
|
|
1449
|
-
data-tooltip-content={tooltipContent}
|
|
1446
|
+
<div
|
|
1450
1447
|
key={key}
|
|
1451
|
-
|
|
1448
|
+
style={{
|
|
1449
|
+
display: 'inline-flex',
|
|
1450
|
+
alignItems: 'center',
|
|
1451
|
+
justifyContent: 'center',
|
|
1452
|
+
backgroundColor:
|
|
1453
|
+
'var(--light-bg-color, #f5f5f5)',
|
|
1454
|
+
borderRadius: '4px',
|
|
1455
|
+
padding: '4px',
|
|
1456
|
+
width: '22px',
|
|
1457
|
+
height: '22px',
|
|
1458
|
+
boxShadow: '0 1px 2px rgba(0,0,0,0.05)',
|
|
1459
|
+
margin: '0 1px',
|
|
1460
|
+
}}
|
|
1461
|
+
>
|
|
1462
|
+
<img
|
|
1463
|
+
src={`${assetPath}${src}`}
|
|
1464
|
+
alt={alt}
|
|
1465
|
+
data-tooltip-id="system-tooltip"
|
|
1466
|
+
data-tooltip-content={tooltipContent}
|
|
1467
|
+
style={{
|
|
1468
|
+
maxHeight: '16px',
|
|
1469
|
+
maxWidth: '16px',
|
|
1470
|
+
objectFit: 'contain',
|
|
1471
|
+
}}
|
|
1472
|
+
/>
|
|
1473
|
+
</div>
|
|
1452
1474
|
);
|
|
1453
1475
|
} else {
|
|
1454
1476
|
let IconComponent = null;
|
|
1455
1477
|
|
|
1456
1478
|
if (icon === 'archive') {
|
|
1457
1479
|
IconComponent = ShippingBoxV1;
|
|
1480
|
+
} else if (icon === 'bookOpen') {
|
|
1481
|
+
IconComponent = BookOpen;
|
|
1458
1482
|
} else if (icon === 'folder') {
|
|
1459
1483
|
IconComponent = Folder;
|
|
1460
1484
|
} else if (icon === 'inbox') {
|
|
@@ -1467,14 +1491,33 @@ const DataGrid = forwardRef(
|
|
|
1467
1491
|
|
|
1468
1492
|
if (IconComponent) {
|
|
1469
1493
|
icons.push(
|
|
1470
|
-
<
|
|
1471
|
-
data-tooltip-id="system-tooltip"
|
|
1472
|
-
data-tooltip-content={tooltipContent}
|
|
1473
|
-
strokeWidth={2}
|
|
1474
|
-
size={18}
|
|
1475
|
-
className={styles.tdaction}
|
|
1494
|
+
<div
|
|
1476
1495
|
key={key}
|
|
1477
|
-
|
|
1496
|
+
style={{
|
|
1497
|
+
display: 'inline-flex',
|
|
1498
|
+
alignItems: 'center',
|
|
1499
|
+
justifyContent: 'center',
|
|
1500
|
+
backgroundColor:
|
|
1501
|
+
'var(--light-bg-color, #f5f5f5)',
|
|
1502
|
+
borderRadius: '4px',
|
|
1503
|
+
padding: '4px',
|
|
1504
|
+
width: '22px',
|
|
1505
|
+
height: '22px',
|
|
1506
|
+
boxShadow: '0 1px 2px rgba(0,0,0,0.05)',
|
|
1507
|
+
margin: '0 1px',
|
|
1508
|
+
}}
|
|
1509
|
+
>
|
|
1510
|
+
<IconComponent
|
|
1511
|
+
data-tooltip-id="system-tooltip"
|
|
1512
|
+
data-tooltip-content={tooltipContent}
|
|
1513
|
+
strokeWidth={2}
|
|
1514
|
+
size={18}
|
|
1515
|
+
className={styles.tdaction}
|
|
1516
|
+
style={{
|
|
1517
|
+
color: 'var(--primary-color, #4a90e2)',
|
|
1518
|
+
}}
|
|
1519
|
+
/>
|
|
1520
|
+
</div>
|
|
1478
1521
|
);
|
|
1479
1522
|
}
|
|
1480
1523
|
}
|
|
@@ -1509,7 +1552,30 @@ const DataGrid = forwardRef(
|
|
|
1509
1552
|
}
|
|
1510
1553
|
});
|
|
1511
1554
|
|
|
1512
|
-
|
|
1555
|
+
// Return icons wrapped in a flex container for better layout
|
|
1556
|
+
return (
|
|
1557
|
+
<div
|
|
1558
|
+
style={{
|
|
1559
|
+
display: 'inline-flex', // Changed to inline-flex to keep icons in a single row
|
|
1560
|
+
flexWrap: 'nowrap', // Prevent wrapping
|
|
1561
|
+
alignItems: 'center',
|
|
1562
|
+
justifyContent: 'flex-start',
|
|
1563
|
+
gap: '1px', // Reduced gap since we have margins on the icons
|
|
1564
|
+
padding: '2px 0',
|
|
1565
|
+
minHeight: '24px',
|
|
1566
|
+
maxWidth: '100%',
|
|
1567
|
+
overflow: 'hidden', // Hide overflow if too many icons
|
|
1568
|
+
}}
|
|
1569
|
+
>
|
|
1570
|
+
{icons.length > 0 ? (
|
|
1571
|
+
icons
|
|
1572
|
+
) : (
|
|
1573
|
+
<span style={{ color: '#999', fontSize: '12px' }}>
|
|
1574
|
+
-
|
|
1575
|
+
</span>
|
|
1576
|
+
)}
|
|
1577
|
+
</div>
|
|
1578
|
+
);
|
|
1513
1579
|
};
|
|
1514
1580
|
|
|
1515
1581
|
/** Table Hooks */
|
|
@@ -3022,6 +3088,287 @@ const DataGrid = forwardRef(
|
|
|
3022
3088
|
}
|
|
3023
3089
|
},
|
|
3024
3090
|
};
|
|
3091
|
+
case 'stageCounter':
|
|
3092
|
+
return {
|
|
3093
|
+
...commonProps,
|
|
3094
|
+
name: column.id,
|
|
3095
|
+
sortable: false,
|
|
3096
|
+
render: ({ data }) => {
|
|
3097
|
+
if (
|
|
3098
|
+
data &&
|
|
3099
|
+
column.stageConfig &&
|
|
3100
|
+
column.stageConfig.key
|
|
3101
|
+
) {
|
|
3102
|
+
// Check if the data has the specified key and it's an array
|
|
3103
|
+
const stageData =
|
|
3104
|
+
data[column.stageConfig.key];
|
|
3105
|
+
|
|
3106
|
+
if (
|
|
3107
|
+
stageData &&
|
|
3108
|
+
Array.isArray(stageData)
|
|
3109
|
+
) {
|
|
3110
|
+
const stageCount =
|
|
3111
|
+
stageData.length;
|
|
3112
|
+
|
|
3113
|
+
// Create a clickable element if link is provided
|
|
3114
|
+
const handleClick = (e) => {
|
|
3115
|
+
e.stopPropagation();
|
|
3116
|
+
e.preventDefault();
|
|
3117
|
+
|
|
3118
|
+
if (
|
|
3119
|
+
column.link &&
|
|
3120
|
+
column.link.url &&
|
|
3121
|
+
column.link.key
|
|
3122
|
+
) {
|
|
3123
|
+
navigate(
|
|
3124
|
+
`${
|
|
3125
|
+
column.link.url
|
|
3126
|
+
}${
|
|
3127
|
+
data[
|
|
3128
|
+
column.link
|
|
3129
|
+
.key
|
|
3130
|
+
]
|
|
3131
|
+
}`
|
|
3132
|
+
);
|
|
3133
|
+
}
|
|
3134
|
+
};
|
|
3135
|
+
|
|
3136
|
+
// Create an array of squares based on the stage data
|
|
3137
|
+
const squares = [];
|
|
3138
|
+
for (
|
|
3139
|
+
let i = 0;
|
|
3140
|
+
i < stageCount;
|
|
3141
|
+
i++
|
|
3142
|
+
) {
|
|
3143
|
+
// Get the stage item
|
|
3144
|
+
const stageItem =
|
|
3145
|
+
stageData[i];
|
|
3146
|
+
|
|
3147
|
+
// Get the label value from the stage item using stageLabelKey if provided
|
|
3148
|
+
let labelValue = '';
|
|
3149
|
+
if (
|
|
3150
|
+
column.stageConfig
|
|
3151
|
+
.stageLabelKey &&
|
|
3152
|
+
stageItem &&
|
|
3153
|
+
stageItem[
|
|
3154
|
+
column.stageConfig
|
|
3155
|
+
.stageLabelKey
|
|
3156
|
+
] !== undefined
|
|
3157
|
+
) {
|
|
3158
|
+
// Get the value from the stage item
|
|
3159
|
+
const rawValue =
|
|
3160
|
+
stageItem[
|
|
3161
|
+
column
|
|
3162
|
+
.stageConfig
|
|
3163
|
+
.stageLabelKey
|
|
3164
|
+
];
|
|
3165
|
+
|
|
3166
|
+
// If it's an object with a name property, use that
|
|
3167
|
+
if (
|
|
3168
|
+
rawValue &&
|
|
3169
|
+
typeof rawValue ===
|
|
3170
|
+
'object' &&
|
|
3171
|
+
rawValue.name
|
|
3172
|
+
) {
|
|
3173
|
+
labelValue =
|
|
3174
|
+
rawValue.name.charAt(
|
|
3175
|
+
0
|
|
3176
|
+
);
|
|
3177
|
+
}
|
|
3178
|
+
// If it's a string, use the first character
|
|
3179
|
+
else if (
|
|
3180
|
+
typeof rawValue ===
|
|
3181
|
+
'string' &&
|
|
3182
|
+
rawValue.length > 0
|
|
3183
|
+
) {
|
|
3184
|
+
labelValue =
|
|
3185
|
+
rawValue.charAt(
|
|
3186
|
+
0
|
|
3187
|
+
);
|
|
3188
|
+
}
|
|
3189
|
+
// Otherwise use the raw value if it can be converted to string
|
|
3190
|
+
else if (
|
|
3191
|
+
rawValue !== null &&
|
|
3192
|
+
rawValue !==
|
|
3193
|
+
undefined
|
|
3194
|
+
) {
|
|
3195
|
+
labelValue =
|
|
3196
|
+
String(
|
|
3197
|
+
rawValue
|
|
3198
|
+
).charAt(0);
|
|
3199
|
+
}
|
|
3200
|
+
}
|
|
3201
|
+
// If no stageLabelKey is provided or no value is found, leave it blank
|
|
3202
|
+
|
|
3203
|
+
// Create tooltip content from the full value if available
|
|
3204
|
+
let tooltipContent = `Stage ${
|
|
3205
|
+
i + 1
|
|
3206
|
+
}`;
|
|
3207
|
+
if (
|
|
3208
|
+
column.stageConfig
|
|
3209
|
+
.stageLabelKey &&
|
|
3210
|
+
stageItem &&
|
|
3211
|
+
stageItem[
|
|
3212
|
+
column.stageConfig
|
|
3213
|
+
.stageLabelKey
|
|
3214
|
+
]
|
|
3215
|
+
) {
|
|
3216
|
+
const rawValue =
|
|
3217
|
+
stageItem[
|
|
3218
|
+
column
|
|
3219
|
+
.stageConfig
|
|
3220
|
+
.stageLabelKey
|
|
3221
|
+
];
|
|
3222
|
+
if (
|
|
3223
|
+
rawValue &&
|
|
3224
|
+
typeof rawValue ===
|
|
3225
|
+
'object' &&
|
|
3226
|
+
rawValue.name
|
|
3227
|
+
) {
|
|
3228
|
+
tooltipContent = `${
|
|
3229
|
+
rawValue.name
|
|
3230
|
+
} (Stage ${i + 1})`;
|
|
3231
|
+
} else if (
|
|
3232
|
+
rawValue !== null &&
|
|
3233
|
+
rawValue !==
|
|
3234
|
+
undefined
|
|
3235
|
+
) {
|
|
3236
|
+
tooltipContent = `Stage ${
|
|
3237
|
+
i + 1
|
|
3238
|
+
})`;
|
|
3239
|
+
}
|
|
3240
|
+
}
|
|
3241
|
+
|
|
3242
|
+
// Determine the background color based on stageColour configuration
|
|
3243
|
+
let backgroundColor =
|
|
3244
|
+
'var(--primary-color, #4a90e2)';
|
|
3245
|
+
|
|
3246
|
+
if (
|
|
3247
|
+
column.stageConfig
|
|
3248
|
+
.stageColour &&
|
|
3249
|
+
column.stageConfig
|
|
3250
|
+
.stageColour.key &&
|
|
3251
|
+
column.stageConfig
|
|
3252
|
+
.stageColour
|
|
3253
|
+
.options &&
|
|
3254
|
+
stageItem
|
|
3255
|
+
) {
|
|
3256
|
+
const colourKey =
|
|
3257
|
+
column.stageConfig
|
|
3258
|
+
.stageColour
|
|
3259
|
+
.key;
|
|
3260
|
+
const colourOptions =
|
|
3261
|
+
column.stageConfig
|
|
3262
|
+
.stageColour
|
|
3263
|
+
.options;
|
|
3264
|
+
|
|
3265
|
+
// Get the value for the color key
|
|
3266
|
+
if (
|
|
3267
|
+
stageItem[
|
|
3268
|
+
colourKey
|
|
3269
|
+
] !== undefined
|
|
3270
|
+
) {
|
|
3271
|
+
const keyValue =
|
|
3272
|
+
stageItem[
|
|
3273
|
+
colourKey
|
|
3274
|
+
];
|
|
3275
|
+
|
|
3276
|
+
// Find matching option
|
|
3277
|
+
const matchingOption =
|
|
3278
|
+
colourOptions.find(
|
|
3279
|
+
(
|
|
3280
|
+
option
|
|
3281
|
+
) => {
|
|
3282
|
+
// Handle both direct value and object with id
|
|
3283
|
+
if (
|
|
3284
|
+
typeof keyValue ===
|
|
3285
|
+
'object' &&
|
|
3286
|
+
keyValue !==
|
|
3287
|
+
null
|
|
3288
|
+
) {
|
|
3289
|
+
// Use loose equality (==) to handle type coercion between string and number
|
|
3290
|
+
return (
|
|
3291
|
+
keyValue.id ==
|
|
3292
|
+
option.id
|
|
3293
|
+
);
|
|
3294
|
+
}
|
|
3295
|
+
// Use loose equality (==) to handle type coercion between string and number
|
|
3296
|
+
return (
|
|
3297
|
+
keyValue ==
|
|
3298
|
+
option.id
|
|
3299
|
+
);
|
|
3300
|
+
}
|
|
3301
|
+
);
|
|
3302
|
+
|
|
3303
|
+
// Use the color from the matching option if found
|
|
3304
|
+
if (
|
|
3305
|
+
matchingOption &&
|
|
3306
|
+
matchingOption.colour
|
|
3307
|
+
) {
|
|
3308
|
+
backgroundColor =
|
|
3309
|
+
matchingOption.colour;
|
|
3310
|
+
}
|
|
3311
|
+
}
|
|
3312
|
+
}
|
|
3313
|
+
|
|
3314
|
+
squares.push(
|
|
3315
|
+
<div
|
|
3316
|
+
key={i}
|
|
3317
|
+
style={{
|
|
3318
|
+
width: '20px',
|
|
3319
|
+
height: '20px',
|
|
3320
|
+
backgroundColor:
|
|
3321
|
+
backgroundColor,
|
|
3322
|
+
borderRadius:
|
|
3323
|
+
'3px',
|
|
3324
|
+
margin: '0 2px',
|
|
3325
|
+
display: 'flex',
|
|
3326
|
+
justifyContent:
|
|
3327
|
+
'center',
|
|
3328
|
+
alignItems:
|
|
3329
|
+
'center',
|
|
3330
|
+
color: 'white',
|
|
3331
|
+
fontSize:
|
|
3332
|
+
'11px',
|
|
3333
|
+
fontWeight:
|
|
3334
|
+
'bold',
|
|
3335
|
+
}}
|
|
3336
|
+
data-tooltip-id="system-tooltip"
|
|
3337
|
+
data-tooltip-content={
|
|
3338
|
+
tooltipContent
|
|
3339
|
+
}
|
|
3340
|
+
>
|
|
3341
|
+
{labelValue}
|
|
3342
|
+
</div>
|
|
3343
|
+
);
|
|
3344
|
+
}
|
|
3345
|
+
|
|
3346
|
+
return (
|
|
3347
|
+
<div
|
|
3348
|
+
onClick={handleClick}
|
|
3349
|
+
style={{
|
|
3350
|
+
display: 'flex',
|
|
3351
|
+
flexWrap: 'wrap',
|
|
3352
|
+
justifyContent:
|
|
3353
|
+
'center',
|
|
3354
|
+
alignItems:
|
|
3355
|
+
'center',
|
|
3356
|
+
cursor: column.link
|
|
3357
|
+
? 'pointer'
|
|
3358
|
+
: 'default',
|
|
3359
|
+
gap: '4px',
|
|
3360
|
+
padding: '2px 0',
|
|
3361
|
+
maxWidth: '100%',
|
|
3362
|
+
}}
|
|
3363
|
+
>
|
|
3364
|
+
{squares}
|
|
3365
|
+
</div>
|
|
3366
|
+
);
|
|
3367
|
+
}
|
|
3368
|
+
}
|
|
3369
|
+
return null;
|
|
3370
|
+
},
|
|
3371
|
+
};
|
|
3025
3372
|
case 'url':
|
|
3026
3373
|
return {
|
|
3027
3374
|
...commonProps,
|