@iotready/nextjs-components-library 1.0.0-preview34 → 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.
|
@@ -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[];
|
|
@@ -360,6 +360,6 @@ const GroupsDevices = ({ userInfo, handleGetUsersList, handleAddUserToGroup, han
|
|
|
360
360
|
transform: 'translate(-50%, -50%)',
|
|
361
361
|
width: 400,
|
|
362
362
|
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,
|
|
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 })] }) }));
|
|
364
364
|
};
|
|
365
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,
|