diff --git a/ui/src/Account.js b/ui/src/Account.js deleted file mode 100644 index 687db2ca..00000000 --- a/ui/src/Account.js +++ /dev/null @@ -1,137 +0,0 @@ -import {useEffect, useState} from "react"; -import {useReactFlow} from "react-flow-renderer"; -import Icon from "@mdi/react"; -import {mdiAccessPointNetwork, mdiDesktopClassic} from "@mdi/js"; -import dagre from "dagre"; -import * as metadata from "./api/metadata"; -import Network from "./Network"; -import Enable from "./Enable"; - -const Account = (props) => { - const [mode, setMode] = useState(<>); - const reactFlow = useReactFlow(); - - useEffect(() => { - let mounted = true - metadata.overview().then(resp => { - if(mounted) { - let overview = resp.data - let g = buildGraph(resp.data) - let nodes = getLayout(g) - let edges = g.edges - - if(resp.data.length > 0) { - setMode() - reactFlow.fitView({maxZoom: 1}) - } else { - setMode() - } - } - }); - }, []) - - useEffect(() => { - let mounted = true - let interval = setInterval(() => { - metadata.overview().then(resp => { - if(mounted) { - let overview = resp.data - let g = buildGraph(resp.data) - let nodes = getLayout(g) - let edges = g.edges - - if(resp.data.length > 0) { - setMode() - reactFlow.fitView({maxZoom: 1}) - } else { - setMode() - } - } - }) - }, 1000) - return () => { - mounted = false - clearInterval(interval) - } - }, []) - - return <>{mode} -} - -function buildGraph(overview) { - let out = { - nodes: [], - edges: [] - } - let id = 1 - overview.forEach((item) => { - let envId = id - out.nodes.push({ - id: '' + envId, - data: { label:
{ item.environment.description }
}, - position: { x: (id * 25), y: 0 }, - style: { width: 'fit-content', backgroundColor: '#aaa', color: 'white' }, - type: 'input', - draggable: true - }); - id++ - if(item.services != null) { - item.services.forEach((item) => { - out.nodes.push({ - id: '' + id, - data: {label:
{ item.token }
}, - position: {x: (id * 25), y: 0}, - style: { width: 'fit-content', backgroundColor: '#9367ef', color: 'white' }, - type: 'output', - draggable: true - }) - out.edges.push({ - id: 'e' + envId + '-' + id, - source: '' + envId, - target: '' + id, - animated: true - }) - id++ - }); - } - }); - return out -} - -const nodeWidth = 100; -const nodeHeight = 75; - -function getLayout(overview) { - const dagreGraph = new dagre.graphlib.Graph(); - dagreGraph.setGraph({ rankdir: 'TB' }); - dagreGraph.setDefaultEdgeLabel(() => ({})); - - overview.nodes.forEach((n) => { - dagreGraph.setNode(n.id, { width: nodeWidth, height: nodeHeight }); - }) - overview.edges.forEach((e) => { - dagreGraph.setEdge(e.source, e.target); - }) - dagre.layout(dagreGraph); - - return overview.nodes.map((n) => { - const nodeWithPosition = dagreGraph.node(n.id); - n.targetPosition = 'top'; - n.sourcePosition = 'bottom'; - n.position = { - x: nodeWithPosition.x - (nodeWidth / 2) + (Math.random() / 1000) + 50, - y: nodeWithPosition.y - (nodeHeight / 2) + 50, - } - return n; - }); -} - -export default Account \ No newline at end of file diff --git a/ui/src/App.js b/ui/src/App.js index a9109740..649e2349 100644 --- a/ui/src/App.js +++ b/ui/src/App.js @@ -1,8 +1,8 @@ import { BrowserRouter as Router, Route, Routes } from 'react-router-dom'; -import Register from "./Register"; +import Register from "./register/Register"; import Console from "./console/Console"; import {useEffect, useState} from "react"; -import Login from "./Login"; +import Login from "./login/Login"; const App = () => { const [user, setUser] = useState(); diff --git a/ui/src/Console.js b/ui/src/Console.js deleted file mode 100644 index 91d76204..00000000 --- a/ui/src/Console.js +++ /dev/null @@ -1,58 +0,0 @@ -import {useEffect, useState} from "react"; -import Login from "./Login"; -import Version from "./Version"; -import Token from "./Token"; -import Logout from "./Logout"; -import Account from "./Account"; -import {ReactFlowProvider} from "react-flow-renderer"; - -const Console = () => { - const [user, setUser] = useState(); - - useEffect(() => { - const localUser = localStorage.getItem("user") - if (localUser) { - setUser(JSON.parse(localUser)) - console.log('reloaded user', localUser) - } - }, []); - - if (!user) { - return ( - - ); - } - - const logout = () => { - setUser(null); - localStorage.clear(); - } - - return ( -
-
-
- ziggy goes to space -

zrok

-
-
-

{user.email}

- -
-
- - -
-
-
-
- - - -
-
-
- ); -} - -export default Console; \ No newline at end of file diff --git a/ui/src/Enable.js b/ui/src/Enable.js deleted file mode 100644 index 17339e62..00000000 --- a/ui/src/Enable.js +++ /dev/null @@ -1,26 +0,0 @@ -import Icon from "@mdi/react"; -import {mdiContentCopy} from "@mdi/js"; - -const Enable = (props) => { - const handleCopy = async () => { - let copiedText = document.getElementById("zrok-enable-command").innerHTML; - try { - await navigator.clipboard.writeText(copiedText); - console.log("copied enable command"); - } catch(err) { - console.error("failed to copy", err); - } - } - - return <> -
-

Enable an Environment

-

To enable your shell for zrok, use this command:

-
-                $ zrok enable {props.token} 
-            
-
- -} - -export default Enable \ No newline at end of file diff --git a/ui/src/Environments.js b/ui/src/Environments.js deleted file mode 100644 index 907381b8..00000000 --- a/ui/src/Environments.js +++ /dev/null @@ -1,75 +0,0 @@ -import DataTable from 'react-data-table-component'; -import Services from './Services'; -import Icon from "@mdi/react"; -import {mdiCloseOutline} from "@mdi/js"; -import * as environment from './api/environment'; - -const Environments = (props) => { - const humanizeDuration = require("humanize-duration") - const disableEnvironment = (envId) => { - if(window.confirm('really disable environment "' + envId +'"?')) { - environment.disable({body: {identity: envId}}).then(resp => { - console.log(resp); - }) - } - } - - const columns = [ - { - name: 'Description', - selector: row => row.environment.description, - sortable: true, - }, - { - name: 'Host', - selector: row => row.environment.host, - sortable: true, - }, - { - name: 'Address', - selector: row => row.environment.address, - sortable: true, - }, - { - name: 'Identity', - selector: row => row.environment.zId, - sortable: true, - }, - { - name: 'Actions', - selector: row => <> - - - }, - { - name: 'Uptime', - selector: row => humanizeDuration(Date.now() - row.environment.updatedAt), - sortable: true, - }, - ] - - const servicesComponent = ({ data }) => - const servicesExpanded = row => row.services != null && row.services.length > 0 - - return ( -
-

Environments

- { props.overview && props.overview.length > 0 && ( -
- -
- )} -
- ) -}; - -export default Environments; diff --git a/ui/src/Logout.js b/ui/src/Logout.js deleted file mode 100644 index 1c874bcd..00000000 --- a/ui/src/Logout.js +++ /dev/null @@ -1,16 +0,0 @@ -import Icon from '@mdi/react'; -import { mdiLogout } from '@mdi/js'; - -const logoutIcon = mdiLogout; - -const Logout = (props) => { - const onClick = () => { - props.logout() - } - - return ( - - ); -} - -export default Logout; diff --git a/ui/src/Network.js b/ui/src/Network.js deleted file mode 100644 index caf7fe5a..00000000 --- a/ui/src/Network.js +++ /dev/null @@ -1,21 +0,0 @@ -import Environments from './Environments'; -import ReactFlow from "react-flow-renderer"; - -const Network = (props) => { - return ( -
-
-

Network

- -
- -
- ) -} - -export default Network; \ No newline at end of file diff --git a/ui/src/Services.js b/ui/src/Services.js deleted file mode 100644 index bf596728..00000000 --- a/ui/src/Services.js +++ /dev/null @@ -1,59 +0,0 @@ -import DataTable from 'react-data-table-component'; -import {Sparklines, SparklinesLine, SparklinesSpots} from 'react-sparklines'; -import {mdiCloseOutline} from "@mdi/js"; -import Icon from "@mdi/react"; -import * as service from './api/service'; - -const Services = (props) => { - const humanizeDuration = require("humanize-duration") - const unshareService = (envId, svcToken) => { - if(window.confirm('really disable service "' + svcToken +'"?')) { - service.unshare({body: {envZId: envId, svcToken: svcToken}}).then(resp => { - console.log(resp) - }) - } - } - - const columns = [ - { - name: 'Frontend', - selector: row => row.frontendEndpoint, - sortable: true, - }, - { - name: 'Backend', - selector: row => row.backendProxyEndpoint, - sortable: true, - }, - { - name: 'Actions', - selector: row => <> - - - }, - { - name: 'Uptime', - selector: row => humanizeDuration(Date.now() - row.updatedAt), - }, - { - name: 'Activity', - cell: row => - } - ] - - return ( -
- { props.services && props.services.length > 0 && ( - - )} -
- ) -} - -export default Services; \ No newline at end of file diff --git a/ui/src/Token.js b/ui/src/Token.js deleted file mode 100644 index ff49e21c..00000000 --- a/ui/src/Token.js +++ /dev/null @@ -1,53 +0,0 @@ -import Icon from "@mdi/react"; -import {mdiKey, mdiContentCopy} from "@mdi/js"; -import Popover from "@mui/material/Popover"; -import {useState} from "react"; - -const Token = (props) => { - const [anchorEl, setAnchorEl] = useState(null); - - const handlePopoverClick = (event) => { - setAnchorEl(event.currentTarget); - }; - const handlePopoverClose = () => { - setAnchorEl(null); - } - const popoverOpen = Boolean(anchorEl); - const popoverId = popoverOpen ? 'token-popover' : undefined; - - const text = "zrok enable " + props.user.token - const handleCopy = async () => { - let copiedText = document.getElementById("zrok-enable-command").innerHTML; - try { - await navigator.clipboard.writeText(copiedText); - console.log("copied enable command"); - } catch(err) { - console.error("failed to copy", err); - } - } - - return ( -
- - -
-

Enable zrok access in your shell:

-
-                        $ {text} 
-                    
-
-
-
- ); -} - -export default Token; \ No newline at end of file diff --git a/ui/src/Version.js b/ui/src/Version.js deleted file mode 100644 index 0b468ec3..00000000 --- a/ui/src/Version.js +++ /dev/null @@ -1,24 +0,0 @@ -import {useEffect, useState} from "react"; -import * as metadata from "./api/metadata"; - -const Version = () => { - const [v, setV] = useState(''); - - useEffect(() => { - let mounted = true; - metadata.version().then(resp => { - if(mounted) { - setV(resp.data); - } - }); - return () => { - mounted = false; - }; - }, []); - - return ( -

{v}

- ); -} - -export default Version; \ No newline at end of file diff --git a/ui/src/console/visualizer/Visualizer.js b/ui/src/console/visualizer/Visualizer.js index c660f760..559b19fe 100644 --- a/ui/src/console/visualizer/Visualizer.js +++ b/ui/src/console/visualizer/Visualizer.js @@ -1,7 +1,7 @@ import React, {useEffect, useState} from "react"; import {Button} from "react-bootstrap"; import Network from "./Network"; -import {buildGraph, mergeGraph} from "./graph"; +import {mergeGraph} from "./graph"; const Visualizer = (props) => { const [networkGraph, setNetworkGraph] = useState({nodes: [], links: []}); diff --git a/ui/src/Login.js b/ui/src/login/Login.js similarity index 95% rename from ui/src/Login.js rename to ui/src/login/Login.js index 585c3225..ac9955b7 100644 --- a/ui/src/Login.js +++ b/ui/src/login/Login.js @@ -1,5 +1,5 @@ import {useState} from "react"; -import * as account from './api/account'; +import * as account from '../api/account'; const Login = (props) => { const [email, setEmail] = useState(''); @@ -34,7 +34,7 @@ const Login = (props) => { return (
- +

zrok

{message}
diff --git a/ui/src/Register.js b/ui/src/register/Register.js similarity index 99% rename from ui/src/Register.js rename to ui/src/register/Register.js index aea54966..5d581af2 100644 --- a/ui/src/Register.js +++ b/ui/src/register/Register.js @@ -2,7 +2,7 @@ import Icon from "@mdi/react"; import { useParams } from 'react-router-dom'; import {useEffect, useState} from "react"; import {mdiContentCopy} from "@mdi/js"; -import * as account from "./api/account"; +import * as account from "../api/account"; const RegistrationForm = (props) => { const [password, setPassword] = useState('');