@topconsultnpm/sdkui-react 6.21.0-dev2.50 → 6.21.0-dev2.52

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.
@@ -144,7 +144,7 @@ const TMMergeToPdfForm = ({ mode, selectedDcmtInfos, onClose, showTMRelationView
144
144
  const pdfFiles = [];
145
145
  const rfo = new RetrieveFileOptions();
146
146
  rfo.retrieveReason = DcmtOpers.None;
147
- rfo.generalRetrieveFormat = GeneralRetrieveFormats.Original;
147
+ rfo.generalRetrieveFormat = GeneralRetrieveFormats.OriginalUnsigned;
148
148
  rfo.cvtFormat = FileFormats.PDF;
149
149
  rfo.invoiceRetrieveFormat = SDKUI_Globals.userSettings?.searchSettings.invoiceRetrieveFormat;
150
150
  rfo.orderRetrieveFormat = SDKUI_Globals.userSettings?.searchSettings.orderRetrieveFormat;
@@ -18,16 +18,49 @@ const isScannerLicenseConfigured = () => {
18
18
  };
19
19
  let abortController = new AbortController();
20
20
  const downloadCountMap = new Map();
21
- const getDownloadFileName = (fileName) => {
22
- const firstDot = fileName.indexOf('.');
23
- const lastDot = fileName.lastIndexOf('.');
24
- if (firstDot === -1 || firstDot === lastDot)
25
- return fileName;
26
- const count = downloadCountMap.get(fileName) ?? 0;
27
- downloadCountMap.set(fileName, count + 1);
28
- if (count === 0)
29
- return fileName;
30
- return `${fileName.slice(0, firstDot)}(${count})${fileName.slice(firstDot)}`;
21
+ /**
22
+ * Genera il nome file per il download con fallback: backend → fileName → DID.
23
+ * Aggiunge estensione se mancante e gestisce duplicati per file multi-estensione.
24
+ */
25
+ const getDownloadFileName = (file, dcmtInfo) => {
26
+ // === FASE 1: Costruzione nome base con fallback ===
27
+ // Determina l'estensione con fallback
28
+ const fileExtFromBackend = file?.name?.split('.').pop()?.toLowerCase();
29
+ const fileExtFromDcmt = dcmtInfo.FILEEXT?.toLowerCase();
30
+ const fileExtension = fileExtFromBackend ?? fileExtFromDcmt ?? '';
31
+ let baseFileName;
32
+ // 1. Priorità massima: nome dal backend
33
+ if (file?.name) {
34
+ baseFileName = file.name;
35
+ }
36
+ // 2. Seconda priorità: nome salvato nel documento
37
+ else if (dcmtInfo.fileName) {
38
+ const hasExtension = dcmtInfo.fileName.includes('.');
39
+ baseFileName = hasExtension
40
+ ? dcmtInfo.fileName
41
+ : (fileExtension ? `${dcmtInfo.fileName}.${fileExtension}` : dcmtInfo.fileName);
42
+ }
43
+ // 3. Fallback finale: ID documento con estensione
44
+ else {
45
+ baseFileName = fileExtension ? `${dcmtInfo.DID}.${fileExtension}` : `${dcmtInfo.DID}`;
46
+ }
47
+ // === FASE 2: Gestione duplicati per file con estensioni multiple ===
48
+ const firstDot = baseFileName.indexOf('.');
49
+ const lastDot = baseFileName.lastIndexOf('.');
50
+ // Se non ci sono punti o c'è una sola estensione, ritorna il nome così com'è
51
+ if (firstDot === -1 || firstDot === lastDot) {
52
+ return baseFileName;
53
+ }
54
+ // Gestisce il contatore per evitare sovrascritture
55
+ const count = downloadCountMap.get(baseFileName) ?? 0;
56
+ downloadCountMap.set(baseFileName, count + 1);
57
+ // Prima occorrenza: nome originale
58
+ if (count === 0) {
59
+ return baseFileName;
60
+ }
61
+ // Download successivi: inserisce contatore dopo il nome base
62
+ // Es: "file.pdf.p7m" -> "file(1).pdf.p7m"
63
+ return `${baseFileName.slice(0, firstDot)}(${count})${baseFileName.slice(firstDot)}`;
31
64
  };
32
65
  export const useDcmtOperations = () => {
33
66
  const [showWaitPanel, setShowWaitPanel] = useState(false);
@@ -126,8 +159,7 @@ export const useDcmtOperations = () => {
126
159
  else {
127
160
  const alink2 = document.createElement('a');
128
161
  alink2.href = fileURL;
129
- const baseFileName = inputDcmts[i].fileName ?? (inputDcmts[i].FILEEXT ? `${inputDcmts[i].DID}.${inputDcmts[i].FILEEXT}` : file?.name);
130
- alink2.download = getDownloadFileName(baseFileName);
162
+ alink2.download = getDownloadFileName(file, inputDcmts[i]);
131
163
  alink2.target = "_blank";
132
164
  alink2.rel = "noreferrer";
133
165
  alink2.click();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@topconsultnpm/sdkui-react",
3
- "version": "6.21.0-dev2.50",
3
+ "version": "6.21.0-dev2.52",
4
4
  "description": "",
5
5
  "scripts": {
6
6
  "test": "echo \"Error: no test specified\" && exit 1",