diff --git a/src/frontend/src/App.tsx b/src/frontend/src/App.tsx index 9b7ec8b75..5e54edae1 100644 --- a/src/frontend/src/App.tsx +++ b/src/frontend/src/App.tsx @@ -16,13 +16,13 @@ import { FETCH_ERROR_MESSAGE, } from "./constants/constants"; import { AuthContext } from "./contexts/authContext"; -import { getHealth, getRepoStars, getVersion } from "./controllers/API"; +import { getHealth } from "./controllers/API"; import Router from "./routes"; import useAlertStore from "./stores/alertStore"; -import { useTypesStore } from "./stores/typesStore"; import { useDarkStore } from "./stores/darkStore"; import useFlowsManagerStore from "./stores/flowsManagerStore"; import { useLocationStore } from "./stores/locationStore"; +import { useTypesStore } from "./stores/typesStore"; export default function App() { const setCurrent = useLocationStore((state) => state.setCurrent); @@ -149,7 +149,6 @@ export default function App() { refreshFlows(); }); } - }, [isAuthenticated]); useEffect(() => { diff --git a/src/frontend/src/CustomNodes/GenericNode/components/parameterComponent/index.tsx b/src/frontend/src/CustomNodes/GenericNode/components/parameterComponent/index.tsx index b688fdb7b..a76a15d17 100644 --- a/src/frontend/src/CustomNodes/GenericNode/components/parameterComponent/index.tsx +++ b/src/frontend/src/CustomNodes/GenericNode/components/parameterComponent/index.tsx @@ -1,11 +1,5 @@ import { cloneDeep } from "lodash"; -import React, { - ReactNode, - useContext, - useEffect, - useRef, - useState, -} from "react"; +import React, { ReactNode, useEffect, useRef, useState } from "react"; import { Handle, Position } from "reactflow"; import ShadTooltip from "../../../../components/ShadTooltipComponent"; import CodeAreaComponent from "../../../../components/codeAreaComponent"; @@ -29,6 +23,8 @@ import { import { postCustomComponentUpdate } from "../../../../controllers/API"; import useAlertStore from "../../../../stores/alertStore"; import useFlowStore from "../../../../stores/flowStore"; +import useFlowsManagerStore from "../../../../stores/flowsManagerStore"; +import { useTypesStore } from "../../../../stores/typesStore"; import { APIClassType } from "../../../../types/api"; import { ParameterComponentType } from "../../../../types/components"; import { NodeDataType } from "../../../../types/flow"; @@ -45,8 +41,6 @@ import { nodeNames, } from "../../../../utils/styleUtils"; import { classNames, groupByFamily } from "../../../../utils/utils"; -import { useTypesStore } from "../../../../stores/typesStore"; -import useFlowsManagerStore from "../../../../stores/flowsManagerStore"; export default function ParameterComponent({ left, @@ -112,7 +106,7 @@ export default function ParameterComponent({ if (data.node!.template[name].value !== newValue) { takeSnapshot(); } - + data.node!.template[name].value = newValue; // necessary to enable ctrl+z inside the input setNode(data.id, (oldNode) => { @@ -300,7 +294,7 @@ export default function ParameterComponent({ ) : (
<>
state.edges); const setErrorData = useAlertStore((state) => state.setErrorData); const setSuccessData = useAlertStore((state) => state.setSuccessData); - const setFlowState = useFlowStore( - (state) => state.setFlowState - ); + const setFlowState = useFlowStore((state) => state.setFlowState); const eventClick = isBuilding ? "pointer-events-none" : ""; const [progress, setProgress] = useState(0); diff --git a/src/frontend/src/components/chatComponent/index.tsx b/src/frontend/src/components/chatComponent/index.tsx index 0ee71c997..a8ad3fc7c 100644 --- a/src/frontend/src/components/chatComponent/index.tsx +++ b/src/frontend/src/components/chatComponent/index.tsx @@ -1,4 +1,4 @@ -import { useContext, useEffect, useRef, useState } from "react"; +import { useEffect, useRef, useState } from "react"; import { useNodes } from "reactflow"; import { ChatType } from "../../types/chat"; import BuildTrigger from "./buildTrigger"; @@ -9,7 +9,6 @@ import { getBuildStatus } from "../../controllers/API"; import FormModal from "../../modals/formModal"; import useFlowStore from "../../stores/flowStore"; import { NodeType } from "../../types/flow"; -import useFlowsManagerStore from "../../stores/flowsManagerStore"; export default function Chat({ flow }: ChatType): JSX.Element { const [open, setOpen] = useState(false); @@ -51,9 +50,7 @@ export default function Chat({ flow }: ChatType): JSX.Element { const currentNodes = nodes.map((node: NodeType) => _.cloneDeep(node.data.node?.template) ); - if ( - JSON.stringify(prevNodes) !== JSON.stringify(currentNodes) - ) { + if (JSON.stringify(prevNodes) !== JSON.stringify(currentNodes)) { setIsBuilt(false); } prevNodesRef.current = currentNodes; @@ -68,16 +65,9 @@ export default function Chat({ flow }: ChatType): JSX.Element { setIsBuilt={setIsBuilt} isBuilt={isBuilt} /> - {isBuilt && - flowState && - !!flowState?.input_keys && ( - - )} + {isBuilt && flowState && !!flowState?.input_keys && ( + + )} { diff --git a/src/frontend/src/components/inputFileComponent/index.tsx b/src/frontend/src/components/inputFileComponent/index.tsx index 0d7b180d2..de63d6d94 100644 --- a/src/frontend/src/components/inputFileComponent/index.tsx +++ b/src/frontend/src/components/inputFileComponent/index.tsx @@ -1,9 +1,9 @@ -import { useContext, useEffect, useState } from "react"; +import { useEffect, useState } from "react"; import { uploadFile } from "../../controllers/API"; import useAlertStore from "../../stores/alertStore"; +import useFlowsManagerStore from "../../stores/flowsManagerStore"; import { FileComponentType } from "../../types/components"; import IconComponent from "../genericIconComponent"; -import useFlowsManagerStore from "../../stores/flowsManagerStore"; export default function InputFileComponent({ value, diff --git a/src/frontend/src/components/intComponent/index.tsx b/src/frontend/src/components/intComponent/index.tsx index 25ac37369..da4839ae1 100644 --- a/src/frontend/src/components/intComponent/index.tsx +++ b/src/frontend/src/components/intComponent/index.tsx @@ -1,6 +1,9 @@ import { useEffect } from "react"; import { IntComponentType } from "../../types/components"; -import { handleKeyDown, handleOnlyIntegerInput } from "../../utils/reactflowUtils"; +import { + handleKeyDown, + handleOnlyIntegerInput, +} from "../../utils/reactflowUtils"; import { Input } from "../ui/input"; export default function IntComponent({ diff --git a/src/frontend/src/components/ui/accordion.tsx b/src/frontend/src/components/ui/accordion.tsx index c77130ea9..ce3f24186 100644 --- a/src/frontend/src/components/ui/accordion.tsx +++ b/src/frontend/src/components/ui/accordion.tsx @@ -27,7 +27,7 @@ const AccordionTrigger = React.forwardRef<
svg]:rotate-180", + "flex flex-1 cursor-pointer items-center justify-between py-4 text-sm font-medium transition-all [&[data-state=open]>svg]:rotate-180", className )} > diff --git a/src/frontend/src/components/ui/checkbox.tsx b/src/frontend/src/components/ui/checkbox.tsx index f7c6b7917..fa58b9a7f 100644 --- a/src/frontend/src/components/ui/checkbox.tsx +++ b/src/frontend/src/components/ui/checkbox.tsx @@ -26,7 +26,13 @@ const Checkbox = React.forwardRef< )); Checkbox.displayName = CheckboxPrimitive.Root.displayName; -const CheckBoxDiv = (({ className = "", checked }: {className?: string, checked?: boolean}) => ( +const CheckBoxDiv = ({ + className = "", + checked, +}: { + className?: string; + checked?: boolean; +}) => (
)}
-)); +); export { CheckBoxDiv, Checkbox }; diff --git a/src/frontend/src/contexts/index.tsx b/src/frontend/src/contexts/index.tsx index f6660e7fe..16f301dc5 100644 --- a/src/frontend/src/contexts/index.tsx +++ b/src/frontend/src/contexts/index.tsx @@ -13,8 +13,8 @@ export default function ContextWrapper({ children }: { children: ReactNode }) { - - {children} + + {children} diff --git a/src/frontend/src/modals/ApiModal/index.tsx b/src/frontend/src/modals/ApiModal/index.tsx index 861194ffe..81d6defee 100644 --- a/src/frontend/src/modals/ApiModal/index.tsx +++ b/src/frontend/src/modals/ApiModal/index.tsx @@ -18,7 +18,7 @@ import { LANGFLOW_SUPPORTED_TYPES, } from "../../constants/constants"; import { AuthContext } from "../../contexts/authContext"; -import useFlowsManagerStore from "../../stores/flowsManagerStore"; +import useFlowStore from "../../stores/flowStore"; import { TemplateVariableType } from "../../types/api"; import { tweakType, uniqueTweakType } from "../../types/components"; import { FlowType, NodeType } from "../../types/flow/index"; @@ -31,7 +31,6 @@ import { tabsArray, } from "../../utils/utils"; import BaseModal from "../baseModal"; -import useFlowStore from "../../stores/flowStore"; const ApiModal = forwardRef( ( @@ -50,9 +49,7 @@ const ApiModal = forwardRef( const tweak = useRef([]); const tweaksList = useRef([]); const [getTweak, setTweak] = useState([]); - const flowState = useFlowStore( - (state) => state.flowState - ); + const flowState = useFlowStore((state) => state.flowState); const pythonApiCode = getPythonApiCode( flow, autoLogin, diff --git a/src/frontend/src/modals/exportModal/index.tsx b/src/frontend/src/modals/exportModal/index.tsx index 658e523fb..cda886b0b 100644 --- a/src/frontend/src/modals/exportModal/index.tsx +++ b/src/frontend/src/modals/exportModal/index.tsx @@ -1,14 +1,14 @@ -import { ReactNode, forwardRef, useContext, useEffect, useState } from "react"; +import { ReactNode, forwardRef, useEffect, useState } from "react"; import EditFlowSettings from "../../components/EditFlowSettingsComponent"; import IconComponent from "../../components/genericIconComponent"; import { Button } from "../../components/ui/button"; import { Checkbox } from "../../components/ui/checkbox"; import { EXPORT_DIALOG_SUBTITLE } from "../../constants/constants"; import useAlertStore from "../../stores/alertStore"; -import { downloadFlow, removeApiKeys } from "../../utils/reactflowUtils"; -import BaseModal from "../baseModal"; import { useDarkStore } from "../../stores/darkStore"; import useFlowsManagerStore from "../../stores/flowsManagerStore"; +import { downloadFlow, removeApiKeys } from "../../utils/reactflowUtils"; +import BaseModal from "../baseModal"; const ExportModal = forwardRef( (props: { children: ReactNode }, ref): JSX.Element => { diff --git a/src/frontend/src/modals/flowSettingsModal/index.tsx b/src/frontend/src/modals/flowSettingsModal/index.tsx index 09c1f1ed5..fb880967d 100644 --- a/src/frontend/src/modals/flowSettingsModal/index.tsx +++ b/src/frontend/src/modals/flowSettingsModal/index.tsx @@ -1,12 +1,12 @@ -import { useContext, useEffect, useState } from "react"; +import { useEffect, useState } from "react"; import EditFlowSettings from "../../components/EditFlowSettingsComponent"; import IconComponent from "../../components/genericIconComponent"; import { Button } from "../../components/ui/button"; import { SETTINGS_DIALOG_SUBTITLE } from "../../constants/constants"; +import useFlowsManagerStore from "../../stores/flowsManagerStore"; import { FlowSettingsPropsType } from "../../types/components"; import { FlowType } from "../../types/flow"; import BaseModal from "../baseModal"; -import useFlowsManagerStore from "../../stores/flowsManagerStore"; export default function FlowSettingsModal({ open, diff --git a/src/frontend/src/modals/formModal/index.tsx b/src/frontend/src/modals/formModal/index.tsx index 68e32a325..c85e77a0d 100644 --- a/src/frontend/src/modals/formModal/index.tsx +++ b/src/frontend/src/modals/formModal/index.tsx @@ -25,8 +25,7 @@ import { AuthContext } from "../../contexts/authContext"; import { getBuildStatus } from "../../controllers/API"; import useAlertStore from "../../stores/alertStore"; import useFlowStore from "../../stores/flowStore"; -import useFlowsManagerStore from "../../stores/flowsManagerStore"; -import { FlowState, FlowsState } from "../../types/tabs"; +import { FlowState } from "../../types/tabs"; import { validateNodes } from "../../utils/reactflowUtils"; export default function FormModal({ @@ -40,12 +39,8 @@ export default function FormModal({ }): JSX.Element { const nodes = useFlowStore((state) => state.nodes); const edges = useFlowStore((state) => state.edges); - const flowState = useFlowStore( - (state) => state.flowState - ); - const setFlowState = useFlowStore( - (state) => state.setFlowState - ); + const flowState = useFlowStore((state) => state.flowState); + const setFlowState = useFlowStore((state) => state.setFlowState); const [chatValue, setChatValue] = useState(() => { try { if (!flowState) { @@ -468,72 +463,63 @@ export default function FormModal({
{flowState?.input_keys - ? Object.keys(flowState?.input_keys!).map( - (key, index) => ( -
- - - {key} - + ? Object.keys(flowState?.input_keys!).map((key, index) => ( +
+ + + {key} + -
{ - event.stopPropagation(); - }} - > - - handleOnCheckedChange(value, key) - } - size="small" - disabled={flowState.handle_keys!.some( - (t) => t === key - )} - /> -
-
- } - key={index} - keyValue={key} - > -
- {flowState?.handle_keys!.some( - (t) => t === key - ) && ( -
- Source: Component -
- )} - + > + + handleOnCheckedChange(value, key) + } + size="small" + disabled={flowState.handle_keys!.some( + (t) => t === key + )} + /> +
- -
- ) - ) + } + key={index} + keyValue={key} + > +
+ {flowState?.handle_keys!.some((t) => t === key) && ( +
+ Source: Component +
+ )} + +
+ +
+ )) : null} {flowState?.memory_keys!.map((key, index) => (
@@ -628,15 +614,11 @@ export default function FormModal({ setChatValue={(value) => { setChatValue(value); if (flowState && chatKey) { - setFlowState( - (old: FlowState | undefined) => { - let newFlowState = cloneDeep(old!); - newFlowState.input_keys![ - chatKey - ] = value; - return newFlowState; - } - ); + setFlowState((old: FlowState | undefined) => { + let newFlowState = cloneDeep(old!); + newFlowState.input_keys![chatKey] = value; + return newFlowState; + }); } }} inputRef={ref} diff --git a/src/frontend/src/modals/shareModal/index.tsx b/src/frontend/src/modals/shareModal/index.tsx index 438b1247c..a5697f2f3 100644 --- a/src/frontend/src/modals/shareModal/index.tsx +++ b/src/frontend/src/modals/shareModal/index.tsx @@ -1,5 +1,5 @@ import { Loader2 } from "lucide-react"; -import { ReactNode, useContext, useEffect, useMemo, useState } from "react"; +import { ReactNode, useEffect, useMemo, useState } from "react"; import EditFlowSettings from "../../components/EditFlowSettingsComponent"; import IconComponent from "../../components/genericIconComponent"; import { TagsSelector } from "../../components/tagsSelectorComponent"; @@ -12,6 +12,8 @@ import { updateFlowStore, } from "../../controllers/API"; import useAlertStore from "../../stores/alertStore"; +import { useDarkStore } from "../../stores/darkStore"; +import useFlowsManagerStore from "../../stores/flowsManagerStore"; import { useStoreStore } from "../../stores/storeStore"; import { FlowType } from "../../types/flow"; import { @@ -22,8 +24,6 @@ import { import { getTagsIds } from "../../utils/storeUtils"; import ConfirmationModal from "../ConfirmationModal"; import BaseModal from "../baseModal"; -import { useDarkStore } from "../../stores/darkStore"; -import useFlowsManagerStore from "../../stores/flowsManagerStore"; export default function ShareModal({ component, diff --git a/src/frontend/src/pages/AdminPage/index.tsx b/src/frontend/src/pages/AdminPage/index.tsx index e206c0b5d..15537d5a6 100644 --- a/src/frontend/src/pages/AdminPage/index.tsx +++ b/src/frontend/src/pages/AdminPage/index.tsx @@ -30,9 +30,9 @@ import { import ConfirmationModal from "../../modals/ConfirmationModal"; import UserManagementModal from "../../modals/UserManagementModal"; import useAlertStore from "../../stores/alertStore"; +import useFlowsManagerStore from "../../stores/flowsManagerStore"; import { Users } from "../../types/api"; import { UserInputType } from "../../types/components"; -import useFlowsManagerStore from "../../stores/flowsManagerStore"; export default function AdminPage() { const [inputValue, setInputValue] = useState(""); @@ -44,7 +44,9 @@ export default function AdminPage() { const setErrorData = useAlertStore((state) => state.setErrorData); const { userData } = useContext(AuthContext); const [totalRowsCount, setTotalRowsCount] = useState(0); - const setCurrentFlowId = useFlowsManagerStore((state) => state.setCurrentFlowId); + const setCurrentFlowId = useFlowsManagerStore( + (state) => state.setCurrentFlowId + ); // set null id useEffect(() => { @@ -333,9 +335,7 @@ export default function AdminPage() {
- +
@@ -367,9 +367,7 @@ export default function AdminPage() {
- +
diff --git a/src/frontend/src/pages/FlowPage/components/PageComponent/index.tsx b/src/frontend/src/pages/FlowPage/components/PageComponent/index.tsx index cd2a5214c..82c2c426a 100644 --- a/src/frontend/src/pages/FlowPage/components/PageComponent/index.tsx +++ b/src/frontend/src/pages/FlowPage/components/PageComponent/index.tsx @@ -18,6 +18,7 @@ import Loading from "../../../../components/ui/loading"; import useAlertStore from "../../../../stores/alertStore"; import useFlowStore from "../../../../stores/flowStore"; import useFlowsManagerStore from "../../../../stores/flowsManagerStore"; +import { useLocationStore } from "../../../../stores/locationStore"; import { useTypesStore } from "../../../../stores/typesStore"; import { APIClassType } from "../../../../types/api"; import { FlowType, NodeType, targetHandleType } from "../../../../types/flow"; @@ -33,7 +34,6 @@ import { cn, getRandomName, isWrappedWithClass } from "../../../../utils/utils"; import ConnectionLineComponent from "../ConnectionLineComponent"; import SelectionMenu from "../SelectionMenuComponent"; import ExtraSidebar from "../extraSidebarComponent"; -import { useLocationStore } from "../../../../stores/locationStore"; const nodeTypes = { genericNode: GenericNode, @@ -179,7 +179,7 @@ export default function Page({ nodes: flow?.data?.nodes ?? [], edges: flow?.data?.edges ?? [], viewport: flow?.data?.viewport ?? { zoom: 1, x: 0, y: 0 }, - }) + }); } // Clear the previous timeout diff --git a/src/frontend/src/pages/FlowPage/components/nodeToolbarComponent/index.tsx b/src/frontend/src/pages/FlowPage/components/nodeToolbarComponent/index.tsx index 97aaca9f3..10c984229 100644 --- a/src/frontend/src/pages/FlowPage/components/nodeToolbarComponent/index.tsx +++ b/src/frontend/src/pages/FlowPage/components/nodeToolbarComponent/index.tsx @@ -1,5 +1,5 @@ import { cloneDeep } from "lodash"; -import { useContext, useEffect, useState } from "react"; +import { useEffect, useState } from "react"; import ShadTooltip from "../../../../components/ShadTooltipComponent"; import IconComponent from "../../../../components/genericIconComponent"; import { @@ -11,7 +11,9 @@ import { import ConfirmationModal from "../../../../modals/ConfirmationModal"; import EditNodeModal from "../../../../modals/EditNodeModal"; import ShareModal from "../../../../modals/shareModal"; +import { useDarkStore } from "../../../../stores/darkStore"; import useFlowStore from "../../../../stores/flowStore"; +import useFlowsManagerStore from "../../../../stores/flowsManagerStore"; import { useStoreStore } from "../../../../stores/storeStore"; import { nodeToolbarPropsType } from "../../../../types/components"; import { FlowType } from "../../../../types/flow"; @@ -22,8 +24,6 @@ import { updateFlowPosition, } from "../../../../utils/reactflowUtils"; import { classNames } from "../../../../utils/utils"; -import { useDarkStore } from "../../../../stores/darkStore"; -import useFlowsManagerStore from "../../../../stores/flowsManagerStore"; export default function NodeToolbarComponent({ data, @@ -33,22 +33,21 @@ export default function NodeToolbarComponent({ numberOfHandles, showNode, }: nodeToolbarPropsType): JSX.Element { - const nodeLength = - Object.keys(data.node!.template).filter( - (templateField) => - templateField.charAt(0) !== "_" && - data.node?.template[templateField].show && - (data.node.template[templateField].type === "str" || - data.node.template[templateField].type === "bool" || - data.node.template[templateField].type === "float" || - data.node.template[templateField].type === "code" || - data.node.template[templateField].type === "prompt" || - data.node.template[templateField].type === "file" || - data.node.template[templateField].type === "Any" || - data.node.template[templateField].type === "int" || - data.node.template[templateField].type === "dict" || - data.node.template[templateField].type === "NestedDict") - ).length; + const nodeLength = Object.keys(data.node!.template).filter( + (templateField) => + templateField.charAt(0) !== "_" && + data.node?.template[templateField].show && + (data.node.template[templateField].type === "str" || + data.node.template[templateField].type === "bool" || + data.node.template[templateField].type === "float" || + data.node.template[templateField].type === "code" || + data.node.template[templateField].type === "prompt" || + data.node.template[templateField].type === "file" || + data.node.template[templateField].type === "Any" || + data.node.template[templateField].type === "int" || + data.node.template[templateField].type === "dict" || + data.node.template[templateField].type === "NestedDict") + ).length; const hasStore = useStoreStore((state) => state.hasStore); const hasApiKey = useStoreStore((state) => state.hasApiKey); diff --git a/src/frontend/src/pages/MainPage/components/components/index.tsx b/src/frontend/src/pages/MainPage/components/components/index.tsx index 5ee0821b2..6c48cc80e 100644 --- a/src/frontend/src/pages/MainPage/components/components/index.tsx +++ b/src/frontend/src/pages/MainPage/components/components/index.tsx @@ -1,4 +1,4 @@ -import { useContext, useEffect, useState } from "react"; +import { useEffect, useState } from "react"; import { Link, useNavigate } from "react-router-dom"; import PaginatorComponent from "../../../../components/PaginatorComponent"; import CollectionCardComponent from "../../../../components/cardComponent"; @@ -7,8 +7,8 @@ import IconComponent from "../../../../components/genericIconComponent"; import { SkeletonCardComponent } from "../../../../components/skeletonCardComponent"; import { Button } from "../../../../components/ui/button"; import useAlertStore from "../../../../stores/alertStore"; -import { FlowType } from "../../../../types/flow"; import useFlowsManagerStore from "../../../../stores/flowsManagerStore"; +import { FlowType } from "../../../../types/flow"; export default function ComponentsComponent({ is_component = true, diff --git a/src/frontend/src/pages/MainPage/index.tsx b/src/frontend/src/pages/MainPage/index.tsx index 74b3e224c..6e0c5cb55 100644 --- a/src/frontend/src/pages/MainPage/index.tsx +++ b/src/frontend/src/pages/MainPage/index.tsx @@ -1,5 +1,5 @@ import { Group, ToyBrick } from "lucide-react"; -import { useContext, useEffect } from "react"; +import { useEffect } from "react"; import { Outlet, useLocation, useNavigate } from "react-router-dom"; import DropdownButton from "../../components/DropdownButtonComponent"; import IconComponent from "../../components/genericIconComponent"; @@ -16,9 +16,7 @@ export default function HomePage(): JSX.Element { const setCurrentFlowId = useFlowsManagerStore( (state) => state.setCurrentFlowId ); - const uploadFlows = useFlowsManagerStore( - (state) => state.uploadFlows - ); + const uploadFlows = useFlowsManagerStore((state) => state.uploadFlows); const setSuccessData = useAlertStore((state) => state.setSuccessData); const setErrorData = useAlertStore((state) => state.setErrorData); const location = useLocation(); diff --git a/src/frontend/src/pages/ProfileSettingsPage/index.tsx b/src/frontend/src/pages/ProfileSettingsPage/index.tsx index f1e9d2f5d..6a5bc7b70 100644 --- a/src/frontend/src/pages/ProfileSettingsPage/index.tsx +++ b/src/frontend/src/pages/ProfileSettingsPage/index.tsx @@ -10,14 +10,16 @@ import { CONTROL_PATCH_USER_STATE } from "../../constants/constants"; import { AuthContext } from "../../contexts/authContext"; import { resetPassword, updateUser } from "../../controllers/API"; import useAlertStore from "../../stores/alertStore"; +import useFlowsManagerStore from "../../stores/flowsManagerStore"; import { inputHandlerEventType, patchUserInputStateType, } from "../../types/components"; import { gradients } from "../../utils/styleUtils"; -import useFlowsManagerStore from "../../stores/flowsManagerStore"; export default function ProfileSettingsPage(): JSX.Element { - const setCurrentFlowId = useFlowsManagerStore((state) => state.setCurrentFlowId); + const setCurrentFlowId = useFlowsManagerStore( + (state) => state.setCurrentFlowId + ); const [inputState, setInputState] = useState( CONTROL_PATCH_USER_STATE diff --git a/src/frontend/src/pages/StorePage/index.tsx b/src/frontend/src/pages/StorePage/index.tsx index c54893033..8321be91d 100644 --- a/src/frontend/src/pages/StorePage/index.tsx +++ b/src/frontend/src/pages/StorePage/index.tsx @@ -28,10 +28,10 @@ import { } from "../../controllers/API"; import StoreApiKeyModal from "../../modals/StoreApiKeyModal"; import useAlertStore from "../../stores/alertStore"; +import useFlowsManagerStore from "../../stores/flowsManagerStore"; import { useStoreStore } from "../../stores/storeStore"; import { storeComponent } from "../../types/store"; import { cn } from "../../utils/utils"; -import useFlowsManagerStore from "../../stores/flowsManagerStore"; export default function StorePage(): JSX.Element { const hasApiKey = useStoreStore((state) => state.hasApiKey); @@ -45,7 +45,9 @@ export default function StorePage(): JSX.Element { const { apiKey } = useContext(AuthContext); const setErrorData = useAlertStore((state) => state.setErrorData); - const setCurrentFlowId = useFlowsManagerStore((state) => state.setCurrentFlowId); + const setCurrentFlowId = useFlowsManagerStore( + (state) => state.setCurrentFlowId + ); const [loading, setLoading] = useState(true); const [loadingTags, setLoadingTags] = useState(true); const { id } = useParams(); diff --git a/src/frontend/src/pages/ViewPage/index.tsx b/src/frontend/src/pages/ViewPage/index.tsx index 3f5f2db98..2e6ac9bac 100644 --- a/src/frontend/src/pages/ViewPage/index.tsx +++ b/src/frontend/src/pages/ViewPage/index.tsx @@ -1,11 +1,13 @@ import { useEffect } from "react"; import { useParams } from "react-router-dom"; -import Page from "../FlowPage/components/PageComponent"; import useFlowsManagerStore from "../../stores/flowsManagerStore"; +import Page from "../FlowPage/components/PageComponent"; export default function ViewPage() { const currentFlow = useFlowsManagerStore((state) => state.currentFlow); - const setCurrentFlowId = useFlowsManagerStore((state) => state.setCurrentFlowId); + const setCurrentFlowId = useFlowsManagerStore( + (state) => state.setCurrentFlowId + ); const { id } = useParams(); // Set flow tab id @@ -15,9 +17,7 @@ export default function ViewPage() { return (
- {currentFlow && ( - - )} + {currentFlow && }
); } diff --git a/src/frontend/src/stores/flowStore.ts b/src/frontend/src/stores/flowStore.ts index 18bd40bea..09cf6e541 100644 --- a/src/frontend/src/stores/flowStore.ts +++ b/src/frontend/src/stores/flowStore.ts @@ -1,6 +1,5 @@ import { cloneDeep } from "lodash"; import { - Connection, Edge, EdgeChange, Node, @@ -33,11 +32,10 @@ const useFlowStore = create((set, get) => ({ nodes: [], edges: [], isBuilding: false, - isBuilt: false, + isBuilt: false, reactFlowInstance: null, lastCopiedSelection: null, - resetFlow: ({ nodes, edges, viewport }) => { set({ nodes, @@ -45,7 +43,6 @@ const useFlowStore = create((set, get) => ({ flowState: undefined, sseData: {}, isBuilt: false, - }); get().reactFlowInstance!.setViewport(viewport); }, @@ -60,11 +57,9 @@ const useFlowStore = create((set, get) => ({ }, setFlowState: (flowState) => { const newFlowState = - typeof flowState === "function" - ? flowState(get().flowState) - : flowState; - - if(newFlowState !== get().flowState){ + typeof flowState === "function" ? flowState(get().flowState) : flowState; + + if (newFlowState !== get().flowState) { set(() => ({ flowState: newFlowState, })); @@ -87,30 +82,39 @@ const useFlowStore = create((set, get) => ({ let newChange = typeof change === "function" ? change(get().nodes) : change; let newEdges = cleanEdges(newChange, get().edges); - set({ edges: newEdges, nodes: newChange, flowState: undefined, isBuilt: false, sseData: {} }); + set({ + edges: newEdges, + nodes: newChange, + flowState: undefined, + isBuilt: false, + sseData: {}, + }); - const flowsManager = useFlowsManagerStore.getState() + const flowsManager = useFlowsManagerStore.getState(); flowsManager.autoSaveCurrentFlow( - newChange, - newEdges, - get().reactFlowInstance?.getViewport() ?? { x: 0, y: 0, zoom: 1 } - ); - + newChange, + newEdges, + get().reactFlowInstance?.getViewport() ?? { x: 0, y: 0, zoom: 1 } + ); }, setEdges: (change) => { let newChange = typeof change === "function" ? change(get().edges) : change; - set({ edges: newChange, flowState: undefined, isBuilt: false, sseData: {} }); + set({ + edges: newChange, + flowState: undefined, + isBuilt: false, + sseData: {}, + }); - const flowsManager = useFlowsManagerStore.getState() + const flowsManager = useFlowsManagerStore.getState(); flowsManager.autoSaveCurrentFlow( - get().nodes, - newChange, - get().reactFlowInstance?.getViewport() ?? { x: 0, y: 0, zoom: 1 } - ); - + get().nodes, + newChange, + get().reactFlowInstance?.getViewport() ?? { x: 0, y: 0, zoom: 1 } + ); }, setNode: (id: string, change: Node | ((oldState: Node) => Node)) => { let newChange = diff --git a/src/frontend/src/stores/flowsManagerStore.ts b/src/frontend/src/stores/flowsManagerStore.ts index e89b2a00f..87050d547 100644 --- a/src/frontend/src/stores/flowsManagerStore.ts +++ b/src/frontend/src/stores/flowsManagerStore.ts @@ -9,8 +9,10 @@ import { uploadFlowsToDatabase, } from "../controllers/API"; import { FlowType, NodeDataType } from "../types/flow"; -import { FlowState } from "../types/tabs"; -import { FlowsManagerStoreType, UseUndoRedoOptions } from "../types/zustand/flowsManager"; +import { + FlowsManagerStoreType, + UseUndoRedoOptions, +} from "../types/zustand/flowsManager"; import { addVersionToDuplicates, createFlowComponent, @@ -333,9 +335,11 @@ const useFlowsManagerStore = create((set, get) => ({ JSON.stringify(past[currentFlowId][pastLength - 1]) !== JSON.stringify(newState) ) { - past[currentFlowId] = past[currentFlowId] - .slice(pastLength - defaultOptions.maxHistorySize + 1, pastLength) - + past[currentFlowId] = past[currentFlowId].slice( + pastLength - defaultOptions.maxHistorySize + 1, + pastLength + ); + past[currentFlowId].push(newState); } else { past[currentFlowId] = [newState]; @@ -352,8 +356,11 @@ const useFlowsManagerStore = create((set, get) => ({ if (pastState) { past[currentFlowId] = past[currentFlowId].slice(0, pastLength - 1); - if(!future[currentFlowId]) future[currentFlowId] = []; - future[currentFlowId].push({ nodes: newState.nodes, edges: newState.edges }); + if (!future[currentFlowId]) future[currentFlowId] = []; + future[currentFlowId].push({ + nodes: newState.nodes, + edges: newState.edges, + }); newState.setNodes(pastState.nodes); newState.setEdges(pastState.edges); @@ -368,8 +375,11 @@ const useFlowsManagerStore = create((set, get) => ({ if (futureState) { future[currentFlowId] = future[currentFlowId].slice(0, futureLength - 1); - if(!past[currentFlowId]) past[currentFlowId] = []; - past[currentFlowId].push({ nodes: newState.nodes, edges: newState.edges }); + if (!past[currentFlowId]) past[currentFlowId] = []; + past[currentFlowId].push({ + nodes: newState.nodes, + edges: newState.edges, + }); newState.setNodes(futureState.nodes); newState.setEdges(futureState.edges); diff --git a/src/frontend/src/stores/locationStore.tsx b/src/frontend/src/stores/locationStore.tsx index 247304712..74445d3f3 100644 --- a/src/frontend/src/stores/locationStore.tsx +++ b/src/frontend/src/stores/locationStore.tsx @@ -2,27 +2,27 @@ import { create } from "zustand"; import { LocationStoreType } from "../types/zustand/location"; export const useLocationStore = create((set, get) => ({ - current: window.location.pathname.replace(/\/$/g, "").split("/"), - isStackedOpen: - window.innerWidth > 1024 && window.location.pathname.split("/")[1] - ? true - : false, - setCurrent: (newState) => { - set({ current: newState }); - }, - setIsStackedOpen: (newState) => { - set({ isStackedOpen: newState }); - }, - showSideBar: window.location.pathname.split("/")[1] ? true : false, - setShowSideBar: (newState) => { - set({ showSideBar: newState }); - }, - extraNavigation: { title: "" }, - setExtraNavigation: (newState) => { - set({ extraNavigation: newState }); - }, - extraComponent: <>, - setExtraComponent: (newState) => { - set({ extraComponent: newState }); - }, + current: window.location.pathname.replace(/\/$/g, "").split("/"), + isStackedOpen: + window.innerWidth > 1024 && window.location.pathname.split("/")[1] + ? true + : false, + setCurrent: (newState) => { + set({ current: newState }); + }, + setIsStackedOpen: (newState) => { + set({ isStackedOpen: newState }); + }, + showSideBar: window.location.pathname.split("/")[1] ? true : false, + setShowSideBar: (newState) => { + set({ showSideBar: newState }); + }, + extraNavigation: { title: "" }, + setExtraNavigation: (newState) => { + set({ extraNavigation: newState }); + }, + extraComponent: <>, + setExtraComponent: (newState) => { + set({ extraComponent: newState }); + }, })); diff --git a/src/frontend/src/types/components/index.ts b/src/frontend/src/types/components/index.ts index d604c8812..0548981ec 100644 --- a/src/frontend/src/types/components/index.ts +++ b/src/frontend/src/types/components/index.ts @@ -4,7 +4,6 @@ import { APIClassType, APITemplateType, TemplateVariableType } from "../api"; import { ChatMessageType } from "../chat"; import { FlowStyleType, FlowType, NodeDataType, NodeType } from "../flow/index"; import { sourceHandleType, targetHandleType } from "./../flow/index"; -import { TypesStoreType } from "../zustand/types"; export type InputComponentType = { autoFocus?: boolean; onBlur?: (event: React.FocusEvent) => void; @@ -263,7 +262,6 @@ export type LoadingComponentProps = { export type ContentProps = { children: ReactNode; - }; export type HeaderProps = { children: ReactNode; description: string }; export type TriggerProps = { @@ -305,10 +303,9 @@ export type ConfirmationModalType = { modalContentTitle?: string; cancelText: string; confirmationText: string; - children: [ - React.ReactElement, - React.ReactElement - ] | React.ReactElement; + children: + | [React.ReactElement, React.ReactElement] + | React.ReactElement; icon: string; data?: any; index?: number; diff --git a/src/frontend/src/types/zustand/flow/index.ts b/src/frontend/src/types/zustand/flow/index.ts index a4ded1642..ffaecf0d5 100644 --- a/src/frontend/src/types/zustand/flow/index.ts +++ b/src/frontend/src/types/zustand/flow/index.ts @@ -1,7 +1,6 @@ import { Edge, Node, - OnConnect, OnEdgesChange, OnNodesChange, ReactFlowInstance, @@ -14,11 +13,20 @@ export type FlowStoreType = { sseData: object; isBuilding: boolean; setIsBuilding: (isBuilding: boolean) => void; - resetFlow: (flow: {nodes: Node[], edges: Edge[], viewport: Viewport}) => void; + resetFlow: (flow: { + nodes: Node[]; + edges: Edge[]; + viewport: Viewport; + }) => void; reactFlowInstance: ReactFlowInstance | null; setReactFlowInstance: (newState: ReactFlowInstance) => void; flowState: FlowState | undefined; - setFlowState: (state: FlowState | undefined | ((oldState: FlowState | undefined) => FlowState)) => void; + setFlowState: ( + state: + | FlowState + | undefined + | ((oldState: FlowState | undefined) => FlowState) + ) => void; nodes: Node[]; edges: Edge[]; onNodesChange: OnNodesChange; @@ -39,5 +47,4 @@ export type FlowStoreType = { ) => void; isBuilt: boolean; setIsBuilt: (isBuilt: boolean) => void; - }; diff --git a/src/frontend/src/types/zustand/flowsManager/index.ts b/src/frontend/src/types/zustand/flowsManager/index.ts index a596ee724..2a20c20d8 100644 --- a/src/frontend/src/types/zustand/flowsManager/index.ts +++ b/src/frontend/src/types/zustand/flowsManager/index.ts @@ -1,6 +1,5 @@ -import { Node, Edge, Viewport, XYPosition } from "reactflow"; +import { Edge, Node, Viewport, XYPosition } from "reactflow"; import { FlowType } from "../../flow"; -import { FlowState, FlowsState } from "../../tabs"; export type FlowsManagerStoreType = { flows: Array; @@ -12,13 +11,35 @@ export type FlowsManagerStoreType = { setIsLoading: (isLoading: boolean) => void; refreshFlows: () => Promise; saveFlow: (flow: FlowType, silent?: boolean) => Promise; - autoSaveCurrentFlow: (nodes: Node[], edges: Edge[], viewport: Viewport) => void; + autoSaveCurrentFlow: ( + nodes: Node[], + edges: Edge[], + viewport: Viewport + ) => void; uploadFlows: () => Promise; - uploadFlow: ({newProject, file, isComponent, position}: {newProject: boolean, file?: File, isComponent?: boolean, position?: XYPosition}) => Promise; - addFlow: (newProject: boolean, flow?: FlowType, override?: boolean, position?: XYPosition) => Promise; + uploadFlow: ({ + newProject, + file, + isComponent, + position, + }: { + newProject: boolean; + file?: File; + isComponent?: boolean; + position?: XYPosition; + }) => Promise; + addFlow: ( + newProject: boolean, + flow?: FlowType, + override?: boolean, + position?: XYPosition + ) => Promise; deleteComponent: (key: string) => Promise; removeFlow: (id: string) => Promise; - saveComponent: (component: any, override: boolean) => Promise; + saveComponent: ( + component: any, + override: boolean + ) => Promise; undo: () => void; redo: () => void; takeSnapshot: () => void; @@ -27,4 +48,4 @@ export type FlowsManagerStoreType = { export type UseUndoRedoOptions = { maxHistorySize: number; enableShortcuts: boolean; -}; \ No newline at end of file +}; diff --git a/src/frontend/src/types/zustand/types/index.ts b/src/frontend/src/types/zustand/types/index.ts index 904e3058e..f18d8b22e 100644 --- a/src/frontend/src/types/zustand/types/index.ts +++ b/src/frontend/src/types/zustand/types/index.ts @@ -1,13 +1,13 @@ import { APIClassType, APIDataType } from "../../api"; export type TypesStoreType = { - types: { [char: string]: string }; - setTypes: (newState: {}) => void; - templates: { [char: string]: APIClassType }; - setTemplates: (newState: {}) => void; - data: APIDataType; - setData: (newState: {}) => void; - getTypes: () => Promise; - setFilterEdge: (newState) => void; - getFilterEdge: any[]; -} \ No newline at end of file + types: { [char: string]: string }; + setTypes: (newState: {}) => void; + templates: { [char: string]: APIClassType }; + setTemplates: (newState: {}) => void; + data: APIDataType; + setData: (newState: {}) => void; + getTypes: () => Promise; + setFilterEdge: (newState) => void; + getFilterEdge: any[]; +}; diff --git a/src/frontend/src/utils/reactflowUtils.ts b/src/frontend/src/utils/reactflowUtils.ts index e382267e9..7c8a0b7c0 100644 --- a/src/frontend/src/utils/reactflowUtils.ts +++ b/src/frontend/src/utils/reactflowUtils.ts @@ -415,7 +415,9 @@ export function handleKeyDown( } } -export function handleOnlyIntegerInput(event: React.KeyboardEvent) { +export function handleOnlyIntegerInput( + event: React.KeyboardEvent +) { if ( event.key === "." || event.key === "-" || diff --git a/src/frontend/src/utils/utils.ts b/src/frontend/src/utils/utils.ts index 86539634c..3d8c92eec 100644 --- a/src/frontend/src/utils/utils.ts +++ b/src/frontend/src/utils/utils.ts @@ -299,13 +299,8 @@ export function buildTweakObject(tweak: tweakType) { export function getChatInputField(flow: FlowType, flowState?: FlowState) { let chat_input_field = "text"; - if ( - flowState && - flowState.input_keys - ) { - chat_input_field = Object.keys( - flowState.input_keys! - )[0]; + if (flowState && flowState.input_keys) { + chat_input_field = Object.keys(flowState.input_keys!)[0]; } return chat_input_field; }