diff --git a/langflow/frontend/src/alerts/alertDropDown/index.tsx b/langflow/frontend/src/alerts/alertDropDown/index.tsx index a20fc6c31..81d2694a8 100644 --- a/langflow/frontend/src/alerts/alertDropDown/index.tsx +++ b/langflow/frontend/src/alerts/alertDropDown/index.tsx @@ -1,54 +1,78 @@ -import { useContext } from "react"; +import { useContext, useEffect, useRef } from "react"; import { alertContext } from "../../contexts/alertContext"; -import { - XMarkIcon, -} from "@heroicons/react/24/solid"; +import { XMarkIcon } from "@heroicons/react/24/solid"; import { TrashIcon } from "@heroicons/react/24/outline"; import SingleAlert from "./components/singleAlertComponent"; import { AlertDropdownType } from "../../types/alerts"; import { PopUpContext } from "../../contexts/popUpContext"; - - export default function AlertDropdown({}: AlertDropdownType) { - const { - notificationList, - clearNotificationList, - removeFromNotificationList, - } = useContext(alertContext); - const {closePopUp} = useContext(PopUpContext) - + const { closePopUp } = useContext(PopUpContext); + const componentRef = useRef(null); - return ( -
-
- Notifications -
- - -
-
-
- {notificationList.length !== 0 ? - notificationList.map((alertItem, index) => ( - - )) - : -
- No new notifications -
- } -
-
- ); + useEffect(() => { + function handleClickOutside(event: MouseEvent) { + if ( + componentRef.current && + !componentRef.current.contains(event.target as Node) + ) { + console.log(event) + closePopUp(); + } + } + + // Bind the event listener + document.addEventListener("mousedown", handleClickOutside); + + // Cleanup the event listener when the component is unmounted + return () => { + document.removeEventListener("mousedown", handleClickOutside); + }; + }, [componentRef]); + + const { + notificationList, + clearNotificationList, + removeFromNotificationList, + } = useContext(alertContext); + + return ( +
+
+ Notifications +
+ + +
+
+
+ {notificationList.length !== 0 ? ( + notificationList.map((alertItem, index) => ( + + )) + ) : ( +
+ No new notifications +
+ )} +
+
+ ); } diff --git a/langflow/frontend/src/components/chatComponent/index.tsx b/langflow/frontend/src/components/chatComponent/index.tsx index 0ddd1764c..b265b414a 100644 --- a/langflow/frontend/src/components/chatComponent/index.tsx +++ b/langflow/frontend/src/components/chatComponent/index.tsx @@ -16,9 +16,8 @@ import ChatMessage from "./chatMessage"; const _ = require("lodash"); export default function Chat({ flow, reactFlowInstance }: ChatType) { - const { updateFlow } = useContext(TabsContext); + const { updateFlow,lockChat,setLockChat,flows,tabIndex } = useContext(TabsContext); const [saveChat, setSaveChat] = useState(false); - const [lockChat, setLockChat] = useState(false); const [open, setOpen] = useState(true); const [chatValue, setChatValue] = useState(""); const [chatHistory, setChatHistory] = useState(flow.chat); @@ -26,10 +25,15 @@ export default function Chat({ flow, reactFlowInstance }: ChatType) { const addChatHistory = ( message: string, isSend: boolean, - thought?: string + thought?: string, ) => { + let tabsChange = false; setChatHistory((old) => { let newChat = _.cloneDeep(old); + if(flow.chat !==old){ + tabsChange = true + return old + } if (thought) { newChat.push({ message, isSend, thought }); } else { @@ -37,6 +41,15 @@ export default function Chat({ flow, reactFlowInstance }: ChatType) { } return newChat; }); + if(tabsChange){ + console.log(flow.chat) + if(thought){ + updateFlow({..._.cloneDeep(flow),chat:[...flow.chat,{isSend,message,thought}]}) + } + else{ + updateFlow({..._.cloneDeep(flow),chat:[...flow.chat,{isSend,message}]}) + } + } setSaveChat((chat) => !chat); }; useEffect(() => { @@ -86,7 +99,7 @@ export default function Chat({ flow, reactFlowInstance }: ChatType) { addChatHistory(message, true); console.log({ ...reactFlowInstance.toObject(), message, chatHistory }); - sendAll({ ...reactFlowInstance.toObject(), message, chatHistory }) + sendAll({ ...reactFlowInstance.toObject(), message, chatHistory}) .then((r) => { console.log(r.data); addChatHistory(r.data.result, false, r.data.thought); @@ -99,7 +112,7 @@ export default function Chat({ flow, reactFlowInstance }: ChatType) { } else { setErrorData({ title: "Error sending message", - list: ["There are required fields not filled yet."], + list: [ "Oops! Looks like you missed some required information. Please fill in all the required fields before continuing."], }); } } else { diff --git a/langflow/frontend/src/contexts/tabsContext.tsx b/langflow/frontend/src/contexts/tabsContext.tsx index 5185013af..3f6cbbf0b 100644 --- a/langflow/frontend/src/contexts/tabsContext.tsx +++ b/langflow/frontend/src/contexts/tabsContext.tsx @@ -14,6 +14,8 @@ const TabsContextInitialValue: TabsContextType = { incrementNodeId: () => 0, downloadFlow: () => {}, uploadFlow: () => {}, + lockChat: false, + setLockChat:(prevState:boolean)=>{} }; export const TabsContext = createContext( @@ -25,6 +27,7 @@ export function TabsProvider({ children }: { children: ReactNode }) { const [tabIndex, setTabIndex] = useState(0); const [flows, setFlows] = useState>([]); const [id, setId] = useState(0); + const [lockChat, setLockChat] = useState(false); const newNodeId = useRef(0); function incrementNodeId() { @@ -166,6 +169,8 @@ export function TabsProvider({ children }: { children: ReactNode }) { return ( number; downloadFlow: () => void; uploadFlow: () => void; + lockChat:boolean, + setLockChat:(prevState:boolean)=>void }; \ No newline at end of file