@iotready/nextjs-components-library 1.0.0-preview35 → 1.0.0-preview37
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 +4 -2
- package/components/groups/GroupUpdate.js +14 -4
- package/components/groups/GroupsDevices.d.ts +3 -9
- package/components/groups/GroupsDevices.js +8 -22
- 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
- package/types/user.d.ts +1 -0
|
@@ -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,7 +7,7 @@ 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
12
|
handleDeleteGroup: (id: string) => Promise<void>;
|
|
13
13
|
container?: "Box" | "Card";
|
|
@@ -16,5 +16,7 @@ declare const GroupUpdate: ({ labelEntity, groupInfo, usersGroup, usersList, dev
|
|
|
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;
|
|
@@ -1,15 +1,16 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
2
|
+
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } 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([]);
|
|
13
14
|
const [loadingUpdateButton, setLoadingUpdateButton] = useState(false);
|
|
14
15
|
const [loadingRemoveUserButton, setLoadingRemoveUserButton] = useState(false);
|
|
15
16
|
const [loadingAddUserButton, setLoadingAddUserButton] = useState(false);
|
|
@@ -92,12 +93,21 @@ 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
|
+
};
|
|
103
|
+
getInitialData();
|
|
104
|
+
}, []);
|
|
95
105
|
const renderGroupUpdate = () => {
|
|
96
106
|
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
107
|
_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
108
|
: _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
109
|
setSelectedUser(newValue);
|
|
100
|
-
}, renderInput: (params) => _jsx(TextField, { ...params, label: "Select user" }) }), _jsxs(LoadingButton, { variant: "contained", color: "
|
|
110
|
+
}, 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 || usersGroup.length > 0, color: "error", loading: loadingDeleteGroupButton, onClick: () => deleteGroup(), size: 'small', children: [_jsx(DeleteIcon, { fontSize: "small", sx: { mr: 1 } }), " Delete"] }), children: !isOrg ? (_jsx(_Fragment, { children: devicesList.length === 0 && usersGroup.length === 0 ? `This action cannot be undone` : `You must manually remove devices and members from ${labelEntity.toLocaleLowerCase()} before deletion` })) : (_jsx(_Fragment, { children: devicesList.length === 0 && usersGroup.length === 0 && organizationsGroup.length === 0 ? `This action cannot be undone` : `You must manually remove devices and members and groups from ${labelEntity.toLocaleLowerCase()} before deletion` })) })] })] }) })] }));
|
|
101
111
|
};
|
|
102
112
|
return (container === "Card" ? (_jsx(Card, { ...containerProps, children: _jsx(CardContent, { children: renderGroupUpdate() }) })) : (_jsx(Box, { ...containerProps, children: renderGroupUpdate() })));
|
|
103
113
|
};
|
|
@@ -1,16 +1,11 @@
|
|
|
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
|
-
handleGetGroups: (userInfo?: UserType) => Promise<any>;
|
|
8
|
+
handleGetGroups: (userInfo?: UserType, parent_id?: string | undefined) => Promise<any>;
|
|
14
9
|
handleGetUsersGroup: (groupID: string) => Promise<any>;
|
|
15
10
|
handleCreateGroup: (group: any) => Promise<any>;
|
|
16
11
|
handleGetDevices: (user: UserType, group: string, selectedGroup: string) => Promise<AssetType[] | TrackleDeviceType[]>;
|
|
@@ -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,8 @@ 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, 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();
|
|
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 () => { closeEditGroup(); await getGroups(); if (!isOrg) {
|
|
348
|
+
setCurrentGroup('all');
|
|
349
|
+
} }, container: 'Card', handleDeleteGroup: handleDeleteGroup, handleUpdateGroup: handleUpdateGroup, devicesList: devices, labelEntity: labelEntity, isOrg: isOrg })] }) }));
|
|
364
350
|
};
|
|
365
351
|
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
|
}
|