From bfa2c0fd00c16adbe98d796e553a66bff28f41c5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ey=C3=BE=C3=B3r=20Magn=C3=BAsson?= Date: Tue, 5 Feb 2019 21:46:32 +0100 Subject: [PATCH] fix(dashboard): conform to new "get config" response --- dashboard/src/api/types.ts | 30 +++++++++++++-------------- dashboard/src/components/logs.tsx | 8 +++---- dashboard/src/components/overview.tsx | 20 +++++++++--------- dashboard/src/containers/logs.tsx | 5 ++--- dashboard/src/containers/overview.tsx | 4 ++-- dashboard/src/util/helpers.ts | 14 +++++++++++++ 6 files changed, 47 insertions(+), 34 deletions(-) create mode 100644 dashboard/src/util/helpers.ts diff --git a/dashboard/src/api/types.ts b/dashboard/src/api/types.ts index 8db9a62418..8e2b56fea9 100644 --- a/dashboard/src/api/types.ts +++ b/dashboard/src/api/types.ts @@ -9,6 +9,10 @@ // TODO: Figure out how to do proper type handling. The types here are mostly just copied from // garden-service to facilitate rendering. +export type Primitive = string | number | boolean + +export interface PrimitiveMap { [key: string]: Primitive } + export interface DashboardPage { title: string description: string @@ -22,27 +26,23 @@ export interface Provider { name: string } -export interface Service { - config: any +export interface CommonServiceSpec { + name: string + dependencies: string[] + outputs: PrimitiveMap +} + +export interface ServiceConfig extends CommonServiceSpec { name: string spec: any } -export interface Module { +export interface ModuleConfig { name: string - buildPath: string + path: string type: string - // version: ModuleVersion - - services: Service[] - serviceNames: string[] - serviceDependencyNames: string[] - - // tasks: Task>[] - taskNames: string[] - taskDependencyNames: string[] - // _ConfigType: ModuleConfig + serviceConfigs: ServiceConfig[] } export interface ServiceIngress { @@ -81,7 +81,7 @@ export interface FetchStatusResponse { export interface FetchConfigResponse { environmentName: string providers: Provider[] - modules: Module[] + moduleConfigs: ModuleConfig[] } export type RenderedNode = { type: RenderedNodeType, name: string } diff --git a/dashboard/src/components/logs.tsx b/dashboard/src/components/logs.tsx index d8e08305a2..8414308463 100644 --- a/dashboard/src/components/logs.tsx +++ b/dashboard/src/components/logs.tsx @@ -7,7 +7,7 @@ */ import styled from "@emotion/styled/macro" -import { flatten, max } from "lodash" +import { max } from "lodash" import React, { Component } from "react" import Terminal from "./terminal" @@ -15,6 +15,7 @@ import { FetchConfigResponse, FetchLogsResponse } from "../api/types" import Card, { CardTitle } from "./card" import { colors } from "../styles/variables" import { LoadLogs } from "../context/data" +import { getServiceNames } from "../util/helpers" interface Props { config: FetchConfigResponse @@ -58,14 +59,13 @@ class Logs extends Component { } refresh() { - const serviceNames = flatten(this.props.config.modules.map(m => m.serviceNames)) - this.props.loadLogs(serviceNames, true) + this.props.loadLogs(getServiceNames(this.props.config.moduleConfigs), true) } render() { const { config, logs } = this.props const { selectedService } = this.state - const serviceNames = flatten(config.modules.map(m => m.serviceNames)) + const serviceNames = getServiceNames(config.moduleConfigs) const maxServiceName = max(serviceNames).length const title = selectedService === "all" ? "All service logs" diff --git a/dashboard/src/components/overview.tsx b/dashboard/src/components/overview.tsx index f33824968f..94223c6c2c 100644 --- a/dashboard/src/components/overview.tsx +++ b/dashboard/src/components/overview.tsx @@ -16,7 +16,7 @@ import { ExternalLink } from "./links" import { ServiceStatus, - Module, + ModuleConfig, ServiceIngress, } from "../api/types" @@ -30,20 +30,20 @@ export function getIngressUrl(ingress: ServiceIngress) { } interface ServicesProps { - modules: Module[] + moduleConfigs: ModuleConfig[] services: { [name: string]: ServiceStatus } } interface ModulesProps { - modules: Module[] + moduleConfigs: ModuleConfig[] } -export const Modules: React.SFC = ({ modules }) => { +export const Modules: React.SFC = ({ moduleConfigs }) => { const rowHeaders = ["Name", "Type", "Services"] - const rows = modules.map(module => [ - module.name, - module.type, - module.services.map(s => s.name).join("\n"), + const rows = moduleConfigs.map(moduleConfig => [ + moduleConfig.name, + moduleConfig.type, + moduleConfig.serviceConfigs.map(s => s.name).join("\n"), ]) return ( = ({ modules }) => { ) } -export const Services: React.SFC = ({ modules, services }) => { +export const Services: React.SFC = ({ moduleConfigs, services }) => { const rowHeaders = ["Name", "Status", "Module", "Ingresses"] const rows = Object.keys(services).map(service => [ service, services[service].state, - modules.find(m => m.serviceNames.includes(service)).name, + moduleConfigs.find(m => m.serviceConfigs.map(s => s.name).includes(service)).name, , ]) return ( diff --git a/dashboard/src/containers/logs.tsx b/dashboard/src/containers/logs.tsx index 82a2765cf2..279f5a4471 100644 --- a/dashboard/src/containers/logs.tsx +++ b/dashboard/src/containers/logs.tsx @@ -6,13 +6,13 @@ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ -import { flatten } from "lodash" import React, { useContext, useEffect } from "react" import PageError from "../components/page-error" import Logs from "../components/logs" import LoadWrapper from "../components/load-wrapper" import { DataContext } from "../context/data" +import { getServiceNames } from "../util/helpers" export default () => { const { @@ -37,9 +37,8 @@ const LogsContainer = () => { store: { config, logs }, } = useContext(DataContext) - const serviceNames = flatten(config.data.modules.map(m => m.serviceNames)) useEffect(() => { - loadLogs(serviceNames) + loadLogs(getServiceNames(config.data.moduleConfigs)) }, []) const isLoading = !logs.data diff --git a/dashboard/src/containers/overview.tsx b/dashboard/src/containers/overview.tsx index 24ab41436a..1f87ac4d68 100644 --- a/dashboard/src/containers/overview.tsx +++ b/dashboard/src/containers/overview.tsx @@ -43,7 +43,7 @@ export default () => { return (
- + { ErrorComponent={PageError} loading={isLoadingServices}> diff --git a/dashboard/src/util/helpers.ts b/dashboard/src/util/helpers.ts new file mode 100644 index 0000000000..7a1280f274 --- /dev/null +++ b/dashboard/src/util/helpers.ts @@ -0,0 +1,14 @@ +/* + * Copyright (C) 2018 Garden Technologies, Inc. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +import { flatten } from "lodash" +import { ModuleConfig } from "../api/types" + +export function getServiceNames(moduleConfigs: ModuleConfig[]) { + return flatten(moduleConfigs.map(m => m.serviceConfigs.map(s => s.name))) +}