@iotready/nextjs-components-library 1.0.0-preview36 → 1.0.0-preview38
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 +5 -3
- package/components/groups/GroupUpdate.js +17 -4
- package/components/groups/GroupsDevices.d.ts +2 -2
- package/components/groups/GroupsDevices.js +5 -1
- package/package.json +1 -1
- package/server-actions/groups.d.ts +1 -0
- package/server-actions/groups.js +21 -0
- package/server-actions/trackle.d.ts +1 -1
- package/server-actions/trackle.js +17 -1
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { AssetType, TrackleDeviceType, UserType } from '../../types';
|
|
2
|
-
declare const GroupUpdate: ({ labelEntity, groupInfo, usersGroup, usersList, devicesList, handleAddUserToGroup, handleRemoveUserFromGroup, handleUpdateGroup, handleDeleteGroup, container, containerProps, afterUpdateCallback, afterRemoveCallback, confirmMui }: {
|
|
2
|
+
declare const GroupUpdate: ({ isOrg, labelEntity, groupInfo, usersGroup, usersList, devicesList, userInfo, handleAddUserToGroup, handleGetGroups, handleRemoveUserFromGroup, handleUpdateGroup, handleDeleteGroup, container, containerProps, afterUpdateCallback, afterRemoveCallback, confirmMui }: {
|
|
3
3
|
groupInfo: any;
|
|
4
4
|
usersGroup: any[];
|
|
5
5
|
usersList: any[];
|
|
@@ -7,14 +7,16 @@ declare const GroupUpdate: ({ labelEntity, groupInfo, usersGroup, usersList, dev
|
|
|
7
7
|
handleAddUserToGroup: (groupID: string, userName: string, userID: string) => Promise<any>;
|
|
8
8
|
handleRemoveUserFromGroup: (groupID: string, userID: string) => Promise<any>;
|
|
9
9
|
handleUpdateDevice: (id: string, body: any, user: UserType) => Promise<any>;
|
|
10
|
-
handleGetGroups: (userInfo?: UserType) => Promise<any>;
|
|
10
|
+
handleGetGroups: (userInfo?: UserType, parent_id?: string) => Promise<any>;
|
|
11
11
|
handleUpdateGroup: (id: string, group: any) => Promise<void>;
|
|
12
|
-
handleDeleteGroup: (id: string) => Promise<void>;
|
|
12
|
+
handleDeleteGroup: (id: string, isOrg: boolean) => Promise<void>;
|
|
13
13
|
container?: "Box" | "Card";
|
|
14
14
|
containerProps?: any;
|
|
15
15
|
afterUpdateCallback?: (groupInfo: any) => Promise<void>;
|
|
16
16
|
afterRemoveCallback?: () => Promise<void>;
|
|
17
17
|
confirmMui?: (options?: any) => Promise<void>;
|
|
18
18
|
labelEntity: string;
|
|
19
|
+
isOrg: boolean;
|
|
20
|
+
userInfo: UserType;
|
|
19
21
|
}) => import("react/jsx-runtime").JSX.Element;
|
|
20
22
|
export default GroupUpdate;
|
|
@@ -2,14 +2,15 @@
|
|
|
2
2
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
3
|
import { Box, Typography, Card, CardContent, TableBody } from '@mui/material';
|
|
4
4
|
import Grid from '@mui/material/Grid2';
|
|
5
|
-
import { useState } from 'react';
|
|
5
|
+
import { useEffect, useState } from 'react';
|
|
6
6
|
import { FormControl, TextField, Autocomplete, Alert, Table, TableRow, TableCell } from '@mui/material';
|
|
7
7
|
import AddIcon from '@mui/icons-material/Add';
|
|
8
8
|
import CloseIcon from '@mui/icons-material/Close';
|
|
9
9
|
import DeleteIcon from '@mui/icons-material/Delete';
|
|
10
10
|
import { LoadingButton } from '@mui/lab';
|
|
11
|
-
const GroupUpdate = ({ labelEntity, groupInfo, usersGroup, usersList, devicesList, handleAddUserToGroup, handleRemoveUserFromGroup, handleUpdateGroup, handleDeleteGroup, container = 'Box', containerProps = {}, afterUpdateCallback, afterRemoveCallback, confirmMui }) => {
|
|
11
|
+
const GroupUpdate = ({ isOrg, labelEntity, groupInfo, usersGroup, usersList, devicesList, userInfo, handleAddUserToGroup, handleGetGroups, handleRemoveUserFromGroup, handleUpdateGroup, handleDeleteGroup, container = 'Box', containerProps = {}, afterUpdateCallback, afterRemoveCallback, confirmMui }) => {
|
|
12
12
|
const [group, setGroup] = useState(groupInfo);
|
|
13
|
+
const [organizationsGroup, setOrganizationsGroup] = useState(null);
|
|
13
14
|
const [loadingUpdateButton, setLoadingUpdateButton] = useState(false);
|
|
14
15
|
const [loadingRemoveUserButton, setLoadingRemoveUserButton] = useState(false);
|
|
15
16
|
const [loadingAddUserButton, setLoadingAddUserButton] = useState(false);
|
|
@@ -80,7 +81,7 @@ const GroupUpdate = ({ labelEntity, groupInfo, usersGroup, usersList, devicesLis
|
|
|
80
81
|
confirm("Are you sure you want to delete the group?");
|
|
81
82
|
}
|
|
82
83
|
setLoadingDeleteGroupButton(true);
|
|
83
|
-
await handleDeleteGroup(group.id);
|
|
84
|
+
await handleDeleteGroup(group.id, isOrg);
|
|
84
85
|
if (afterRemoveCallback) {
|
|
85
86
|
afterRemoveCallback();
|
|
86
87
|
}
|
|
@@ -92,12 +93,24 @@ const GroupUpdate = ({ labelEntity, groupInfo, usersGroup, usersList, devicesLis
|
|
|
92
93
|
setLoadingDeleteGroupButton(false);
|
|
93
94
|
}
|
|
94
95
|
};
|
|
96
|
+
useEffect(() => {
|
|
97
|
+
const getInitialData = async () => {
|
|
98
|
+
if (isOrg) {
|
|
99
|
+
const response = await handleGetGroups(userInfo, group.id);
|
|
100
|
+
setOrganizationsGroup(response);
|
|
101
|
+
}
|
|
102
|
+
else {
|
|
103
|
+
setOrganizationsGroup([]);
|
|
104
|
+
}
|
|
105
|
+
};
|
|
106
|
+
getInitialData();
|
|
107
|
+
}, []);
|
|
95
108
|
const renderGroupUpdate = () => {
|
|
96
109
|
return (_jsxs(Box, { component: "div", children: [_jsx(Grid, { container: true, spacing: 2, children: _jsx(Grid, { size: { xs: 12, md: 8 }, children: _jsxs(Box, { component: "div", children: [_jsx(FormControl, { fullWidth: true, children: _jsx(TextField, { sx: { flexGrow: 1 }, label: "Name", value: group.name, name: "name", onChange: handleChange }) }), _jsx(FormControl, { fullWidth: true, sx: { mt: 2 }, children: _jsx(TextField, { sx: { flexGrow: 1 }, label: "Description", value: group.description, name: "description", multiline: true, rows: 4, onChange: handleChange }) }), _jsx(LoadingButton, { variant: "contained", color: "primary", loading: loadingUpdateButton, sx: { mt: 2 }, onClick: () => updateGroup(), children: "Update" })] }) }) }), _jsx(Grid, { container: true, spacing: 2, sx: { mt: 4 }, children: _jsxs(Grid, { size: { xs: 12, md: 8 }, children: [_jsx(Typography, { variant: 'body1', sx: { fontWeight: 'bold' }, children: "Add members" }), _jsx(Box, { component: "div", sx: { mt: 2 }, children: usersGroup && usersGroup.length > 0 ?
|
|
97
110
|
_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
111
|
: _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
112
|
setSelectedUser(newValue);
|
|
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` })] })] }) })] }));
|
|
113
|
+
}, 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()] }), !isOrg ? (_jsx(Alert, { severity: "error", sx: { mt: 2 }, action: _jsxs(LoadingButton, { variant: "contained", disabled: devicesList.length > 0 || usersGroup.length > 0, color: "error", loading: loadingDeleteGroupButton, onClick: () => deleteGroup(), size: 'small', children: [_jsx(DeleteIcon, { fontSize: "small", sx: { mr: 1 } }), " Delete"] }), children: devicesList.length === 0 && usersGroup.length === 0 ? `This action cannot be undone` : `You must manually remove devices and members from ${labelEntity.toLocaleLowerCase()} before deletion` })) : organizationsGroup && (_jsx(Alert, { severity: "error", sx: { mt: 2 }, action: _jsxs(LoadingButton, { variant: "contained", disabled: devicesList.length > 0 || usersGroup.length > 0 || organizationsGroup.length > 0, color: "error", loading: loadingDeleteGroupButton, onClick: () => deleteGroup(), size: 'small', children: [_jsx(DeleteIcon, { fontSize: "small", sx: { mr: 1 } }), " Delete"] }), children: devicesList.length === 0 && usersGroup.length === 0 && organizationsGroup.length === 0 ? `This action cannot be undone` : `You must manually remove devices, members and groups from ${labelEntity.toLocaleLowerCase()} before deletion` }))] })] }) })] }));
|
|
101
114
|
};
|
|
102
115
|
return (container === "Card" ? (_jsx(Card, { ...containerProps, children: _jsx(CardContent, { children: renderGroupUpdate() }) })) : (_jsx(Box, { ...containerProps, children: renderGroupUpdate() })));
|
|
103
116
|
};
|
|
@@ -5,14 +5,14 @@ declare const GroupsDevices: ({ userInfo, handleGetUsersList, handleAddUserToGro
|
|
|
5
5
|
handleGetUsersList: () => Promise<UserType[]>;
|
|
6
6
|
handleAddUserToGroup: (groupID: string, userName: string, userID: string) => Promise<any>;
|
|
7
7
|
handleRemoveUserFromGroup: (groupID: string, userID: string) => Promise<any>;
|
|
8
|
-
handleGetGroups: (userInfo?: UserType) => Promise<any>;
|
|
8
|
+
handleGetGroups: (userInfo?: UserType, parent_id?: string | undefined) => Promise<any>;
|
|
9
9
|
handleGetUsersGroup: (groupID: string) => Promise<any>;
|
|
10
10
|
handleCreateGroup: (group: any) => Promise<any>;
|
|
11
11
|
handleGetDevices: (user: UserType, group: string, selectedGroup: string) => Promise<AssetType[] | TrackleDeviceType[]>;
|
|
12
12
|
handleGetPositions?: (devices: any) => Promise<DevicePositionType[]>;
|
|
13
13
|
handleAddDevicesToGroup: (user: UserType, group: string, devicesToPatch: AssetType[] | TrackleDeviceType[]) => Promise<TrackleDeviceType[]>;
|
|
14
14
|
handleRemoveDevicesFromGroup: (user: UserType, group: string, devicesToPatch: AssetType[] | TrackleDeviceType[]) => Promise<TrackleDeviceType[]>;
|
|
15
|
-
handleDeleteGroup: (id: string) => Promise<void>;
|
|
15
|
+
handleDeleteGroup: (id: string, iOrg: boolean) => Promise<void>;
|
|
16
16
|
handleUpdateGroup: (id: string, group: any) => Promise<void>;
|
|
17
17
|
handleUpdateDevice: (id: string, body: any, user: UserType) => Promise<void>;
|
|
18
18
|
group: string;
|
|
@@ -344,6 +344,10 @@ const GroupsDevices = ({ userInfo, handleGetUsersList, handleAddUserToGroup, han
|
|
|
344
344
|
transform: 'translate(-50%, -50%)',
|
|
345
345
|
width: 400,
|
|
346
346
|
borderRadius: 4
|
|
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 () => {
|
|
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, { userInfo: userInfo, 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 () => { if (!isOrg) {
|
|
348
|
+
closeEditGroup();
|
|
349
|
+
setCurrentGroup('all');
|
|
350
|
+
await getGroups();
|
|
351
|
+
} }, container: 'Card', handleDeleteGroup: handleDeleteGroup, handleUpdateGroup: handleUpdateGroup, devicesList: devices, labelEntity: labelEntity, isOrg: isOrg })] }) }));
|
|
348
352
|
};
|
|
349
353
|
export default GroupsDevices;
|
package/package.json
CHANGED
|
@@ -19,3 +19,4 @@ export declare const removeUserGroup: (db: Firestore, groupID: string, userID: s
|
|
|
19
19
|
export declare const getUserOrganizations: (db: Firestore, productID: number, userID?: string, searchParentIds?: boolean, assetID?: string) => Promise<{
|
|
20
20
|
id: string;
|
|
21
21
|
}[]>;
|
|
22
|
+
export declare const getCustomerOrganizations: (db: Firestore, userOrganizations: string[]) => Promise<any[]>;
|
package/server-actions/groups.js
CHANGED
|
@@ -171,3 +171,24 @@ export const getUserOrganizations = async (db, productID, userID, searchParentId
|
|
|
171
171
|
}));
|
|
172
172
|
return organizations;
|
|
173
173
|
};
|
|
174
|
+
export const getCustomerOrganizations = async (db, userOrganizations) => {
|
|
175
|
+
if (userOrganizations.length === 0) {
|
|
176
|
+
return [];
|
|
177
|
+
}
|
|
178
|
+
const chunks = [];
|
|
179
|
+
const organizations = [];
|
|
180
|
+
for (let i = 0; i < userOrganizations.length; i += 10) {
|
|
181
|
+
chunks.push(userOrganizations.slice(i, i + 10));
|
|
182
|
+
}
|
|
183
|
+
for (const chunk of chunks) {
|
|
184
|
+
const groupsSnapshot = await db
|
|
185
|
+
.collection("groups")
|
|
186
|
+
.where("__name__", "in", chunk)
|
|
187
|
+
.get();
|
|
188
|
+
organizations.push(...groupsSnapshot.docs.map((doc) => ({
|
|
189
|
+
id: doc.id,
|
|
190
|
+
...doc.data()
|
|
191
|
+
})));
|
|
192
|
+
}
|
|
193
|
+
return organizations;
|
|
194
|
+
};
|
|
@@ -38,4 +38,4 @@ export declare function put(trackleConfig: TrackleConfig, id: string, endpoint:
|
|
|
38
38
|
return_value: number;
|
|
39
39
|
}>;
|
|
40
40
|
export declare function addDevicesToGroup(trackleConfig: TrackleConfig, productId: number, group: string, devicesToPatch: TrackleDeviceType[], uid?: string): Promise<TrackleDeviceType[]>;
|
|
41
|
-
export declare function removeDevicesFromGroup(trackleConfig: TrackleConfig, productId: number, group: string, devicesToPatch: TrackleDeviceType[], uid?: string): Promise<TrackleDeviceType[]>;
|
|
41
|
+
export declare function removeDevicesFromGroup(trackleConfig: TrackleConfig, productId: number, group: string | string[], devicesToPatch: TrackleDeviceType[], uid?: string): Promise<TrackleDeviceType[]>;
|
|
@@ -147,7 +147,7 @@ export async function removeDevicesFromGroup(trackleConfig, productId, group, de
|
|
|
147
147
|
let newGroups = device.state?.groups && device.state?.groups instanceof Array
|
|
148
148
|
? device.state?.groups
|
|
149
149
|
: [];
|
|
150
|
-
if (newGroups.includes(group)) {
|
|
150
|
+
if (typeof group === "string" && newGroups.includes(group)) {
|
|
151
151
|
newGroups = newGroups.filter((newGroup) => newGroup !== group);
|
|
152
152
|
const api = uid ? wretchApi(trackleConfig, uid) : wretchApi(trackleConfig);
|
|
153
153
|
await api
|
|
@@ -156,8 +156,24 @@ export async function removeDevicesFromGroup(trackleConfig, productId, group, de
|
|
|
156
156
|
: `/products/${productId}/devices/${device.id}/groups`)
|
|
157
157
|
.setTimeout(trackleConfig.apiTimeout)
|
|
158
158
|
.res();
|
|
159
|
+
device.state.groups = newGroups;
|
|
159
160
|
devicesPatched.push(device);
|
|
160
161
|
}
|
|
162
|
+
else if (Array.isArray(group)) {
|
|
163
|
+
const intersection = newGroups.filter((g) => group.includes(g));
|
|
164
|
+
if (intersection.length > 0) {
|
|
165
|
+
newGroups = newGroups.filter((g) => !group.includes(g));
|
|
166
|
+
const api = uid ? wretchApi(trackleConfig, uid) : wretchApi(trackleConfig);
|
|
167
|
+
await api
|
|
168
|
+
.put({ value: newGroups }, uid
|
|
169
|
+
? `/devices/${device.id}/groups`
|
|
170
|
+
: `/products/${productId}/devices/${device.id}/groups`)
|
|
171
|
+
.setTimeout(trackleConfig.apiTimeout)
|
|
172
|
+
.res();
|
|
173
|
+
device.state.groups = newGroups;
|
|
174
|
+
devicesPatched.push(device);
|
|
175
|
+
}
|
|
176
|
+
}
|
|
161
177
|
}
|
|
162
178
|
return devicesPatched;
|
|
163
179
|
}
|