From 0da1dcee48ba3cef6dbe2478e0328727a64cc0f1 Mon Sep 17 00:00:00 2001 From: Andrew Kingston Date: Thu, 12 Dec 2024 14:48:06 +0000 Subject: [PATCH 1/4] Convert portal admin store to typescript --- packages/builder/src/api.ts | 6 ++--- packages/builder/src/index.d.ts | 8 ------- .../src/stores/portal/{admin.js => admin.ts} | 23 +++++++++++-------- 3 files changed, 16 insertions(+), 21 deletions(-) delete mode 100644 packages/builder/src/index.d.ts rename packages/builder/src/stores/portal/{admin.js => admin.ts} (86%) diff --git a/packages/builder/src/api.ts b/packages/builder/src/api.ts index 5d1a0beaeb..907354499f 100644 --- a/packages/builder/src/api.ts +++ b/packages/builder/src/api.ts @@ -8,7 +8,7 @@ import { get } from "svelte/store" import { auth, navigation } from "./stores/portal" export const API = createAPIClient({ - attachHeaders: (headers: Record) => { + attachHeaders: headers => { // Attach app ID header from store let appId = get(appStore).appId if (appId) { @@ -22,7 +22,7 @@ export const API = createAPIClient({ } }, - onError: (error: any) => { + onError: error => { const { url, message, status, method, handled } = error || {} // Log any errors that we haven't manually handled @@ -45,7 +45,7 @@ export const API = createAPIClient({ } } }, - onMigrationDetected: (appId: string) => { + onMigrationDetected: appId => { const updatingUrl = `/builder/app/updating/${appId}` if (window.location.pathname === updatingUrl) { diff --git a/packages/builder/src/index.d.ts b/packages/builder/src/index.d.ts deleted file mode 100644 index 1cbad4f12c..0000000000 --- a/packages/builder/src/index.d.ts +++ /dev/null @@ -1,8 +0,0 @@ -declare module "api" { - const API: { - getPlugins: () => Promise - createPlugin: (plugin: object) => Promise - uploadPlugin: (plugin: FormData) => Promise - deletePlugin: (id: string) => Promise - } -} diff --git a/packages/builder/src/stores/portal/admin.js b/packages/builder/src/stores/portal/admin.ts similarity index 86% rename from packages/builder/src/stores/portal/admin.js rename to packages/builder/src/stores/portal/admin.ts index 54757fb314..9003be8953 100644 --- a/packages/builder/src/stores/portal/admin.js +++ b/packages/builder/src/stores/portal/admin.ts @@ -2,23 +2,26 @@ import { writable, get } from "svelte/store" import { API } from "api" import { auth } from "stores/portal" import { banner } from "@budibase/bbui" +import { + ConfigChecklistResponse, + GetEnvironmentResponse, + SystemStatusResponse, +} from "@budibase/types" -export const DEFAULT_CONFIG = { +interface PortalAdminStore extends GetEnvironmentResponse { + loaded: boolean + checklist?: ConfigChecklistResponse + status?: SystemStatusResponse +} + +export const DEFAULT_CONFIG: PortalAdminStore = { loaded: false, multiTenancy: false, cloud: false, isDev: false, disableAccountPortal: false, - accountPortalUrl: "", - importComplete: false, - checklist: { - apps: { checked: false }, - smtp: { checked: false }, - adminUser: { checked: false }, - sso: { checked: false }, - }, - maintenance: [], offlineMode: false, + maintenance: [], } export function createAdminStore() { From 512d87ac36de50e1e596c65759200db83b052801 Mon Sep 17 00:00:00 2001 From: Andrew Kingston Date: Thu, 12 Dec 2024 14:57:24 +0000 Subject: [PATCH 2/4] Remove redundant default store value --- packages/builder/src/stores/portal/admin.ts | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/packages/builder/src/stores/portal/admin.ts b/packages/builder/src/stores/portal/admin.ts index 9003be8953..2141cf1b9c 100644 --- a/packages/builder/src/stores/portal/admin.ts +++ b/packages/builder/src/stores/portal/admin.ts @@ -14,18 +14,16 @@ interface PortalAdminStore extends GetEnvironmentResponse { status?: SystemStatusResponse } -export const DEFAULT_CONFIG: PortalAdminStore = { - loaded: false, - multiTenancy: false, - cloud: false, - isDev: false, - disableAccountPortal: false, - offlineMode: false, - maintenance: [], -} - export function createAdminStore() { - const admin = writable(DEFAULT_CONFIG) + const admin = writable({ + loaded: false, + multiTenancy: false, + cloud: false, + isDev: false, + disableAccountPortal: false, + offlineMode: false, + maintenance: [], + }) async function init() { await getChecklist() From 3dfdb740acc6d77d40a2a2e913782b9de06e8d12 Mon Sep 17 00:00:00 2001 From: Andrew Kingston Date: Thu, 12 Dec 2024 14:58:55 +0000 Subject: [PATCH 3/4] Ensure admin store checklist is optional --- .../automation/AutomationBuilder/FlowChart/ActionModal.svelte | 2 +- packages/builder/src/pages/builder/admin/_layout.svelte | 2 +- .../src/pages/builder/portal/settings/email/index.svelte | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/builder/src/components/automation/AutomationBuilder/FlowChart/ActionModal.svelte b/packages/builder/src/components/automation/AutomationBuilder/FlowChart/ActionModal.svelte index 524e70e329..88201aa225 100644 --- a/packages/builder/src/components/automation/AutomationBuilder/FlowChart/ActionModal.svelte +++ b/packages/builder/src/components/automation/AutomationBuilder/FlowChart/ActionModal.svelte @@ -49,7 +49,7 @@ const disabled = () => { return { SEND_EMAIL_SMTP: { - disabled: !$admin.checklist.smtp.checked, + disabled: !$admin.checklist?.smtp?.checked, message: "Please configure SMTP", }, COLLECT: { diff --git a/packages/builder/src/pages/builder/admin/_layout.svelte b/packages/builder/src/pages/builder/admin/_layout.svelte index f03a7b8285..b304d91710 100644 --- a/packages/builder/src/pages/builder/admin/_layout.svelte +++ b/packages/builder/src/pages/builder/admin/_layout.svelte @@ -9,7 +9,7 @@ $: useAccountPortal = cloud && !$admin.disableAccountPortal onMount(() => { - if ($admin?.checklist?.adminUser.checked || useAccountPortal) { + if ($admin?.checklist?.adminUser?.checked || useAccountPortal) { $redirect("../") } else { loaded = true diff --git a/packages/builder/src/pages/builder/portal/settings/email/index.svelte b/packages/builder/src/pages/builder/portal/settings/email/index.svelte index 0b9fb44bac..4d76c4f49c 100644 --- a/packages/builder/src/pages/builder/portal/settings/email/index.svelte +++ b/packages/builder/src/pages/builder/portal/settings/email/index.svelte @@ -177,7 +177,7 @@ From b57aa1675baab7ad4b4d10cfb58e2636b7178867 Mon Sep 17 00:00:00 2001 From: Andrew Kingston Date: Thu, 12 Dec 2024 15:00:45 +0000 Subject: [PATCH 4/4] Update tests --- packages/builder/src/stores/portal/admin.test.js | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/packages/builder/src/stores/portal/admin.test.js b/packages/builder/src/stores/portal/admin.test.js index a3f1e645c3..a4adb4320a 100644 --- a/packages/builder/src/stores/portal/admin.test.js +++ b/packages/builder/src/stores/portal/admin.test.js @@ -1,5 +1,5 @@ import { it, expect, describe, beforeEach, vi } from "vitest" -import { DEFAULT_CONFIG, createAdminStore } from "./admin" +import { createAdminStore } from "./admin" import { writable, get } from "svelte/store" import { API } from "api" @@ -45,11 +45,6 @@ describe("admin store", () => { ctx.returnedStore = createAdminStore() }) - it("inits the writable store with the default config", () => { - expect(writable).toHaveBeenCalledTimes(1) - expect(writable).toHaveBeenCalledWith(DEFAULT_CONFIG) - }) - it("returns the created store", ctx => { expect(ctx.returnedStore).toEqual({ subscribe: expect.toBe(ctx.writableReturn.subscribe),