diff --git a/frontend/src/views/Detection.jsx b/frontend/src/views/Detection.jsx index 63567584..80d2f821 100644 --- a/frontend/src/views/Detection.jsx +++ b/frontend/src/views/Detection.jsx @@ -7,6 +7,7 @@ import { Typography, Button, } from "@mui/material"; +import { toast } from "react-toastify"; import RuleCard from "./RuleCard"; import { styled } from "@mui/system"; @@ -15,7 +16,36 @@ const ConnectedButton = styled(Button)({ color: "white", }); -const Detection = ({ globalUrl, ruleInfo, openEditBar }) => { +const handleDirectoryChange = ( folderDisabled, setFolderDisabled, globalUrl) => { + + const action = folderDisabled ? "enable_folder" : "disable_folder" + const url = `${globalUrl}/api/v1/files/detection/${action}`; + + fetch(url, { + method: "PUT", + credentials: "include", + headers: { + "Content-Type": "application/json", + }, + }) + .then((response) => + response.json().then((responseJson) => { + if (responseJson["success"] === true) { + if (action === "enable_folder") setFolderDisabled(false); + else setFolderDisabled(true); + } else { + //toast(`failed to disable rule`); + } + }) + ) + .catch((error) => { + console.log(`Error in ${action} the rule: `, error); + toast(`An error occurred while ${action} the rule`); + }); + +} + +const Detection = ({ globalUrl, ruleInfo, folderDisabled, setFolderDisabled, openEditBar }) => { return ( @@ -47,7 +77,10 @@ const Detection = ({ globalUrl, ruleInfo, openEditBar }) => { Global disable/enable - + handleDirectoryChange(folderDisabled, setFolderDisabled, globalUrl)} + /> { description={card.description} file_id={card.file_id} globalUrl={globalUrl} + folderDisabled={folderDisabled} openEditBar={() => openEditBar(card)} {...card} />