Merge branch 'staging_environment' into dev_environment
This commit is contained in:
commit
7dd291cf96
3 changed files with 35 additions and 5 deletions
|
|
@ -62,6 +62,7 @@ interface Props {
|
||||||
refreshCallback: () => void;
|
refreshCallback: () => void;
|
||||||
canEdit?: boolean;
|
canEdit?: boolean;
|
||||||
groupDevices?: Device[];
|
groupDevices?: Device[];
|
||||||
|
removeGroupCallback?: Function;
|
||||||
}
|
}
|
||||||
|
|
||||||
export default function GroupSettings(props: Props) {
|
export default function GroupSettings(props: Props) {
|
||||||
|
|
@ -75,6 +76,7 @@ export default function GroupSettings(props: Props) {
|
||||||
refreshCallback,
|
refreshCallback,
|
||||||
canEdit,
|
canEdit,
|
||||||
groupDevices,
|
groupDevices,
|
||||||
|
removeGroupCallback,
|
||||||
} = props;
|
} = props;
|
||||||
const prevInitialGroup = usePrevious(initialGroup);
|
const prevInitialGroup = usePrevious(initialGroup);
|
||||||
const [{as}] = useGlobalState();
|
const [{as}] = useGlobalState();
|
||||||
|
|
@ -94,6 +96,15 @@ export default function GroupSettings(props: Props) {
|
||||||
|
|
||||||
const [groupDeviceNumbers, setGroupDeviceNumbers] = useState<number[]>([])
|
const [groupDeviceNumbers, setGroupDeviceNumbers] = useState<number[]>([])
|
||||||
|
|
||||||
|
// Use a ref to store removeGroupCallback
|
||||||
|
const removeCallbackRef = React.useRef(removeGroupCallback);
|
||||||
|
|
||||||
|
// Update ref when prop changes
|
||||||
|
useEffect(() => {
|
||||||
|
console.log("Updating removeCallbackRef with:", removeGroupCallback);
|
||||||
|
removeCallbackRef.current = removeGroupCallback;
|
||||||
|
}, [removeGroupCallback]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
let newNumbers: number[] = []
|
let newNumbers: number[] = []
|
||||||
groupDevices?.forEach(device => {
|
groupDevices?.forEach(device => {
|
||||||
|
|
@ -471,11 +482,14 @@ export default function GroupSettings(props: Props) {
|
||||||
};
|
};
|
||||||
|
|
||||||
const dialogs = () => {
|
const dialogs = () => {
|
||||||
|
console.log("dialogs: removeCallbackRef.current =", removeCallbackRef.current); // Log ref
|
||||||
|
console.log("dialogs: removeGroupCallback =", removeGroupCallback); // Log prop
|
||||||
return (
|
return (
|
||||||
<RemoveGroup
|
<RemoveGroup
|
||||||
group={group}
|
group={group}
|
||||||
isDialogOpen={isRemoveGroupOpen}
|
isDialogOpen={isRemoveGroupOpen}
|
||||||
closeDialogCallback={closeRemoveGroup}
|
closeDialogCallback={closeRemoveGroup}
|
||||||
|
removeCallback={removeCallbackRef.current}
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -25,6 +25,7 @@ interface Props {
|
||||||
group: Group;
|
group: Group;
|
||||||
isDialogOpen: boolean;
|
isDialogOpen: boolean;
|
||||||
closeDialogCallback: Function;
|
closeDialogCallback: Function;
|
||||||
|
removeCallback?: Function;
|
||||||
}
|
}
|
||||||
|
|
||||||
export default function RemoveGroup(props: Props) {
|
export default function RemoveGroup(props: Props) {
|
||||||
|
|
@ -32,7 +33,7 @@ export default function RemoveGroup(props: Props) {
|
||||||
const navigate = useNavigate();
|
const navigate = useNavigate();
|
||||||
const groupAPI = useGroupAPI();
|
const groupAPI = useGroupAPI();
|
||||||
const { success, error, warning } = useSnackbar();
|
const { success, error, warning } = useSnackbar();
|
||||||
const { group, isDialogOpen, closeDialogCallback } = props;
|
const { group, isDialogOpen, closeDialogCallback, removeCallback } = props;
|
||||||
let groupName = group.name();
|
let groupName = group.name();
|
||||||
|
|
||||||
const closeDialog = () => {
|
const closeDialog = () => {
|
||||||
|
|
@ -45,10 +46,15 @@ export default function RemoveGroup(props: Props) {
|
||||||
.then((response: any) => {
|
.then((response: any) => {
|
||||||
success(groupName + " was successfully removed");
|
success(groupName + " was successfully removed");
|
||||||
// navigate("/groups");
|
// navigate("/groups");
|
||||||
|
console.log(removeCallback)
|
||||||
|
if (removeCallback) removeCallback()
|
||||||
|
// removeCallback()
|
||||||
})
|
})
|
||||||
.catch((err: any) => {
|
.catch((err: any) => {
|
||||||
err ? warning(err) : error("Error occured while removing " + groupName);
|
err ? warning(err) : error("Error occured while removing " + groupName);
|
||||||
closeDialog();
|
closeDialog();
|
||||||
|
}).finally(() => {
|
||||||
|
closeDialogCallback()
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -6,7 +6,7 @@ import ResponsiveTable, { Column } from "common/ResponsiveTable";
|
||||||
import ProvisionDevice from "device/ProvisionDevice";
|
import ProvisionDevice from "device/ProvisionDevice";
|
||||||
import { pond } from "protobuf-ts/pond";
|
import { pond } from "protobuf-ts/pond";
|
||||||
import { useDeviceAPI, useGlobalState, useGroupAPI } from "providers";
|
import { useDeviceAPI, useGlobalState, useGroupAPI } from "providers";
|
||||||
import { useEffect, useState } from "react";
|
import { useCallback, useEffect, useState } from "react";
|
||||||
import PageContainer from "./PageContainer";
|
import PageContainer from "./PageContainer";
|
||||||
import { useMobile } from "hooks";
|
import { useMobile } from "hooks";
|
||||||
import { useLocation, useNavigate, useParams } from "react-router-dom";
|
import { useLocation, useNavigate, useParams } from "react-router-dom";
|
||||||
|
|
@ -121,15 +121,13 @@ export default function Devices() {
|
||||||
};
|
};
|
||||||
|
|
||||||
const getGroup = () => {
|
const getGroup = () => {
|
||||||
let group = groups[parseInt(tab)]
|
return groups[parseInt(tab)]
|
||||||
return group
|
|
||||||
}
|
}
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
setGroupPermissions([])
|
setGroupPermissions([])
|
||||||
if (tab === "all") return
|
if (tab === "all") return
|
||||||
groupAPI.getGroupPermissions(getGroup().id()).then(resp => {
|
groupAPI.getGroupPermissions(getGroup().id()).then(resp => {
|
||||||
console.log(resp)
|
|
||||||
setGroupPermissions(resp.data.permissions)
|
setGroupPermissions(resp.data.permissions)
|
||||||
})
|
})
|
||||||
}, [tab])
|
}, [tab])
|
||||||
|
|
@ -142,6 +140,15 @@ export default function Devices() {
|
||||||
setIsProvisionDialogOpen(false);
|
setIsProvisionDialogOpen(false);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const removeGroupCallback = useCallback(() => {
|
||||||
|
console.log("Remove callback");
|
||||||
|
let newGroups = [...groups];
|
||||||
|
newGroups.splice(parseInt(tab), 1);
|
||||||
|
setGroups(newGroups);
|
||||||
|
setTab("all");
|
||||||
|
setGroupSettingsIsOpen(false);
|
||||||
|
}, [groups, tab]); // Include dependencies
|
||||||
|
|
||||||
const openGroupSettings = (
|
const openGroupSettings = (
|
||||||
group: Group | undefined,
|
group: Group | undefined,
|
||||||
mode: "add" | "update" | "remove" | undefined
|
mode: "add" | "update" | "remove" | undefined
|
||||||
|
|
@ -155,6 +162,7 @@ export default function Devices() {
|
||||||
setGroupSettingsIsOpen(false);
|
setGroupSettingsIsOpen(false);
|
||||||
setGroupSettingsMode(undefined);
|
setGroupSettingsMode(undefined);
|
||||||
setSelectedGroup(undefined);
|
setSelectedGroup(undefined);
|
||||||
|
console.log("close callback")
|
||||||
};
|
};
|
||||||
|
|
||||||
const getKeys = () => {
|
const getKeys = () => {
|
||||||
|
|
@ -202,6 +210,7 @@ export default function Devices() {
|
||||||
}
|
}
|
||||||
|
|
||||||
const loadDevices = () => {
|
const loadDevices = () => {
|
||||||
|
console.log("load callback")
|
||||||
setDevicesLoading(true)
|
setDevicesLoading(true)
|
||||||
deviceAPI.list(
|
deviceAPI.list(
|
||||||
limit,
|
limit,
|
||||||
|
|
@ -498,6 +507,7 @@ export default function Devices() {
|
||||||
refreshCallback={loadDevices}
|
refreshCallback={loadDevices}
|
||||||
canEdit={true}
|
canEdit={true}
|
||||||
groupDevices={devices}
|
groupDevices={devices}
|
||||||
|
removeGroupCallback={removeGroupCallback}
|
||||||
/>
|
/>
|
||||||
</PageContainer>
|
</PageContainer>
|
||||||
)
|
)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue