@iotready/nextjs-components-library 1.0.0-preview34 → 1.0.0-preview36
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.
- package/components/groups/GroupUpdate.d.ts +0 -1
- package/components/groups/GroupUpdate.js +1 -1
- package/components/groups/GroupsDevices.d.ts +2 -8
- package/components/groups/GroupsDevices.js +6 -22
- package/package.json +1 -1
- package/server-actions/groups.d.ts +1 -1
- package/server-actions/groups.js +25 -21
- package/types/user.d.ts +1 -0
|
@@ -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[];
|
|
@@ -97,7 +97,7 @@ const GroupUpdate = ({ labelEntity, groupInfo, usersGroup, usersList, devicesLis
|
|
|
97
97
|
_jsx(Table, { size: "small", children: _jsx(TableBody, { children: usersGroup.map((ug) => (_jsxs(TableRow, { children: [_jsx(TableCell, { children: _jsx(Typography, { variant: "body1", children: ug.user.fullName }) }), _jsx(TableCell, { align: 'right', children: _jsx(LoadingButton, { size: "small", color: "error", loading: loadingRemoveUserButton, onClick: () => removeUserFromCurrentGroup(ug.user.userId), children: _jsx(CloseIcon, { sx: { m: 0, p: 0 }, fontSize: "small" }) }) })] }, ug.id))) }) })
|
|
98
98
|
: _jsx(Box, { component: 'div', sx: { mt: 2 }, children: "No members found" }) }), _jsxs(Box, { component: "div", sx: { mt: 4, display: 'flex', alignItems: 'center' }, children: [_jsx(Autocomplete, { fullWidth: true, disablePortal: true, options: usersList || [], value: selectedUser, size: 'small', onChange: (event, newValue) => {
|
|
99
99
|
setSelectedUser(newValue);
|
|
100
|
-
}, renderInput: (params) => _jsx(TextField, { ...params, label: "Select user" }) }), _jsxs(LoadingButton, { variant: "contained", color: "
|
|
100
|
+
}, renderInput: (params) => _jsx(TextField, { ...params, label: "Select user" }) }), _jsxs(LoadingButton, { variant: "contained", color: "primary", loading: loadingAddUserButton, sx: { ml: 2 }, disabled: !selectedUser, onClick: () => addUserToCurrentGroup(), children: [_jsx(AddIcon, { sx: { mr: 1 } }), " Add"] })] }), _jsxs(Box, { component: "div", sx: { mt: 4 }, children: [_jsxs(Typography, { variant: 'body1', sx: { fontWeight: 'bold' }, children: ["Delete ", labelEntity.toLocaleLowerCase()] }), _jsx(Alert, { severity: "error", sx: { mt: 2 }, action: _jsxs(LoadingButton, { variant: "contained", disabled: devicesList.length > 0, color: "error", loading: loadingDeleteGroupButton, onClick: () => deleteGroup(), size: 'small', children: [_jsx(DeleteIcon, { fontSize: "small", sx: { mr: 1 } }), " Delete"] }), children: devicesList.length === 0 ? `This action cannot be undone` : `You must manually remove devices from ${labelEntity.toLocaleLowerCase()} before deletion` })] })] }) })] }));
|
|
101
101
|
};
|
|
102
102
|
return (container === "Card" ? (_jsx(Card, { ...containerProps, children: _jsx(CardContent, { children: renderGroupUpdate() }) })) : (_jsx(Box, { ...containerProps, children: renderGroupUpdate() })));
|
|
103
103
|
};
|
|
@@ -1,13 +1,8 @@
|
|
|
1
1
|
import { Theme } from "@emotion/react";
|
|
2
2
|
import { UserType, AssetType, DevicePositionType, TrackleDeviceType } from "../../types";
|
|
3
|
-
declare const GroupsDevices: ({ userInfo, handleGetUsersList, handleAddUserToGroup, handleRemoveUserFromGroup, handleGetGroups, handleGetUsersGroup, handleGetDevices, handleUpdateDevice, handleGetPositions, handleAddDevicesToGroup, handleRemoveDevicesFromGroup, handleCreateGroup, handleDeleteGroup, handleUpdateGroup, group, columnsArray, containerDataGrid, props, propsDatagrid, loadingComponent, containerProps, enableMaps, mapsHeight, mapsClickCallback, theme, confirmMui, propsHeaderGroups, forceGetDevices, customToolbar, groupsLabelAll, addDevicesLabel, noDevicesLabel, groupUpdateRoles, isOrg, currentOrg
|
|
3
|
+
declare const GroupsDevices: ({ userInfo, handleGetUsersList, handleAddUserToGroup, handleRemoveUserFromGroup, handleGetGroups, handleGetUsersGroup, handleGetDevices, handleUpdateDevice, handleGetPositions, handleAddDevicesToGroup, handleRemoveDevicesFromGroup, handleCreateGroup, handleDeleteGroup, handleUpdateGroup, group, columnsArray, containerDataGrid, props, propsDatagrid, loadingComponent, containerProps, enableMaps, mapsHeight, mapsClickCallback, theme, confirmMui, propsHeaderGroups, forceGetDevices, customToolbar, groupsLabelAll, addDevicesLabel, noDevicesLabel, groupUpdateRoles, isOrg, currentOrg }: {
|
|
4
4
|
userInfo: UserType;
|
|
5
|
-
handleGetUsersList: (
|
|
6
|
-
page: number;
|
|
7
|
-
pageSize: number;
|
|
8
|
-
}) => Promise<{
|
|
9
|
-
users: UserType[];
|
|
10
|
-
}>;
|
|
5
|
+
handleGetUsersList: () => Promise<UserType[]>;
|
|
11
6
|
handleAddUserToGroup: (groupID: string, userName: string, userID: string) => Promise<any>;
|
|
12
7
|
handleRemoveUserFromGroup: (groupID: string, userID: string) => Promise<any>;
|
|
13
8
|
handleGetGroups: (userInfo?: UserType) => Promise<any>;
|
|
@@ -22,7 +17,6 @@ declare const GroupsDevices: ({ userInfo, handleGetUsersList, handleAddUserToGro
|
|
|
22
17
|
handleUpdateDevice: (id: string, body: any, user: UserType) => Promise<void>;
|
|
23
18
|
group: string;
|
|
24
19
|
columnsArray: any[];
|
|
25
|
-
userGroupsRole?: string[];
|
|
26
20
|
containerDataGrid?: "Card" | "Box";
|
|
27
21
|
props?: any;
|
|
28
22
|
propsDatagrid?: any;
|
|
@@ -15,7 +15,7 @@ import GroupUpdate from "./GroupUpdate";
|
|
|
15
15
|
import BackIcon from '@mui/icons-material/ArrowBack';
|
|
16
16
|
import dynamic from "next/dynamic";
|
|
17
17
|
import { ThemeProvider } from '@mui/material/styles';
|
|
18
|
-
const GroupsDevices = ({ userInfo, handleGetUsersList, handleAddUserToGroup, handleRemoveUserFromGroup, handleGetGroups, handleGetUsersGroup, handleGetDevices, handleUpdateDevice, handleGetPositions, handleAddDevicesToGroup, handleRemoveDevicesFromGroup, handleCreateGroup, handleDeleteGroup, handleUpdateGroup, group = 'all', columnsArray = [], containerDataGrid = 'Card', props = {}, propsDatagrid = {}, loadingComponent = _jsx(CircularProgress, {}), containerProps = {}, enableMaps = true, mapsHeight = '400px', mapsClickCallback = () => { }, theme, confirmMui, propsHeaderGroups, forceGetDevices = 0, customToolbar, groupsLabelAll, addDevicesLabel, noDevicesLabel, groupUpdateRoles, isOrg = false, currentOrg
|
|
18
|
+
const GroupsDevices = ({ userInfo, handleGetUsersList, handleAddUserToGroup, handleRemoveUserFromGroup, handleGetGroups, handleGetUsersGroup, handleGetDevices, handleUpdateDevice, handleGetPositions, handleAddDevicesToGroup, handleRemoveDevicesFromGroup, handleCreateGroup, handleDeleteGroup, handleUpdateGroup, group = 'all', columnsArray = [], containerDataGrid = 'Card', props = {}, propsDatagrid = {}, loadingComponent = _jsx(CircularProgress, {}), containerProps = {}, enableMaps = true, mapsHeight = '400px', mapsClickCallback = () => { }, theme, confirmMui, propsHeaderGroups, forceGetDevices = 0, customToolbar, groupsLabelAll, addDevicesLabel, noDevicesLabel, groupUpdateRoles, isOrg = false, currentOrg }) => {
|
|
19
19
|
const [devices, setDevices] = useState([]);
|
|
20
20
|
const [positions, setPositions] = useState([]);
|
|
21
21
|
const [loadingDevices, setLoadingDevices] = useState(false);
|
|
@@ -47,29 +47,13 @@ const GroupsDevices = ({ userInfo, handleGetUsersList, handleAddUserToGroup, han
|
|
|
47
47
|
}), []);
|
|
48
48
|
const getUsersList = async () => {
|
|
49
49
|
try {
|
|
50
|
-
|
|
51
|
-
const pageSize = 100;
|
|
52
|
-
let usersData = [];
|
|
53
|
-
let moreData = true;
|
|
54
|
-
while (moreData) {
|
|
55
|
-
const usersList = await handleGetUsersList({
|
|
56
|
-
page,
|
|
57
|
-
pageSize,
|
|
58
|
-
});
|
|
59
|
-
if (usersList.users && usersList.users.length > 0) {
|
|
60
|
-
usersData = [...usersData, ...usersList.users];
|
|
61
|
-
}
|
|
62
|
-
// Se il numero di utenti restituiti è minore di pageSize, non ci sono più pagine da caricare
|
|
63
|
-
moreData = usersList.users.length === pageSize;
|
|
64
|
-
page++;
|
|
65
|
-
}
|
|
50
|
+
const usersData = await handleGetUsersList();
|
|
66
51
|
const userGroupsUserIds = usersGroup && usersGroup.map((ug) => ug.user.userId) || [];
|
|
67
52
|
setUsersList(usersData
|
|
68
|
-
.filter((user) =>
|
|
69
|
-
!userGroupsUserIds.includes(user.uid))
|
|
53
|
+
.filter((user) => !userGroupsUserIds.includes(user.uid))
|
|
70
54
|
.map((user) => {
|
|
71
|
-
const userName = user.name ? user.name.replace("/", " ") : "";
|
|
72
|
-
return { label: `${userName} (${user.email})`, id: user.uid };
|
|
55
|
+
const userName = user.profile.name ? user.profile.name.replace("/", " ") : "";
|
|
56
|
+
return { label: `${userName} (${user.profile.email})`, id: user.uid };
|
|
73
57
|
}));
|
|
74
58
|
}
|
|
75
59
|
catch (err) {
|
|
@@ -360,6 +344,6 @@ const GroupsDevices = ({ userInfo, handleGetUsersList, handleAddUserToGroup, han
|
|
|
360
344
|
transform: 'translate(-50%, -50%)',
|
|
361
345
|
width: 400,
|
|
362
346
|
borderRadius: 4
|
|
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,
|
|
347
|
+
}, 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 })] }) }));
|
|
364
348
|
};
|
|
365
349
|
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,
|