From 9e0a10955a6aa77b468ccc5d6661e346810d6f81 Mon Sep 17 00:00:00 2001 From: Rory Powell Date: Thu, 24 Feb 2022 14:41:24 +0000 Subject: [PATCH] Add status banner that reacts to cypress healthcheck failures --- packages/backend-core/src/cloud/accounts.js | 15 +++++++ packages/bbui/src/Banner/Banner.svelte | 6 +++ packages/bbui/src/Banner/BannerDisplay.svelte | 42 +++++++++++++++++++ packages/bbui/src/Stores/banner.js | 37 ++++++++++++++++ packages/bbui/src/index.js | 2 + packages/bbui/yarn.lock | 8 ++-- packages/builder/src/App.svelte | 3 +- packages/builder/src/stores/portal/admin.js | 23 ++++++++++ packages/frontend-core/src/api/other.js | 9 ++++ .../src/api/controllers/global/users.js | 15 +++++++ .../src/api/controllers/system/status.js | 9 ++++ packages/worker/src/api/index.js | 5 ++- packages/worker/src/api/routes/index.js | 2 + .../worker/src/api/routes/system/status.js | 8 ++++ 14 files changed, 178 insertions(+), 6 deletions(-) create mode 100644 packages/bbui/src/Banner/BannerDisplay.svelte create mode 100644 packages/bbui/src/Stores/banner.js create mode 100644 packages/worker/src/api/controllers/system/status.js create mode 100644 packages/worker/src/api/routes/system/status.js diff --git a/packages/backend-core/src/cloud/accounts.js b/packages/backend-core/src/cloud/accounts.js index b2e8817ad6..5730bc67a5 100644 --- a/packages/backend-core/src/cloud/accounts.js +++ b/packages/backend-core/src/cloud/accounts.js @@ -22,3 +22,18 @@ exports.getAccount = async email => { return json[0] } + +exports.getStatus = async () => { + const response = await api.get(`/api/status`, { + headers: { + [Headers.API_KEY]: env.ACCOUNT_PORTAL_API_KEY, + }, + }) + const json = await response.json() + + if (response.status !== 200) { + throw new Error(`Error getting status`) + } + + return json +} diff --git a/packages/bbui/src/Banner/Banner.svelte b/packages/bbui/src/Banner/Banner.svelte index f28ee09d9c..63dfdd341f 100644 --- a/packages/bbui/src/Banner/Banner.svelte +++ b/packages/bbui/src/Banner/Banner.svelte @@ -57,3 +57,9 @@ {/if} + + diff --git a/packages/bbui/src/Banner/BannerDisplay.svelte b/packages/bbui/src/Banner/BannerDisplay.svelte new file mode 100644 index 0000000000..f048a3c030 --- /dev/null +++ b/packages/bbui/src/Banner/BannerDisplay.svelte @@ -0,0 +1,42 @@ + + + + + + + diff --git a/packages/bbui/src/Stores/banner.js b/packages/bbui/src/Stores/banner.js new file mode 100644 index 0000000000..81a9ee2204 --- /dev/null +++ b/packages/bbui/src/Stores/banner.js @@ -0,0 +1,37 @@ +import { writable } from "svelte/store" + +export function createBannerStore() { + const DEFAULT_CONFIG = {} + + const banner = writable(DEFAULT_CONFIG) + + const show = async ( + // eslint-disable-next-line + config = { message, type, extraButtonText, extraButtonAction, onChange } + ) => { + banner.update(store => { + return { + ...store, + ...config, + } + }) + } + + const showStatus = async () => { + const config = { + message: "Some systems are experiencing issues", + type: "negative", + extraButtonText: "View Status", + extraButtonAction: () => window.open("https://status.budibase.com/"), + } + + await show(config) + } + + return { + subscribe: banner.subscribe, + showStatus, + } +} + +export const banner = createBannerStore() diff --git a/packages/bbui/src/index.js b/packages/bbui/src/index.js index d3bc11cf9d..2b16f32b84 100644 --- a/packages/bbui/src/index.js +++ b/packages/bbui/src/index.js @@ -60,6 +60,7 @@ export { default as StatusLight } from "./StatusLight/StatusLight.svelte" export { default as ColorPicker } from "./ColorPicker/ColorPicker.svelte" export { default as InlineAlert } from "./InlineAlert/InlineAlert.svelte" export { default as Banner } from "./Banner/Banner.svelte" +export { default as BannerDisplay } from "./Banner/BannerDisplay.svelte" export { default as MarkdownEditor } from "./Markdown/MarkdownEditor.svelte" export { default as MarkdownViewer } from "./Markdown/MarkdownViewer.svelte" export { default as RichTextField } from "./Form/RichTextField.svelte" @@ -84,6 +85,7 @@ export { default as clickOutside } from "./Actions/click_outside" // Stores export { notifications, createNotificationStore } from "./Stores/notifications" +export { banner } from "./Stores/banner" // Helpers export * as Helpers from "./helpers" diff --git a/packages/bbui/yarn.lock b/packages/bbui/yarn.lock index 28c009b331..33c3c391be 100644 --- a/packages/bbui/yarn.lock +++ b/packages/bbui/yarn.lock @@ -53,10 +53,10 @@ to-gfm-code-block "^0.1.1" year "^0.2.1" -"@budibase/string-templates@^1.0.66-alpha.0": - version "1.0.72" - resolved "https://registry.yarnpkg.com/@budibase/string-templates/-/string-templates-1.0.72.tgz#acc154e402cce98ea30eedde9c6124183ee9b37c" - integrity sha512-w715TjgO6NUHkZNqoOEo8lAKJ/PQ4b00ATWSX5VB523SAu7y/uOiqKqV1E3fgwxq1o8L+Ff7rn9FTkiYtjkV/g== +"@budibase/string-templates@^1.0.72-alpha.0": + version "1.0.75" + resolved "https://registry.yarnpkg.com/@budibase/string-templates/-/string-templates-1.0.75.tgz#5b4061f1a626160ec092f32f036541376298100c" + integrity sha512-hPgr6n5cpSCGFEha5DS/P+rtRXOLc72M6y4J/scl59JvUi/ZUJkjRgJdpQPdBLu04CNKp89V59+rAqAuDjOC0g== dependencies: "@budibase/handlebars-helpers" "^0.11.7" dayjs "^1.10.4" diff --git a/packages/builder/src/App.svelte b/packages/builder/src/App.svelte index 60051ea043..97b7d70fad 100644 --- a/packages/builder/src/App.svelte +++ b/packages/builder/src/App.svelte @@ -1,7 +1,7 @@ +