Skip to content
This repository has been archived by the owner on Jul 2, 2024. It is now read-only.

Commit

Permalink
feat(webui): show current project in the navbar
Browse files Browse the repository at this point in the history
  • Loading branch information
tsirysndr committed Jun 4, 2023
1 parent 873e59b commit ab5dd67
Show file tree
Hide file tree
Showing 23 changed files with 313 additions and 21 deletions.
9 changes: 6 additions & 3 deletions crates/webui/webui/build/asset-manifest.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"files": {
"main.css": "/static/css/main.61403641.css",
"main.js": "/static/js/main.650773b9.js",
"main.js": "/static/js/main.1a5e8dec.js",
"static/js/787.cb4325f6.chunk.js": "/static/js/787.cb4325f6.chunk.js",
"static/media/ubuntu-all-400-normal.woff": "/static/media/ubuntu-all-400-normal.8629f83ad2c45e75a914.woff",
"static/media/RockfordSans-ExtraBold.otf": "/static/media/RockfordSans-ExtraBold.1513e8fd97078bfb7708.otf",
Expand All @@ -22,17 +22,20 @@
"static/media/bun.svg": "/static/media/bun.4f94828236634ff78a332e705f09fc79.svg",
"static/media/mysql.svg": "/static/media/mysql.0697e026464104aea8919845703174b9.svg",
"static/media/redis.svg": "/static/media/redis.ac3daad2b9f9bf478a2bf49dbb4c3d4c.svg",
"static/media/kafka.svg": "/static/media/kafka.e7d8fe1d18b91a8871b9c66cf80d4ca1.svg",
"static/media/nodejs.svg": "/static/media/nodejs.7ca28bcc5b19ce40dfc23043cfb31f27.svg",
"static/media/mongodb.svg": "/static/media/mongodb.9f73d8c9195613a2ef106c244c01e6e7.svg",
"static/media/fresh.svg": "/static/media/fresh.75b33975f7b385b15fc9d97346088431.svg",
"static/media/rabbitmq.svg": "/static/media/rabbitmq.c9f156289726ee6cbe5d77e85fa38346.svg",
"index.html": "/index.html",
"static/media/wasm.svg": "/static/media/wasm.d2b14cf4214ab0d03cbe5738090c6c22.svg",
"static/media/nats.svg": "/static/media/nats.5ee42c5209de5b1699f3ca8886f11379.svg",
"main.61403641.css.map": "/static/css/main.61403641.css.map",
"main.650773b9.js.map": "/static/js/main.650773b9.js.map",
"main.1a5e8dec.js.map": "/static/js/main.1a5e8dec.js.map",
"787.cb4325f6.chunk.js.map": "/static/js/787.cb4325f6.chunk.js.map"
},
"entrypoints": [
"static/css/main.61403641.css",
"static/js/main.650773b9.js"
"static/js/main.1a5e8dec.js"
]
}
2 changes: 1 addition & 1 deletion crates/webui/webui/build/index.html
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<!doctype html><html lang="en"><head><meta charset="utf-8"/><link rel="icon" href="/favicon.ico"/><meta name="viewport" content="width=device-width,initial-scale=1"/><meta name="theme-color" content="#630be2"/><meta name="description" content="Web site created using create-react-app"/><link rel="apple-touch-icon" href="/logo192.png"/><link rel="manifest" href="/manifest.json"/><title>Superviseur Dashboard</title><script defer="defer" src="/static/js/main.650773b9.js"></script><link href="/static/css/main.61403641.css" rel="stylesheet"></head><body><noscript>You need to enable JavaScript to run this app.</noscript><div id="root"></div></body></html>
<!doctype html><html lang="en"><head><meta charset="utf-8"/><link rel="icon" href="/favicon.ico"/><meta name="viewport" content="width=device-width,initial-scale=1"/><meta name="theme-color" content="#630be2"/><meta name="description" content="Web site created using create-react-app"/><link rel="apple-touch-icon" href="/logo192.png"/><link rel="manifest" href="/manifest.json"/><title>Superviseur Dashboard</title><script defer="defer" src="/static/js/main.1a5e8dec.js"></script><link href="/static/css/main.61403641.css" rel="stylesheet"></head><body><noscript>You need to enable JavaScript to run this app.</noscript><div id="root"></div></body></html>
2 changes: 1 addition & 1 deletion crates/webui/webui/build/service-worker.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion crates/webui/webui/build/service-worker.js.map

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
import { FC, useEffect, useState } from "react";
import { Folder } from "@styled-icons/bootstrap";
import { Edit } from "@styled-icons/remix-line";
import styled from "@emotion/styled";
import { Controller, useForm } from "react-hook-form";

const ProjectName = styled.div`
color: #fff;
`;

const EditIcon = styled(Edit)`
margin-left: 5px;
color: #ffffff86;
&:hover {
color: #fff;
}
`;

const EditButton = styled.button`
background-color: transparent;
border: none;
cursor: pointer;
`;

const Input = styled.input`
background-color: transparent;
border: none;
color: #fff;
font-size: 16px;
font-family: RockfordSansRegular;
padding: 0;
&:focus {
outline: none;
}
`;

export type CurrentProjectProps = {
projectId?: string;
projectName?: string;
onEdit: (projectName: string) => void;
};

const CurrentProject: FC<CurrentProjectProps> = ({
projectId,
projectName,
onEdit,
}) => {
const [edit, setEdit] = useState(false);
const { control, watch } = useForm();

useEffect(() => {
const subscription = watch(
(value, { name }) => name && onEdit(value[name])
);
return () => subscription.unsubscribe();
}, [watch, onEdit]);

useEffect(() => {
const keyDownHandler = (event: any) => {
console.log("User pressed: ", event.key);

if (event.key === "Enter") {
event.preventDefault();
setEdit(false);
}
};

document.addEventListener("keydown", keyDownHandler);

return () => {
document.removeEventListener("keydown", keyDownHandler);
};
// eslint-disable-next-line react-hooks/exhaustive-deps
}, []);

return (
<>
{projectId && (
<>
<Folder size={18} color="#fff" style={{ marginRight: 10 }} />
{!edit && <ProjectName>{projectName}</ProjectName>}
{edit && (
<Controller
render={({ field }) => (
<Input
{...(field as any)}
autoFocus={true}
onBlur={() => setEdit(false)}
/>
)}
name="projectName"
control={control}
defaultValue={projectName}
/>
)}
{!edit && (
<EditButton onClick={() => setEdit(true)}>
<EditIcon size={18} />
</EditButton>
)}
</>
)}
</>
);
};

export default CurrentProject;
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { atom } from "recoil";

export const currentProjectState = atom({
key: "currentProjectState",
default: {
id: "",
name: "",
},
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import { FC, useEffect } from "react";
import CurrentProject from "./CurrentProject";
import { useParams } from "react-router-dom";
import { useGetProjectQuery } from "../../../Hooks/GraphQL";
import { useRecoilState } from "recoil";
import { currentProjectState } from "./CurrentProjectState";

const CurrentProjectWithData: FC = () => {
const [state, setState] = useRecoilState(currentProjectState);
const { projectId } = useParams();
const { data } = useGetProjectQuery({ variables: { id: projectId! } });
const name = data?.project?.name;

useEffect(() => {
if (name) {
setState({ ...state, name });
}
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [name]);

const setProjectName = (name: string) => {
setState({ ...state, name });
};

return (
<CurrentProject
projectId={projectId}
projectName={state.name}
onEdit={setProjectName}
/>
);
};

export default CurrentProjectWithData;
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import CurrentProject from "./CurrentProjectWithData";

export default CurrentProject;
33 changes: 26 additions & 7 deletions crates/webui/webui/src/Components/Navbar/Navbar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import { Service } from "../../Hooks/GraphQL";
import ServiceDetails from "../ServiceDetails";
import { Drawer } from "baseui/drawer";
import { Link } from "react-router-dom";
import CurrentProject from "./CurrentProject";

const Container = styled.div`
display: flex;
Expand All @@ -25,20 +26,28 @@ const Container = styled.div`
const Logo = styled.div`
color: #fff;
font-weight: bold;
width: 225px;
width: 112px;
text-align: left;
padding-left: 25px;
`;

const Settings = styled.div`
width: 200px;
flex: 1;
display: flex;
flex-direction: row;
align-items: center;
justify-content: flex-end;
padding-right: 25px;
`;

const LeftNav = styled.div`
display: flex;
flex-direction: row;
align-items: center;
justify-content: flex-start;
flex: 1;
`;

interface NavbarProps {
onSearch: (value: string) => void;
results: Service[];
Expand All @@ -57,9 +66,12 @@ const Navbar: FC<NavbarProps> = ({ onSearch, results }) => {
}, [watch, onSearch]);
return (
<Container>
<Link to="/" style={{ textDecoration: "none" }}>
<Logo>Superviseur</Logo>
</Link>
<LeftNav>
<Link to="/" style={{ textDecoration: "none" }}>
<Logo>Superviseur</Logo>
</Link>
<CurrentProject />
</LeftNav>
<Controller
render={({ field }) => (
<Popover
Expand All @@ -79,7 +91,14 @@ const Navbar: FC<NavbarProps> = ({ onSearch, results }) => {
)}
overrides={styles.popover}
>
<div>
<div
style={{
display: "flex",
flex: 1,
alignItems: "center",
justifyContent: "center",
}}
>
<Input
{...(field as any)}
placeholder="Search for a project, service ..."
Expand Down Expand Up @@ -149,7 +168,7 @@ const styles = {
Root: {
style: {
width: "400px",
height: "35px",
height: "43px",
borderWidth: "0px",
borderRadius: "2px",
backgroundColor: "#5a10c5",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import { FC } from "react";
import styled from "@emotion/styled";
import { Stack } from "@styled-icons/octicons";

const Action = styled.div`
height: 50px;
width: 100%;
display: flex;
align-items: center;
padding-left: 20px;
cursor: pointer;
&:hover {
color: #630be2;
background-color: #fbfbfb;
}
`;

const Logo = styled.img`
height: 18px;
margin-right: 15px;
`;

export type MessagingProps = {
data: any[];
};

const Messaging: FC<MessagingProps> = ({ data }) => {
return (
<>
{data.map((template) => (
<Action key={template.id} onClick={() => {}}>
{template.icon && <Logo src={template.icon} />}
{!template.icon && (
<Stack color="#ff0a80" size={20} style={{ marginRight: 15 }} />
)}
<div>{template.name}</div>
</Action>
))}
</>
);
};

export default Messaging;
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@ import { Input } from "baseui/input";
import { Modal, ModalBody } from "baseui/modal";
import { FC, useState } from "react";
import { Stack, ChevronRight } from "@styled-icons/octicons";
import { MessageCircleOutline } from "@styled-icons/evaicons-outline";
import { Terminal } from "@styled-icons/remix-fill";
import { Database2 } from "@styled-icons/remix-line";
import Templates from "./Templates";
import Databases from "./Databases";
import Messaging from "./Messaging";

const Action = styled.div`
height: 50px;
Expand Down Expand Up @@ -35,15 +37,18 @@ export type NewServiceModalProps = {
onClose: () => void;
templates: any[];
databases: any[];
messaging: any[];
};

const NewServiceModal: FC<NewServiceModalProps> = ({
isOpen,
onClose,
templates,
databases,
messaging,
}) => {
const [tab, setTab] = useState<"templates" | "databases" | null>(null);
const [tab, setTab] =
useState<"templates" | "databases" | "messaging" | null>(null);
const _onClose = () => {
onClose();
setTab(null);
Expand Down Expand Up @@ -103,6 +108,19 @@ const NewServiceModal: FC<NewServiceModalProps> = ({
color="#000"
/>
</Action>
<Action onClick={() => setTab("messaging")}>
<MessageCircleOutline
color="#ff0a80"
size={20}
style={{ marginRight: 15 }}
/>
<div>Messaging</div>
<ChevronRight
size={20}
style={{ marginLeft: "auto" }}
color="#000"
/>
</Action>
<Action>
<Terminal
color="#ff0a80"
Expand All @@ -115,6 +133,7 @@ const NewServiceModal: FC<NewServiceModalProps> = ({
)}
{tab === "templates" && <Templates data={templates} />}
{tab === "databases" && <Databases data={databases} />}
{tab === "messaging" && <Messaging data={messaging} />}
</CardContent>
</ModalBody>
</Modal>
Expand Down
Loading

0 comments on commit ab5dd67

Please sign in to comment.