Merge branch 'master' into builder-store-conversions-pc
This commit is contained in:
commit
961ff82c96
|
@ -34,7 +34,7 @@
|
|||
async function saveTemplate() {
|
||||
try {
|
||||
// Save your template config
|
||||
await email.templates.save(selectedTemplate)
|
||||
await email.saveTemplate(selectedTemplate)
|
||||
notifications.success("Template saved")
|
||||
} catch (error) {
|
||||
notifications.error("Failed to update template settings")
|
||||
|
|
|
@ -5,7 +5,7 @@
|
|||
|
||||
onMount(async () => {
|
||||
try {
|
||||
await email.templates.fetch()
|
||||
await email.fetchTemplates()
|
||||
} catch (error) {
|
||||
notifications.error("Error fetching email templates")
|
||||
}
|
||||
|
|
|
@ -10,7 +10,8 @@
|
|||
let deleteDialog
|
||||
|
||||
const save = async data => {
|
||||
await environment.updateVariable(data)
|
||||
const { name, ...rest } = data
|
||||
await environment.updateVariable(name, rest)
|
||||
editVariableModal.hide()
|
||||
}
|
||||
</script>
|
||||
|
|
|
@ -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 { createBackupsStore } from "./backups"
|
||||
import { BackupStore } from "./backups"
|
||||
import { writable } from "svelte/store"
|
||||
import { API } from "@/api"
|
||||
|
||||
|
@ -33,7 +33,7 @@ describe("backups store", () => {
|
|||
ctx.writableReturn = { update: vi.fn(), subscribe: vi.fn() }
|
||||
writable.mockReturnValue(ctx.writableReturn)
|
||||
|
||||
ctx.returnedStore = createBackupsStore()
|
||||
ctx.returnedStore = new BackupStore()
|
||||
})
|
||||
|
||||
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()
|
|
@ -1,36 +0,0 @@
|
|||
import { writable } from "svelte/store"
|
||||
import { API } from "@/api"
|
||||
|
||||
export function createEmailStore() {
|
||||
const store = writable({})
|
||||
|
||||
return {
|
||||
subscribe: store.subscribe,
|
||||
templates: {
|
||||
fetch: async () => {
|
||||
// Fetch the email template definitions and templates
|
||||
const definitions = await API.getEmailTemplateDefinitions()
|
||||
const templates = await API.getEmailTemplates()
|
||||
store.set({
|
||||
definitions,
|
||||
templates,
|
||||
})
|
||||
},
|
||||
save: async template => {
|
||||
// Save your template config
|
||||
const savedTemplate = await API.saveEmailTemplate(template)
|
||||
template._rev = savedTemplate._rev
|
||||
template._id = savedTemplate._id
|
||||
store.update(state => {
|
||||
const currentIdx = state.templates.findIndex(
|
||||
template => template.purpose === savedTemplate.purpose
|
||||
)
|
||||
state.templates.splice(currentIdx, 1, template)
|
||||
return state
|
||||
})
|
||||
},
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
export const email = createEmailStore()
|
|
@ -0,0 +1,43 @@
|
|||
import { API } from "@/api"
|
||||
import { BudiStore } from "../BudiStore"
|
||||
import {
|
||||
FetchGlobalTemplateDefinitionResponse,
|
||||
Template,
|
||||
} from "@budibase/types"
|
||||
|
||||
interface EmailState {
|
||||
definitions?: FetchGlobalTemplateDefinitionResponse
|
||||
templates: Template[]
|
||||
}
|
||||
|
||||
class EmailStore extends BudiStore<EmailState> {
|
||||
constructor() {
|
||||
super({
|
||||
templates: [],
|
||||
})
|
||||
}
|
||||
|
||||
async fetchTemplates() {
|
||||
const definitions = await API.getEmailTemplateDefinitions()
|
||||
const templates = await API.getEmailTemplates()
|
||||
this.set({
|
||||
definitions,
|
||||
templates,
|
||||
})
|
||||
}
|
||||
|
||||
async saveTemplate(template: Template) {
|
||||
const savedTemplate = await API.saveEmailTemplate(template)
|
||||
template._rev = savedTemplate._rev
|
||||
template._id = savedTemplate._id
|
||||
this.update(state => {
|
||||
const currentIdx = state.templates.findIndex(
|
||||
template => template.purpose === savedTemplate.purpose
|
||||
)
|
||||
state.templates.splice(currentIdx, 1, template)
|
||||
return state
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
export const email = new EmailStore()
|
|
@ -1,71 +0,0 @@
|
|||
import { writable, get } from "svelte/store"
|
||||
import { API } from "@/api"
|
||||
import { Constants } from "@budibase/frontend-core"
|
||||
import { licensing } from "@/stores/portal"
|
||||
|
||||
export function createEnvironmentStore() {
|
||||
const { subscribe, update } = writable({
|
||||
variables: [],
|
||||
status: {},
|
||||
})
|
||||
|
||||
async function checkStatus() {
|
||||
const status = await API.checkEnvironmentVariableStatus()
|
||||
update(store => {
|
||||
store.status = status
|
||||
return store
|
||||
})
|
||||
}
|
||||
|
||||
async function loadVariables() {
|
||||
if (get(licensing).environmentVariablesEnabled) {
|
||||
const envVars = await API.fetchEnvironmentVariables()
|
||||
const mappedVars = envVars.variables.map(name => ({ name }))
|
||||
update(store => {
|
||||
store.variables = mappedVars
|
||||
return store
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
async function createVariable(data) {
|
||||
await API.createEnvironmentVariable(data)
|
||||
let mappedVar = { name: data.name }
|
||||
update(store => {
|
||||
store.variables = [mappedVar, ...store.variables]
|
||||
return store
|
||||
})
|
||||
}
|
||||
|
||||
async function deleteVariable(varName) {
|
||||
await API.deleteEnvironmentVariable(varName)
|
||||
update(store => {
|
||||
store.variables = store.variables.filter(
|
||||
envVar => envVar.name !== varName
|
||||
)
|
||||
return store
|
||||
})
|
||||
}
|
||||
|
||||
async function updateVariable(data) {
|
||||
await API.updateEnvironmentVariable(data)
|
||||
}
|
||||
|
||||
async function upgradePanelOpened() {
|
||||
await API.publishEvent(
|
||||
Constants.EventPublishType.ENV_VAR_UPGRADE_PANEL_OPENED
|
||||
)
|
||||
}
|
||||
|
||||
return {
|
||||
subscribe,
|
||||
checkStatus,
|
||||
loadVariables,
|
||||
createVariable,
|
||||
deleteVariable,
|
||||
updateVariable,
|
||||
upgradePanelOpened,
|
||||
}
|
||||
}
|
||||
|
||||
export const environment = createEnvironmentStore()
|
|
@ -0,0 +1,79 @@
|
|||
import { get } from "svelte/store"
|
||||
import { API } from "@/api"
|
||||
import { licensing } from "@/stores/portal"
|
||||
import { BudiStore } from "../BudiStore"
|
||||
import {
|
||||
CreateEnvironmentVariableRequest,
|
||||
EventPublishType,
|
||||
StatusEnvironmentVariableResponse,
|
||||
UpdateEnvironmentVariableRequest,
|
||||
} from "@budibase/types"
|
||||
|
||||
type EnvVar = {
|
||||
name: string
|
||||
}
|
||||
|
||||
interface EnvironmentState {
|
||||
variables: EnvVar[]
|
||||
status: StatusEnvironmentVariableResponse
|
||||
}
|
||||
|
||||
class EnvironmentStore extends BudiStore<EnvironmentState> {
|
||||
constructor() {
|
||||
super({
|
||||
variables: [],
|
||||
status: {
|
||||
encryptionKeyAvailable: false,
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
async checkStatus() {
|
||||
const status = await API.checkEnvironmentVariableStatus()
|
||||
this.update(store => {
|
||||
store.status = status
|
||||
return store
|
||||
})
|
||||
}
|
||||
|
||||
async loadVariables() {
|
||||
if (get(licensing).environmentVariablesEnabled) {
|
||||
const envVars: string[] = (await API.fetchEnvironmentVariables())
|
||||
.variables
|
||||
const mappedVars = envVars.map(name => ({ name }))
|
||||
this.update(store => {
|
||||
store.variables = mappedVars
|
||||
return store
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
async createVariable(data: CreateEnvironmentVariableRequest) {
|
||||
await API.createEnvironmentVariable(data)
|
||||
let mappedVar = { name: data.name }
|
||||
this.update(state => {
|
||||
state.variables = [mappedVar, ...state.variables]
|
||||
return state
|
||||
})
|
||||
}
|
||||
|
||||
async deleteVariable(name: string) {
|
||||
await API.deleteEnvironmentVariable(name)
|
||||
this.update(state => {
|
||||
state.variables = state.variables.filter(envVar => envVar.name !== name)
|
||||
return state
|
||||
})
|
||||
}
|
||||
|
||||
async updateVariable(name: string, data: UpdateEnvironmentVariableRequest) {
|
||||
await API.updateEnvironmentVariable(name, data)
|
||||
}
|
||||
|
||||
async upgradePanelOpened() {
|
||||
await API.publishEvent(
|
||||
EventPublishType.ENVIRONMENT_VARIABLE_UPGRADE_PANEL_OPENED
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
export const environment = new EnvironmentStore()
|
Loading…
Reference in New Issue