1
0
Fork 0
mirror of synced 2024-09-21 20:01:32 +12:00
budibase/packages/builder/src/components/start/ExportAppModal.svelte

95 lines
2.4 KiB
Svelte
Raw Normal View History

2022-05-25 20:26:10 +12:00
<script>
2023-06-13 22:21:54 +12:00
import {
ModalContent,
Toggle,
Body,
InlineAlert,
Input,
} from "@budibase/bbui"
2023-06-13 22:57:56 +12:00
import { createValidationStore } from "helpers/validation/yup"
2022-05-25 20:26:10 +12:00
export let app
export let published
2023-06-13 21:00:01 +12:00
let includeInternalTablesRows = true
let encypt = true
2023-06-13 22:57:56 +12:00
2023-06-13 22:21:54 +12:00
let password
2023-06-13 22:57:56 +12:00
const validation = createValidationStore()
validation.addValidatorType("password", "password", "true")
function validate() {
return validation.check({ password })
}
$: {
if ($validation.errors.length) {
validate()
}
}
2022-05-25 20:26:10 +12:00
2023-06-13 22:15:32 +12:00
const Step = { CONFIG: "config", SET_PASSWORD: "set_password" }
2023-06-13 22:57:56 +12:00
let currentStep = Step.SET_PASSWORD
2023-06-13 22:15:32 +12:00
$: exportButtonText = published ? "Export published" : "Export latest"
$: stepConfig = {
[Step.CONFIG]: {
title: published ? "Export published app" : "Export latest app",
confirmText: encypt ? "Continue" : exportButtonText,
onConfirm: () => {
if (!encypt) {
exportApp()
} else {
currentStep = Step.SET_PASSWORD
return false
}
},
},
[Step.SET_PASSWORD]: {
title: "Add password to encrypt your export",
confirmText: exportButtonText,
2023-06-13 22:57:56 +12:00
onConfirm: async () => {
await validate()
if (!$validation.valid) {
2023-06-13 22:21:54 +12:00
return false
}
2023-06-13 22:15:32 +12:00
exportApp()
},
},
}
2022-05-25 20:26:10 +12:00
const exportApp = () => {
const id = published ? app.prodId : app.devId
2022-05-25 20:26:10 +12:00
const appName = encodeURIComponent(app.name)
2023-06-13 21:00:01 +12:00
window.location = `/api/backups/export?appId=${id}&appname=${appName}&excludeRows=${!includeInternalTablesRows}`
2022-05-25 20:26:10 +12:00
}
</script>
2023-06-13 22:15:32 +12:00
<ModalContent
title={stepConfig[currentStep].title}
confirmText={stepConfig[currentStep].confirmText}
onConfirm={stepConfig[currentStep].onConfirm}
>
2023-06-13 22:21:54 +12:00
{#if currentStep === Step.CONFIG}
2023-06-13 22:57:56 +12:00
<Body>
<Toggle
text="Export rows from internal tables"
bind:value={includeInternalTablesRows}
/>
<Toggle text="Encrypt my export" bind:value={encypt} />
</Body>
{#if !encypt}
<InlineAlert
header="Do not share your budibase application exports publicly as they may contain sensitive information such as database credentials or secret keys."
2023-06-13 22:21:54 +12:00
/>
{/if}
{/if}
{#if currentStep === Step.SET_PASSWORD}
<Input
2023-06-13 22:57:56 +12:00
type="password"
2023-06-13 22:21:54 +12:00
label="Password"
placeholder="Type here..."
bind:value={password}
2023-06-13 22:57:56 +12:00
error={$validation.errors.password}
2023-06-13 21:00:01 +12:00
/>
{/if}
2022-05-25 20:26:10 +12:00
</ModalContent>