@topconsultnpm/sdkui-react 6.20.0-dev2.11 → 6.20.0-dev2.13

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.
@@ -8,6 +8,20 @@ import { useFileDialog } from './useInputDialog';
8
8
  import { isXMLFileExt } from '../helper/dcmtsHelper';
9
9
  import { ShowConfirm } from '../components/base/TMConfirm';
10
10
  let abortController = new AbortController();
11
+ const downloadCountMap = new Map();
12
+ const compoundExts = ['.p7m', '.p7s', '.p7c', '.p7b'];
13
+ const getDownloadFileName = (fileName) => {
14
+ const lower = fileName.toLowerCase();
15
+ const isCompound = compoundExts.some(ext => lower.endsWith(ext) && lower.slice(0, -ext.length).includes('.'));
16
+ if (!isCompound)
17
+ return fileName;
18
+ const count = downloadCountMap.get(fileName) ?? 0;
19
+ downloadCountMap.set(fileName, count + 1);
20
+ if (count === 0)
21
+ return fileName;
22
+ const dotIndex = fileName.indexOf('.');
23
+ return `${fileName.slice(0, dotIndex)}(${count})${fileName.slice(dotIndex)}`;
24
+ };
11
25
  export function useDcmtOperations() {
12
26
  const [showWaitPanel, setShowWaitPanel] = useState(false);
13
27
  const [waitPanelTitle, setWaitPanelTitle] = useState('');
@@ -96,8 +110,8 @@ export function useDcmtOperations() {
96
110
  else {
97
111
  const alink2 = document.createElement('a');
98
112
  alink2.href = fileURL;
99
- const downloadFileName = inputDcmts[i].fileName ?? (inputDcmts[i].FILEEXT ? `${inputDcmts[i].DID}.${inputDcmts[i].FILEEXT}` : file?.name);
100
- alink2.download = downloadFileName;
113
+ const baseFileName = inputDcmts[i].fileName ?? (inputDcmts[i].FILEEXT ? `${inputDcmts[i].DID}.${inputDcmts[i].FILEEXT}` : file?.name);
114
+ alink2.download = getDownloadFileName(baseFileName);
101
115
  alink2.target = "_blank";
102
116
  alink2.rel = "noreferrer";
103
117
  alink2.click();
@@ -225,9 +225,6 @@ export const useRelatedDocuments = ({ selectedSearchResult, focusedItem, current
225
225
  const filterRelationsWithAssociations = (relations) => {
226
226
  return relations.filter(rel => rel.associations && rel.associations.length > 0);
227
227
  };
228
- const getRelatedDcmt = async (relation, type) => {
229
- return await DcmtTypeListCacheService.GetAsync(type === 'detail' ? relation.detailTID : relation.masterTID);
230
- };
231
228
  const showNoRelationsAlert = (type) => {
232
229
  ShowAlert({
233
230
  message: type === 'detail'
@@ -282,6 +279,26 @@ export const useRelatedDocuments = ({ selectedSearchResult, focusedItem, current
282
279
  TMExceptionBoxManager.show({ exception: error });
283
280
  }
284
281
  }, [mapAssociationsToMids]);
282
+ const filterRelationsByPermission = async (relations, type) => {
283
+ const dataSourcePromises = relations.map(async (rel) => {
284
+ const targetTID = type === 'detail' ? rel.detailTID : rel.masterTID;
285
+ const dtd = await DcmtTypeListCacheService.GetWithNotGrantedAsync(targetTID, undefined);
286
+ const hasPermission = dtd?.perm?.canArchive === AccessLevelsEx.Yes || dtd?.perm?.canArchive === AccessLevelsEx.Mixed;
287
+ return { id: rel?.id, name: dtd?.name, hasPermission, relation: rel };
288
+ });
289
+ const allResults = await Promise.all(dataSourcePromises);
290
+ return allResults.filter(r => r.hasPermission);
291
+ };
292
+ const showNoPermissionAlert = (type) => {
293
+ ShowAlert({
294
+ message: type === 'detail'
295
+ ? SDKUI_Localizator.YouDoNotHavePermissionsToArchiveDetailDocumentsOfThisType
296
+ : SDKUI_Localizator.YouDoNotHavePermissionsToArchiveMasterDocumentsOfThisType,
297
+ mode: 'warning',
298
+ title: type === 'detail' ? SDKUI_Localizator.DcmtsDetail : SDKUI_Localizator.DcmtsMaster,
299
+ duration: 5000
300
+ });
301
+ };
285
302
  const archiveRelatedDocuments = useCallback(async (tid, type) => {
286
303
  try {
287
304
  TMSpinner.show({ description: SDKUI_Localizator.Loading });
@@ -300,14 +317,20 @@ export const useRelatedDocuments = ({ selectedSearchResult, focusedItem, current
300
317
  }
301
318
  setRelatedDcmts(withAssociations);
302
319
  if (withAssociations.length > 1) {
303
- const dataSourcePromises = withAssociations.map(async (rel) => {
304
- const relatedDcmt = await getRelatedDcmt(rel, type);
305
- return { id: rel?.id, name: relatedDcmt?.name };
306
- });
307
- const dataSource = await Promise.all(dataSourcePromises);
308
- setRelatedDcmtsChooserDataSource(dataSource);
309
- setArchiveType(type);
310
- setShowRelatedDcmtsChooser(true);
320
+ const permittedResults = await filterRelationsByPermission(withAssociations, type);
321
+ if (permittedResults.length === 0) {
322
+ showNoPermissionAlert(type);
323
+ return;
324
+ }
325
+ if (permittedResults.length === 1) {
326
+ await archiveRelatedDcmtHandler(permittedResults[0].relation, type);
327
+ }
328
+ else {
329
+ const dataSource = permittedResults.map(r => ({ id: r.id, name: r.name }));
330
+ setRelatedDcmtsChooserDataSource(dataSource);
331
+ setArchiveType(type);
332
+ setShowRelatedDcmtsChooser(true);
333
+ }
311
334
  }
312
335
  else {
313
336
  await archiveRelatedDcmtHandler(withAssociations[0], type);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@topconsultnpm/sdkui-react",
3
- "version": "6.20.0-dev2.11",
3
+ "version": "6.20.0-dev2.13",
4
4
  "description": "",
5
5
  "scripts": {
6
6
  "test": "echo \"Error: no test specified\" && exit 1",