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 + + + Create a new variable + + + + + Variable name + + + + Variable Value + + + + + + Save variable + + + ); +} diff --git a/src/frontend/src/pages/globalVariablesPage/index.tsx b/src/frontend/src/pages/globalVariablesPage/index.tsx new file mode 100644 index 000000000..c70ec8a02 --- /dev/null +++ b/src/frontend/src/pages/globalVariablesPage/index.tsx @@ -0,0 +1,26 @@ +import PageLayout from "../../components/pageLayout"; +import { useGlobalVariablesStore } from "../../stores/globalVariables"; +import AddNewVariableButton from "./components/addNewVariableButton"; + +export default function GlobalVariablesPage() { + const globalVariables = useGlobalVariablesStore( + (state) => state.globalVariables + ); + return ( + + {Object.keys(globalVariables).length > 0 ? ( + + ) : ( + + + create your first variable + + + + )} + + ); +} diff --git a/src/frontend/src/routes.tsx b/src/frontend/src/routes.tsx index b48e5147d..0c3cd1ac8 100644 --- a/src/frontend/src/routes.tsx +++ b/src/frontend/src/routes.tsx @@ -15,6 +15,7 @@ import ProfileSettingsPage from "./pages/ProfileSettingsPage"; import StorePage from "./pages/StorePage"; import ViewPage from "./pages/ViewPage"; import DeleteAccountPage from "./pages/deleteAccountPage"; +import GlobalVariablesPage from "./pages/globalVariablesPage"; import LoginPage from "./pages/loginPage"; import SignUp from "./pages/signUpPage"; @@ -153,6 +154,14 @@ const Router = () => { } > + + + + } + > ); }; diff --git a/src/frontend/src/stores/globalVariables.ts b/src/frontend/src/stores/globalVariables.ts index 69a72f677..c71986090 100644 --- a/src/frontend/src/stores/globalVariables.ts +++ b/src/frontend/src/stores/globalVariables.ts @@ -1,9 +1,15 @@ import { create } from "zustand"; import { GlobalVariablesStore } from "../types/zustand/globalVariables"; -const useGlobalVariablesStore = create((set, get) => ({ - globalVariables: [], - setGlobalVariables: (variables) => { - set({ globalVariables: variables }); - }, -})); +export const useGlobalVariablesStore = create( + (set, get) => ({ + globalVariablesEntries: [], + globalVariables: {}, + setGlobalVariables: (variables) => { + set({ + globalVariables: variables, + globalVariablesEntries: Object.keys(variables), + }); + }, + }) +); diff --git a/src/frontend/src/types/zustand/globalVariables/index.ts b/src/frontend/src/types/zustand/globalVariables/index.ts index 51f45a85c..df9c29d02 100644 --- a/src/frontend/src/types/zustand/globalVariables/index.ts +++ b/src/frontend/src/types/zustand/globalVariables/index.ts @@ -1,4 +1,5 @@ export type GlobalVariablesStore = { - globalVariables: Array; - setGlobalVariables: (variables: Array) => void; + globalVariablesEntries: Array; + globalVariables: { [key: string]: string }; + setGlobalVariables: (variables: { [key: string]: string }) => void; };
create your first variable