From 5b632a9a46c0b157cc94d8b81bd291a457b20f14 Mon Sep 17 00:00:00 2001 From: Thomas E Lackey Date: Wed, 9 Dec 2020 18:45:09 -0600 Subject: [PATCH 1/8] fix: detect running addon and add their links to the console sidebar (#57) --- packages/console-app/config-testnet.yml | 2 +- .../console-app/src/components/Sidebar.js | 25 +++++++++++++ .../console-app/src/gql/addon_list.graphql | 9 +++++ packages/console-app/src/version.json | 4 +- packages/console-server/src/gql/api.graphql | 1 + .../console-server/src/resolvers/addons.js | 37 +++++++++++++++++++ .../console-server/src/resolvers/index.js | 3 +- 7 files changed, 77 insertions(+), 4 deletions(-) create mode 100644 packages/console-app/src/gql/addon_list.graphql create mode 100644 packages/console-server/src/resolvers/addons.js diff --git a/packages/console-app/config-testnet.yml b/packages/console-app/config-testnet.yml index 45ac94c..9860696 100644 --- a/packages/console-app/config-testnet.yml +++ b/packages/console-app/config-testnet.yml @@ -11,7 +11,7 @@ app: publicUrl: '/console' api: - server: 'https://apollo1.kube.moon.dxos.network' + server: 'http://127.0.0.1:9004' path: '/api' intervalLog: 5000 pollInterval: 10000 diff --git a/packages/console-app/src/components/Sidebar.js b/packages/console-app/src/components/Sidebar.js index fd81ea4..7ce498b 100644 --- a/packages/console-app/src/components/Sidebar.js +++ b/packages/console-app/src/components/Sidebar.js @@ -4,13 +4,17 @@ import clsx from 'clsx'; import React from 'react'; +import { useQuery } from '@apollo/react-hooks'; import { useHistory, useParams } from 'react-router'; import { makeStyles } from '@material-ui/core'; import List from '@material-ui/core/List'; import ListItem from '@material-ui/core/ListItem'; import ListItemIcon from '@material-ui/core/ListItemIcon'; +import LinkIcon from '@material-ui/icons/ExitToApp'; import ListItemText from '@material-ui/core/ListItemText'; +import { useQueryStatusReducer } from "../hooks"; +import ADDON_LIST from "../gql/addon_list.graphql"; const useStyles = makeStyles(theme => ({ root: { @@ -39,6 +43,13 @@ const Sidebar = ({ modules: { services, settings } }) => { const history = useHistory(); const { module } = useParams(); + const { data: addonResponse } = useQueryStatusReducer(useQuery(ADDON_LIST)); + console.log(addonResponse); + if (!addonResponse) { + return null; + } + const addons = JSON.parse(addonResponse.addon_list.json); + const isSelected = path => path === `/${module}`; const Modules = ({ modules }) => ( @@ -54,9 +65,23 @@ const Sidebar = ({ modules: { services, settings } }) => { ); + const Addons = ({ addons }) => ( + + {addons.map(({ url, title }) => ( + window.location = url}> + + + + + + ))} + + ); + return (
+
); diff --git a/packages/console-app/src/gql/addon_list.graphql b/packages/console-app/src/gql/addon_list.graphql new file mode 100644 index 0000000..3079e1c --- /dev/null +++ b/packages/console-app/src/gql/addon_list.graphql @@ -0,0 +1,9 @@ +# +# Copyright 2020 DXOS.org +# + +query { + addon_list { + json + } +} diff --git a/packages/console-app/src/version.json b/packages/console-app/src/version.json index d0ef15f..f0079e4 100644 --- a/packages/console-app/src/version.json +++ b/packages/console-app/src/version.json @@ -1,7 +1,7 @@ { "build": { "name": "@dxos/console-app", - "buildDate": "2020-12-03T20:40:32.208Z", - "version": "1.2.4-alpha.2" + "buildDate": "2020-12-09T23:25:12.047Z", + "version": "1.2.4-alpha.3" } } diff --git a/packages/console-server/src/gql/api.graphql b/packages/console-server/src/gql/api.graphql index 8ab636c..4f844b2 100644 --- a/packages/console-server/src/gql/api.graphql +++ b/packages/console-server/src/gql/api.graphql @@ -22,6 +22,7 @@ type Query { system_status: JSONResult! wns_status: JSONResult! bot_list: JSONResult! + addon_list: JSONResult! } type Mutation { diff --git a/packages/console-server/src/resolvers/addons.js b/packages/console-server/src/resolvers/addons.js new file mode 100644 index 0000000..36aea43 --- /dev/null +++ b/packages/console-server/src/resolvers/addons.js @@ -0,0 +1,37 @@ +// +// Copyright 2020 DXOS.org +// + +import childProcess from 'child_process'; + +// TODO(telackey): Make pluggable. +const ifRadicle = () => { + try { + const result = childProcess.execSync('docker ps -f "ancestor=dxos/radicle-seed-node" -q'); + if (result) { + return { title: 'Radicle', url: '/' }; + } + } catch (e) {} +}; + +// TODO(telackey): Use the local Sentry. +const ifSentry = () => { + return { + title: 'Sentry', + url: 'http://sentry.kube.dxos.network:9000/' + }; +}; + +export const addonResolvers = { + Query: { + addon_list: async (_, __, { config }) => { + return { + timestamp: new Date().toUTCString(), + json: JSON.stringify([ + ifSentry(), + ifRadicle() + ].filter(x => x)) + }; + } + } +}; diff --git a/packages/console-server/src/resolvers/index.js b/packages/console-server/src/resolvers/index.js index 65bd157..05f31bd 100644 --- a/packages/console-server/src/resolvers/index.js +++ b/packages/console-server/src/resolvers/index.js @@ -5,6 +5,7 @@ import debug from 'debug'; import defaultsDeep from 'lodash.defaultsdeep'; +import { addonResolvers } from './addons'; import { ipfsResolvers } from './ipfs'; import { systemResolvers } from './system'; import { logResolvers } from './log'; @@ -22,4 +23,4 @@ export const resolvers = defaultsDeep({ // TODO(burdon): Auth. // https://www.apollographql.com/docs/apollo-server/data/errors/#codes -}, ipfsResolvers, systemResolvers, logResolvers, botsResolvers); +}, ipfsResolvers, systemResolvers, logResolvers, botsResolvers, addonResolvers); From 01a2bfbcba8e03d7984e3f97becd0e2daccfcf06 Mon Sep 17 00:00:00 2001 From: Thomas E Lackey Date: Wed, 9 Dec 2020 18:51:31 -0600 Subject: [PATCH 2/8] fix: lint --- packages/console-app/src/components/Sidebar.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/console-app/src/components/Sidebar.js b/packages/console-app/src/components/Sidebar.js index 7ce498b..80a9337 100644 --- a/packages/console-app/src/components/Sidebar.js +++ b/packages/console-app/src/components/Sidebar.js @@ -13,8 +13,8 @@ import ListItem from '@material-ui/core/ListItem'; import ListItemIcon from '@material-ui/core/ListItemIcon'; import LinkIcon from '@material-ui/icons/ExitToApp'; import ListItemText from '@material-ui/core/ListItemText'; -import { useQueryStatusReducer } from "../hooks"; -import ADDON_LIST from "../gql/addon_list.graphql"; +import { useQueryStatusReducer } from '../hooks'; +import ADDON_LIST from '../gql/addon_list.graphql'; const useStyles = makeStyles(theme => ({ root: { @@ -68,7 +68,7 @@ const Sidebar = ({ modules: { services, settings } }) => { const Addons = ({ addons }) => ( {addons.map(({ url, title }) => ( - window.location = url}> + { window.location = url; return true; }}> From 89f1d7d462070be27aadac2b931186fb04a5e971 Mon Sep 17 00:00:00 2001 From: DXOS Date: Thu, 10 Dec 2020 00:55:10 +0000 Subject: [PATCH 3/8] v1.2.4-alpha.4 --- lerna.json | 2 +- packages/console-app/package.json | 2 +- packages/console-server/package.json | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lerna.json b/lerna.json index 2e638ec..7959f8e 100644 --- a/lerna.json +++ b/lerna.json @@ -1,5 +1,5 @@ { - "version": "1.2.4-alpha.3", + "version": "1.2.4-alpha.4", "useWorkspaces": true, "npmClient": "yarn" } diff --git a/packages/console-app/package.json b/packages/console-app/package.json index 984ff27..05104d1 100644 --- a/packages/console-app/package.json +++ b/packages/console-app/package.json @@ -1,6 +1,6 @@ { "name": "@dxos/console-app", - "version": "1.2.4-alpha.3", + "version": "1.2.4-alpha.4", "description": "Kubenet Console Client", "repository": "https://github.com/dxos/console", "main": "dist/es/index.js", diff --git a/packages/console-server/package.json b/packages/console-server/package.json index 72c7fab..e2afb26 100644 --- a/packages/console-server/package.json +++ b/packages/console-server/package.json @@ -1,6 +1,6 @@ { "name": "@dxos/console-server", - "version": "1.2.4-alpha.3", + "version": "1.2.4-alpha.4", "description": "Kubenet Console Server", "main": "dist/es/index.js", "bin": { @@ -31,7 +31,7 @@ "dependencies": { "@babel/polyfill": "^7.8.7", "@babel/runtime": "^7.8.7", - "@dxos/console-app": "^1.2.4-alpha.3", + "@dxos/console-app": "^1.2.4-alpha.4", "@wirelineio/wns-schema": "^0.1.1", "apollo-boost": "^0.4.9", "apollo-server-express": "^2.13.1", From d10df2a25060a1a96716d032708980d7c2232edd Mon Sep 17 00:00:00 2001 From: Thomas E Lackey Date: Wed, 9 Dec 2020 19:15:27 -0600 Subject: [PATCH 4/8] fix: R before S --- packages/console-server/src/resolvers/addons.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/console-server/src/resolvers/addons.js b/packages/console-server/src/resolvers/addons.js index 36aea43..4661dcf 100644 --- a/packages/console-server/src/resolvers/addons.js +++ b/packages/console-server/src/resolvers/addons.js @@ -28,8 +28,8 @@ export const addonResolvers = { return { timestamp: new Date().toUTCString(), json: JSON.stringify([ - ifSentry(), - ifRadicle() + ifRadicle(), + ifSentry() ].filter(x => x)) }; } From 7ac9f854a2306f9664be51ccedbb1be320b809cd Mon Sep 17 00:00:00 2001 From: DXOS Date: Thu, 10 Dec 2020 01:19:05 +0000 Subject: [PATCH 5/8] v1.2.4-alpha.5 --- lerna.json | 2 +- packages/console-app/package.json | 2 +- packages/console-server/package.json | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lerna.json b/lerna.json index 7959f8e..556556f 100644 --- a/lerna.json +++ b/lerna.json @@ -1,5 +1,5 @@ { - "version": "1.2.4-alpha.4", + "version": "1.2.4-alpha.5", "useWorkspaces": true, "npmClient": "yarn" } diff --git a/packages/console-app/package.json b/packages/console-app/package.json index 05104d1..61d040d 100644 --- a/packages/console-app/package.json +++ b/packages/console-app/package.json @@ -1,6 +1,6 @@ { "name": "@dxos/console-app", - "version": "1.2.4-alpha.4", + "version": "1.2.4-alpha.5", "description": "Kubenet Console Client", "repository": "https://github.com/dxos/console", "main": "dist/es/index.js", diff --git a/packages/console-server/package.json b/packages/console-server/package.json index e2afb26..a8cfbf5 100644 --- a/packages/console-server/package.json +++ b/packages/console-server/package.json @@ -1,6 +1,6 @@ { "name": "@dxos/console-server", - "version": "1.2.4-alpha.4", + "version": "1.2.4-alpha.5", "description": "Kubenet Console Server", "main": "dist/es/index.js", "bin": { @@ -31,7 +31,7 @@ "dependencies": { "@babel/polyfill": "^7.8.7", "@babel/runtime": "^7.8.7", - "@dxos/console-app": "^1.2.4-alpha.4", + "@dxos/console-app": "^1.2.4-alpha.5", "@wirelineio/wns-schema": "^0.1.1", "apollo-boost": "^0.4.9", "apollo-server-express": "^2.13.1", From 9ff8873d9b51b2600790806bc3ea7df9303e0fee Mon Sep 17 00:00:00 2001 From: Thomas E Lackey Date: Wed, 9 Dec 2020 19:23:10 -0600 Subject: [PATCH 6/8] fix: test result.toString() --- packages/console-app/config-testnet.yml | 2 +- packages/console-server/src/resolvers/addons.js | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/console-app/config-testnet.yml b/packages/console-app/config-testnet.yml index 9860696..45ac94c 100644 --- a/packages/console-app/config-testnet.yml +++ b/packages/console-app/config-testnet.yml @@ -11,7 +11,7 @@ app: publicUrl: '/console' api: - server: 'http://127.0.0.1:9004' + server: 'https://apollo1.kube.moon.dxos.network' path: '/api' intervalLog: 5000 pollInterval: 10000 diff --git a/packages/console-server/src/resolvers/addons.js b/packages/console-server/src/resolvers/addons.js index 4661dcf..2a90166 100644 --- a/packages/console-server/src/resolvers/addons.js +++ b/packages/console-server/src/resolvers/addons.js @@ -8,7 +8,7 @@ import childProcess from 'child_process'; const ifRadicle = () => { try { const result = childProcess.execSync('docker ps -f "ancestor=dxos/radicle-seed-node" -q'); - if (result) { + if (result && result.toString()) { return { title: 'Radicle', url: '/' }; } } catch (e) {} From ab8c9e8baa75e951fe16d16511a65d49b90486e7 Mon Sep 17 00:00:00 2001 From: Thomas E Lackey Date: Wed, 9 Dec 2020 19:26:34 -0600 Subject: [PATCH 7/8] bump version --- lerna.json | 2 +- package.json | 2 +- packages/console-app/package.json | 2 +- packages/console-app/src/version.json | 2 +- packages/console-server/package.json | 4 ++-- 5 files changed, 6 insertions(+), 6 deletions(-) diff --git a/lerna.json b/lerna.json index 556556f..3120d0a 100644 --- a/lerna.json +++ b/lerna.json @@ -1,5 +1,5 @@ { - "version": "1.2.4-alpha.5", + "version": "1.2.5-alpha.0", "useWorkspaces": true, "npmClient": "yarn" } diff --git a/package.json b/package.json index c78cd30..f7f8834 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@dxos/console", - "version": "1.2.4-alpha.0", + "version": "1.2.5-alpha.0", "description": "Console", "main": "index.js", "private": true, diff --git a/packages/console-app/package.json b/packages/console-app/package.json index 61d040d..ef9da25 100644 --- a/packages/console-app/package.json +++ b/packages/console-app/package.json @@ -1,6 +1,6 @@ { "name": "@dxos/console-app", - "version": "1.2.4-alpha.5", + "version": "1.2.5-alpha.0", "description": "Kubenet Console Client", "repository": "https://github.com/dxos/console", "main": "dist/es/index.js", diff --git a/packages/console-app/src/version.json b/packages/console-app/src/version.json index f0079e4..93851e5 100644 --- a/packages/console-app/src/version.json +++ b/packages/console-app/src/version.json @@ -2,6 +2,6 @@ "build": { "name": "@dxos/console-app", "buildDate": "2020-12-09T23:25:12.047Z", - "version": "1.2.4-alpha.3" + "version": "1.2.5-alpha.0" } } diff --git a/packages/console-server/package.json b/packages/console-server/package.json index a8cfbf5..bd97888 100644 --- a/packages/console-server/package.json +++ b/packages/console-server/package.json @@ -1,6 +1,6 @@ { "name": "@dxos/console-server", - "version": "1.2.4-alpha.5", + "version": "1.2.5-alpha.0", "description": "Kubenet Console Server", "main": "dist/es/index.js", "bin": { @@ -31,7 +31,7 @@ "dependencies": { "@babel/polyfill": "^7.8.7", "@babel/runtime": "^7.8.7", - "@dxos/console-app": "^1.2.4-alpha.5", + "@dxos/console-app": "^1.2.5-alpha.0", "@wirelineio/wns-schema": "^0.1.1", "apollo-boost": "^0.4.9", "apollo-server-express": "^2.13.1", From a3f6e3ba266fff673c6c950844e8ff5bfe74e09c Mon Sep 17 00:00:00 2001 From: DXOS Date: Thu, 10 Dec 2020 01:30:04 +0000 Subject: [PATCH 8/8] v1.2.5-alpha.1 --- lerna.json | 2 +- packages/console-app/package.json | 2 +- packages/console-server/package.json | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lerna.json b/lerna.json index 3120d0a..74f6dab 100644 --- a/lerna.json +++ b/lerna.json @@ -1,5 +1,5 @@ { - "version": "1.2.5-alpha.0", + "version": "1.2.5-alpha.1", "useWorkspaces": true, "npmClient": "yarn" } diff --git a/packages/console-app/package.json b/packages/console-app/package.json index ef9da25..9addf3c 100644 --- a/packages/console-app/package.json +++ b/packages/console-app/package.json @@ -1,6 +1,6 @@ { "name": "@dxos/console-app", - "version": "1.2.5-alpha.0", + "version": "1.2.5-alpha.1", "description": "Kubenet Console Client", "repository": "https://github.com/dxos/console", "main": "dist/es/index.js", diff --git a/packages/console-server/package.json b/packages/console-server/package.json index bd97888..25a3462 100644 --- a/packages/console-server/package.json +++ b/packages/console-server/package.json @@ -1,6 +1,6 @@ { "name": "@dxos/console-server", - "version": "1.2.5-alpha.0", + "version": "1.2.5-alpha.1", "description": "Kubenet Console Server", "main": "dist/es/index.js", "bin": { @@ -31,7 +31,7 @@ "dependencies": { "@babel/polyfill": "^7.8.7", "@babel/runtime": "^7.8.7", - "@dxos/console-app": "^1.2.5-alpha.0", + "@dxos/console-app": "^1.2.5-alpha.1", "@wirelineio/wns-schema": "^0.1.1", "apollo-boost": "^0.4.9", "apollo-server-express": "^2.13.1",