Merge pull request #15280 from Budibase/type-portal-backups-store
Convert portal backups store to TS
This commit is contained in:
commit
9ca9416188
|
@ -1,40 +0,0 @@
|
||||||
import { writable } from "svelte/store"
|
|
||||||
import { API } from "@/api"
|
|
||||||
|
|
||||||
export function createBackupsStore() {
|
|
||||||
const store = writable({})
|
|
||||||
|
|
||||||
function selectBackup(backupId) {
|
|
||||||
store.update(state => {
|
|
||||||
state.selectedBackup = backupId
|
|
||||||
return state
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
async function searchBackups(appId, opts) {
|
|
||||||
return API.searchBackups(appId, opts)
|
|
||||||
}
|
|
||||||
|
|
||||||
async function restoreBackup(appId, backupId, name) {
|
|
||||||
return API.restoreBackup(appId, backupId, name)
|
|
||||||
}
|
|
||||||
|
|
||||||
async function deleteBackup(appId, backupId) {
|
|
||||||
return API.deleteBackup(appId, backupId)
|
|
||||||
}
|
|
||||||
|
|
||||||
async function createManualBackup(appId) {
|
|
||||||
return API.createManualBackup(appId)
|
|
||||||
}
|
|
||||||
|
|
||||||
return {
|
|
||||||
createManualBackup,
|
|
||||||
searchBackups,
|
|
||||||
selectBackup,
|
|
||||||
deleteBackup,
|
|
||||||
restoreBackup,
|
|
||||||
subscribe: store.subscribe,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
export const backups = createBackupsStore()
|
|
|
@ -1,5 +1,5 @@
|
||||||
import { it, expect, describe, beforeEach, vi } from "vitest"
|
import { it, expect, describe, beforeEach, vi } from "vitest"
|
||||||
import { createBackupsStore } from "./backups"
|
import { BackupStore } from "./backups"
|
||||||
import { writable } from "svelte/store"
|
import { writable } from "svelte/store"
|
||||||
import { API } from "@/api"
|
import { API } from "@/api"
|
||||||
|
|
||||||
|
@ -33,7 +33,7 @@ describe("backups store", () => {
|
||||||
ctx.writableReturn = { update: vi.fn(), subscribe: vi.fn() }
|
ctx.writableReturn = { update: vi.fn(), subscribe: vi.fn() }
|
||||||
writable.mockReturnValue(ctx.writableReturn)
|
writable.mockReturnValue(ctx.writableReturn)
|
||||||
|
|
||||||
ctx.returnedStore = createBackupsStore()
|
ctx.returnedStore = new BackupStore()
|
||||||
})
|
})
|
||||||
|
|
||||||
it("inits the writable store with the default config", () => {
|
it("inits the writable store with the default config", () => {
|
||||||
|
|
|
@ -0,0 +1,38 @@
|
||||||
|
import { API } from "@/api"
|
||||||
|
import { BudiStore } from "../BudiStore"
|
||||||
|
import { SearchAppBackupsRequest } from "@budibase/types"
|
||||||
|
|
||||||
|
interface BackupState {
|
||||||
|
selectedBackup?: string
|
||||||
|
}
|
||||||
|
|
||||||
|
export class BackupStore extends BudiStore<BackupState> {
|
||||||
|
constructor() {
|
||||||
|
super({})
|
||||||
|
}
|
||||||
|
|
||||||
|
selectBackup(backupId: string) {
|
||||||
|
this.update(state => {
|
||||||
|
state.selectedBackup = backupId
|
||||||
|
return state
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
async searchBackups(appId: string, opts: SearchAppBackupsRequest) {
|
||||||
|
return API.searchBackups(appId, opts)
|
||||||
|
}
|
||||||
|
|
||||||
|
async restoreBackup(appId: string, backupId: string, name?: string) {
|
||||||
|
return API.restoreBackup(appId, backupId, name)
|
||||||
|
}
|
||||||
|
|
||||||
|
async deleteBackup(appId: string, backupId: string) {
|
||||||
|
return API.deleteBackup(appId, backupId)
|
||||||
|
}
|
||||||
|
|
||||||
|
async createManualBackup(appId: string) {
|
||||||
|
return API.createManualBackup(appId)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export const backups = new BackupStore()
|
Loading…
Reference in New Issue