Merge pull request #15170 from Budibase/ts-portal-admin-store

Convert portal admin store to typescript
This commit is contained in:
Andrew Kingston 2024-12-17 10:26:47 +00:00 committed by GitHub
commit a63b3a0c66
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 22 additions and 26 deletions

View File

@ -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: {

View File

@ -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

View File

@ -177,7 +177,7 @@
<Button
secondary
on:click={deleteSmtp}
disabled={!$admin.checklist.smtp.checked}
disabled={!$admin.checklist?.smtp?.checked}
>
Reset
</Button>

View File

@ -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),

View File

@ -2,27 +2,28 @@ 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 function createAdminStore() {
const admin = writable<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,
}
export function createAdminStore() {
const admin = writable(DEFAULT_CONFIG)
maintenance: [],
})
async function init() {
await getChecklist()