@topconsultnpm/sdkui-react 6.20.0-dev1.54 → 6.20.0-dev1.55
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,5 +1,6 @@
|
|
|
1
1
|
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
|
|
2
2
|
import { useState, useRef, useEffect } from 'react';
|
|
3
|
+
import { createPortal } from 'react-dom';
|
|
3
4
|
import * as S from './styles';
|
|
4
5
|
import { useIsMobile, useMenuPosition, useIsIOS } from './hooks';
|
|
5
6
|
import { IconArrowLeft } from '../../../helper';
|
|
@@ -297,6 +298,6 @@ const TMContextMenu = ({ items, trigger = 'right', children, externalControl, ke
|
|
|
297
298
|
display: 'inline-block',
|
|
298
299
|
WebkitTouchCallout: isIOS ? 'none' : undefined,
|
|
299
300
|
WebkitUserSelect: isIOS ? 'none' : undefined,
|
|
300
|
-
}, children: children })), menuState.visible && (_jsxs(_Fragment, { children: [_jsxs(S.MenuContainer, { ref: menuRef, "$x": menuState.position.x, "$y": menuState.position.y, "$openLeft": openLeft, "$openUp": openUp, "$isPositioned": isCalculated, "$externalControl": !!externalControl, children: [isMobile && menuState.parentNames.length > 0 && (_jsxs(S.MobileMenuHeader, { children: [_jsx(S.BackButton, { onClick: handleBack, "aria-label": "Go back", children: _jsx(IconArrowLeft, {}) }), _jsx(S.HeaderTitle, { children: currentParentName })] })), renderMenuItems(currentMenu, 0)] }), !isMobile && hoveredSubmenus.map((submenu, idx) => (_jsx(S.Submenu, { "$parentRect": submenu.parentRect, "$openUp": submenu.openUp, "data-submenu": "true", onMouseEnter: handleSubmenuMouseEnter, onMouseLeave: () => handleMouseLeave(submenu.depth), children: renderMenuItems(submenu.items, submenu.depth) }, `submenu-${submenu.depth}-${idx}`)))] }))] }));
|
|
301
|
+
}, children: children })), menuState.visible && createPortal(_jsxs(_Fragment, { children: [_jsxs(S.MenuContainer, { ref: menuRef, "$x": menuState.position.x, "$y": menuState.position.y, "$openLeft": openLeft, "$openUp": openUp, "$isPositioned": isCalculated, "$externalControl": !!externalControl, children: [isMobile && menuState.parentNames.length > 0 && (_jsxs(S.MobileMenuHeader, { children: [_jsx(S.BackButton, { onClick: handleBack, "aria-label": "Go back", children: _jsx(IconArrowLeft, {}) }), _jsx(S.HeaderTitle, { children: currentParentName })] })), renderMenuItems(currentMenu, 0)] }), !isMobile && hoveredSubmenus.map((submenu, idx) => (_jsx(S.Submenu, { "$parentRect": submenu.parentRect, "$openUp": submenu.openUp, "data-submenu": "true", onMouseEnter: handleSubmenuMouseEnter, onMouseLeave: () => handleMouseLeave(submenu.depth), children: renderMenuItems(submenu.items, submenu.depth) }, `submenu-${submenu.depth}-${idx}`)))] }), document.body)] }));
|
|
301
302
|
};
|
|
302
303
|
export default TMContextMenu;
|
|
@@ -3,8 +3,8 @@ import React, { useEffect, useState } from 'react';
|
|
|
3
3
|
import styled from 'styled-components';
|
|
4
4
|
import { SharingModes, SDK_Globals, SDK_Localizator } from '@topconsultnpm/sdk-ts';
|
|
5
5
|
import { LocalizeSharingModes } from '../../../helper/Enum_Localizator';
|
|
6
|
-
import
|
|
7
|
-
import { SDKUI_Localizator, Globalization,
|
|
6
|
+
import TMContextMenu from '../../NewComponents/ContextMenu/TMContextMenu';
|
|
7
|
+
import { SDKUI_Localizator, Globalization, IconStar, IconDelete, IconDashboard, IconSavedQuery, IconApply, IconInfo, IconCloseOutline } from '../../../helper';
|
|
8
8
|
import { TMColors } from '../../../utils/theme';
|
|
9
9
|
import ShowAlert from '../../base/TMAlert';
|
|
10
10
|
import { TMMessageBoxManager, ButtonNames, TMExceptionBoxManager } from '../../base/TMPopUp';
|
|
@@ -81,45 +81,38 @@ export const getTooltipBySqd = (sqd) => {
|
|
|
81
81
|
return (_jsxs("div", { style: { textAlign: "left", fontSize: '1rem', color: TMColors.primaryColor }, children: [_jsxs("div", { style: { display: 'flex', alignItems: 'center', gap: 10 }, children: [_jsx(IconSavedQuery, { color: getSharingModeColor(sqd.sharingMode), fontSize: 20, style: { flexShrink: 0 } }), _jsxs("div", { style: { display: 'flex', flexDirection: 'column', gap: 2 }, children: [_jsxs("div", { children: ["ID: ", sqd.id] }), _jsxs("div", { children: ["Master TID: ", sqd.masterTID] }), sqd.description && _jsx("div", { children: `${SDKUI_Localizator.Description}: ${sqd.description}` })] })] }), _jsx("hr", {}), _jsxs("div", { children: [SDKUI_Localizator.OwnerName, ": ", sqd.ownerName, " (", sqd.ownerID, ")"] }), _jsx("div", { children: LocalizeSharingModes(sqd.sharingMode) }), _jsxs("div", { children: ["Default: ", sqd.isDefault == 1 ? SDKUI_Localizator.Yes : SDKUI_Localizator.No] }), _jsxs("div", { children: ["Filtro semplice", ": ", sqd.isEasyWhere == 1 ? SDKUI_Localizator.Yes : SDKUI_Localizator.No] }), _jsxs("div", { children: ["Esegui ricerca immediatamente", ": ", sqd.runSearchWhenSelected == 1 ? SDKUI_Localizator.Yes : SDKUI_Localizator.No] }), _jsx("hr", {}), _jsxs("div", { children: [SDKUI_Localizator.CreationTime, ": ", Globalization.getDateTimeDisplayValue(sqd.creationTime)] }), _jsxs("div", { children: [SDKUI_Localizator.LastUpdateTime, ": ", Globalization.getDateTimeDisplayValue(sqd.lastUpdateTime)] })] }));
|
|
82
82
|
};
|
|
83
83
|
const initialSQDsMaxItems = 12;
|
|
84
|
-
const
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
] : [])
|
|
109
|
-
], target: `#sqd-item-${sqd.id}`, onItemClick: (e) => {
|
|
110
|
-
if (e.itemIndex == 0)
|
|
111
|
-
setDefaultAsync?.(sqd);
|
|
112
|
-
else if (e.itemIndex == 1)
|
|
113
|
-
deleteAsync?.(sqd);
|
|
114
|
-
else if (e.itemIndex == 2)
|
|
115
|
-
favManageAsync?.(sqd);
|
|
116
|
-
} });
|
|
84
|
+
const getContextMenuItems = (sqd, manageDefault, isMobile, deleteAsync, setDefaultAsync, favManageAsync, setInfoSQD) => [
|
|
85
|
+
...(manageDefault ? [{
|
|
86
|
+
name: SDKUI_Localizator.SetAsDefault2,
|
|
87
|
+
icon: _jsx(IconStar, { color: 'rgb(248, 215, 117)' }),
|
|
88
|
+
onClick: () => setDefaultAsync(sqd)
|
|
89
|
+
}] : []),
|
|
90
|
+
{
|
|
91
|
+
name: SDKUI_Localizator.Delete,
|
|
92
|
+
disabled: (sqd.id == 1),
|
|
93
|
+
icon: _jsx(IconDelete, {}),
|
|
94
|
+
onClick: () => deleteAsync(sqd)
|
|
95
|
+
},
|
|
96
|
+
{
|
|
97
|
+
name: SDKUI_Localizator.AddToHomePage,
|
|
98
|
+
disabled: (sqd.id == 1),
|
|
99
|
+
icon: _jsx(IconDashboard, {}),
|
|
100
|
+
onClick: () => favManageAsync?.(sqd)
|
|
101
|
+
},
|
|
102
|
+
...(isMobile ? [{
|
|
103
|
+
name: SDKUI_Localizator.About,
|
|
104
|
+
icon: _jsx(IconInfo, { color: TMColors.info }),
|
|
105
|
+
onClick: () => { setInfoSQD?.(sqd); }
|
|
106
|
+
}] : [])
|
|
107
|
+
];
|
|
117
108
|
const TMSavedQuerySelector = React.memo(({ items, selectedId, allowShowSearch = true, height, manageDefault = true, onItemClick, onDeleted, onFavoritesAdded, onRefreshData }) => {
|
|
118
109
|
const [dataSource, setDataSource] = useState([]);
|
|
119
110
|
const [selectedItem, setSelectedItem] = useState();
|
|
120
111
|
const [searchText, setSearchText] = useState('');
|
|
121
112
|
const [showAllRoot, setShowAllRoot] = useState(false);
|
|
122
113
|
const [infoSQD, setInfoSQD] = useState();
|
|
114
|
+
// Context menu state
|
|
115
|
+
const [contextMenuState, setContextMenuState] = useState({ visible: false, position: { x: 0, y: 0 }, sqd: null });
|
|
123
116
|
const deviceType = useDeviceType();
|
|
124
117
|
const isMobile = deviceType === DeviceType.MOBILE;
|
|
125
118
|
const panelRef = useOutsideClick(() => {
|
|
@@ -187,40 +180,52 @@ const TMSavedQuerySelector = React.memo(({ items, selectedId, allowShowSearch =
|
|
|
187
180
|
overflow: 'auto'
|
|
188
181
|
}, children: dataSource.slice(0, showAllRoot || searchText.length > 0 ? dataSource.length : initialSQDsMaxItems).filter(o => searchText.length <= 0 || (searchText.length > 0 && o.name?.toLocaleLowerCase().includes(searchText.toLocaleLowerCase())) || o.description?.toLocaleLowerCase().includes(searchText.toLocaleLowerCase())).map((sqd, index) => {
|
|
189
182
|
const isCurrent = selectedItem?.id == sqd.id;
|
|
190
|
-
return (
|
|
183
|
+
return (_jsx(StyledSqdItem, { "$isMobile": isMobile, onClick: () => {
|
|
191
184
|
setSelectedItem(sqd);
|
|
192
185
|
onItemClick?.(sqd);
|
|
193
|
-
},
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
186
|
+
}, onContextMenu: (e) => {
|
|
187
|
+
e.preventDefault();
|
|
188
|
+
e.stopPropagation();
|
|
189
|
+
setContextMenuState({
|
|
190
|
+
visible: true,
|
|
191
|
+
position: { x: e.clientX, y: e.clientY },
|
|
192
|
+
sqd: sqd
|
|
193
|
+
});
|
|
194
|
+
}, children: _jsxs(StyledDivHorizontal, { style: { alignItems: 'center', gap: 8, width: '100%' }, children: [!isMobile && (_jsx("span", { className: "info-icon", style: {
|
|
195
|
+
marginRight: 4,
|
|
196
|
+
display: 'flex',
|
|
197
|
+
alignItems: 'center'
|
|
198
|
+
}, children: _jsx(TMTooltip, { content: getTooltipBySqd(sqd), children: _jsx(IconInfo, { color: TMColors.primaryColor }) }) })), _jsxs("div", { style: {
|
|
199
|
+
flex: 1,
|
|
200
|
+
display: 'flex',
|
|
201
|
+
alignItems: 'center',
|
|
202
|
+
justifyContent: 'center',
|
|
203
|
+
minWidth: 0
|
|
204
|
+
}, children: [_jsx("p", { style: {
|
|
205
|
+
fontSize: '1rem',
|
|
206
|
+
fontWeight: sqd.id === 1 ? 600 : 'normal',
|
|
207
|
+
whiteSpace: 'nowrap',
|
|
208
|
+
overflow: 'hidden',
|
|
209
|
+
textOverflow: 'ellipsis',
|
|
210
|
+
color: TMColors.primaryColor,
|
|
211
|
+
paddingRight: '15px'
|
|
212
|
+
}, children: sqd.name }), manageDefault && sqd.isDefault == 1 && _jsx(IconStar, { fontSize: 16, color: 'rgb(248, 215, 117)' })] }), _jsx("span", { style: {
|
|
213
|
+
width: 24,
|
|
214
|
+
height: 24,
|
|
215
|
+
borderRadius: 24,
|
|
216
|
+
display: 'flex',
|
|
217
|
+
alignItems: 'center',
|
|
218
|
+
justifyContent: 'center',
|
|
219
|
+
fontSize: '1rem',
|
|
220
|
+
fontWeight: 'bold',
|
|
221
|
+
marginLeft: 8,
|
|
222
|
+
visibility: isCurrent ? 'visible' : 'hidden'
|
|
223
|
+
}, children: _jsx(IconApply, { fontSize: 24, color: 'green' }) })] }) }, sqd.id));
|
|
223
224
|
}) }), dataSource.length > initialSQDsMaxItems && searchText.length <= 0 &&
|
|
224
|
-
_jsx("div", { style: { display: 'flex', justifyContent: 'flex-end', padding: '10px', position: 'relative' }, children: _jsx(TMShowAllOrMaxItemsButton, { showAll: showAllRoot, dataSourceLength: dataSource.length, onClick: () => { setShowAllRoot(!showAllRoot); } }) }),
|
|
225
|
+
_jsx("div", { style: { display: 'flex', justifyContent: 'flex-end', padding: '10px', position: 'relative' }, children: _jsx(TMShowAllOrMaxItemsButton, { showAll: showAllRoot, dataSourceLength: dataSource.length, onClick: () => { setShowAllRoot(!showAllRoot); } }) }), contextMenuState.sqd && (_jsx(TMContextMenu, { items: getContextMenuItems(contextMenuState.sqd, manageDefault, isMobile, deleteSQDAsync, setDefaultSQDAsync, favManageSQDAsync, setInfoSQD), externalControl: {
|
|
226
|
+
visible: contextMenuState.visible,
|
|
227
|
+
position: contextMenuState.position,
|
|
228
|
+
onClose: () => setContextMenuState(prev => ({ ...prev, visible: false, sqd: null }))
|
|
229
|
+
} })), _jsxs(StyledOffCanvasPanel, { ref: panelRef, "$isOpen": isMobile && infoSQD !== undefined, children: [_jsxs(StyledDivHorizontal, { style: { gap: 10, padding: '10px 8px', width: '100%', alignItems: 'center' }, children: [_jsx("p", { style: { fontSize: '1.1rem', fontWeight: 'bold' }, children: `${SDK_Localizator.SavedQuery} - ${SDKUI_Localizator.About}` }), _jsx(IconCloseOutline, { style: { marginLeft: 'auto', cursor: 'pointer' }, onClick: () => setInfoSQD(undefined) })] }), getTooltipBySqd(infoSQD)] })] }));
|
|
225
230
|
});
|
|
226
231
|
export default TMSavedQuerySelector;
|