Skip to content

Commit

Permalink
Main page layout of the SRE bot (#266)
Browse files Browse the repository at this point in the history
* Committing google app frontend

* Adding backend and frontend url as env. variables

* Additional changes to the frontedn

* Adding static files

* Reverting using env for frontend/backend

* Adding a catch all route

* Adding final Google login elements

* Adding env variables to the ci_code action tests

* Update App.js

Removing comments.

* Removing the SRE bot logo image from App.js

* Committing initial dashboard

* Added dashboard components

* Adding changes to the dashboard

* Adding logout button to the sidebar

* Adding files to make dashboard

* Changing the names of the topbar and sidebar components

* Linting code
  • Loading branch information
sylviamclaughlin authored Sep 19, 2023
1 parent 4ea1a3e commit 4008f0e
Show file tree
Hide file tree
Showing 27 changed files with 4,556 additions and 180 deletions.
6 changes: 6 additions & 0 deletions app/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion app/server/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ async def auth(request: Request):
user_data = access_token.get("userinfo")
if user_data:
request.session["user"] = dict(user_data)
return RedirectResponse(url="/home")
return RedirectResponse(url="/")


# User route. Returns the user's first name that is currently logged into the application
Expand Down
2,161 changes: 2,066 additions & 95 deletions frontend/package-lock.json

Large diffs are not rendered by default.

18 changes: 16 additions & 2 deletions frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,29 @@
"version": "0.1.0",
"private": true,
"dependencies": {
"@emotion/react": "^11.11.1",
"@emotion/styled": "^11.11.0",
"@mui/icons-material": "^5.14.9",
"@mui/material": "^5.14.9",
"@mui/x-data-grid": "^6.14.0",
"@nivo/bar": "^0.83.0",
"@nivo/core": "^0.83.0",
"@nivo/geo": "^0.83.0",
"@nivo/line": "^0.83.0",
"@nivo/pie": "^0.83.0",
"@testing-library/jest-dom": "^5.17.0",
"@testing-library/react": "^13.4.0",
"@testing-library/user-event": "^13.5.0",
"axios": "^1.5.0",
"formik": "^2.4.4",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-router-dom": "^6.15.0",
"react-pro-sidebar": "^0.7.1",
"react-router-dom": "^6.16.0",
"react-scripts": "5.0.1",
"web-vitals": "^2.1.4"
"recharts": "^2.8.0",
"web-vitals": "^2.1.4",
"yup": "^1.2.0"
},
"scripts": {
"start": "react-scripts start",
Expand Down
Binary file added frontend/public/static/favicon.ico
Binary file not shown.
Binary file added frontend/public/static/sre_bot_logo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
14 changes: 0 additions & 14 deletions frontend/src/App.css

This file was deleted.

179 changes: 155 additions & 24 deletions frontend/src/App.js
Original file line number Diff line number Diff line change
@@ -1,29 +1,160 @@
import './App.css';
import sre_bot_logo from './sre_bot_logo.png';


import {BrowserRouter, Routes, Route} from 'react-router-dom';
import { CssBaseline, ThemeProvider } from "@mui/material";
import { BrowserRouter, Routes, Route } from "react-router-dom";
import { ColorModeContext, useMode } from "./theme";
import { React, useState, useEffect } from "react";
import LandingPage from './pages/LandingPage.js';
import HomePage from './pages/HomePage.js';
import Topmenu from "./scenes/global/Topmenu";
import Dashboard from "./scenes/dashboard";
import Sidemenu from "./scenes/global/Sidemenu";
import Webhooks from './scenes/webhooks';
import Incident from './scenes/incident';
import IncidentHistory from './scenes/incident_history';
import Geolocate from './scenes/geolocate';
import Faq from './scenes/faq';

/**
* The main component of the application.
*/
function App() {
return (
<div className="hero min-h-screen bg-base-200">

<div className="hero-content flex-col lg:flex-row">

// Get the current theme and color mode
const [theme, colorMode] = useMode();

// Set the initial state of the Sidemenu
const [isSidemenu, setIsSidemenu] = useState(true);

/**
* Custom hook to get user data from the server.
* @returns {boolean} Whether the user is authenticated or not.
*/
const useUserData = () => {
const [userData, setUserData] = useState(null);

useEffect(() => {
// Make a GET request to the "/user" endpoint
fetch('/user')
.then(response => {
// Check if the response status code is OK (200)
if (!response.ok) {
throw new Error('Network response was not ok');
}
// Parse the JSON response
return response.json();
})
.then(data => {
// Handle the JSON data from the response
setUserData(data);
})
.catch(error => {
console.error('There was a problem with the fetch operation:', error);
});
}, []);

// if the user is not logged in, then return false. Otherwise, return true
if (userData && userData.error === "Not logged in") {
return false;
}
return true;
};

// Check if the user is authenticated
const isAuthenticated = useUserData();

<img src = {sre_bot_logo} alt="sre_bot"></img>
<div>
// Render the application. If the user is authenticated, show the Sidemenu, Topmenu and menu items.
// Otherwise (ie user is not logged in), show the landing page where an user can log in.
return (
<BrowserRouter>
<Routes>
<Route path="/" element={<LandingPage/>} />
<Route path="/home" element={<HomePage/>} />
</Routes>
</BrowserRouter>
</div>
</div>
</div>
);
}

export default App;
<Routes>
{isAuthenticated ? (
<>
<Route path="/" element={
<ColorModeContext.Provider value={colorMode}>
<ThemeProvider theme={theme}>
<CssBaseline />
<div className="app">
<Sidemenu isSidemenu={isSidemenu} />
<main className="content">
<Topmenu setIsSidemenu={setIsSidemenu} />
<Dashboard/>
</main>
</div>
</ThemeProvider>
</ColorModeContext.Provider>
} />
<Route path="/webhooks" element={
<ColorModeContext.Provider value={colorMode}>
<ThemeProvider theme={theme}>
<CssBaseline />
<div className="app">
<Sidemenu isSidemenu={isSidemenu} />
<main className="content">
<Topmenu setIsSidemenu={setIsSidemenu} />
<Webhooks/>
</main>
</div>
</ThemeProvider>
</ColorModeContext.Provider>} />
<Route path="/incident" element={
<ColorModeContext.Provider value={colorMode}>
<ThemeProvider theme={theme}>
<CssBaseline />
<div className="app">
<Sidemenu isSidemenu={isSidemenu} />
<main className="content">
<Topmenu setIsSidemenu={setIsSidemenu} />
<Incident/>
</main>
</div>
</ThemeProvider>
</ColorModeContext.Provider>} />
<Route path="/incident_history" element={
<ColorModeContext.Provider value={colorMode}>
<ThemeProvider theme={theme}>
<CssBaseline />
<div className="app">
<Sidemenu isSidemenu={isSidemenu} />
<main className="content">
<Topmenu setIsSidemenu={setIsSidemenu} />
<IncidentHistory/>
</main>
</div>
</ThemeProvider>
</ColorModeContext.Provider>} />
<Route path="/geolocate" element={
<ColorModeContext.Provider value={colorMode}>
<ThemeProvider theme={theme}>
<CssBaseline />
<div className="app">
<Sidemenu isSidemenu={isSidemenu} />
<main className="content">
<Topmenu setIsSidemenu={setIsSidemenu} />
<Geolocate/>
</main>
</div>
</ThemeProvider>
</ColorModeContext.Provider>} />
<Route path="/faq" element={
<ColorModeContext.Provider value={colorMode}>
<ThemeProvider theme={theme}>
<CssBaseline />
<div className="app">
<Sidemenu isSidemenu={isSidemenu} />
<main className="content">
<Topmenu setIsSidemenu={setIsSidemenu} />
<Faq/>
</main>
</div>
</ThemeProvider>
</ColorModeContext.Provider>} />
<Route path="/logout" element = {<LandingPage/>} />
</>
) : (
<Route path="/" element={<LandingPage />} />
)}
</Routes>
</BrowserRouter>
);
}


export default App;
8 changes: 0 additions & 8 deletions frontend/src/App.test.js

This file was deleted.

24 changes: 24 additions & 0 deletions frontend/src/components/Header.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { Typography, Box, useTheme } from "@mui/material";
import { tokens } from "../theme";

const Header = ({ title, subtitle }) => {
const theme = useTheme();
const colors = tokens(theme.palette.mode);
return (
<Box mb="30px">
<Typography
variant="h2"
color={colors.grey[100]}
fontWeight="bold"
sx={{ m: "0 0 5px 0" }}
>
{title}
</Typography>
<Typography variant="h5" color={colors.greenAccent[400]}>
{subtitle}
</Typography>
</Box>
);
};

export default Header;
44 changes: 34 additions & 10 deletions frontend/src/index.css
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,40 @@
@tailwind components;
@tailwind utilities;

body {
margin: 0;
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', 'Oxygen',
'Ubuntu', 'Cantarell', 'Fira Sans', 'Droid Sans', 'Helvetica Neue',
sans-serif;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
/* @import url('https://fonts.googleapis.com/css2?family=Source+Serif+4:opsz,[email protected],400;8..60,600;8..60,700&display=swap'); */
@import url('https://fonts.googleapis.com/css2?family=Lato:wght@400;700;900&family=Source+Serif+4:opsz,[email protected],400;8..60,600;8..60,700&display=swap');

html,
body,
#root,
.app,
.content {
height: 100%;
width: 100%;
/* font-family: 'Source Serif 4', sans-serif; */
font-family: 'Lato', sans-serif;
}

.app {
display: flex;
position: relative;
}

::-webkit-scrollbar {
width: 10px;
}

/* Track */
::-webkit-scrollbar-track {
background: #e0e0e0;
}

code {
font-family: source-code-pro, Menlo, Monaco, Consolas, 'Courier New',
monospace;

/* Handle */
::-webkit-scrollbar-thumb {
background: #888;
}
/* Handle on hover */
::-webkit-scrollbar-thumb:hover {
background: #555;
}
13 changes: 6 additions & 7 deletions frontend/src/index.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
/**
* Entry point of the React application.
* Renders the <App /> component inside the root element of the HTML document.
*/
import React from 'react';
import ReactDOM from 'react-dom/client';
import './index.css';
import App from './App';
import reportWebVitals from './reportWebVitals';


const root = ReactDOM.createRoot(document.getElementById('root'));
root.render(
<React.StrictMode>
<App />
</React.StrictMode>
);

// If you want to start measuring performance in your app, pass a function
// to log results (for example: reportWebVitals(console.log))
// or send to an analytics endpoint. Learn more: https://bit.ly/CRA-vitals
reportWebVitals();
);
16 changes: 15 additions & 1 deletion frontend/src/pages/LandingPage.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,24 @@
import React, {} from 'react';
import sre_bot_logo from '../sre_bot_logo.png';

// Landing page. This is the initial screen that the user sees when they visit the site, prompting them to log in.
// You can login with a google account tied only to the organization

export default function LoginPage() {

// Google login function to handling logging in.
const googleLogin = () => {
var login_url = "/login"
console.log("login_url", login_url)
window.location.href = login_url
}
return (
<div className="hero min-h-screen bg-base-200">

<div className="hero-content flex-col lg:flex-row">

<img src = {sre_bot_logo} alt="sre_bot"></img>
<div>
<section>
<div>
<h1 className="text-5xl font-bold">Welcome!</h1>
Expand All @@ -17,5 +28,8 @@ export default function LoginPage() {
<button onClick={googleLogin} className="btn btn-xs sm:btn-sm md:btn-md lg:btn-lg border-zinc-950">Login with Google</button>
</div>
</section>
);
</div>
</div>
</div>
);
}
Loading

0 comments on commit 4008f0e

Please sign in to comment.