diff --git a/src/app/App.tsx b/src/app/App.tsx index dbbcab1..34e0c92 100644 --- a/src/app/App.tsx +++ b/src/app/App.tsx @@ -60,7 +60,7 @@ function App() { { token ? - + : { @@ -48,10 +49,15 @@ const globalDefault = { showErrors: false, userTeamPermissions: [], backgroundTasksComplete: false, - firmware: new Map() + firmware: new Map(), } -export default function UserWrapper() { +interface Props { + token: string; +} + +export default function UserWrapper(props: Props) { + const { token } = props; const [loading, setLoading] = useState(false) const userAPI = useUserAPI(); const classes = useStyles(); @@ -98,7 +104,9 @@ export default function UserWrapper() {
- + + +
diff --git a/src/common/SmartBreadcrumb.tsx b/src/common/SmartBreadcrumb.tsx index 240af69..7a912cb 100644 --- a/src/common/SmartBreadcrumb.tsx +++ b/src/common/SmartBreadcrumb.tsx @@ -288,7 +288,9 @@ export default function SmartBreadcrumb(props: Props) { return [linkComponent("/", "Dashboard", true)]; } - if (prependPaths) pathnames.unshift(...prependPaths) + // if (prependPaths) pathnames.unshift(...prependPaths) + // if (prependPaths) pathnames.push(...prependPaths) + if (prependPaths) pathnames.splice(pathnames.length - 1, 0, ...prependPaths); //console.log(pathnames) diff --git a/src/group/GroupSettings.tsx b/src/group/GroupSettings.tsx index f03ff72..f40a07e 100644 --- a/src/group/GroupSettings.tsx +++ b/src/group/GroupSettings.tsx @@ -35,6 +35,7 @@ import { groupsAreEqual } from "pbHelpers/Group"; import { useGlobalState } from "providers"; import React, { useCallback, useEffect, useState } from "react"; import RemoveGroup from "./RemoveGroup"; +import { pond } from "protobuf-ts/pond"; const useStyles = makeStyles((theme: Theme) => { return ({ @@ -63,6 +64,7 @@ interface Props { canEdit?: boolean; groupDevices?: Device[]; removeGroupCallback?: Function; + addGroupCallback?: (group: pond.GroupSettings) => void } export default function GroupSettings(props: Props) { @@ -77,6 +79,7 @@ export default function GroupSettings(props: Props) { canEdit, groupDevices, removeGroupCallback, + addGroupCallback, } = props; const prevInitialGroup = usePrevious(initialGroup); const [{as}] = useGlobalState(); @@ -96,15 +99,6 @@ export default function GroupSettings(props: Props) { const [groupDeviceNumbers, setGroupDeviceNumbers] = useState([]) - // Use a ref to store removeGroupCallback - const removeCallbackRef = React.useRef(removeGroupCallback); - - // Update ref when prop changes - useEffect(() => { - console.log("Updating removeCallbackRef with:", removeGroupCallback); - if (removeGroupCallback) removeCallbackRef.current = removeGroupCallback; - }, [removeGroupCallback]); - useEffect(() => { let newNumbers: number[] = [] groupDevices?.forEach(device => { @@ -116,7 +110,7 @@ export default function GroupSettings(props: Props) { const loadDevices = useCallback(() => { setLoadingDevices(true); deviceAPI - .list(1000000, 0, "asc", undefined,undefined,undefined,undefined,undefined,undefined,undefined,undefined,undefined,undefined,undefined,undefined,as) + .list(1000000, 0, "asc") .then((response: any) => { let rDevices: Device[] = response.data.devices ? response.data.devices.map((device: any) => Device.any(device)) @@ -154,10 +148,13 @@ export default function GroupSettings(props: Props) { case "add": groupAPI .addGroup(group.settings) - .then((_response: any) => { + .then((response: any) => { success(groupName + " was successfully created"); close(); - refreshCallback(); + console.log(response) + group.settings.groupId = parseInt(response.data.id) + if (addGroupCallback) addGroupCallback(group.settings) + else refreshCallback(); }) .catch((err: any) => { err.response.data.error @@ -482,14 +479,12 @@ export default function GroupSettings(props: Props) { }; const dialogs = () => { - console.log("dialogs: removeCallbackRef.current =", removeCallbackRef.current); // Log ref - console.log("dialogs: removeGroupCallback =", removeGroupCallback); // Log prop return ( ); }; diff --git a/src/group/RemoveGroup.tsx b/src/group/RemoveGroup.tsx index f5d10aa..ede2ac7 100644 --- a/src/group/RemoveGroup.tsx +++ b/src/group/RemoveGroup.tsx @@ -10,7 +10,6 @@ import { import { makeStyles } from "@mui/styles"; import { useGroupAPI, useSnackbar } from "hooks"; import { Group } from "models"; -import { useNavigate } from "react-router-dom"; const useStyles = makeStyles((theme: Theme) => { return ({ @@ -30,7 +29,7 @@ interface Props { export default function RemoveGroup(props: Props) { const classes = useStyles(); - const navigate = useNavigate(); + // const navigate = useNavigate(); const groupAPI = useGroupAPI(); const { success, error, warning } = useSnackbar(); const { group, isDialogOpen, closeDialogCallback, removeCallback } = props; @@ -43,12 +42,9 @@ export default function RemoveGroup(props: Props) { const submit = () => { groupAPI .removeGroup(group.id()) - .then((response: any) => { + .then((_response: any) => { success(groupName + " was successfully removed"); - // navigate("/groups"); - console.log(removeCallback) if (removeCallback) removeCallback() - // removeCallback() }) .catch((err: any) => { err ? warning(err) : error("Error occured while removing " + groupName); diff --git a/src/pages/Devices.tsx b/src/pages/Devices.tsx index d9a843d..5e71a4e 100644 --- a/src/pages/Devices.tsx +++ b/src/pages/Devices.tsx @@ -141,7 +141,6 @@ export default function Devices() { }; const removeGroupCallback = useCallback(() => { - console.log("Remove callback"); let newGroups = [...groups]; newGroups.splice(parseInt(tab), 1); setGroups(newGroups); @@ -149,6 +148,16 @@ export default function Devices() { setGroupSettingsIsOpen(false); }, [groups, tab]); // Include dependencies + const addGroupCallback = useCallback((groupSettings: pond.GroupSettings) => { + let newGroups = [...groups]; + let group = pond.Group.create({ + settings: groupSettings + }) + newGroups.push(Group.create(group)) + setGroups(newGroups); + // setTab(groups.length.toString()) + }, [groups, tab]); // Include dependencies + const openGroupSettings = ( group: Group | undefined, mode: "add" | "update" | "remove" | undefined @@ -162,7 +171,6 @@ export default function Devices() { setGroupSettingsIsOpen(false); setGroupSettingsMode(undefined); setSelectedGroup(undefined); - console.log("close callback") }; const getKeys = () => { @@ -197,7 +205,9 @@ export default function Devices() { orderGroup, orderGroupBy, searchGroup, - undefined + undefined, + getKeys(), + getTypes(), ).then(resp => { let newGroups: Group[] = [] resp.data.groups?.forEach((group: pond.Group) => { @@ -210,7 +220,6 @@ export default function Devices() { } const loadDevices = () => { - console.log("load callback") setDevicesLoading(true) deviceAPI.list( limit, @@ -499,6 +508,18 @@ export default function Devices() { refreshCallback={loadDevices} closeDialogCallback={closeProvisionDialog} /> + {/* This GroupSettings is used for adding */} + {}} + canEdit={true} + groupDevices={devices} + removeGroupCallback={removeGroupCallback} + addGroupCallback={addGroupCallback} + /> ) } \ No newline at end of file diff --git a/src/providers/pond/groupAPI.tsx b/src/providers/pond/groupAPI.tsx index 8166af2..ef0ba34 100644 --- a/src/providers/pond/groupAPI.tsx +++ b/src/providers/pond/groupAPI.tsx @@ -123,10 +123,14 @@ export default function GroupProvider(props: PropsWithChildren) { }; const removeGroup = (id: number) => { - let url = pondURL("/groups/" + id) - if (as) url = pondURL("/groups/" + id + "?as=" + as) + const params = { + keys: getContextKeys(), + types: getContextTypes(), + as: getContextTypes().includes("team") ? undefined : as + } + pondURL(`/groups/${id}${buildQueryString(params)}`) return new Promise((resolve, reject) => { - del(url).then(resp => { + del(pondURL(`/groups/${id}${buildQueryString(params)}`)).then(resp => { return resolve(resp) }).catch(err => { return reject(err)