Convert admin store to BudiStore
This commit is contained in:
parent
12b283d41e
commit
502c160530
|
@ -1,4 +1,4 @@
|
||||||
import { writable, get } from "svelte/store"
|
import { get } from "svelte/store"
|
||||||
import { API } from "@/api"
|
import { API } from "@/api"
|
||||||
import { auth } from "@/stores/portal"
|
import { auth } from "@/stores/portal"
|
||||||
import { banner } from "@budibase/bbui"
|
import { banner } from "@budibase/bbui"
|
||||||
|
@ -7,42 +7,44 @@ import {
|
||||||
GetEnvironmentResponse,
|
GetEnvironmentResponse,
|
||||||
SystemStatusResponse,
|
SystemStatusResponse,
|
||||||
} from "@budibase/types"
|
} from "@budibase/types"
|
||||||
|
import { BudiStore } from "../BudiStore"
|
||||||
|
|
||||||
interface PortalAdminStore extends GetEnvironmentResponse {
|
interface AdminState extends GetEnvironmentResponse {
|
||||||
loaded: boolean
|
loaded: boolean
|
||||||
checklist?: ConfigChecklistResponse
|
checklist?: ConfigChecklistResponse
|
||||||
status?: SystemStatusResponse
|
status?: SystemStatusResponse
|
||||||
}
|
}
|
||||||
|
|
||||||
export function createAdminStore() {
|
class AdminStore extends BudiStore<AdminState> {
|
||||||
const admin = writable<PortalAdminStore>({
|
constructor() {
|
||||||
loaded: false,
|
super({
|
||||||
multiTenancy: false,
|
loaded: false,
|
||||||
cloud: false,
|
multiTenancy: false,
|
||||||
isDev: false,
|
cloud: false,
|
||||||
disableAccountPortal: false,
|
isDev: false,
|
||||||
offlineMode: false,
|
disableAccountPortal: false,
|
||||||
maintenance: [],
|
offlineMode: false,
|
||||||
})
|
maintenance: [],
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
async function init() {
|
async init() {
|
||||||
await getChecklist()
|
await this.getChecklist()
|
||||||
await getEnvironment()
|
await this.getEnvironment()
|
||||||
// enable system status checks in the cloud
|
// enable system status checks in the cloud
|
||||||
if (get(admin).cloud) {
|
if (get(this.store).cloud) {
|
||||||
await getSystemStatus()
|
await this.getSystemStatus()
|
||||||
checkStatus()
|
this.checkStatus()
|
||||||
}
|
}
|
||||||
|
this.update(store => {
|
||||||
admin.update(store => {
|
|
||||||
store.loaded = true
|
store.loaded = true
|
||||||
return store
|
return store
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
async function getEnvironment() {
|
async getEnvironment() {
|
||||||
const environment = await API.getEnvironment()
|
const environment = await API.getEnvironment()
|
||||||
admin.update(store => {
|
this.update(store => {
|
||||||
store.multiTenancy = environment.multiTenancy
|
store.multiTenancy = environment.multiTenancy
|
||||||
store.cloud = environment.cloud
|
store.cloud = environment.cloud
|
||||||
store.disableAccountPortal = environment.disableAccountPortal
|
store.disableAccountPortal = environment.disableAccountPortal
|
||||||
|
@ -56,43 +58,36 @@ export function createAdminStore() {
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
const checkStatus = async () => {
|
async checkStatus() {
|
||||||
const health = get(admin)?.status?.health
|
const health = get(this.store).status?.health
|
||||||
if (!health?.passing) {
|
if (!health?.passing) {
|
||||||
await banner.showStatus()
|
await banner.showStatus()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function getSystemStatus() {
|
async getSystemStatus() {
|
||||||
const status = await API.getSystemStatus()
|
const status = await API.getSystemStatus()
|
||||||
admin.update(store => {
|
this.update(store => {
|
||||||
store.status = status
|
store.status = status
|
||||||
return store
|
return store
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
async function getChecklist() {
|
async getChecklist() {
|
||||||
const tenantId = get(auth).tenantId
|
const tenantId = get(auth).tenantId
|
||||||
const checklist = await API.getChecklist(tenantId)
|
const checklist = await API.getChecklist(tenantId)
|
||||||
admin.update(store => {
|
this.update(store => {
|
||||||
store.checklist = checklist
|
store.checklist = checklist
|
||||||
return store
|
return store
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
function unload() {
|
unload() {
|
||||||
admin.update(store => {
|
this.update(store => {
|
||||||
store.loaded = false
|
store.loaded = false
|
||||||
return store
|
return store
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
return {
|
|
||||||
subscribe: admin.subscribe,
|
|
||||||
init,
|
|
||||||
unload,
|
|
||||||
getChecklist,
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export const admin = createAdminStore()
|
export const admin = new AdminStore()
|
||||||
|
|
Loading…
Reference in New Issue