From e4e5b061851439a7e3e26a0897bfd7b78f423d38 Mon Sep 17 00:00:00 2001 From: anovazzi1 Date: Mon, 5 Feb 2024 15:47:31 -0300 Subject: [PATCH] fix(App.tsx): import getGlobalVariables function from API controller to fix missing import error feat(App.tsx): add support for fetching global variables and setting them in the global variables store feat(App.tsx): add useGlobalVariablesStore hook to access and set global variables in the component feat(addNewVariableButton.tsx): create a new component for adding a new variable feat(GlobalVariablesPage.tsx): create GlobalVariablesPage component to display and manage global variables feat(routes.tsx): add route for GlobalVariablesPage component feat(globalVariables.ts): update globalVariables store to include globalVariablesEntries array and modify setGlobalVariables function to set both globalVariables and globalVariablesEntries feat(index.ts): add types for globalVariables store --- src/frontend/src/App.tsx | 9 ++++- src/frontend/src/controllers/API/index.ts | 2 +- .../components/addNewVariableButton.tsx | 38 +++++++++++++++++++ .../src/pages/globalVariablesPage/index.tsx | 26 +++++++++++++ src/frontend/src/routes.tsx | 9 +++++ src/frontend/src/stores/globalVariables.ts | 18 ++++++--- .../types/zustand/globalVariables/index.ts | 5 ++- 7 files changed, 97 insertions(+), 10 deletions(-) create mode 100644 src/frontend/src/pages/globalVariablesPage/components/addNewVariableButton.tsx create mode 100644 src/frontend/src/pages/globalVariablesPage/index.tsx diff --git a/src/frontend/src/App.tsx b/src/frontend/src/App.tsx index d126f5fa9..96cf5817a 100644 --- a/src/frontend/src/App.tsx +++ b/src/frontend/src/App.tsx @@ -15,11 +15,12 @@ import { FETCH_ERROR_MESSAGE, } from "./constants/constants"; import { AuthContext } from "./contexts/authContext"; -import { getHealth } from "./controllers/API"; +import { getGlobalVariables, getHealth } from "./controllers/API"; import Router from "./routes"; import useAlertStore from "./stores/alertStore"; import { useDarkStore } from "./stores/darkStore"; import useFlowsManagerStore from "./stores/flowsManagerStore"; +import { useGlobalVariablesStore } from "./stores/globalVariables"; import { useTypesStore } from "./stores/typesStore"; export default function App() { @@ -124,6 +125,9 @@ export default function App() { const getTypes = useTypesStore((state) => state.getTypes); const refreshVersion = useDarkStore((state) => state.refreshVersion); const refreshStars = useDarkStore((state) => state.refreshStars); + const setGlobalVariables = useGlobalVariablesStore( + (state) => state.setGlobalVariables + ); useEffect(() => { refreshStars(); @@ -135,6 +139,9 @@ export default function App() { getTypes().then(() => { refreshFlows(); }); + getGlobalVariables().then((res) => { + setGlobalVariables(res); + }); } }, [isAuthenticated]); diff --git a/src/frontend/src/controllers/API/index.ts b/src/frontend/src/controllers/API/index.ts index 88bf23222..970500efe 100644 --- a/src/frontend/src/controllers/API/index.ts +++ b/src/frontend/src/controllers/API/index.ts @@ -851,7 +851,7 @@ export async function requestLogout() { } } -export async function getGlobalVariables() { +export async function getGlobalVariables(): Promise<{ [key: string]: string }> { // mocked for now but will eventually be a real API call const globalVariables = window.sessionStorage.getItem("globalVariables"); return globalVariables ? JSON.parse(globalVariables) : {}; diff --git a/src/frontend/src/pages/globalVariablesPage/components/addNewVariableButton.tsx b/src/frontend/src/pages/globalVariablesPage/components/addNewVariableButton.tsx new file mode 100644 index 000000000..59e86fe3e --- /dev/null +++ b/src/frontend/src/pages/globalVariablesPage/components/addNewVariableButton.tsx @@ -0,0 +1,38 @@ +import { Button } from "../../../components/ui/button"; +import { Input } from "../../../components/ui/input"; +import { Label } from "../../../components/ui/label"; +import { Textarea } from "../../../components/ui/textarea"; +import BaseModal from "../../../modals/baseModal"; + +//TODO IMPLEMENT FORM LOGIC + +export default function AddNewVariableButton(): JSX.Element { + function handleSaveVariable() {} + return ( + + + Create a new Variable + + + + + +
+
+ + +
+
+ +