@topconsultnpm/sdkui-react 6.20.0-dev2.1 → 6.20.0-dev2.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.
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
2
|
import { useEffect, useMemo, useRef, useState } from 'react';
|
|
3
3
|
import styled from 'styled-components';
|
|
4
|
-
import { RetrieveFileOptions, DcmtOpers, GeneralRetrieveFormats, FileFormats } from '@topconsultnpm/sdk-ts';
|
|
5
|
-
import { extensionHandler, sleep, getExceptionMessage, formatBytes, IconMenuVertical, IconCloseCircle, IconClear, IconCloseOutline, IconPreview, SDKUI_Globals, IconZoomOutLinear, IconZoomInLinear, IconPrintOutline, SDKUI_Localizator, IconRefresh, IconCache } from '../../../helper';
|
|
4
|
+
import { RetrieveFileOptions, DcmtOpers, GeneralRetrieveFormats, FileFormats, SDK_Globals } from '@topconsultnpm/sdk-ts';
|
|
5
|
+
import { extensionHandler, sleep, getExceptionMessage, formatBytes, IconMenuVertical, IconCloseCircle, IconClear, IconCloseOutline, IconPreview, SDKUI_Globals, IconZoomOutLinear, IconZoomInLinear, IconPrintOutline, SDKUI_Localizator, IconRefresh, IconCache, dcmtsFileCachePreview, CACHE_SIZE_LIMIT } from '../../../helper';
|
|
6
6
|
import { useDcmtOperations } from '../../../hooks/useDcmtOperations';
|
|
7
7
|
import { FileExtensionHandler, FormModes } from '../../../ts';
|
|
8
8
|
import { TMColors } from '../../../utils/theme';
|
|
@@ -29,7 +29,15 @@ const TMDcmtPreview = ({ dcmtData, isResizingActive, isVisible, canNext, canPrev
|
|
|
29
29
|
const [error, setError] = useState('');
|
|
30
30
|
const [isAbortError, setIsAbortError] = useState(false);
|
|
31
31
|
const { abortController, showWaitPanel, waitPanelTitle, showPrimary, waitPanelTextPrimary, waitPanelValuePrimary, waitPanelMaxValuePrimary, showSecondary, waitPanelTextSecondary, waitPanelValueSecondary, waitPanelMaxValueSecondary, getDcmtFileAsync, clearDcmtsFileCache, removeDcmtsFileCache, isDcmtFileInCache } = useDcmtOperations();
|
|
32
|
-
const
|
|
32
|
+
const isBasketMode = !!(dcmtData?.btid !== undefined && dcmtData?.bid !== undefined && dcmtData?.bfid !== undefined);
|
|
33
|
+
const getCacheKey = () => {
|
|
34
|
+
if (!dcmtData)
|
|
35
|
+
return '00';
|
|
36
|
+
if (isBasketMode)
|
|
37
|
+
return `basket-${dcmtData.btid}-${dcmtData.bid}-${dcmtData.bfid}`;
|
|
38
|
+
return `${dcmtData.tid}-${dcmtData.did}`;
|
|
39
|
+
};
|
|
40
|
+
const cacheKey = getCacheKey();
|
|
33
41
|
const [hasLoadedDataOnce, setHasLoadedDataOnce] = useState(false);
|
|
34
42
|
const [lastLoadedDid, setLastLoadedDid] = useState(undefined);
|
|
35
43
|
useEffect(() => {
|
|
@@ -41,10 +49,10 @@ const TMDcmtPreview = ({ dcmtData, isResizingActive, isVisible, canNext, canPrev
|
|
|
41
49
|
setShowPreview(false);
|
|
42
50
|
return;
|
|
43
51
|
}
|
|
44
|
-
const currentCacheKey = `${dcmtData.tid}-${dcmtData.did}`;
|
|
52
|
+
const currentCacheKey = isBasketMode ? `basket-${dcmtData.btid}-${dcmtData.bid}-${dcmtData.bfid}` : `${dcmtData.tid}-${dcmtData.did}`;
|
|
45
53
|
const shouldFetch = isVisible && (!hasLoadedDataOnce || currentCacheKey !== lastLoadedDid);
|
|
46
54
|
if (isDcmtFileInCache(currentCacheKey)) {
|
|
47
|
-
loadDocumentWithCache();
|
|
55
|
+
isBasketMode ? loadBasketFile() : loadDocumentWithCache();
|
|
48
56
|
setShowPreview(true);
|
|
49
57
|
return;
|
|
50
58
|
}
|
|
@@ -52,7 +60,11 @@ const TMDcmtPreview = ({ dcmtData, isResizingActive, isVisible, canNext, canPrev
|
|
|
52
60
|
setDcmtBlob(undefined);
|
|
53
61
|
setError('');
|
|
54
62
|
setIsAbortError(false);
|
|
55
|
-
if (
|
|
63
|
+
if (isBasketMode) {
|
|
64
|
+
loadBasketFile();
|
|
65
|
+
setShowPreview(true);
|
|
66
|
+
}
|
|
67
|
+
else if ((extensionHandler(dcmtData.fileExt) !== FileExtensionHandler.NONE) && ((dcmtData.fileSize ?? 0) <= (SDKUI_Globals.userSettings.searchSettings.previewThreshold * 1024))) {
|
|
56
68
|
loadDocumentWithCache();
|
|
57
69
|
setShowPreview(true);
|
|
58
70
|
}
|
|
@@ -63,6 +75,46 @@ const TMDcmtPreview = ({ dcmtData, isResizingActive, isVisible, canNext, canPrev
|
|
|
63
75
|
setLastLoadedDid(currentCacheKey);
|
|
64
76
|
}
|
|
65
77
|
}, [dcmtData?.did, isVisible, hasLoadedDataOnce, lastLoadedDid]);
|
|
78
|
+
const loadBasketFile = async () => {
|
|
79
|
+
try {
|
|
80
|
+
// Check cache first
|
|
81
|
+
if (dcmtsFileCachePreview.has(cacheKey)) {
|
|
82
|
+
setDcmtBlob(dcmtsFileCachePreview.get(cacheKey));
|
|
83
|
+
setIsFromCache(true);
|
|
84
|
+
setError('');
|
|
85
|
+
setIsAbortError(false);
|
|
86
|
+
return;
|
|
87
|
+
}
|
|
88
|
+
await sleep(300);
|
|
89
|
+
const basketEngine = SDK_Globals.tmSession?.NewBasketEngine();
|
|
90
|
+
const file = await basketEngine?.RetrieveFileAsync(dcmtData?.btid, dcmtData?.bid, dcmtData?.bfid, abortController.signal);
|
|
91
|
+
// Store in cache
|
|
92
|
+
if (file) {
|
|
93
|
+
if (dcmtsFileCachePreview.size >= CACHE_SIZE_LIMIT) {
|
|
94
|
+
const oldestKey = dcmtsFileCachePreview.keys().next().value;
|
|
95
|
+
dcmtsFileCachePreview.delete(oldestKey);
|
|
96
|
+
}
|
|
97
|
+
dcmtsFileCachePreview.set(cacheKey, file);
|
|
98
|
+
}
|
|
99
|
+
setDcmtBlob(file);
|
|
100
|
+
setIsFromCache(false);
|
|
101
|
+
setError('');
|
|
102
|
+
setIsAbortError(false);
|
|
103
|
+
}
|
|
104
|
+
catch (ex) {
|
|
105
|
+
const err = ex;
|
|
106
|
+
if (err.name === 'CanceledError') {
|
|
107
|
+
setError('Operazione annullata.');
|
|
108
|
+
setIsAbortError(true);
|
|
109
|
+
ShowAlert({ message: err.message, mode: 'warning', duration: 3000, title: 'Abort' });
|
|
110
|
+
}
|
|
111
|
+
else {
|
|
112
|
+
setError(getExceptionMessage(ex));
|
|
113
|
+
setIsAbortError(false);
|
|
114
|
+
TMExceptionBoxManager.show({ exception: ex });
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
};
|
|
66
118
|
const loadDocumentWithCache = async () => {
|
|
67
119
|
const rfo = new RetrieveFileOptions();
|
|
68
120
|
rfo.retrieveReason = DcmtOpers.None;
|
|
@@ -94,7 +146,7 @@ const TMDcmtPreview = ({ dcmtData, isResizingActive, isVisible, canNext, canPrev
|
|
|
94
146
|
};
|
|
95
147
|
const titleHandler = () => {
|
|
96
148
|
let title = 'Anteprima ';
|
|
97
|
-
if (!dcmtData?.did)
|
|
149
|
+
if (!dcmtData?.did && !isBasketMode)
|
|
98
150
|
return title;
|
|
99
151
|
let extensionInfo;
|
|
100
152
|
if (dcmtData.fileExt !== null) {
|
|
@@ -120,7 +172,7 @@ const TMDcmtPreview = ({ dcmtData, isResizingActive, isVisible, canNext, canPrev
|
|
|
120
172
|
setIsAbortError(false);
|
|
121
173
|
setDcmtBlob(undefined);
|
|
122
174
|
try {
|
|
123
|
-
await loadDocumentWithCache();
|
|
175
|
+
isBasketMode ? await loadBasketFile() : await loadDocumentWithCache();
|
|
124
176
|
}
|
|
125
177
|
catch (error) {
|
|
126
178
|
console.error('Error reopening document:', error);
|
|
@@ -132,7 +184,7 @@ const TMDcmtPreview = ({ dcmtData, isResizingActive, isVisible, canNext, canPrev
|
|
|
132
184
|
], [cacheKey, removeDcmtsFileCache, clearDcmtsFileCache, setIsFromCache]);
|
|
133
185
|
return (_jsx(TMLayoutWaitingContainer, { direction: 'vertical', showWaitPanel: showWaitPanel, showWaitPanelPrimary: showPrimary, showWaitPanelSecondary: showSecondary, waitPanelTitle: waitPanelTitle, waitPanelTextPrimary: waitPanelTextPrimary, waitPanelValuePrimary: waitPanelValuePrimary, waitPanelMaxValuePrimary: waitPanelMaxValuePrimary, waitPanelTextSecondary: waitPanelTextSecondary, waitPanelValueSecondary: waitPanelValueSecondary, waitPanelMaxValueSecondary: waitPanelMaxValueSecondary, isCancelable: true, abortController: abortController, children: _jsx(TMPanel, { padding: '0', title: titleHandler(), onClose: onClosePanel, allowMaximize: allowMaximize, onMaximize: onMaximizePanel, onHeaderDoubleClick: onMaximizePanel, toolbar: _jsxs("div", { style: { width: 'max-content', display: 'flex', alignItems: 'center', gap: '10px' }, children: [onPrev && _jsx(TMSaveFormButtonPrevious, { btnStyle: 'icon', isModified: false, formMode: FormModes.ReadOnly, canPrev: canPrev, onPrev: onPrev }), onNext && _jsx(TMSaveFormButtonNext, { btnStyle: 'icon', isModified: false, formMode: FormModes.ReadOnly, canNext: canNext, onNext: onNext }), _jsx(StyledHeaderIcon, { "$color": TMColors.primaryColor, children: _jsx(ContextMenu, { items: cacheMenuItems, trigger: "left", children: _jsx(IconMenuVertical, {}) }) }), _jsx(StyledHeaderIcon, { onClick: reOpenDcmt, "$color": TMColors.primaryColor, children: _jsx(TMTooltip, { content: SDKUI_Localizator.ReopenDocument, children: _jsx(IconRefresh, {}) }) })] }), children: error
|
|
134
186
|
? _jsx(ErrorContent, { error: error, isAbortError: isAbortError, onRetry: reOpenDcmt })
|
|
135
|
-
: renderedPreview(dcmtData?.tid, dcmtData?.did, dcmtData?.fileExt, dcmtData?.fileSize, dcmtData?.fileCount, extensionHandler(dcmtData?.fileExt), showPreview, isResizingActive, () => { loadDocumentWithCache(); setShowPreview(true); }, dcmtBlob) }) }));
|
|
187
|
+
: renderedPreview(dcmtData?.tid, dcmtData?.did, dcmtData?.fileExt, dcmtData?.fileSize, dcmtData?.fileCount, extensionHandler(dcmtData?.fileExt), showPreview, isResizingActive, () => { isBasketMode ? loadBasketFile() : loadDocumentWithCache(); setShowPreview(true); }, dcmtBlob, isBasketMode) }) }));
|
|
136
188
|
};
|
|
137
189
|
export default TMDcmtPreview;
|
|
138
190
|
export const TMFileViewer = ({ fileBlob, isResizingActive }) => {
|
|
@@ -382,13 +434,13 @@ const ImageViewer = ({ fileBlob, alt = 'Image', className }) => {
|
|
|
382
434
|
export const TMNothingToShow = ({ text = '', secondText, fileExt, icon = _jsx(IconPreview, { fontSize: 96 }) }) => {
|
|
383
435
|
return (_jsx(StyledAnimatedComponentOpacity, { style: { width: '100%', height: '100%' }, children: _jsxs(StyledPanelStatusContainer, { children: [icon, _jsxs(StyledPreviewNotAvailable, { children: [text && _jsx("div", { children: text }), _jsxs("div", { children: [" ", secondText ?? SDKUI_Localizator.PreviewNotAvailable, fileExt && _jsx("b", { children: ` (*.${fileExt})` })] })] })] }) }));
|
|
384
436
|
};
|
|
385
|
-
const renderedPreview = (tid, did, fileExt, fileSize, fileCount, extHandler, showPreview, isResizingActive, onDownloadShowPreviewClick, dcmtBlob) => {
|
|
386
|
-
if (!did)
|
|
437
|
+
const renderedPreview = (tid, did, fileExt, fileSize, fileCount, extHandler, showPreview, isResizingActive, onDownloadShowPreviewClick, dcmtBlob, isBasketMode) => {
|
|
438
|
+
if (!isBasketMode && !did)
|
|
387
439
|
return _jsx(TMNothingToShow, { text: `${SDKUI_Localizator.NoDcmtSelected}.` });
|
|
388
|
-
if (fileCount == 0) {
|
|
440
|
+
if (!isBasketMode && fileCount == 0) {
|
|
389
441
|
return _jsx(TMNothingToShow, { text: SDKUI_Localizator.MetadataOnlyDocument });
|
|
390
442
|
}
|
|
391
|
-
if (fileExt && extHandler === FileExtensionHandler.NONE) {
|
|
443
|
+
if (!isBasketMode && fileExt && extHandler === FileExtensionHandler.NONE) {
|
|
392
444
|
return _jsx(TMNothingToShow, { fileExt: fileExt });
|
|
393
445
|
}
|
|
394
446
|
if (showPreview) {
|
package/lib/ts/types.d.ts
CHANGED
package/package.json
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@topconsultnpm/sdkui-react",
|
|
3
|
-
"version": "6.20.0-dev2.
|
|
3
|
+
"version": "6.20.0-dev2.2",
|
|
4
4
|
"description": "",
|
|
5
5
|
"scripts": {
|
|
6
|
-
"test": "echo \"Error: no test specified\"
|
|
6
|
+
"test": "echo \"Error: no test specified\" && exit 1",
|
|
7
7
|
"clean": "powershell Remove-Item lib/ -recurse",
|
|
8
8
|
"copy-files": "copyfiles -u 1 src/assets/*.* src/assets/ImageLibrary/*.* src/assets/thumbnails/*.* src/assets/IconsS4t/*.* src/assets/Metadata/*.* src/css/tm-sdkui.css lib/",
|
|
9
|
-
"tm-build": "npm run clean
|
|
9
|
+
"tm-build": "npm run clean && tsc && npm run copy-files",
|
|
10
10
|
"tm-watch": "tsc -w",
|
|
11
11
|
"tm-publish": "npm publish --tag latest",
|
|
12
12
|
"tm-publish_wl": "npm publish",
|
|
@@ -40,18 +40,18 @@
|
|
|
40
40
|
"lib"
|
|
41
41
|
],
|
|
42
42
|
"dependencies": {
|
|
43
|
-
"react-router-dom": "^6.15.0",
|
|
44
|
-
"react-pdf": "^10.3.0",
|
|
45
|
-
"htmlparser2": "^10.0.0",
|
|
46
|
-
"buffer": "^6.0.3",
|
|
47
43
|
"@topconsultnpm/sdk-ts": "6.20.0-test1",
|
|
48
|
-
"
|
|
44
|
+
"buffer": "^6.0.3",
|
|
49
45
|
"devextreme": "25.2.4",
|
|
50
|
-
"
|
|
46
|
+
"devextreme-react": "25.2.4",
|
|
47
|
+
"exceljs": "^4.4.0",
|
|
48
|
+
"htmlparser2": "^10.0.0",
|
|
51
49
|
"pdfjs-dist": "5.4.296",
|
|
52
|
-
"
|
|
50
|
+
"react-pdf": "^10.3.0",
|
|
51
|
+
"react-router-dom": "^6.15.0",
|
|
52
|
+
"styled-components": "^6.1.1"
|
|
53
53
|
},
|
|
54
54
|
"overrides": {
|
|
55
55
|
"esbuild": "^0.25.0"
|
|
56
56
|
}
|
|
57
|
-
}
|
|
57
|
+
}
|