From 51a76f668dbd461b03249d57ce3bdc60b01c529d Mon Sep 17 00:00:00 2001 From: Thomas von Rosenberg Date: Fri, 12 Mar 2021 09:39:13 +0100 Subject: [PATCH] Allow changing projects and dashboards --- ui/src/Chart.tsx | 2 +- ui/src/Root.tsx | 83 +++++++++++++++++++++++++++++++++++++++++------- 2 files changed, 72 insertions(+), 13 deletions(-) diff --git a/ui/src/Chart.tsx b/ui/src/Chart.tsx index 6925102..28d357b 100644 --- a/ui/src/Chart.tsx +++ b/ui/src/Chart.tsx @@ -62,6 +62,6 @@ const useMetrics = ({keys, limit, start, end, sort, project}: MetricRequest): Fl .then((res) => res.json()) .then((data) => setData(data.map((m: Metric) => ({__key: m.key, ...m.values})))); // eslint-disable-next-line react-hooks/exhaustive-deps - }, []); + }, [keys, limit, start, end, sort, project]); return data; }; diff --git a/ui/src/Root.tsx b/ui/src/Root.tsx index c523b14..b4a176a 100644 --- a/ui/src/Root.tsx +++ b/ui/src/Root.tsx @@ -1,6 +1,16 @@ import React from 'react'; import {Config, ConfigDashboard, useConfig} from './Config'; -import {AppBar, Button, CircularProgress, Container, Paper, Toolbar, Typography} from '@material-ui/core'; +import { + AppBar, + Button, + CircularProgress, + Container, + Paper, + Toolbar, + Typography, + Menu, + MenuItem, +} from '@material-ui/core'; import {Chart} from './Chart'; export const Root = () => { @@ -18,8 +28,14 @@ export const Root = () => { }; const WithConfig = ({config}: {config: Config}) => { - const [project] = React.useState(() => Object.keys(config.projects)[0]); - const [dashboard] = React.useState(() => config.projects[project].dashboards?.[0]); + const [project, setProject] = React.useState(() => Object.keys(config.projects)[0]); + const [dashboard, setDashboard] = React.useState(() => config.projects[project].dashboards?.[0]); + + const projects = Object.keys(config.projects); + const dashboards = config.projects[project].dashboards ?? []; + + const [projectAnchor, setProjectAnchor] = React.useState(null); + const [dashboardAnchor, setDashboardAnchor] = React.useState(null); return ( @@ -28,16 +44,59 @@ const WithConfig = ({config}: {config: Config}) => { Perfably - + setProjectAnchor(null)}> + {projects.map((project) => { + return ( + { + setProject(project); + setProjectAnchor(null); + }}> + {project} + + ); + })} + + + - {dashboard === undefined ? ( - 'no dashboards configured' - ) : ( - - )} + setDashboardAnchor(null)}> + {dashboards.map((dashboard) => { + return ( + { + setDashboard(dashboard); + setDashboardAnchor(null); + }}> + {dashboard.name} + + ); + })} + {dashboard ? : undefined}