@iotready/nextjs-components-library 1.0.0-preview33 → 1.0.0-preview35
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.
|
@@ -850,7 +850,7 @@ const TrendChart = ({ filter, measures1, annotationsDataFn, measures2, enableDat
|
|
|
850
850
|
'& .MuiToggleButton-root': {
|
|
851
851
|
color: 'text.primary', fontSize: '0.95rem', fontWeight: 'normal', paddingTop: '6px', paddingBottom: '6px'
|
|
852
852
|
}
|
|
853
|
-
}, disabled: chartLoading, children: [_jsx(ToggleButton, { value: "1D", sx: { px: 1 }, children: "1d" }), _jsx(ToggleButton, { value: "1W", sx: { px: 1 }, children: "1w" }), _jsx(ToggleButton, { value: "1M", sx: { px: 1 }, children: "1M" }), _jsx(ToggleButton, { value: "3M", sx: { px: 1 }, children: "3M" }), _jsx(ToggleButton, { value: "6M", sx: { px: 1 }, children: "6M" }), _jsx(ToggleButton, { value: "1Y", sx: { px: 1 }, children: "1Y" }), _jsx(ToggleButton, { value: "ALL", sx: { px: 1 }, children: "ALL" })] }), _jsx(MuiTooltip, { placement: "top", arrow: true, title: "Connect point values", children: _jsx("span", { children: _jsx(ToggleButton, { value: "check", color: "primary", size: "small", selected: spanGapsOption, disabled: chartLoading, onChange: () => handleSpanGaps(!spanGapsOption), sx: { ml: 1 }, children: _jsx(TimelineIcon, {}) }) }) }), annotationsData !== null && (_jsx(MuiTooltip, { placement: "top", arrow: true, title: "Show annotations", children: _jsx("span", { children: _jsx(ToggleButton, { value: "check", color: "primary", size: "small", selected: annotationsEnabled, disabled: chartLoading, onChange: () => setAnnotationsEnabled(!annotationsEnabled), sx: { ml: 1 }, children: _jsx(EditNoteIcon, {}) }) }) }))] })] }), _jsx(Box, { component: 'div', className: "chart-container", sx: { mt: 2, height: '100%' }, children: chartJsLoaded && !chartLoading && typeof window !== 'undefined' ?
|
|
853
|
+
}, disabled: chartLoading, children: [_jsx(ToggleButton, { value: "1D", sx: { px: 1 }, children: "1d" }), _jsx(ToggleButton, { value: "1W", sx: { px: 1 }, children: "1w" }), _jsx(ToggleButton, { value: "1M", sx: { px: 1 }, children: "1M" }), _jsx(ToggleButton, { value: "3M", sx: { px: 1 }, children: "3M" }), _jsx(ToggleButton, { value: "6M", sx: { px: 1 }, children: "6M" }), _jsx(ToggleButton, { value: "1Y", sx: { px: 1 }, children: "1Y" }), _jsx(ToggleButton, { value: "ALL", sx: { px: 1 }, children: "ALL" })] }), _jsx(MuiTooltip, { placement: "top", arrow: true, title: "Connect point values", children: _jsx("span", { children: _jsx(ToggleButton, { value: "check", color: "primary", size: "small", selected: spanGapsOption, disabled: chartLoading, onChange: () => handleSpanGaps(!spanGapsOption), sx: { ml: 1 }, children: _jsx(TimelineIcon, {}) }) }) }), annotationsDataFn && annotationsData !== null && (_jsx(MuiTooltip, { placement: "top", arrow: true, title: "Show annotations", children: _jsx("span", { children: _jsx(ToggleButton, { value: "check", color: "primary", size: "small", selected: annotationsEnabled, disabled: chartLoading, onChange: () => setAnnotationsEnabled(!annotationsEnabled), sx: { ml: 1 }, children: _jsx(EditNoteIcon, {}) }) }) }))] })] }), _jsx(Box, { component: 'div', className: "chart-container", sx: { mt: 2, height: '100%' }, children: chartJsLoaded && !chartLoading && typeof window !== 'undefined' ?
|
|
854
854
|
_jsx(_Fragment, { children: dataMeasures && (dataMeasures.length > 1 || (dataMeasures.length === 1 && dataMeasures[0].data?.length)) ?
|
|
855
855
|
(_jsx(Line, { options: options, data: {
|
|
856
856
|
// datasets: dataMeasures || [{ data: [] }]
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { AssetType, TrackleDeviceType, UserType } from '../../types';
|
|
2
2
|
declare const GroupUpdate: ({ labelEntity, groupInfo, usersGroup, usersList, devicesList, handleAddUserToGroup, handleRemoveUserFromGroup, handleUpdateGroup, handleDeleteGroup, container, containerProps, afterUpdateCallback, afterRemoveCallback, confirmMui }: {
|
|
3
|
-
userInfo: UserType;
|
|
4
3
|
groupInfo: any;
|
|
5
4
|
usersGroup: any[];
|
|
6
5
|
usersList: any[];
|
|
@@ -134,6 +134,9 @@ const GroupsDevices = ({ userInfo, handleGetUsersList, handleAddUserToGroup, han
|
|
|
134
134
|
getUsersGroup(currentGroup);
|
|
135
135
|
}
|
|
136
136
|
fetchDevices(currentGroup, currentGroup);
|
|
137
|
+
if (isOrg) {
|
|
138
|
+
setCheckboxSelection(true);
|
|
139
|
+
}
|
|
137
140
|
}
|
|
138
141
|
}, [currentGroup, groups]);
|
|
139
142
|
useEffect(() => {
|
|
@@ -254,26 +257,64 @@ const GroupsDevices = ({ userInfo, handleGetUsersList, handleAddUserToGroup, han
|
|
|
254
257
|
}, onCellClick: (params) => {
|
|
255
258
|
clickedIdRef.current = params.id.toString(); // aggiornamento immediato
|
|
256
259
|
}, onRowSelectionModelChange: (ids) => {
|
|
257
|
-
if (!checkboxSelection
|
|
260
|
+
if (!checkboxSelection)
|
|
258
261
|
return;
|
|
259
|
-
|
|
260
|
-
clickedIdRef.current
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
262
|
+
// Se abbiamo un clickedIdRef, gestiamo il click individuale
|
|
263
|
+
if (clickedIdRef.current) {
|
|
264
|
+
const clickedId = clickedIdRef.current;
|
|
265
|
+
clickedIdRef.current = null; // resetta subito dopo l'uso
|
|
266
|
+
setDevicesToAdd(prevIds => {
|
|
267
|
+
const updated = prevIds.includes(clickedId)
|
|
268
|
+
? prevIds.filter(id => id !== clickedId)
|
|
269
|
+
: [...prevIds, clickedId];
|
|
270
|
+
return updated;
|
|
271
|
+
});
|
|
272
|
+
setDeviceSelectedObjs(prevObjs => {
|
|
273
|
+
const isDeselecting = prevObjs.some(d => d.id.toString() === clickedId);
|
|
274
|
+
if (isDeselecting) {
|
|
275
|
+
return prevObjs.filter(d => d.id.toString() !== clickedId);
|
|
276
|
+
}
|
|
277
|
+
else {
|
|
278
|
+
const device = devices.find(d => d.id.toString() === clickedId);
|
|
279
|
+
return device ? [...prevObjs, device] : prevObjs;
|
|
280
|
+
}
|
|
281
|
+
});
|
|
282
|
+
}
|
|
283
|
+
else {
|
|
284
|
+
// Gestione del "check all" - confronta con il modello di selezione attuale
|
|
285
|
+
const currentSelection = (checkboxSelection && currentGroup === 'all')
|
|
286
|
+
? [
|
|
287
|
+
...devices
|
|
288
|
+
.filter(d => d.groups?.includes(selectedGroup))
|
|
289
|
+
.map(d => d.id.toString()),
|
|
290
|
+
...devicesToAdd,
|
|
291
|
+
]
|
|
292
|
+
: devicesToAdd;
|
|
293
|
+
// Se la selezione è diversa, aggiorna devicesToAdd
|
|
294
|
+
if (JSON.stringify(ids.sort()) !== JSON.stringify(currentSelection.sort())) {
|
|
295
|
+
// Filtra solo i dispositivi che non sono già nel gruppo
|
|
296
|
+
const selectableDevices = devices
|
|
297
|
+
.filter(d => !d.groups?.includes(selectedGroup))
|
|
298
|
+
.map(d => d.id.toString());
|
|
299
|
+
// Calcola i nuovi dispositivi da aggiungere
|
|
300
|
+
const newDevicesToAdd = ids.filter(id => selectableDevices.includes(id) && !devicesToAdd.includes(id));
|
|
301
|
+
// Calcola i dispositivi da rimuovere dalla selezione
|
|
302
|
+
const devicesToRemove = devicesToAdd.filter(id => !ids.includes(id));
|
|
303
|
+
// Aggiorna devicesToAdd
|
|
304
|
+
setDevicesToAdd(prevIds => {
|
|
305
|
+
return prevIds
|
|
306
|
+
.filter(id => !devicesToRemove.includes(id))
|
|
307
|
+
.concat(newDevicesToAdd);
|
|
308
|
+
});
|
|
309
|
+
// Aggiorna deviceSelectedObjs
|
|
310
|
+
setDeviceSelectedObjs(prevObjs => {
|
|
311
|
+
return prevObjs
|
|
312
|
+
.filter(d => !devicesToRemove.includes(d.id.toString()))
|
|
313
|
+
.concat(devices.filter(d => newDevicesToAdd.includes(d.id.toString()) &&
|
|
314
|
+
!prevObjs.some(obj => obj.id.toString() === d.id.toString())));
|
|
315
|
+
});
|
|
275
316
|
}
|
|
276
|
-
}
|
|
317
|
+
}
|
|
277
318
|
}, disableDensitySelector: true, disableColumnSelector: true, disableRowSelectionOnClick: true, loading: loadingDevices, rows: devices, columns: checkboxSelection
|
|
278
319
|
? columnsArray.filter(col => col.field !== 'id')
|
|
279
320
|
: columnsArray, slots: {
|
|
@@ -298,7 +339,7 @@ const GroupsDevices = ({ userInfo, handleGetUsersList, handleAddUserToGroup, han
|
|
|
298
339
|
_jsx(Card, { ...containerProps, children: renderDataGrid }) : _jsx(Box, { ...containerProps, children: renderDataGrid }));
|
|
299
340
|
if (!userInfo || !groups || !devices)
|
|
300
341
|
return loadingComponent;
|
|
301
|
-
return (_jsx(ThemeProvider, { theme: theme, children: _jsxs(Box, { ...props, children: [_jsxs(Box, { component: "div", sx: { display: 'flex', alignItems: 'center', mb: 1, backgroundColor: editGroup && !isOrg ? 'secondary.light' : '', borderRadius: 3, px: editGroup ? 2 : 0, py: 1, height: 50, ...propsHeaderGroups }, children: [editGroup ?
|
|
342
|
+
return (_jsx(ThemeProvider, { theme: theme, children: _jsxs(Box, { ...props, children: [_jsxs(Box, { component: "div", sx: { display: 'flex', alignItems: 'center', mb: 1, backgroundColor: editGroup && !isOrg ? 'secondary.light' : '', borderRadius: 3, px: editGroup ? 2 : 0, py: 1, height: 50, ...propsHeaderGroups }, children: [editGroup ? _jsx(Typography, { variant: isOrg ? 'h6' : 'subtitle1', children: _jsxs("b", { children: [labelEntity, " \"", groupInfo?.name, "\""] }) }) : '', groups && !checkboxSelection && !isOrg && !(editGroup && currentGroup === 'all') ?
|
|
302
343
|
_jsx(Autocomplete, { disablePortal: true, onChange: handleChangeGroupSelect, value: groupInfo?.name || groupsLabelAll || 'All devices', disableClearable: currentGroup === 'all', isOptionEqualToValue: (o, v) => o.label === v, options: [{ label: groupsLabelAll || 'All devices', id: 'all' }, ...groups.map((grp) => ({ label: grp.name, id: grp.id }))], sx: { width: { xs: 200, sm: 300 }, textAlign: 'left' }, size: 'small', renderInput: (params) => _jsx(TextField, { ...params, label: labelEntity }) })
|
|
303
344
|
: '', (userInfo.role === 'admin' || (groupUpdateRoles && groupUpdateRoles.includes(userInfo.role))) &&
|
|
304
345
|
_jsxs(Box, { sx: { ml: 2 }, children: [checkboxSelection ?
|
|
@@ -319,6 +360,6 @@ const GroupsDevices = ({ userInfo, handleGetUsersList, handleAddUserToGroup, han
|
|
|
319
360
|
transform: 'translate(-50%, -50%)',
|
|
320
361
|
width: 400,
|
|
321
362
|
borderRadius: 4
|
|
322
|
-
}, children: [_jsx(CardHeader, { title: "
|
|
363
|
+
}, children: [_jsx(CardHeader, { title: "New " + labelEntity, action: _jsx(IconButton, { onClick: handleCloseAdd, children: _jsx(CloseIcon, {}) }) }), _jsx(CardContent, { children: _jsxs("form", { onSubmit: handleSubmit, children: [_jsx(TextField, { fullWidth: true, label: labelEntity + " Name", value: groupName, onChange: (e) => setGroupName(e.target.value), required: true }), _jsx(TextField, { fullWidth: true, label: "Description", value: description, onChange: (e) => setDescription(e.target.value), margin: "normal", multiline: true, rows: 4 }), _jsxs(Box, { mt: 2, display: "flex", justifyContent: "space-between", children: [_jsx(Button, { variant: "contained", color: "info", onClick: handleCloseAdd, children: "Cancel" }), _jsx(LoadingButton, { loading: loadingAdd, variant: "contained", color: "primary", type: "submit", children: "Create" })] })] }) })] }) }), !groupUpdateVisible && renderDatagridAndMaps, groupInfo && editGroup && groupUpdateVisible && _jsx(GroupUpdate, { confirmMui: confirmMui, usersGroup: usersGroup, usersList: usersList, handleGetGroups: handleGetGroups, handleUpdateDevice: handleUpdateDevice, handleAddUserToGroup: handleAddUserToGroup, handleRemoveUserFromGroup: handleRemoveUserFromGroup, groupInfo: groupInfo, afterUpdateCallback: async (groupInfo) => { setGroupInfo(groupInfo); await getGroups(); await getUsersGroup(groupInfo.id); }, afterRemoveCallback: async () => { closeEditGroup(); await getGroups(); setCurrentGroup('all'); }, container: 'Card', handleDeleteGroup: handleDeleteGroup, handleUpdateGroup: handleUpdateGroup, devicesList: devices, labelEntity: labelEntity })] }) }));
|
|
323
364
|
};
|
|
324
365
|
export default GroupsDevices;
|
package/package.json
CHANGED
|
@@ -16,6 +16,6 @@ export declare const getGroupsUser: (db: Firestore, userID: string) => Promise<{
|
|
|
16
16
|
}[]>;
|
|
17
17
|
export declare const addUsersGroup: (db: Firestore, groupID: string, userName: string, userID: string) => Promise<string>;
|
|
18
18
|
export declare const removeUserGroup: (db: Firestore, groupID: string, userID: string) => Promise<string | undefined>;
|
|
19
|
-
export declare const getUserOrganizations: (db: Firestore, productID: number, userID?: string, assetID?: string) => Promise<{
|
|
19
|
+
export declare const getUserOrganizations: (db: Firestore, productID: number, userID?: string, searchParentIds?: boolean, assetID?: string) => Promise<{
|
|
20
20
|
id: string;
|
|
21
21
|
}[]>;
|
package/server-actions/groups.js
CHANGED
|
@@ -115,10 +115,8 @@ export const removeUserGroup = async (db, groupID, userID) => {
|
|
|
115
115
|
}
|
|
116
116
|
};
|
|
117
117
|
// 9. GET ORGANIZATIONS
|
|
118
|
-
export const getUserOrganizations = async (db, productID, userID, assetID) => {
|
|
119
|
-
let groupsRef = db
|
|
120
|
-
.collection("groups")
|
|
121
|
-
.where("productID", "==", productID);
|
|
118
|
+
export const getUserOrganizations = async (db, productID, userID, searchParentIds, assetID) => {
|
|
119
|
+
let groupsRef = db.collection("groups").where("productID", "==", productID);
|
|
122
120
|
if (assetID) {
|
|
123
121
|
groupsRef = groupsRef.where("assets", "array-contains", assetID);
|
|
124
122
|
}
|
|
@@ -130,24 +128,30 @@ export const getUserOrganizations = async (db, productID, userID, assetID) => {
|
|
|
130
128
|
.where("user.userId", "==", userID)
|
|
131
129
|
.get();
|
|
132
130
|
const userGroupIds = userGroupsSnapshot.docs.map((doc) => doc.data().groupId);
|
|
133
|
-
let parentIds = [];
|
|
134
131
|
if (userGroupIds.length > 0) {
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
132
|
+
if (searchParentIds) {
|
|
133
|
+
const chunks = [];
|
|
134
|
+
let parentIds = [];
|
|
135
|
+
for (let i = 0; i < userGroupIds.length; i += 10) {
|
|
136
|
+
chunks.push(userGroupIds.slice(i, i + 10));
|
|
137
|
+
}
|
|
138
|
+
for (const chunk of chunks) {
|
|
139
|
+
const groupsSnapshot = await db
|
|
140
|
+
.collection("groups")
|
|
141
|
+
.where("__name__", "in", chunk)
|
|
142
|
+
.get();
|
|
143
|
+
const ids = groupsSnapshot.docs
|
|
144
|
+
.map((doc) => doc.data().parent_id)
|
|
145
|
+
.filter((id) => id !== null && id !== undefined);
|
|
146
|
+
parentIds.push(...ids);
|
|
147
|
+
}
|
|
148
|
+
// Rimuove duplicati
|
|
149
|
+
groupIds = Array.from(new Set(parentIds));
|
|
138
150
|
}
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
.where("__name__", "in", chunk)
|
|
143
|
-
.get();
|
|
144
|
-
const ids = groupsSnapshot.docs
|
|
145
|
-
.map((doc) => doc.data().parent_id)
|
|
146
|
-
.filter((id) => id !== null && id !== undefined);
|
|
147
|
-
parentIds.push(...ids);
|
|
151
|
+
else {
|
|
152
|
+
// support role
|
|
153
|
+
groupIds = userGroupIds;
|
|
148
154
|
}
|
|
149
|
-
// Rimuove duplicati
|
|
150
|
-
groupIds = Array.from(new Set(parentIds));
|
|
151
155
|
}
|
|
152
156
|
else {
|
|
153
157
|
groupIds = [];
|
|
@@ -158,8 +162,8 @@ export const getUserOrganizations = async (db, productID, userID, assetID) => {
|
|
|
158
162
|
.filter((doc) => {
|
|
159
163
|
const data = doc.data();
|
|
160
164
|
const parentId = data.parent_id;
|
|
161
|
-
return (parentId === null || parentId === undefined) &&
|
|
162
|
-
(!groupIds || groupIds.includes(doc.id));
|
|
165
|
+
return ((parentId === null || parentId === undefined) &&
|
|
166
|
+
(!groupIds || groupIds.includes(doc.id)));
|
|
163
167
|
})
|
|
164
168
|
.map((doc) => ({
|
|
165
169
|
id: doc.id,
|