@topconsultnpm/sdkui-react-beta 6.16.29 → 6.16.30

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,6 +1,7 @@
1
1
  import React from 'react';
2
- import { DiagramItem } from './interfaces';
2
+ import { DiagramItem, WfInfo } from './interfaces';
3
3
  interface DiagramItemComponentProps {
4
+ wf?: WfInfo | null;
4
5
  item: DiagramItem;
5
6
  isSelected: boolean;
6
7
  isCurrent: boolean;
@@ -1,8 +1,10 @@
1
1
  import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
2
2
  import React, { useState, useCallback, useRef, useEffect, useMemo } from 'react';
3
+ import { DiagramItemTypes } from './interfaces';
3
4
  import styled, { keyframes, css } from 'styled-components';
4
5
  import DiagramItemSvgContent from './DiagramItemSvgContent';
5
6
  import { calculateDiagramItemFullDimensions, FONT_SIZE, MAX_ITEM_WIDTH, MAX_LINES, PADDING_HORIZONTAL, PADDING_TOP, SPACING_SVG_TEXT, SVG_ICON_SIZE, wrapText } from './workflowHelpers';
7
+ import { DataListCacheService } from '@topconsultnpm/sdk-ts-beta';
6
8
  const blink = keyframes `
7
9
  0%, 100% { opacity: 1; }
8
10
  50% { opacity: 0.4; }
@@ -80,7 +82,7 @@ const ConnectorHitArea = styled.circle `
80
82
  opacity: 0;
81
83
  pointer-events: all;
82
84
  `;
83
- const DiagramItemComponent = ({ item, isSelected, isCurrent, readOnly, onClick, onDrag, onDragEnd, onConnectorMouseDown, onConnectorMouseUp, onDimensionsChange, onDoubleClick, }) => {
85
+ const DiagramItemComponent = ({ wf, item, isSelected, isCurrent, readOnly, onClick, onDrag, onDragEnd, onConnectorMouseDown, onConnectorMouseUp, onDimensionsChange, onDoubleClick, }) => {
84
86
  const diagramItemRef = useRef(null);
85
87
  const textRef = useRef(null);
86
88
  const [isDragging, setIsDragging] = useState(false);
@@ -88,6 +90,26 @@ const DiagramItemComponent = ({ item, isSelected, isCurrent, readOnly, onClick,
88
90
  const [startDragOffset, setStartDragOffset] = useState(null);
89
91
  const [currentPosition, setCurrentPosition] = useState({ x: item.Left, y: item.Top });
90
92
  const [textDimensions, setTextDimensions] = useState({ width: 0, height: 0 });
93
+ const [statusData, setStatusData] = useState(undefined);
94
+ useEffect(() => {
95
+ const fetchStatusData = async () => {
96
+ if (item.Type === DiagramItemTypes.Status && wf?.MStatusDLID) {
97
+ try {
98
+ const fullDataList = await DataListCacheService.GetAsync(wf.MStatusDLID);
99
+ const foundItem = fullDataList?.items?.find(o => o.value == item.StatusValue);
100
+ setStatusData(foundItem);
101
+ }
102
+ catch (error) {
103
+ console.error("Errore durante il recupero dei dati di stato:", error);
104
+ setStatusData(undefined);
105
+ }
106
+ }
107
+ else {
108
+ setStatusData(undefined);
109
+ }
110
+ };
111
+ fetchStatusData();
112
+ }, [item.Type, item.StatusValue, wf?.MStatusDLID]);
91
113
  // Calcola le dimensioni totali dell'elemento usando la funzione di utilità
92
114
  const { calculatedWidth, calculatedHeight } = useMemo(() => {
93
115
  return calculateDiagramItemFullDimensions(item, textDimensions);
@@ -235,7 +257,7 @@ const DiagramItemComponent = ({ item, isSelected, isCurrent, readOnly, onClick,
235
257
  isTruncated = textLines[textLines.length - 1].endsWith('...');
236
258
  }
237
259
  }
238
- return (_jsxs(_Fragment, { children: [isTruncated && _jsx("title", { children: item.ItemName }), _jsx("rect", { x: "0", y: "0", width: calculatedWidth, height: calculatedHeight, className: "item-main-shape" }), _jsx("g", { transform: `translate(${svgX}, ${svgY})`, children: _jsx(DiagramItemSvgContent, { itemType: item.Type, width: iconRenderWidth, height: iconRenderHeight }) }), textLines.length > 0 && (_jsx("text", { ref: textRef, x: calculatedWidth / 2, dominantBaseline: "central", className: "item-text", children: textLines.map((line, index) => (_jsx("tspan", { x: calculatedWidth / 2, dy: index === 0 ? PADDING_TOP + SVG_ICON_SIZE + SPACING_SVG_TEXT : FONT_SIZE + 1, children: line }, index))) })), connectors] }));
260
+ return (_jsxs(_Fragment, { children: [isTruncated && _jsx("title", { children: item.ItemName }), _jsx("rect", { x: "0", y: "0", width: calculatedWidth, height: calculatedHeight, className: "item-main-shape" }), _jsx("g", { transform: `translate(${svgX}, ${svgY})`, children: _jsx(DiagramItemSvgContent, { itemType: item.Type, width: iconRenderWidth, height: iconRenderHeight, statusData: statusData }) }), textLines.length > 0 && (_jsx("text", { ref: textRef, x: calculatedWidth / 2, dominantBaseline: "central", className: "item-text", children: textLines.map((line, index) => (_jsx("tspan", { x: calculatedWidth / 2, dy: index === 0 ? PADDING_TOP + SVG_ICON_SIZE + SPACING_SVG_TEXT : FONT_SIZE + 1, children: line }, index))) })), connectors] }));
239
261
  };
240
262
  return (_jsx(StyledDiagramItem, { ref: diagramItemRef, transform: `translate(${currentPosition.x}, ${currentPosition.y})`, "$isSelected": isSelected, "$itemType": item.Type, "$isDragging": isDragging, "$isHovered": isHovered, "$isReadOnly": readOnly, onMouseDown: handleMouseDown, onClick: handleItemClick, onMouseEnter: handleMouseEnter, onMouseLeave: handleMouseLeave, onDoubleClick: handleDoubleClick, children: _jsx(AnimatingGroup, { "$isCurrent": isCurrent, children: renderContent() }) }));
241
263
  };
@@ -1,10 +1,12 @@
1
1
  import React from 'react';
2
2
  import { DiagramItemTypes } from './interfaces';
3
+ import { DataListItemDescriptor } from '@topconsultnpm/sdk-ts-beta';
3
4
  interface DiagramItemSvgContentProps {
4
5
  itemType: DiagramItemTypes;
5
6
  width: number;
6
7
  height: number;
7
8
  isToolboxPreview?: boolean;
9
+ statusData?: DataListItemDescriptor;
8
10
  }
9
11
  declare const DiagramItemSvgContent: React.FC<DiagramItemSvgContentProps>;
10
12
  export default DiagramItemSvgContent;
@@ -1,6 +1,7 @@
1
1
  import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
2
2
  import { DiagramItemTypes } from './interfaces'; // Assicurati che il percorso sia corretto
3
3
  import styled from 'styled-components';
4
+ import { TMImageLibrary } from '../../../../helper';
4
5
  // Stili per il contenitore SVG nella toolbox per centrare l'elemento
5
6
  const StyledToolboxSvgContainer = styled.div `
6
7
  width: 100%;
@@ -15,7 +16,7 @@ const StyledToolboxSvgContainer = styled.div `
15
16
  display: block; // Rimuove spazi extra sotto l'SVG
16
17
  }
17
18
  `;
18
- const DiagramItemSvgContent = ({ itemType, width, height, isToolboxPreview = false }) => {
19
+ const DiagramItemSvgContent = ({ itemType, width, height, isToolboxPreview = false, statusData }) => {
19
20
  const PADDING = 10;
20
21
  // ICON_SIZE e SMALL_ICON_SIZE possono essere regolati a seconda se è una preview o l'elemento reale
21
22
  const ICON_SIZE = isToolboxPreview ? Math.min(width, height) * 0.6 : 40;
@@ -39,7 +40,19 @@ const DiagramItemSvgContent = ({ itemType, width, height, isToolboxPreview = fal
39
40
  svgContent = (_jsx("polygon", { points: `${svgCenterX},${PADDING} ${calculatedWidth - PADDING},${svgCenterY} ${svgCenterX},${calculatedHeight - PADDING} ${PADDING},${svgCenterY}`, fill: "#87d1df", stroke: "#62d3e2", strokeWidth: "2" }));
40
41
  break;
41
42
  case DiagramItemTypes.Status:
42
- svgContent = (_jsx("svg", { x: svgCenterX - ICON_SIZE / 2, y: svgCenterY - ICON_SIZE / 2, width: ICON_SIZE, height: ICON_SIZE, viewBox: "0 0 24 24", fill: "orange", children: _jsx("path", { d: "M12 2C6.48 2 2 6.48 2 12s4.48 10 10 10 10-4.48 10-10S17.52 2 12 2zm1 15h-2v-6h2v6zm0-8h-2V7h2v2z" }) }));
43
+ // Se i dati non sono disponibili o è una preview, mostra l'icona di fallback
44
+ if (isToolboxPreview || !statusData?.imageID) {
45
+ svgContent = (_jsx("svg", { x: svgCenterX - ICON_SIZE / 2, y: svgCenterY - ICON_SIZE / 2, width: ICON_SIZE, height: ICON_SIZE, viewBox: "0 0 24 24", fill: "orange", children: _jsx("path", { d: "M12 2C6.48 2 2 6.48 2 12s4.48 10 10 10 10-4.48 10-10S17.52 2 12 2zm1 15h-2v-6h2v6zm0-8h-2V7h2v2z" }) }));
46
+ }
47
+ else { // Altrimenti, mostra l'immagine personalizzata
48
+ svgContent = (_jsx("foreignObject", { x: (width - ICON_SIZE) / 2, y: (height - ICON_SIZE) / 2, width: ICON_SIZE, height: ICON_SIZE, children: _jsx("div", { style: {
49
+ display: 'flex',
50
+ alignItems: 'center',
51
+ justifyContent: 'center',
52
+ width: '100%',
53
+ height: '100%'
54
+ }, children: statusData?.imageID && _jsx(TMImageLibrary, { imageID: statusData.imageID }) }) }));
55
+ }
43
56
  break;
44
57
  case DiagramItemTypes.DataEntry:
45
58
  case DiagramItemTypes.Approval:
@@ -339,12 +339,17 @@ const WFDiagram = ({ xmlDiagramString, currentSetID, readOnly = false, zoomLevel
339
339
  if (!wfDiagram || (selectedItems.size === 0 && selectedConnections.size === 0)) {
340
340
  return;
341
341
  }
342
+ // 1. Filtra i nodi "Start" e "End" dal set di elementi selezionati
343
+ const nonDeletableItems = wfDiagram.DiagramItems.filter(item => item.Type === DiagramItemTypes.Start || item.Type === DiagramItemTypes.End);
344
+ const deletableSelectedItems = new Set([...selectedItems].filter(id => !nonDeletableItems.some(item => item.ID === id)));
342
345
  let newDiagramItems = wfDiagram.DiagramItems;
343
346
  let newConnections = wfDiagram.Connections;
344
- if (selectedItems.size > 0) {
345
- newDiagramItems = wfDiagram.DiagramItems.filter(item => !selectedItems.has(item.ID));
346
- newConnections = newConnections.filter(conn => !selectedItems.has(conn.Source.ParentDiagramItem.ID) &&
347
- !selectedItems.has(conn.Sink.ParentDiagramItem.ID));
347
+ if (deletableSelectedItems.size > 0) {
348
+ // 2. Filtra gli elementi del diagramma usando il set filtrato
349
+ newDiagramItems = wfDiagram.DiagramItems.filter(item => !deletableSelectedItems.has(item.ID));
350
+ // 3. Filtra le connessioni usando il set filtrato
351
+ newConnections = newConnections.filter(conn => !deletableSelectedItems.has(conn.Source.ParentDiagramItem.ID) &&
352
+ !deletableSelectedItems.has(conn.Sink.ParentDiagramItem.ID));
348
353
  }
349
354
  if (selectedConnections.size > 0) {
350
355
  newConnections = newConnections.filter(conn => !selectedConnections.has(conn.ID));
@@ -354,7 +359,8 @@ const WFDiagram = ({ xmlDiagramString, currentSetID, readOnly = false, zoomLevel
354
359
  DiagramItems: newDiagramItems,
355
360
  Connections: newConnections,
356
361
  };
357
- setSelectedItems(new Set());
362
+ // Assicura che i nodi non cancellabili restino selezionati per coerenza UI
363
+ setSelectedItems(new Set([...deletableSelectedItems, ...[...selectedItems].filter(id => nonDeletableItems.some(item => item.ID === id))]));
358
364
  setSelectedConnections(new Set());
359
365
  updateDiagram(newWfDiagram, false);
360
366
  }, [wfDiagram, selectedItems, selectedConnections, setWfDiagram, setSelectedItems, setSelectedConnections, updateDiagram, readOnly]);
@@ -1380,7 +1386,7 @@ const WFDiagram = ({ xmlDiagramString, currentSetID, readOnly = false, zoomLevel
1380
1386
  }
1381
1387
  }, [wfDiagram]);
1382
1388
  return (_jsxs(CanvasContainer, { children: [!readOnly && (_jsxs(ToolbarContainer, { "$isCollapsed": isToolbarCollapsed, "$isFloating": isToolbarFloating, "$isToolboxVisible": isToolboxVisible, children: [_jsx(ButtonGroup, { "$isFloating": isToolbarFloating, children: _jsxs("button", { onClick: handleToggleToolboxVisibility, title: "Show toolbox", children: [_jsx(IconFlowChart, {}), !isToolbarCollapsed && _jsx("span", { children: "Mostra/nascondi toolbox" })] }) }), _jsxs(ButtonGroup, { "$isFloating": isToolbarFloating, children: [_jsxs("button", { onClick: handleUndo, disabled: historyIndex === 0, title: "Undo", children: [_jsx(IconUndo, {}), " ", !isToolbarCollapsed && _jsx("span", { children: "Undo" })] }), _jsxs("button", { onClick: handleRedo, disabled: historyIndex === wfDiagramHistory.length - 1, title: "Redo", children: [_jsx(IconUndo, { style: { transform: 'scaleX(-1)' } }), " ", !isToolbarCollapsed && _jsx("span", { children: "Redo" })] }), _jsxs("button", { onClick: handleRestore, title: "Restore", children: [_jsx(IconRestore, {}), " ", !isToolbarCollapsed && _jsx("span", { children: "Restore" })] }), _jsxs("button", { onClick: handleNew, title: "New diagram", disabled: readOnly, children: [_jsx(IconNew, {}), " ", !isToolbarCollapsed && _jsx("span", { children: "New" })] })] }), _jsx(ButtonGroup, { "$isFloating": isToolbarFloating, children: _jsxs("button", { onClick: handleAutoAdjust, title: "Auto adjust", children: [_jsx(IconAdjust, {}), " ", !isToolbarCollapsed && _jsx("span", { children: "Auto Adjust" })] }) }), _jsxs(ButtonGroup, { "$isFloating": isToolbarFloating, children: [_jsxs("button", { onClick: handleCopy, disabled: selectedItems.size === 0, title: "Copy", children: [_jsx(IconCopy, {}), " ", !isToolbarCollapsed && _jsx("span", { children: "Copy" })] }), _jsxs("button", { onClick: handleCut, disabled: selectedItems.size === 0, title: "Cut", children: [_jsx(IconCut, {}), " ", !isToolbarCollapsed && _jsx("span", { children: "Cut" })] }), _jsxs("button", { onClick: handlePaste, disabled: copiedItems.length === 0 && copiedConnections.length === 0, title: "Paste", children: [_jsx(IconPaste, {}), " ", !isToolbarCollapsed && _jsx("span", { children: "Paste" })] })] }), _jsxs("button", { onClick: handleToggleToolbarMode, title: isToolbarFloating ? "Dock Toolbar" : "Float Toolbar", children: [isToolbarFloating ? _jsx(IconPin, {}) : _jsx(IconUnpin, {}), !isToolbarCollapsed && !isToolbarFloating && _jsx("span", { children: "Toggle Mode" })] }), !isToolbarFloating && _jsx(ToolbarToggle, { onClick: () => setIsToolbarCollapsed(!isToolbarCollapsed), title: isToolbarCollapsed ? "Expand Toolbar" : "Collapse Toolbar", children: isToolbarCollapsed ? _jsx(IconChevronRight, {}) : _jsx(IconCloseOutline, {}) })] })), !readOnly && (_jsx(ToolboxContainer, { "$isVisible": isToolboxVisible, children: isToolboxVisible && availableItemTypes.map(type => (_jsxs(ToolboxItem, { draggable: true, onDragStart: (e) => handleToolboxDragStart(e, type), onDragEnd: handleToolboxDragEnd, children: [_jsx(DiagramItemSvgContent, { itemType: type, width: 40, height: 40, isToolboxPreview: true }), _jsx("span", { children: DiagramItemTypes[type] })] }, type))) })), _jsx(SvgScrollContainer, { children: isLoading ?
1383
- (_jsxs(StyledLoadingContainer, { children: [_jsx(StyledSpinner, {}), _jsx("span", { children: `${'Caricamento diagramma'}...` })] })) : wfDiagram ? (_jsx(StyledSvg, { ref: svgRef, tabIndex: 0, onKeyDownCapture: handleKeyDown, onMouseMove: handleMouseMove, onMouseUp: handleMouseUp, onMouseDown: handleMouseDown, onDrop: handleDropOnCanvas, onDragOver: handleDragOver, width: svgWidth, height: svgHeight, children: _jsxs(ScalableGroup, { "$scale": zoomLevel, "$translateX": translateX, "$translateY": translateY, children: [wfDiagram?.DiagramItems.map(item => (_jsx(DiagramItemComponent, { readOnly: readOnly, item: item, isSelected: selectedItems.has(item.ID), isCurrent: item.ID === currentSetID, onClick: handleDiagramItemClick, onDrag: handleDrag, onDragEnd: handleDragEnd, onConnectorMouseDown: handleConnectorMouseDown, onConnectorMouseUp: handleConnectorMouseUp, onDimensionsChange: handleItemDimensionsChange, onDoubleClick: handleDoubleClickItem }, item.ID))), calculatedConnections.map(connection => {
1389
+ (_jsxs(StyledLoadingContainer, { children: [_jsx(StyledSpinner, {}), _jsx("span", { children: `${'Caricamento diagramma'}...` })] })) : wfDiagram ? (_jsx(StyledSvg, { ref: svgRef, tabIndex: 0, onKeyDownCapture: handleKeyDown, onMouseMove: handleMouseMove, onMouseUp: handleMouseUp, onMouseDown: handleMouseDown, onDrop: handleDropOnCanvas, onDragOver: handleDragOver, width: svgWidth, height: svgHeight, children: _jsxs(ScalableGroup, { "$scale": zoomLevel, "$translateX": translateX, "$translateY": translateY, children: [wfDiagram?.DiagramItems.map(item => (_jsx(DiagramItemComponent, { wf: wfDiagram?.Info, readOnly: readOnly, item: item, isSelected: selectedItems.has(item.ID), isCurrent: item.ID === currentSetID, onClick: handleDiagramItemClick, onDrag: handleDrag, onDragEnd: handleDragEnd, onConnectorMouseDown: handleConnectorMouseDown, onConnectorMouseUp: handleConnectorMouseUp, onDimensionsChange: handleItemDimensionsChange, onDoubleClick: handleDoubleClickItem }, item.ID))), calculatedConnections.map(connection => {
1384
1390
  const sourceItem = wfDiagram?.DiagramItems.find(item => item.ID === connection.Source.ParentDiagramItem.ID);
1385
1391
  const sinkItem = wfDiagram?.DiagramItems.find(item => item.ID === connection.Sink.ParentDiagramItem.ID);
1386
1392
  if (!sourceItem || !sinkItem)
package/package.json CHANGED
@@ -1,12 +1,13 @@
1
1
  {
2
2
  "name": "@topconsultnpm/sdkui-react-beta",
3
- "version": "6.16.29",
3
+ "version": "6.16.30",
4
4
  "description": "",
5
5
  "scripts": {
6
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
9
  "tm-build": "npm run clean && tsc && npm run copy-files",
10
+ "tm-watch": "tsc -w",
10
11
  "tm-publish": "npm publish",
11
12
  "storybook": "storybook dev -p 6006",
12
13
  "build-storybook": "storybook build"