@visns-studio/visns-components 5.12.1 → 5.12.2
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.12.
|
|
90
|
+
"version": "5.12.2",
|
|
91
91
|
"description": "Various packages to assist in the development of our Custom Applications.",
|
|
92
92
|
"main": "src/index.js",
|
|
93
93
|
"files": [
|
package/src/components/Field.jsx
CHANGED
|
@@ -1027,7 +1027,7 @@ function Field({
|
|
|
1027
1027
|
<div className={styles['file-image-preview']}>
|
|
1028
1028
|
<img
|
|
1029
1029
|
src={fileImageSrc}
|
|
1030
|
-
alt={file.name || file.file_name || 'Preview'}
|
|
1030
|
+
alt={file.name || file.file_name || file.filename || 'Preview'}
|
|
1031
1031
|
className={styles['file-thumbnail']}
|
|
1032
1032
|
onError={(e) => {
|
|
1033
1033
|
e.target.style.display = 'none';
|
|
@@ -1050,6 +1050,7 @@ function Field({
|
|
|
1050
1050
|
<span className={styles['file-name']}>
|
|
1051
1051
|
{file.name ||
|
|
1052
1052
|
file.file_name ||
|
|
1053
|
+
file.filename ||
|
|
1053
1054
|
''}
|
|
1054
1055
|
</span>
|
|
1055
1056
|
|
|
@@ -1107,7 +1108,7 @@ function Field({
|
|
|
1107
1108
|
{inputValue ? getFileIcon(inputValue) : '📁'}
|
|
1108
1109
|
</span>
|
|
1109
1110
|
<span className={styles['file-button-text']}>
|
|
1110
|
-
{inputValue?.filename || inputValue?.name
|
|
1111
|
+
{inputValue?.filename || inputValue?.name || inputValue?.file_name
|
|
1111
1112
|
? isImage
|
|
1112
1113
|
? 'Replace Image...'
|
|
1113
1114
|
: 'Replace File...'
|
|
@@ -1133,7 +1134,7 @@ function Field({
|
|
|
1133
1134
|
<div className={styles['image-preview-container']}>
|
|
1134
1135
|
<img
|
|
1135
1136
|
src={imageSrc}
|
|
1136
|
-
alt={inputValue.filename || inputValue.name || 'Preview'}
|
|
1137
|
+
alt={inputValue.filename || inputValue.name || inputValue.file_name || 'Preview'}
|
|
1137
1138
|
className={styles['image-preview']}
|
|
1138
1139
|
onError={(e) => {
|
|
1139
1140
|
e.target.style.display = 'none';
|
|
@@ -1145,14 +1146,14 @@ function Field({
|
|
|
1145
1146
|
|
|
1146
1147
|
<div className={styles['file-details']}>
|
|
1147
1148
|
<span className={styles['file-name-display']}>
|
|
1148
|
-
{inputValue.filename || inputValue.name || ''}
|
|
1149
|
+
{inputValue.filename || inputValue.name || inputValue.file_name || ''}
|
|
1149
1150
|
</span>
|
|
1150
1151
|
|
|
1151
|
-
{inputValue.key && inputValue.uuid && (
|
|
1152
|
+
{((inputValue.key && inputValue.uuid) || inputValue.file_url || inputValue.file_path || inputValue.id) && (
|
|
1152
1153
|
<button
|
|
1153
1154
|
className={styles['download-button']}
|
|
1154
1155
|
data-tooltip-id="system-tooltip"
|
|
1155
|
-
data-tooltip-content={`Download ${inputValue.filename || inputValue.name}`}
|
|
1156
|
+
data-tooltip-content={`Download ${inputValue.filename || inputValue.name || inputValue.file_name}`}
|
|
1156
1157
|
onClick={(e) => {
|
|
1157
1158
|
e.preventDefault();
|
|
1158
1159
|
onFileDownload(inputValue);
|
package/src/components/Form.jsx
CHANGED
|
@@ -443,11 +443,65 @@ function Form({
|
|
|
443
443
|
}
|
|
444
444
|
};
|
|
445
445
|
|
|
446
|
-
const handleFileDownload = async (
|
|
446
|
+
const handleFileDownload = async (fileData) => {
|
|
447
447
|
try {
|
|
448
|
-
console.info(
|
|
448
|
+
console.info('File download data:', fileData);
|
|
449
|
+
|
|
450
|
+
if (!fileData) {
|
|
451
|
+
toast.error('No file data available for download');
|
|
452
|
+
return;
|
|
453
|
+
}
|
|
454
|
+
|
|
455
|
+
// Handle different file data structures
|
|
456
|
+
let downloadUrl = null;
|
|
457
|
+
let fileName = fileData.filename || fileData.name || fileData.file_name || 'download';
|
|
458
|
+
|
|
459
|
+
// Priority order for download methods:
|
|
460
|
+
// 1. Direct file URL (S3, CDN, etc.)
|
|
461
|
+
if (fileData.file_url) {
|
|
462
|
+
downloadUrl = fileData.file_url;
|
|
463
|
+
}
|
|
464
|
+
// 2. File path (construct URL if needed)
|
|
465
|
+
else if (fileData.file_path || fileData.file_full_path) {
|
|
466
|
+
const filePath = fileData.file_full_path || fileData.file_path;
|
|
467
|
+
// If it's already a full URL, use it directly
|
|
468
|
+
if (filePath.startsWith('http')) {
|
|
469
|
+
downloadUrl = filePath;
|
|
470
|
+
} else {
|
|
471
|
+
// Construct URL - adjust this based on your API structure
|
|
472
|
+
downloadUrl = `/api/files/download?path=${encodeURIComponent(filePath)}`;
|
|
473
|
+
}
|
|
474
|
+
}
|
|
475
|
+
// 3. Legacy key/uuid method
|
|
476
|
+
else if (fileData.key && fileData.uuid) {
|
|
477
|
+
downloadUrl = `/api/files/download/${fileData.uuid}/${fileData.key}`;
|
|
478
|
+
}
|
|
479
|
+
// 4. File ID method
|
|
480
|
+
else if (fileData.id) {
|
|
481
|
+
downloadUrl = `/api/files/download/${fileData.id}`;
|
|
482
|
+
}
|
|
483
|
+
|
|
484
|
+
if (!downloadUrl) {
|
|
485
|
+
toast.error('Unable to determine download URL for this file');
|
|
486
|
+
return;
|
|
487
|
+
}
|
|
488
|
+
|
|
489
|
+
// Create a temporary anchor element to trigger download
|
|
490
|
+
const link = document.createElement('a');
|
|
491
|
+
link.href = downloadUrl;
|
|
492
|
+
link.download = fileName;
|
|
493
|
+
link.target = '_blank';
|
|
494
|
+
|
|
495
|
+
// Add to DOM, click, and remove
|
|
496
|
+
document.body.appendChild(link);
|
|
497
|
+
link.click();
|
|
498
|
+
document.body.removeChild(link);
|
|
499
|
+
|
|
500
|
+
toast.success(`Downloading ${fileName}...`);
|
|
501
|
+
|
|
449
502
|
} catch (error) {
|
|
450
|
-
console.error(error);
|
|
503
|
+
console.error('File download error:', error);
|
|
504
|
+
toast.error('Failed to download file');
|
|
451
505
|
}
|
|
452
506
|
};
|
|
453
507
|
|
|
@@ -1721,6 +1775,7 @@ function Form({
|
|
|
1721
1775
|
handleChangeSignature
|
|
1722
1776
|
}
|
|
1723
1777
|
onChangeToggle={handleChangeToggle}
|
|
1778
|
+
onFileDownload={handleFileDownload}
|
|
1724
1779
|
settings={item}
|
|
1725
1780
|
setFormData={setFormData}
|
|
1726
1781
|
style={style}
|
|
@@ -163,6 +163,7 @@ const GenericReportForm = ({ config, userProfile, onExport, onFormChange }) => {
|
|
|
163
163
|
onChangeRicheditor={() => {}}
|
|
164
164
|
onChangeSelect={handleChangeSelect}
|
|
165
165
|
onChangeToggle={() => {}}
|
|
166
|
+
onFileDownload={() => console.warn('File download not implemented in GenericReportForm')}
|
|
166
167
|
settings={item}
|
|
167
168
|
setFormData={setFormData}
|
|
168
169
|
style={userProfile?.settings?.style}
|