@topconsultnpm/sdkui-react 6.19.0-dev1.45 → 6.19.0-dev1.46
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.
|
@@ -402,38 +402,56 @@ const TMMetadataValues = ({ showCheckBoxes = ShowCheckBoxesMode.Never, checkPerm
|
|
|
402
402
|
return (_jsx("div", { style: { width: '100%' }, children: dsAttachsData.length > 0 && _jsx(TMAccordion, { title: SDKUI_Localizator.Attachment, children: dsAttachsData.map(item => renderMetadataItem(item, isReadOnly)) }) }));
|
|
403
403
|
}, [metadataValues, showCheckBoxes, showNullValueCheckBoxes, isReadOnly, dynDataListsToBeRefreshed, validationItems, selectedMID, isOpenDistinctValues, openChooserBySingleClick, metadataValuesOrig]);
|
|
404
404
|
const layoutCustom = useMemo(() => {
|
|
405
|
+
console.log('Rendering custom layout with layout:', layout);
|
|
405
406
|
if (!layout || !layout.items || layout.items.length === 0) {
|
|
406
407
|
return metadataValues.map((item) => renderMetadataItem(item));
|
|
407
408
|
}
|
|
408
|
-
// Build a map of items by ID for quick lookup
|
|
409
|
+
// Build a map of items by ID for quick lookup (include negative/zero IDs)
|
|
409
410
|
const itemsById = new Map();
|
|
410
411
|
layout.items.forEach(item => {
|
|
411
|
-
if (item.layoutItemID) {
|
|
412
|
+
if (item.layoutItemID !== undefined && item.layoutItemID !== null) {
|
|
412
413
|
itemsById.set(item.layoutItemID, item);
|
|
413
414
|
}
|
|
414
415
|
});
|
|
415
|
-
//
|
|
416
|
-
|
|
417
|
-
|
|
416
|
+
// Determine root items. Prefer explicit LayoutRoot items if present;
|
|
417
|
+
// otherwise fall back to items with no parent (parentID undefined or -1).
|
|
418
|
+
const hasExplicitRoot = layout.items.some(item => item.type === LayoutItemTypes.LayoutRoot);
|
|
419
|
+
const rootItems = hasExplicitRoot
|
|
420
|
+
? layout.items.filter(item => item.type === LayoutItemTypes.LayoutRoot)
|
|
421
|
+
: layout.items.filter(item => item.parentID === undefined || item.parentID === -1);
|
|
422
|
+
// Recursive function to get children of an item. Handle parentID === -1 and undefined
|
|
423
|
+
// because some layouts use -1 for root while children use undefined.
|
|
418
424
|
const getChildren = (parentID) => {
|
|
425
|
+
if (parentID === -1) {
|
|
426
|
+
return layout.items?.filter(item => item.parentID === -1 || item.parentID === undefined) || [];
|
|
427
|
+
}
|
|
428
|
+
if (parentID === undefined) {
|
|
429
|
+
return layout.items?.filter(item => item.parentID === undefined) || [];
|
|
430
|
+
}
|
|
419
431
|
return layout.items?.filter(item => item.parentID === parentID) || [];
|
|
420
432
|
};
|
|
421
433
|
// Recursive function to render layout items with depth tracking for indentation
|
|
422
|
-
|
|
434
|
+
// Prevent infinite recursion by tracking visited layoutItemIDs (handles malformed layouts where an item
|
|
435
|
+
// may reference itself as a child or cycles exist).
|
|
436
|
+
const renderLayoutItem = (layoutItem, depth = 0, visited = new Set()) => {
|
|
437
|
+
const id = layoutItem.layoutItemID ?? 0;
|
|
438
|
+
if (visited.has(id))
|
|
439
|
+
return null;
|
|
440
|
+
visited.add(id);
|
|
423
441
|
// Check if this is a LayoutRoot - just render its children
|
|
424
442
|
if (layoutItem.type === LayoutItemTypes.LayoutRoot) {
|
|
425
|
-
const children = getChildren(layoutItem.layoutItemID
|
|
426
|
-
return (_jsx(React.Fragment, { children: children.map(child => renderLayoutItem(child, depth)) }, `root-${layoutItem.layoutItemID}`));
|
|
443
|
+
const children = getChildren(layoutItem.layoutItemID);
|
|
444
|
+
return (_jsx(React.Fragment, { children: children.map(child => renderLayoutItem(child, depth, visited)) }, `root-${layoutItem.layoutItemID}`));
|
|
427
445
|
}
|
|
428
446
|
// Check if this is a LayoutGroup
|
|
429
447
|
else if (layoutItem.type === LayoutItemTypes.LayoutGroup && layoutItem.lgd) {
|
|
430
|
-
const children = getChildren(layoutItem.layoutItemID
|
|
448
|
+
const children = getChildren(layoutItem.layoutItemID);
|
|
431
449
|
const groupDescriptor = layoutItem.lgd;
|
|
432
450
|
const groupTitle = groupDescriptor.caption || `Group ${layoutItem.layoutItemID}`;
|
|
433
451
|
const isCollapsed = false; // LayoutGroupDescriptor doesn't have collapsed property
|
|
434
452
|
// Apply indentation only to subgroups (depth > 0), not to root groups
|
|
435
453
|
const indentationPx = depth > 0 ? depth * 10 : 0;
|
|
436
|
-
return (_jsx("div", { style: { paddingLeft: `${indentationPx}px` }, children: _jsx(TMAccordion, { title: groupTitle, defaultCollapsed: isCollapsed, children: children.map(child => renderLayoutItem(child, depth + 1)) }) }, `group-wrapper-${layoutItem.layoutItemID}`));
|
|
454
|
+
return (_jsx("div", { style: { paddingLeft: `${indentationPx}px` }, children: _jsx(TMAccordion, { title: groupTitle, defaultCollapsed: isCollapsed, children: children.map(child => renderLayoutItem(child, depth + 1, visited)) }) }, `group-wrapper-${layoutItem.layoutItemID}`));
|
|
437
455
|
}
|
|
438
456
|
// Check if this is a LayoutControlItem (metadata field)
|
|
439
457
|
else if (layoutItem.type === LayoutItemTypes.LayoutControlItem && layoutItem.lcid) {
|
|
@@ -455,7 +473,10 @@ const TMMetadataValues = ({ showCheckBoxes = ShowCheckBoxesMode.Never, checkPerm
|
|
|
455
473
|
}
|
|
456
474
|
return null;
|
|
457
475
|
};
|
|
458
|
-
return (_jsx("div", { style: { width: '100%' }, children:
|
|
476
|
+
return (_jsx("div", { style: { width: '100%' }, children: (() => {
|
|
477
|
+
const visited = new Set();
|
|
478
|
+
return rootItems.map(item => renderLayoutItem(item, 0, visited));
|
|
479
|
+
})() }));
|
|
459
480
|
}, [layout, metadataValues, showCheckBoxes, showNullValueCheckBoxes, isReadOnly, dynDataListsToBeRefreshed, validationItems, selectedMID, isOpenDistinctValues, openChooserBySingleClick, metadataValuesOrig]);
|
|
460
481
|
const renderForm = useMemo(() => {
|
|
461
482
|
// Se currentDTD non è ancora stato caricato, non renderizzare nulla
|