1
0
Fork 0
mirror of synced 2024-09-11 15:08:05 +12:00

Merge branch 'feature/environment-variables' of github.com:Budibase/budibase into feature/environment-variables

This commit is contained in:
mike12345567 2023-01-27 18:35:32 +00:00
commit 27f66c5ede
4 changed files with 73 additions and 15 deletions

View file

@ -16,6 +16,7 @@
runtimeToReadableMap, runtimeToReadableMap,
} from "builderStore/dataBinding" } from "builderStore/dataBinding"
import { cloneDeep } from "lodash/fp" import { cloneDeep } from "lodash/fp"
import { getEnvironmentBindings } from "builderStore/dataBinding"
export let datasource export let datasource
export let queries export let queries
@ -93,6 +94,7 @@
headings headings
bind:object={datasource.config.staticVariables} bind:object={datasource.config.staticVariables}
on:change on:change
bindings={getEnvironmentBindings()}
/> />
</Layout> </Layout>
<div /> <div />

View file

@ -1,9 +1,22 @@
<script> <script>
import { onMount } from "svelte" import { onMount } from "svelte"
import { ModalContent, Layout, Select, Body, Input } from "@budibase/bbui" import {
ModalContent,
Layout,
Select,
Body,
Input,
EnvDropdown,
Modal,
} from "@budibase/bbui"
import { AUTH_TYPE_LABELS, AUTH_TYPES } from "./authTypes" import { AUTH_TYPE_LABELS, AUTH_TYPES } from "./authTypes"
import BindableCombobox from "components/common/bindings/BindableCombobox.svelte" import BindableCombobox from "components/common/bindings/BindableCombobox.svelte"
import { getAuthBindings } from "builderStore/dataBinding" import {
getAuthBindings,
getEnvironmentBindings,
} from "builderStore/dataBinding"
import { environment, licensing, auth } from "stores/portal"
import CreateEditVariableModal from "components/portal/environment/CreateEditVariableModal.svelte"
export let configs export let configs
export let currentConfig export let currentConfig
@ -28,7 +41,16 @@
let hasErrors = false let hasErrors = false
let hasChanged = false let hasChanged = false
onMount(() => { let createVariableModal
let formFieldkey
onMount(async () => {
await environment.loadVariables()
if ($auth.user) {
await licensing.init()
}
if (currentConfig) { if (currentConfig) {
deconstructConfig() deconstructConfig()
} }
@ -146,6 +168,12 @@
} }
} }
const save = data => {
environment.createVariable(data)
form.basic[formFieldkey] = `{{ env.${data.name} }}`
createVariableModal.hide()
}
const onFieldChange = () => { const onFieldChange = () => {
checkErrors() checkErrors()
checkChanged() checkChanged()
@ -154,6 +182,16 @@
const onConfirmInternal = () => { const onConfirmInternal = () => {
onConfirm(constructConfig()) onConfirm(constructConfig())
} }
async function handleUpgradePanel() {
await environment.upgradePanelOpened()
$licensing.goToUpgradePage()
}
function showModal(key) {
formFieldkey = key
createVariableModal.show()
}
</script> </script>
<ModalContent <ModalContent
@ -189,26 +227,39 @@
error={blurred.type ? errors.type : null} error={blurred.type ? errors.type : null}
/> />
{#if form.type === AUTH_TYPES.BASIC} {#if form.type === AUTH_TYPES.BASIC}
<Input <EnvDropdown
label="Username" label="Username"
bind:value={form.basic.username} bind:value={form.basic.username}
on:change={onFieldChange} on:change={onFieldChange}
on:blur={() => (blurred.basic.username = true)} on:blur={() => (blurred.basic.username = true)}
error={blurred.basic.username ? errors.basic.username : null} error={blurred.basic.username ? errors.basic.username : null}
showModal={() => showModal("configKey")}
variables={$environment.variables}
environmentVariablesEnabled={$licensing.environmentVariablesEnabled}
{handleUpgradePanel}
/> />
<Input <EnvDropdown
label="Password" label="Password"
bind:value={form.basic.password} bind:value={form.basic.password}
on:change={onFieldChange} on:change={onFieldChange}
on:blur={() => (blurred.basic.password = true)} on:blur={() => (blurred.basic.password = true)}
error={blurred.basic.password ? errors.basic.password : null} error={blurred.basic.password ? errors.basic.password : null}
showModal={() => showModal("configKey")}
variables={$environment.variables}
environmentVariablesEnabled={$licensing.environmentVariablesEnabled}
{handleUpgradePanel}
/> />
{/if} {/if}
{#if form.type === AUTH_TYPES.BEARER} {#if form.type === AUTH_TYPES.BEARER}
<BindableCombobox <BindableCombobox
label="Token" label="Token"
value={form.bearer.token} value={form.bearer.token}
bindings={getAuthBindings()} bindings={[
...getAuthBindings(),
...($licensing.environmentVariablesEnabled
? getEnvironmentBindings()
: []),
]}
on:change={e => { on:change={e => {
form.bearer.token = e.detail form.bearer.token = e.detail
onFieldChange() onFieldChange()
@ -226,3 +277,7 @@
{/if} {/if}
</Layout> </Layout>
</ModalContent> </ModalContent>
<Modal bind:this={createVariableModal}>
<CreateEditVariableModal {save} />
</Modal>

View file

@ -20,7 +20,6 @@
let name = row?.name || "" let name = row?.name || ""
let productionValue let productionValue
let developmentValue let developmentValue
let useProductionValue = true let useProductionValue = true
const deleteVariable = name => { const deleteVariable = name => {
@ -71,7 +70,7 @@
<Input <Input
type="password" type="password"
on:change={e => { on:change={e => {
developmentValue = e.target.value developmentValue = e.detail
}} }}
disabled={useProductionValue} disabled={useProductionValue}
label="Value" label="Value"

View file

@ -56,7 +56,7 @@
<Heading size="M">Environment Variables</Heading> <Heading size="M">Environment Variables</Heading>
{#if !$licensing.environmentVariablesEnabled} {#if !$licensing.environmentVariablesEnabled}
<Tags> <Tags>
<Tag icon="LockClosed">Pro plan</Tag> <Tag icon="LockClosed">Business plan</Tag>
</Tags> </Tags>
{/if} {/if}
</div> </div>
@ -64,6 +64,8 @@
>Add and manage environment variables for development and production</Body >Add and manage environment variables for development and production</Body
> >
</Layout> </Layout>
<Divider size="S" />
{#if $licensing.environmentVariablesEnabled} {#if $licensing.environmentVariablesEnabled}
{#if noEncryptionKey} {#if noEncryptionKey}
<InlineAlert <InlineAlert
@ -72,7 +74,12 @@
type="error" type="error"
/> />
{/if} {/if}
<Divider size="S" /> <div>
<Button on:click={modal.show} cta disabled={noEncryptionKey}
>Add Variable</Button
>
</div>
<Layout noPadding> <Layout noPadding>
<Table <Table
{schema} {schema}
@ -83,11 +90,6 @@
{customRenderers} {customRenderers}
/> />
</Layout> </Layout>
<div>
<Button on:click={modal.show} cta disabled={noEncryptionKey}
>Add Variable</Button
>
</div>
{:else} {:else}
<div class="buttons"> <div class="buttons">
<Button <Button