@topconsultnpm/sdkui-react-beta 6.14.11 → 6.14.12

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.
@@ -4,14 +4,12 @@ import { TID_MID } from '../../../ts';
4
4
  import { AdvancedMenuClickEventArgs } from '../../editors/TMMetadataValues';
5
5
  interface ITMSearchQueryEditorProps {
6
6
  qd: QueryDescriptor | undefined;
7
- fromDTD?: DcmtTypeDescriptor;
8
7
  dcmtTypesList?: DcmtTypeDescriptor[];
9
8
  isExpertMode?: boolean;
10
9
  showAllMdWhere?: boolean;
11
- isOpenDistinctValuesPanel: boolean;
12
10
  onQdChanged?: (qd: QueryDescriptor) => void;
13
11
  onAdvancedMenuClick?: (e: AdvancedMenuClickEventArgs) => void;
14
12
  onFocusedMetadataChanged?: (tid_mid: TID_MID | undefined) => void;
15
13
  }
16
- declare const TMSearchQueryEditor: React.FunctionComponent<ITMSearchQueryEditorProps>;
17
- export default TMSearchQueryEditor;
14
+ declare const _default: React.NamedExoticComponent<ITMSearchQueryEditorProps>;
15
+ export default _default;
@@ -1,5 +1,5 @@
1
1
  import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
2
- import React, { useEffect, useState } from 'react';
2
+ import React, { useCallback, useEffect, useMemo, useState } from 'react';
3
3
  import { LayoutModes, DcmtTypeListCacheService, PlatformObjectValidator, MetadataDataTypes, QueryOperators, DataListCacheService, MetadataDataDomains, SDK_Localizator, UserListCacheService } from '@topconsultnpm/sdk-ts-beta';
4
4
  import styled from 'styled-components';
5
5
  import { LocalizeQueryOperators, getDefaultOperator, SDKUI_Localizator, IconUndo, IconPencil, IconDataList, IconFunction, IconMenuVertical, IconClearButton, displayMetadataValue, SDKUI_Globals } from '../../../helper';
@@ -28,202 +28,68 @@ const StyledMetadataListItem = styled.div `
28
28
  cursor: pointer;
29
29
  }
30
30
  `;
31
- const TMSearchQueryEditor = ({ qd, fromDTD, dcmtTypesList = [], isOpenDistinctValuesPanel, isExpertMode = SDKUI_Globals.userSettings.advancedSettings.expertMode === 1, showAllMdWhere, onQdChanged, onFocusedMetadataChanged, onAdvancedMenuClick }) => {
31
+ const TMSearchQueryEditor = ({ qd, dcmtTypesList = [], isExpertMode = SDKUI_Globals.userSettings.advancedSettings.expertMode === 1, showAllMdWhere, onQdChanged, onFocusedMetadataChanged, onAdvancedMenuClick }) => {
32
32
  const [dynDataListsToBeRefreshed, setDynDataListsToBeRefreshed] = useState([]);
33
- const [showDistinctValuesPanel, setShowDistinctValuesPanel] = useState(false);
34
33
  const [currentEditingMID, setCurrentEditingMID] = useState(0);
35
34
  const [isEditableList, addOrRemoveEditableList] = useMetadataEditableList();
36
35
  const [focusedTidMid, setFocusedTidMid] = useState();
37
36
  const deviceType = useDeviceType();
38
37
  let initialMaxItems = deviceType === DeviceType.MOBILE ? 8 : 12;
39
- useEffect(() => { setShowDistinctValuesPanel(isOpenDistinctValuesPanel); }, [isOpenDistinctValuesPanel]);
40
38
  useEffect(() => {
41
39
  onFocusedMetadataChanged?.(focusedTidMid);
42
40
  }, [focusedTidMid]);
43
- const handleMetadataSelection = (tid, mid) => {
41
+ // --- Callbacks Memoizzate ---
42
+ const handleWhereItemChanged = useCallback((wi) => {
43
+ if (!wi || !qd?.where)
44
+ return;
45
+ const whereCopy = qd.where.map((curItem) => (curItem.mid !== wi.mid ? curItem : wi));
46
+ onQdChanged?.({ ...qd, where: whereCopy });
47
+ }, [qd, onQdChanged]);
48
+ const handleItemSelect = useCallback((tid, mid) => {
44
49
  if (currentEditingMID !== mid)
45
50
  setCurrentEditingMID(mid);
46
- if (mid !== focusedTidMid?.mid)
51
+ if (!focusedTidMid || mid !== focusedTidMid.mid) {
47
52
  setFocusedTidMid({ tid: tid, mid: mid });
48
- };
49
- const handleWhereItemChanged = (wi) => {
50
- if (!wi)
53
+ }
54
+ }, [currentEditingMID, focusedTidMid]);
55
+ const handleAdvancedMenuClick = useCallback((e) => {
56
+ if (e.button === AdvancedMenuButtons.MakeEditable && e.mid) {
57
+ addOrRemoveEditableList(e.mid);
58
+ }
59
+ // Propaga l'evento al genitore
60
+ onAdvancedMenuClick?.(e);
61
+ }, [addOrRemoveEditableList, onAdvancedMenuClick]);
62
+ const handleCascadeRefresh = useCallback((ddlToBeRefreshed) => {
63
+ setDynDataListsToBeRefreshed(prevList => {
64
+ const newList = prevList.filter(item => !ddlToBeRefreshed.some(o => o.mid === item.mid || (o.mid === -1 && o.midStarter === item.midStarter)));
65
+ const itemsToAdd = ddlToBeRefreshed.filter(item => item.queryParams.length > 0 && item.mid && item.mid > 0);
66
+ return [...newList, ...itemsToAdd];
67
+ });
68
+ }, []);
69
+ const handleCascadeUpdate = useCallback((midsToBeUpdated) => {
70
+ if (!qd?.where)
51
71
  return;
52
- const whereCopy = qd?.where?.map((curItem) => {
53
- if (curItem.mid != wi.mid)
54
- return curItem;
72
+ let changed = false;
73
+ const whereCopy = qd.where.map(wi => {
74
+ const updateInfo = midsToBeUpdated.find(item => item.mid === wi.mid);
75
+ if (updateInfo) {
76
+ changed = true;
77
+ return { ...wi, value1: updateInfo.value };
78
+ }
55
79
  return wi;
56
80
  });
57
- onQdChanged?.({ ...qd, where: whereCopy });
58
- };
59
- const getQueryOperatorsMenuItems = (wi, index) => {
60
- const onChange_WhereItem_QueryOperator = (qo, index) => {
61
- handleWhereItemChanged({ ...wi, operator: qo, value1: undefined, value2: undefined });
62
- };
63
- let items = [];
64
- items.push({ text: LocalizeQueryOperators(QueryOperators.Equal), onClick: () => onChange_WhereItem_QueryOperator(QueryOperators.Equal, index) });
65
- items.push({ text: LocalizeQueryOperators(QueryOperators.NotEqual), onClick: () => onChange_WhereItem_QueryOperator(QueryOperators.NotEqual, index) });
66
- items.push({ text: LocalizeQueryOperators(QueryOperators.IsNull), onClick: () => onChange_WhereItem_QueryOperator(QueryOperators.IsNull, index) });
67
- items.push({ text: LocalizeQueryOperators(QueryOperators.IsNotNull), onClick: () => onChange_WhereItem_QueryOperator(QueryOperators.IsNotNull, index) });
68
- items.push({ text: LocalizeQueryOperators(QueryOperators.In), onClick: () => onChange_WhereItem_QueryOperator(QueryOperators.In, index) });
69
- items.push({ text: LocalizeQueryOperators(QueryOperators.NotIn), onClick: () => onChange_WhereItem_QueryOperator(QueryOperators.NotIn, index) });
70
- let md = fromDTD?.metadata?.find(o => o.id == wi.mid);
71
- let mdDataType = md?.dataType;
72
- if (mdDataType != MetadataDataTypes.Varchar) {
73
- items.push({ text: LocalizeQueryOperators(QueryOperators.Greater), onClick: () => onChange_WhereItem_QueryOperator(QueryOperators.Greater, index) });
74
- items.push({ text: LocalizeQueryOperators(QueryOperators.GreaterOrEqual), onClick: () => onChange_WhereItem_QueryOperator(QueryOperators.GreaterOrEqual, index) });
75
- items.push({ text: LocalizeQueryOperators(QueryOperators.Less), onClick: () => onChange_WhereItem_QueryOperator(QueryOperators.Less, index) });
76
- items.push({ text: LocalizeQueryOperators(QueryOperators.LessOrEqual), onClick: () => onChange_WhereItem_QueryOperator(QueryOperators.LessOrEqual, index) });
77
- items.push({ text: LocalizeQueryOperators(QueryOperators.BetweenExclusive), onClick: () => onChange_WhereItem_QueryOperator(QueryOperators.BetweenExclusive, index) });
78
- items.push({ text: LocalizeQueryOperators(QueryOperators.BetweenInclusive), onClick: () => onChange_WhereItem_QueryOperator(QueryOperators.BetweenInclusive, index) });
79
- items.push({ text: LocalizeQueryOperators(QueryOperators.OutsideExclusive), onClick: () => onChange_WhereItem_QueryOperator(QueryOperators.OutsideExclusive, index) });
80
- items.push({ text: LocalizeQueryOperators(QueryOperators.OutsideInclusive), onClick: () => onChange_WhereItem_QueryOperator(QueryOperators.OutsideInclusive, index) });
81
- }
82
- else {
83
- items.push({ text: LocalizeQueryOperators(QueryOperators.Contain), onClick: () => onChange_WhereItem_QueryOperator(QueryOperators.Contain, index) });
84
- items.push({ text: LocalizeQueryOperators(QueryOperators.NotContain), onClick: () => onChange_WhereItem_QueryOperator(QueryOperators.NotContain, index) });
85
- items.push({ text: LocalizeQueryOperators(QueryOperators.BeginWith), onClick: () => onChange_WhereItem_QueryOperator(QueryOperators.BeginWith, index) });
86
- items.push({ text: LocalizeQueryOperators(QueryOperators.NotBeginWith), onClick: () => onChange_WhereItem_QueryOperator(QueryOperators.NotBeginWith, index) });
87
- items.push({ text: LocalizeQueryOperators(QueryOperators.EndWith), onClick: () => onChange_WhereItem_QueryOperator(QueryOperators.EndWith, index) });
88
- items.push({ text: LocalizeQueryOperators(QueryOperators.NotEndWith), onClick: () => onChange_WhereItem_QueryOperator(QueryOperators.NotEndWith, index) });
89
- items.push({ text: LocalizeQueryOperators(QueryOperators.Like), onClick: () => onChange_WhereItem_QueryOperator(QueryOperators.Like, index) });
90
- items.push({ text: LocalizeQueryOperators(QueryOperators.NotLike), onClick: () => onChange_WhereItem_QueryOperator(QueryOperators.NotLike, index) });
91
- }
92
- items.push({ text: LocalizeQueryOperators(QueryOperators.Custom), onClick: () => onChange_WhereItem_QueryOperator(QueryOperators.Custom, index) });
93
- if (mdDataType == MetadataDataTypes.DateTime) {
94
- items.push({
95
- text: "Operatori speciali", items: [
96
- { text: LocalizeQueryOperators(QueryOperators.Yesterday), onClick: () => onChange_WhereItem_QueryOperator(QueryOperators.Yesterday, index) },
97
- { text: LocalizeQueryOperators(QueryOperators.Today), onClick: () => onChange_WhereItem_QueryOperator(QueryOperators.Today, index) },
98
- { text: LocalizeQueryOperators(QueryOperators.Tomorrow), onClick: () => onChange_WhereItem_QueryOperator(QueryOperators.Tomorrow, index) },
99
- { text: LocalizeQueryOperators(QueryOperators.PreviousWeek), onClick: () => onChange_WhereItem_QueryOperator(QueryOperators.PreviousWeek, index) },
100
- { text: LocalizeQueryOperators(QueryOperators.ThisWeek), onClick: () => onChange_WhereItem_QueryOperator(QueryOperators.ThisWeek, index) },
101
- { text: LocalizeQueryOperators(QueryOperators.NextWeek), onClick: () => onChange_WhereItem_QueryOperator(QueryOperators.NextWeek, index) },
102
- { text: LocalizeQueryOperators(QueryOperators.PreviousMonth), onClick: () => onChange_WhereItem_QueryOperator(QueryOperators.PreviousMonth, index) },
103
- { text: LocalizeQueryOperators(QueryOperators.ThisMonth), onClick: () => onChange_WhereItem_QueryOperator(QueryOperators.ThisMonth, index) },
104
- { text: LocalizeQueryOperators(QueryOperators.NextMonth), onClick: () => onChange_WhereItem_QueryOperator(QueryOperators.NextMonth, index) },
105
- { text: LocalizeQueryOperators(QueryOperators.PreviousYear), onClick: () => onChange_WhereItem_QueryOperator(QueryOperators.PreviousYear, index) },
106
- { text: LocalizeQueryOperators(QueryOperators.ThisYear), onClick: () => onChange_WhereItem_QueryOperator(QueryOperators.ThisYear, index) },
107
- { text: LocalizeQueryOperators(QueryOperators.NextYear), onClick: () => onChange_WhereItem_QueryOperator(QueryOperators.NextYear, index) },
108
- { text: LocalizeQueryOperators(QueryOperators.LastXHours), onClick: () => onChange_WhereItem_QueryOperator(QueryOperators.LastXHours, index) },
109
- { text: LocalizeQueryOperators(QueryOperators.NextXHours), onClick: () => onChange_WhereItem_QueryOperator(QueryOperators.NextXHours, index) },
110
- { text: LocalizeQueryOperators(QueryOperators.LastXDays), onClick: () => onChange_WhereItem_QueryOperator(QueryOperators.LastXDays, index) },
111
- { text: LocalizeQueryOperators(QueryOperators.NextXDays), onClick: () => onChange_WhereItem_QueryOperator(QueryOperators.NextXDays, index) },
112
- { text: LocalizeQueryOperators(QueryOperators.LastXWeeks), onClick: () => onChange_WhereItem_QueryOperator(QueryOperators.LastXWeeks, index) },
113
- { text: LocalizeQueryOperators(QueryOperators.NextXWeeks), onClick: () => onChange_WhereItem_QueryOperator(QueryOperators.NextXWeeks, index) },
114
- { text: LocalizeQueryOperators(QueryOperators.LastXMonths), onClick: () => onChange_WhereItem_QueryOperator(QueryOperators.LastXMonths, index) },
115
- { text: LocalizeQueryOperators(QueryOperators.NextXMonths), onClick: () => onChange_WhereItem_QueryOperator(QueryOperators.NextXMonths, index) },
116
- { text: LocalizeQueryOperators(QueryOperators.LastXYears), onClick: () => onChange_WhereItem_QueryOperator(QueryOperators.LastXYears, index) },
117
- { text: LocalizeQueryOperators(QueryOperators.NextXYears), onClick: () => onChange_WhereItem_QueryOperator(QueryOperators.NextXYears, index) }
118
- ]
119
- });
81
+ if (changed) {
82
+ onQdChanged?.({ ...qd, where: whereCopy });
120
83
  }
121
- return items;
122
- };
123
- const getOperatorColor = (whereItem) => {
124
- if (dcmtTypesList.length <= 0)
125
- return 'green';
126
- let dtd = dcmtTypesList.find(o => o.id === whereItem.tid);
127
- let md = dtd?.metadata?.find(o => o.id === whereItem.mid);
128
- return whereItem.operator === getDefaultOperator(md?.dataDomain, md?.dataType) ? 'green' : TMColors.tertiary;
129
- };
130
- const getAdvancedMenuItems = (tid, mid) => {
131
- let isEditable = isEditableList(mid);
132
- let dtd = dcmtTypesList.find(o => o.id == tid);
133
- if (!dtd)
134
- return [];
135
- let md = dtd.metadata?.find(o => o.id == mid);
136
- if (!md)
137
- return [];
138
- const menu = [
139
- // Only add MakeEditable/Restore if isExpertMode is true
140
- ...(isExpertMode ? [{
141
- text: isEditable ? SDKUI_Localizator.Restore : SDKUI_Localizator.MakeEditable,
142
- icon: isEditable ? _jsx(IconUndo, {}) : _jsx(IconPencil, {}),
143
- onClick: () => {
144
- addOrRemoveEditableList(mid);
145
- onAdvancedMenuClick?.({ tid: tid, mid: mid, button: AdvancedMenuButtons.MakeEditable });
146
- }
147
- }] : []),
148
- {
149
- text: SDKUI_Localizator.DistinctValues,
150
- icon: _jsx(IconDataList, {}),
151
- onClick: () => {
152
- handleMetadataSelection(tid, mid);
153
- setShowDistinctValuesPanel(!showDistinctValuesPanel);
154
- onAdvancedMenuClick?.({ tid: tid, mid: mid, button: AdvancedMenuButtons.DistinctValues });
155
- }
156
- }
157
- ];
158
- return menu;
159
- };
84
+ }, [qd, onQdChanged]);
85
+ const itemsToRender = qd?.where?.slice(0, showAllMdWhere ? qd.where.length : initialMaxItems) ?? [];
160
86
  return (_jsx(_Fragment, { children: deviceType === DeviceType.MOBILE ?
161
- _jsx("div", { style: { overflow: 'auto', display: 'flex', flexDirection: 'column', height: '100%', padding: '5px', gap: '5px' }, children: qd?.where?.slice(0, showAllMdWhere ? qd?.where.length : initialMaxItems).map((wi, index) => (_jsx(StyledMetadataListItem, { id: `wi-item-${wi.mid}`, onClick: () => { handleMetadataSelection(wi.tid, wi.mid); }, onFocus: () => { handleMetadataSelection(wi.tid, wi.mid); }, "$backgroundColor": !PlatformObjectValidator.WhereItemHasValues(wi) ? `${TMColors.primary}66` : 'rgba(236, 202, 156, 1)', "$hoverColor": !PlatformObjectValidator.WhereItemHasValues(wi) ? `${TMColors.primary}33` : 'rgba(236, 202, 156, .5)', children: _jsx(TMSearchWhereItemCard, { isSelected: showDistinctValuesPanel && wi.mid === focusedTidMid?.mid, index: index, whereItem: wi, showEditor: currentEditingMID == wi.mid, isEditableList: isEditableList(wi.mid), queryParamsDynDataList: dynDataListsToBeRefreshed.find(o => o.mid == wi.mid)?.queryParams ?? [], onCascadeRefreshDynDataLists: (ddlToBeRefreshed) => {
162
- let newDynDataListsToBeRefreshed = [];
163
- for (const item of dynDataListsToBeRefreshed) {
164
- let index = ddlToBeRefreshed.findIndex(o => o.mid == item.mid || (o.mid == -1 && o.midStarter == item.midStarter));
165
- if (index >= 0)
166
- continue;
167
- newDynDataListsToBeRefreshed.push(item);
168
- }
169
- for (const item of ddlToBeRefreshed) {
170
- if (item.queryParams.length <= 0)
171
- continue;
172
- if (!item.mid)
173
- continue;
174
- if (item.mid <= 0)
175
- continue;
176
- newDynDataListsToBeRefreshed.push(item);
177
- }
178
- setDynDataListsToBeRefreshed(newDynDataListsToBeRefreshed);
179
- }, onCascadeUpdateMIDs: (midsToBeUpdated) => {
180
- for (const item of midsToBeUpdated) {
181
- const whereItem = qd?.where?.find(o => o.mid === item.mid);
182
- if (whereItem) {
183
- whereItem.value1 = item.value;
184
- handleWhereItemChanged(whereItem);
185
- }
186
- }
187
- }, onWhereItemChange: (newWi) => { handleWhereItemChanged(newWi); }, onHideEditor: () => { setCurrentEditingMID(0); } }) }, `${wi.tid}_${wi.mid}_${index}`))) })
87
+ _jsx("div", { style: { overflow: 'auto', display: 'flex', flexDirection: 'column', height: '100%', padding: '5px', gap: '5px' }, children: itemsToRender.map((wi, index) => (_jsx(WhereItemRow, { whereItem: wi, index: index, dcmtTypesList: dcmtTypesList, isExpertMode: isExpertMode, isSelected: false, isEditable: isEditableList(wi.mid), currentEditingMID: currentEditingMID, queryParamsDynDataList: dynDataListsToBeRefreshed.find(o => o.mid === wi.mid)?.queryParams ?? [], onItemChange: handleWhereItemChanged, onItemSelect: handleItemSelect, onAdvancedMenuClick: handleAdvancedMenuClick, onCascadeRefreshDynDataLists: handleCascadeRefresh, onCascadeUpdateMIDs: handleCascadeUpdate, onHideMobileEditor: () => setCurrentEditingMID(0) }, `${wi.tid}_${wi.mid}_${index}`))) })
188
88
  :
189
- _jsx("div", { style: { display: 'grid', borderRadius: '8px', alignItems: 'center', overflow: 'auto', padding: '5px', gap: '8px', gridTemplateColumns: 'minmax(0, max-content) minmax(0, max-content) minmax(50%, 1fr)' }, children: qd?.where?.slice(0, showAllMdWhere ? qd?.where.length : initialMaxItems).map((whereItem, index) => {
190
- return (_jsxs(React.Fragment, { children: [_jsx("div", { id: `wi-item-${whereItem.mid}`, style: { gridColumn: 1 }, children: _jsx(TMMidViewer, { color: TMColors.primaryColor, isMetadataSelected: showDistinctValuesPanel && whereItem.mid === focusedTidMid?.mid, showIcon: true, tid_mid: { tid: whereItem?.tid, mid: whereItem?.mid, aliasTID: whereItem?.alias } }) }), _jsx("div", { style: { gridColumn: 2, paddingLeft: '5px', paddingRight: '5px' }, children: _jsx(TMDropDownMenu, { backgroundColor: colorOperator, color: getOperatorColor(whereItem), items: getQueryOperatorsMenuItems(whereItem, index), content: _jsx(StyledItemWrapper, { children: LocalizeQueryOperators(whereItem.operator) }) }) }), _jsxs("div", { style: { gridColumn: 3, position: 'relative' }, onClick: () => { handleMetadataSelection(whereItem.tid, whereItem.mid); }, onFocus: () => { handleMetadataSelection(whereItem.tid, whereItem.mid); }, children: [_jsx(TMSearchWhereItemEditor, { isSelected: showDistinctValuesPanel && whereItem.mid === focusedTidMid?.mid, openChooserBySingleClick: !showDistinctValuesPanel, whereItem: whereItem, index: index, isEditableList: isEditableList(whereItem.mid), queryParamsDynDataList: dynDataListsToBeRefreshed.find(o => o.mid == whereItem.mid)?.queryParams ?? [], onValueChanged: (values) => {
191
- handleWhereItemChanged({ ...whereItem, value1: values[0], value2: values[1] });
192
- }, onCascadeRefreshDynDataLists: (ddlToBeRefreshed) => {
193
- let newDynDataListsToBeRefreshed = [];
194
- for (const item of dynDataListsToBeRefreshed) {
195
- let index = ddlToBeRefreshed.findIndex(o => o.mid == item.mid || (o.mid == -1 && o.midStarter == item.midStarter));
196
- if (index >= 0)
197
- continue;
198
- newDynDataListsToBeRefreshed.push(item);
199
- }
200
- for (const item of ddlToBeRefreshed) {
201
- if (item.queryParams.length <= 0)
202
- continue;
203
- if (!item.mid)
204
- continue;
205
- if (item.mid <= 0)
206
- continue;
207
- newDynDataListsToBeRefreshed.push(item);
208
- }
209
- setDynDataListsToBeRefreshed(newDynDataListsToBeRefreshed);
210
- }, onCascadeUpdateMIDs: (midsToBeUpdated) => {
211
- for (const item of midsToBeUpdated) {
212
- const whereItem = qd?.where?.find(o => o.mid === item.mid);
213
- if (whereItem) {
214
- whereItem.value1 = item.value;
215
- handleWhereItemChanged(whereItem);
216
- }
217
- }
218
- } }), FormulaHelper.isFormula(whereItem.value1)
219
- ? _jsx(IconFunction, { color: "#1a89d3", fontSize: 14, style: { position: "absolute", top: '-5px', left: '-10px' } })
220
- : (isEditableList(whereItem.mid))
221
- ? _jsx(IconPencil, { color: "#138603", fontSize: 14, style: { position: "absolute", top: '-5px', left: '-10px' } })
222
- : _jsx(_Fragment, {})] }), _jsx("div", { style: { gridColumn: 4 }, children: _jsx(TMDropDownMenu, { backgroundColor: 'white', color: TMColors.button_icon, borderRadius: '3px', content: _jsx(TMButton, { btnStyle: 'icon', icon: _jsx(IconMenuVertical, {}), showTooltip: false }), items: getAdvancedMenuItems(whereItem.tid, whereItem.mid) }) })] }, `${whereItem.tid}_${whereItem.mid}_${index}`));
223
- }) }) }));
89
+ _jsx("div", { style: { display: 'grid', borderRadius: '8px', alignItems: 'center', overflow: 'auto', padding: '5px', gap: '8px', gridTemplateColumns: 'minmax(0, max-content) minmax(0, max-content) minmax(50%, 1fr) minmax(0, max-content)' }, children: itemsToRender.map((wi, index) => (_jsx(WhereItemRow, { whereItem: wi, index: index, dcmtTypesList: dcmtTypesList, isExpertMode: isExpertMode, isSelected: false, isEditable: isEditableList(wi.mid), currentEditingMID: currentEditingMID, queryParamsDynDataList: dynDataListsToBeRefreshed.find(o => o.mid === wi.mid)?.queryParams ?? [], onItemChange: handleWhereItemChanged, onItemSelect: handleItemSelect, onAdvancedMenuClick: handleAdvancedMenuClick, onCascadeRefreshDynDataLists: handleCascadeRefresh, onCascadeUpdateMIDs: handleCascadeUpdate, onHideMobileEditor: () => setCurrentEditingMID(0) }, `${wi.tid}_${wi.mid}_${index}`))) }) }));
224
90
  };
225
- export default TMSearchQueryEditor;
226
- const TMSearchWhereItemEditor = ({ whereItem, queryParamsDynDataList, index, isSelected, isEditableList, autoFocus, openChooserBySingleClick, onValueChanged, onCascadeRefreshDynDataLists, onCascadeUpdateMIDs }) => {
91
+ export default React.memo(TMSearchQueryEditor);
92
+ const TMSearchWhereItemEditor = React.memo(({ whereItem, queryParamsDynDataList, index, isSelected, isEditableList, autoFocus, openChooserBySingleClick, onValueChanged, onCascadeRefreshDynDataLists, onCascadeUpdateMIDs }) => {
227
93
  const [showValue1, setShowValue1] = useState(true);
228
94
  const [showValue2, setShowValue2] = useState(false);
229
95
  const [dataList, setDataList] = useState();
@@ -286,8 +152,8 @@ const TMSearchWhereItemEditor = ({ whereItem, queryParamsDynDataList, index, isS
286
152
  onValueChanged?.(newValues);
287
153
  };
288
154
  return (_jsxs(StyledRowItem, { style: { marginBottom: 0 }, children: [showValue1 && _jsx(TMMetadataEditor, { openChooserBySingleClick: openChooserBySingleClick, isSelected: isSelected, tid: whereItem.tid, mid: whereItem.mid, layoutMode: LayoutModes.None, isEditable: isEditableList, value: whereItem.value1, queryOperator: whereItem.operator, queryParamsDynDataList: queryParamsDynDataList, autoFocus: autoFocus ?? false, containerElement: undefined, onValueChanged: (value) => { normalizeValue(value, true); }, onCascadeRefreshDynDataLists: onCascadeRefreshDynDataLists, onCascadeUpdateMIDs: onCascadeUpdateMIDs }), showValue2 && _jsx(TMMetadataEditor, { openChooserBySingleClick: openChooserBySingleClick, isSelected: isSelected, tid: whereItem.tid, mid: whereItem.mid, layoutMode: LayoutModes.None, isEditable: isEditableList, value: whereItem.value2, queryOperator: whereItem.operator, autoFocus: autoFocus ?? false, containerElement: undefined, onValueChanged: (value) => { normalizeValue(value, false); } })] }));
289
- };
290
- const TMSearchWhereItemCard = ({ index, whereItem, isSelected, queryParamsDynDataList, showEditor, showCompleteMetadataName, showId, isEditableList, onWhereItemChange, onHideEditor, onCascadeRefreshDynDataLists, onCascadeUpdateMIDs }) => {
155
+ });
156
+ const TMSearchWhereItemCard = React.memo(({ index, whereItem, isSelected, queryParamsDynDataList, showEditor, showCompleteMetadataName, showId, isEditableList, onWhereItemChange, onHideEditor, onCascadeRefreshDynDataLists, onCascadeUpdateMIDs }) => {
291
157
  const [isOpen, setIsOpen] = useState(false);
292
158
  const [md, setMd] = useState();
293
159
  useEffect(() => { getMetadata().then((mdOut) => { setMd(mdOut); }); }, [whereItem]);
@@ -361,8 +227,8 @@ const TMSearchWhereItemCard = ({ index, whereItem, isSelected, queryParamsDynDat
361
227
  };
362
228
  return (_jsxs("div", { style: { width: "100%", fontSize: '1rem', userSelect: 'none' }, children: [_jsxs("div", { style: { display: 'flex', flexDirection: 'row', justifyContent: 'space-between' }, children: [_jsx(TMSearchWhereItemViewer, { isSelected: isSelected, whereItem: whereItem, showCompleteMetadataName: showCompleteMetadataName, showId: showId, showValue: !isOpen }), isOpen &&
363
229
  _jsx("div", { onClick: (e) => e.stopPropagation(), children: _jsx(TMButton, { btnStyle: 'icon', icon: _jsx(IconClearButton, { color: 'red' }), caption: SDKUI_Localizator.Close, showTooltip: false, onClick: () => { onHideEditor?.(); } }) })] }), _jsx("div", { style: { display: isOpen ? 'flex' : 'none', flexDirection: 'column', paddingTop: 5, gap: '5px' }, children: _jsxs(StyledDivHorizontal, { style: { gap: '5px' }, children: [_jsx(TMDropDownMenu, { backgroundColor: colorOperator, color: 'green', content: _jsx(StyledItemWrapper, { children: LocalizeQueryOperators(whereItem.operator) }), items: getQueryOperatorsMenuItems(whereItem, index) }), _jsx(TMSearchWhereItemEditor, { isSelected: isSelected, whereItem: whereItem, index: index, isEditableList: isEditableList, autoFocus: !!isOpen, onValueChanged: (values) => { onWhereItemChange?.({ ...whereItem, value1: values[0], value2: values[1] }); }, queryParamsDynDataList: queryParamsDynDataList, onCascadeRefreshDynDataLists: onCascadeRefreshDynDataLists, onCascadeUpdateMIDs: onCascadeUpdateMIDs })] }) })] }));
364
- };
365
- const TMSearchWhereItemViewer = ({ isSelected = false, whereItem, showCompleteMetadataName, showId, showValue }) => {
230
+ });
231
+ const TMSearchWhereItemViewer = React.memo(({ isSelected = false, whereItem, showCompleteMetadataName, showId, showValue }) => {
366
232
  const [numberOfOperands, setNumberOfOperands] = useState(0);
367
233
  const [md, setMd] = useState();
368
234
  useEffect(() => {
@@ -379,4 +245,111 @@ const TMSearchWhereItemViewer = ({ isSelected = false, whereItem, showCompleteMe
379
245
  ? _jsx(_Fragment, { children: whereItem.value1 })
380
246
  // ? <>{numberOfOperands == 11 ? whereItem.value1?.split(',').map((item: string) => !item.startsWith("'") ? item : item.slice(1, -1)).join(",") : whereItem.value1}</>
381
247
  : _jsxs(_Fragment, { children: [displayMetadataValue(md, whereItem.value1, ""), numberOfOperands == 2 && (whereItem.value2 && whereItem.value2 != '' ? ` - ${displayMetadataValue(md, whereItem.value2, "")}` : ' - ?')] }) })] }));
382
- };
248
+ });
249
+ const WhereItemRow = React.memo(({ whereItem, index, dcmtTypesList, isExpertMode, isSelected, isEditable, currentEditingMID, queryParamsDynDataList, onItemChange, onItemSelect, onAdvancedMenuClick, onCascadeRefreshDynDataLists, onCascadeUpdateMIDs, onHideMobileEditor }) => {
250
+ const deviceType = useDeviceType();
251
+ // Trova il metadata descriptor per l'item corrente
252
+ const md = useMemo(() => {
253
+ const dtd = dcmtTypesList.find(o => o.id === whereItem.tid);
254
+ return dtd?.metadata?.find(o => o.id === whereItem.mid);
255
+ }, [dcmtTypesList, whereItem.tid, whereItem.mid]);
256
+ // --- Memoized Menu Items ---
257
+ const queryOperatorsItems = useMemo(() => {
258
+ const onChange_WhereItem_QueryOperator = (qo) => {
259
+ onItemChange({ ...whereItem, operator: qo, value1: undefined, value2: undefined });
260
+ };
261
+ let items = [];
262
+ items.push({ text: LocalizeQueryOperators(QueryOperators.Equal), onClick: () => onChange_WhereItem_QueryOperator(QueryOperators.Equal) });
263
+ items.push({ text: LocalizeQueryOperators(QueryOperators.NotEqual), onClick: () => onChange_WhereItem_QueryOperator(QueryOperators.NotEqual) });
264
+ items.push({ text: LocalizeQueryOperators(QueryOperators.IsNull), onClick: () => onChange_WhereItem_QueryOperator(QueryOperators.IsNull) });
265
+ items.push({ text: LocalizeQueryOperators(QueryOperators.IsNotNull), onClick: () => onChange_WhereItem_QueryOperator(QueryOperators.IsNotNull) });
266
+ items.push({ text: LocalizeQueryOperators(QueryOperators.In), onClick: () => onChange_WhereItem_QueryOperator(QueryOperators.In) });
267
+ items.push({ text: LocalizeQueryOperators(QueryOperators.NotIn), onClick: () => onChange_WhereItem_QueryOperator(QueryOperators.NotIn) });
268
+ if (md?.dataType !== MetadataDataTypes.Varchar) {
269
+ items.push({ text: LocalizeQueryOperators(QueryOperators.Greater), onClick: () => onChange_WhereItem_QueryOperator(QueryOperators.Greater) });
270
+ items.push({ text: LocalizeQueryOperators(QueryOperators.GreaterOrEqual), onClick: () => onChange_WhereItem_QueryOperator(QueryOperators.GreaterOrEqual) });
271
+ items.push({ text: LocalizeQueryOperators(QueryOperators.Less), onClick: () => onChange_WhereItem_QueryOperator(QueryOperators.Less) });
272
+ items.push({ text: LocalizeQueryOperators(QueryOperators.LessOrEqual), onClick: () => onChange_WhereItem_QueryOperator(QueryOperators.LessOrEqual) });
273
+ items.push({ text: LocalizeQueryOperators(QueryOperators.BetweenExclusive), onClick: () => onChange_WhereItem_QueryOperator(QueryOperators.BetweenExclusive) });
274
+ items.push({ text: LocalizeQueryOperators(QueryOperators.BetweenInclusive), onClick: () => onChange_WhereItem_QueryOperator(QueryOperators.BetweenInclusive) });
275
+ items.push({ text: LocalizeQueryOperators(QueryOperators.OutsideExclusive), onClick: () => onChange_WhereItem_QueryOperator(QueryOperators.OutsideExclusive) });
276
+ items.push({ text: LocalizeQueryOperators(QueryOperators.OutsideInclusive), onClick: () => onChange_WhereItem_QueryOperator(QueryOperators.OutsideInclusive) });
277
+ }
278
+ else {
279
+ items.push({ text: LocalizeQueryOperators(QueryOperators.Contain), onClick: () => onChange_WhereItem_QueryOperator(QueryOperators.Contain) });
280
+ items.push({ text: LocalizeQueryOperators(QueryOperators.NotContain), onClick: () => onChange_WhereItem_QueryOperator(QueryOperators.NotContain) });
281
+ items.push({ text: LocalizeQueryOperators(QueryOperators.BeginWith), onClick: () => onChange_WhereItem_QueryOperator(QueryOperators.BeginWith) });
282
+ items.push({ text: LocalizeQueryOperators(QueryOperators.NotBeginWith), onClick: () => onChange_WhereItem_QueryOperator(QueryOperators.NotBeginWith) });
283
+ items.push({ text: LocalizeQueryOperators(QueryOperators.EndWith), onClick: () => onChange_WhereItem_QueryOperator(QueryOperators.EndWith) });
284
+ items.push({ text: LocalizeQueryOperators(QueryOperators.NotEndWith), onClick: () => onChange_WhereItem_QueryOperator(QueryOperators.NotEndWith) });
285
+ items.push({ text: LocalizeQueryOperators(QueryOperators.Like), onClick: () => onChange_WhereItem_QueryOperator(QueryOperators.Like) });
286
+ items.push({ text: LocalizeQueryOperators(QueryOperators.NotLike), onClick: () => onChange_WhereItem_QueryOperator(QueryOperators.NotLike) });
287
+ }
288
+ items.push({ text: LocalizeQueryOperators(QueryOperators.Custom), onClick: () => onChange_WhereItem_QueryOperator(QueryOperators.Custom) });
289
+ if (md?.dataType == MetadataDataTypes.DateTime) {
290
+ items.push({
291
+ text: "Operatori speciali", items: [
292
+ { text: LocalizeQueryOperators(QueryOperators.Yesterday), onClick: () => onChange_WhereItem_QueryOperator(QueryOperators.Yesterday) },
293
+ { text: LocalizeQueryOperators(QueryOperators.Today), onClick: () => onChange_WhereItem_QueryOperator(QueryOperators.Today) },
294
+ { text: LocalizeQueryOperators(QueryOperators.Tomorrow), onClick: () => onChange_WhereItem_QueryOperator(QueryOperators.Tomorrow) },
295
+ { text: LocalizeQueryOperators(QueryOperators.PreviousWeek), onClick: () => onChange_WhereItem_QueryOperator(QueryOperators.PreviousWeek) },
296
+ { text: LocalizeQueryOperators(QueryOperators.ThisWeek), onClick: () => onChange_WhereItem_QueryOperator(QueryOperators.ThisWeek) },
297
+ { text: LocalizeQueryOperators(QueryOperators.NextWeek), onClick: () => onChange_WhereItem_QueryOperator(QueryOperators.NextWeek) },
298
+ { text: LocalizeQueryOperators(QueryOperators.PreviousMonth), onClick: () => onChange_WhereItem_QueryOperator(QueryOperators.PreviousMonth) },
299
+ { text: LocalizeQueryOperators(QueryOperators.ThisMonth), onClick: () => onChange_WhereItem_QueryOperator(QueryOperators.ThisMonth) },
300
+ { text: LocalizeQueryOperators(QueryOperators.NextMonth), onClick: () => onChange_WhereItem_QueryOperator(QueryOperators.NextMonth) },
301
+ { text: LocalizeQueryOperators(QueryOperators.PreviousYear), onClick: () => onChange_WhereItem_QueryOperator(QueryOperators.PreviousYear) },
302
+ { text: LocalizeQueryOperators(QueryOperators.ThisYear), onClick: () => onChange_WhereItem_QueryOperator(QueryOperators.ThisYear) },
303
+ { text: LocalizeQueryOperators(QueryOperators.NextYear), onClick: () => onChange_WhereItem_QueryOperator(QueryOperators.NextYear) },
304
+ { text: LocalizeQueryOperators(QueryOperators.LastXHours), onClick: () => onChange_WhereItem_QueryOperator(QueryOperators.LastXHours) },
305
+ { text: LocalizeQueryOperators(QueryOperators.NextXHours), onClick: () => onChange_WhereItem_QueryOperator(QueryOperators.NextXHours) },
306
+ { text: LocalizeQueryOperators(QueryOperators.LastXDays), onClick: () => onChange_WhereItem_QueryOperator(QueryOperators.LastXDays) },
307
+ { text: LocalizeQueryOperators(QueryOperators.NextXDays), onClick: () => onChange_WhereItem_QueryOperator(QueryOperators.NextXDays) },
308
+ { text: LocalizeQueryOperators(QueryOperators.LastXWeeks), onClick: () => onChange_WhereItem_QueryOperator(QueryOperators.LastXWeeks) },
309
+ { text: LocalizeQueryOperators(QueryOperators.NextXWeeks), onClick: () => onChange_WhereItem_QueryOperator(QueryOperators.NextXWeeks) },
310
+ { text: LocalizeQueryOperators(QueryOperators.LastXMonths), onClick: () => onChange_WhereItem_QueryOperator(QueryOperators.LastXMonths) },
311
+ { text: LocalizeQueryOperators(QueryOperators.NextXMonths), onClick: () => onChange_WhereItem_QueryOperator(QueryOperators.NextXMonths) },
312
+ { text: LocalizeQueryOperators(QueryOperators.LastXYears), onClick: () => onChange_WhereItem_QueryOperator(QueryOperators.LastXYears) },
313
+ { text: LocalizeQueryOperators(QueryOperators.NextXYears), onClick: () => onChange_WhereItem_QueryOperator(QueryOperators.NextXYears) }
314
+ ]
315
+ });
316
+ }
317
+ return items;
318
+ }, [whereItem, md, onItemChange]);
319
+ const advancedMenuItems = useMemo(() => {
320
+ const menu = [
321
+ ...(isExpertMode ? [{
322
+ text: isEditable ? SDKUI_Localizator.Restore : SDKUI_Localizator.MakeEditable,
323
+ icon: isEditable ? _jsx(IconUndo, {}) : _jsx(IconPencil, {}),
324
+ onClick: () => {
325
+ onAdvancedMenuClick({ tid: whereItem.tid, mid: whereItem.mid, button: AdvancedMenuButtons.MakeEditable });
326
+ }
327
+ }] : []),
328
+ {
329
+ text: SDKUI_Localizator.DistinctValues,
330
+ icon: _jsx(IconDataList, {}),
331
+ onClick: () => {
332
+ onItemSelect(whereItem.tid, whereItem.mid); // Seleziona prima di chiamare l'azione
333
+ onAdvancedMenuClick({ tid: whereItem.tid, mid: whereItem.mid, button: AdvancedMenuButtons.DistinctValues });
334
+ }
335
+ }
336
+ ];
337
+ return menu;
338
+ }, [whereItem, isEditable, isExpertMode, onAdvancedMenuClick, onItemSelect]);
339
+ const getOperatorColor = () => {
340
+ if (!md)
341
+ return 'green';
342
+ return whereItem.operator === getDefaultOperator(md.dataDomain, md.dataType) ? 'green' : TMColors.tertiary;
343
+ };
344
+ // --- Rendering ---
345
+ if (deviceType === DeviceType.MOBILE) {
346
+ return (_jsx(StyledMetadataListItem, { id: `wi-item-${whereItem.mid}`, onClick: () => onItemSelect(whereItem.tid, whereItem.mid), onFocus: () => onItemSelect(whereItem.tid, whereItem.mid), "$backgroundColor": !PlatformObjectValidator.WhereItemHasValues(whereItem) ? `${TMColors.primary}66` : 'rgba(236, 202, 156, 1)', "$hoverColor": !PlatformObjectValidator.WhereItemHasValues(whereItem) ? `${TMColors.primary}33` : 'rgba(236, 202, 156, .5)', children: _jsx(TMSearchWhereItemCard, { isSelected: isSelected, index: index, whereItem: whereItem, showEditor: currentEditingMID === whereItem.mid, isEditableList: isEditable, queryParamsDynDataList: queryParamsDynDataList, onWhereItemChange: onItemChange, onHideEditor: onHideMobileEditor, onCascadeRefreshDynDataLists: onCascadeRefreshDynDataLists, onCascadeUpdateMIDs: onCascadeUpdateMIDs }) }));
347
+ }
348
+ return (_jsxs(React.Fragment, { children: [_jsx("div", { id: `wi-item-${whereItem.mid}`, style: { gridColumn: 1 }, children: _jsx(TMMidViewer, { color: TMColors.primaryColor, isMetadataSelected: isSelected, showIcon: true, tid_mid: { tid: whereItem?.tid, mid: whereItem?.mid, aliasTID: whereItem?.alias } }) }), _jsx("div", { style: { gridColumn: 2, paddingLeft: '5px', paddingRight: '5px' }, children: _jsx(TMDropDownMenu, { backgroundColor: colorOperator, color: getOperatorColor(), items: queryOperatorsItems, content: _jsx(StyledItemWrapper, { children: LocalizeQueryOperators(whereItem.operator) }) }) }), _jsxs("div", { style: { gridColumn: 3, position: 'relative' }, onClick: () => onItemSelect(whereItem.tid, whereItem.mid), onFocus: () => onItemSelect(whereItem.tid, whereItem.mid), children: [_jsx(TMSearchWhereItemEditor, { isSelected: isSelected, openChooserBySingleClick: !isSelected, whereItem: whereItem, index: index, isEditableList: isEditable, queryParamsDynDataList: queryParamsDynDataList, onValueChanged: (values) => {
349
+ onItemChange({ ...whereItem, value1: values[0], value2: values[1] });
350
+ }, onCascadeRefreshDynDataLists: onCascadeRefreshDynDataLists, onCascadeUpdateMIDs: onCascadeUpdateMIDs }), FormulaHelper.isFormula(whereItem.value1)
351
+ ? _jsx(IconFunction, { color: "#1a89d3", fontSize: 14, style: { position: "absolute", top: '-5px', left: '-10px' } })
352
+ : isEditable
353
+ ? _jsx(IconPencil, { color: "#138603", fontSize: 14, style: { position: "absolute", top: '-5px', left: '-10px' } })
354
+ : null] }), _jsx("div", { style: { gridColumn: 4 }, children: _jsx(TMDropDownMenu, { backgroundColor: 'white', color: TMColors.button_icon, borderRadius: '3px', content: _jsx(TMButton, { btnStyle: 'icon', icon: _jsx(IconMenuVertical, {}), showTooltip: false }), items: advancedMenuItems }) })] }));
355
+ });
@@ -1,6 +1,5 @@
1
1
  import React from 'react';
2
2
  import { DcmtTypeDescriptor, QueryDescriptor, SavedQueryDescriptor, SearchResultDescriptor } from '@topconsultnpm/sdk-ts-beta';
3
- import { TID_MID } from '../../../ts';
4
3
  interface ITMSearchQueryPanelProps {
5
4
  fromDTD?: DcmtTypeDescriptor;
6
5
  SQD?: SavedQueryDescriptor;
@@ -9,7 +8,6 @@ interface ITMSearchQueryPanelProps {
9
8
  onBack?: () => void;
10
9
  onBackToResult?: () => void;
11
10
  onSqdSaved?: (newSqd: SavedQueryDescriptor) => void;
12
- onFocusedMetadataChanged?: (tid_mid: TID_MID | undefined) => void;
13
11
  onSearchCompleted?: (searchResult: SearchResultDescriptor[], qd: QueryDescriptor | undefined) => void;
14
12
  onClosePanel?: () => void;
15
13
  onMaximizePanel?: () => void;