Use EnvVariableInput
This commit is contained in:
parent
c8a3a59e2b
commit
dfc7c49afa
|
@ -9,7 +9,8 @@
|
||||||
import CreateEditVariableModal from "./CreateEditVariableModal.svelte"
|
import CreateEditVariableModal from "./CreateEditVariableModal.svelte"
|
||||||
import type { CreateEnvironmentVariableRequest } from "@budibase/types"
|
import type { CreateEnvironmentVariableRequest } from "@budibase/types"
|
||||||
|
|
||||||
export let type: EnvDropdownType
|
export let label: string = ""
|
||||||
|
export let type: EnvDropdownType = "text"
|
||||||
export let value: string | undefined = undefined
|
export let value: string | undefined = undefined
|
||||||
export let error: string | undefined = undefined
|
export let error: string | undefined = undefined
|
||||||
export let placeholder: string | undefined = undefined
|
export let placeholder: string | undefined = undefined
|
||||||
|
@ -32,9 +33,11 @@
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
{value}
|
||||||
<EnvDropdown
|
<EnvDropdown
|
||||||
on:change
|
on:change
|
||||||
on:blur
|
on:blur
|
||||||
|
{label}
|
||||||
type={type === "port" ? "string" : type}
|
type={type === "port" ? "string" : type}
|
||||||
{value}
|
{value}
|
||||||
{error}
|
{error}
|
||||||
|
|
|
@ -1,20 +1,23 @@
|
||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import { onMount } from "svelte"
|
import { onMount } from "svelte"
|
||||||
import {
|
import { ModalContent, Layout, Select, Body, Input } from "@budibase/bbui"
|
||||||
ModalContent,
|
|
||||||
Layout,
|
|
||||||
Select,
|
|
||||||
Body,
|
|
||||||
Input,
|
|
||||||
EnvDropdown,
|
|
||||||
Modal,
|
|
||||||
notifications,
|
|
||||||
} 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"
|
import { BindableCombobox } from "@/components/common/bindings"
|
||||||
import { getAuthBindings, getEnvironmentBindings } from "@/dataBinding"
|
import { getAuthBindings, getEnvironmentBindings } from "@/dataBinding"
|
||||||
import { environment, licensing, auth } from "@/stores/portal"
|
import { environment, licensing, auth } from "@/stores/portal"
|
||||||
import CreateEditVariableModal from "@/components/portal/environment/CreateEditVariableModal.svelte"
|
import EnvVariableInput from "@/components/portal/environment/EnvVariableInput.svelte"
|
||||||
|
|
||||||
|
interface FormData {
|
||||||
|
name?: string
|
||||||
|
type?: string
|
||||||
|
basic: {
|
||||||
|
username?: string
|
||||||
|
password?: string
|
||||||
|
}
|
||||||
|
bearer: {
|
||||||
|
token?: string
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
export let configs
|
export let configs
|
||||||
export let currentConfig
|
export let currentConfig
|
||||||
|
@ -49,9 +52,6 @@
|
||||||
let hasErrors = false
|
let hasErrors = false
|
||||||
let hasChanged = false
|
let hasChanged = false
|
||||||
|
|
||||||
let createVariableModal: Modal
|
|
||||||
let formFieldkey: string
|
|
||||||
|
|
||||||
onMount(async () => {
|
onMount(async () => {
|
||||||
try {
|
try {
|
||||||
await environment.loadVariables()
|
await environment.loadVariables()
|
||||||
|
@ -179,16 +179,6 @@
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const save = async (data: any) => {
|
|
||||||
try {
|
|
||||||
await environment.createVariable(data)
|
|
||||||
form.basic[formFieldkey] = `{{ env.${data.name} }}`
|
|
||||||
createVariableModal.hide()
|
|
||||||
} catch (err: any) {
|
|
||||||
notifications.error(`Failed to create variable: ${err.message}`)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const onFieldChange = () => {
|
const onFieldChange = () => {
|
||||||
checkErrors()
|
checkErrors()
|
||||||
checkChanged()
|
checkChanged()
|
||||||
|
@ -197,16 +187,6 @@
|
||||||
const onConfirmInternal = () => {
|
const onConfirmInternal = () => {
|
||||||
onConfirm(constructConfig())
|
onConfirm(constructConfig())
|
||||||
}
|
}
|
||||||
|
|
||||||
async function handleUpgradePanel() {
|
|
||||||
await environment.upgradePanelOpened()
|
|
||||||
$licensing.goToUpgradePage()
|
|
||||||
}
|
|
||||||
|
|
||||||
function showModal(key: any) {
|
|
||||||
formFieldkey = key
|
|
||||||
createVariableModal.show()
|
|
||||||
}
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<ModalContent
|
<ModalContent
|
||||||
|
@ -242,28 +222,21 @@
|
||||||
error={blurred.type ? errors.type : undefined}
|
error={blurred.type ? errors.type : undefined}
|
||||||
/>
|
/>
|
||||||
{#if form.type === AUTH_TYPES.BASIC}
|
{#if form.type === AUTH_TYPES.BASIC}
|
||||||
<EnvDropdown
|
<EnvVariableInput
|
||||||
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 : undefined}
|
||||||
showModal={() => showModal("configKey")}
|
|
||||||
variables={$environment.variables}
|
|
||||||
environmentVariablesEnabled={$licensing.environmentVariablesEnabled}
|
|
||||||
{handleUpgradePanel}
|
|
||||||
/>
|
/>
|
||||||
<EnvDropdown
|
|
||||||
|
<EnvVariableInput
|
||||||
label="Password"
|
label="Password"
|
||||||
type="password"
|
type="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 : undefined}
|
||||||
showModal={() => showModal("configKey")}
|
|
||||||
variables={$environment.variables}
|
|
||||||
environmentVariablesEnabled={$licensing.environmentVariablesEnabled}
|
|
||||||
{handleUpgradePanel}
|
|
||||||
/>
|
/>
|
||||||
{/if}
|
{/if}
|
||||||
{#if form.type === AUTH_TYPES.BEARER}
|
{#if form.type === AUTH_TYPES.BEARER}
|
||||||
|
@ -291,7 +264,3 @@
|
||||||
{/if}
|
{/if}
|
||||||
</Layout>
|
</Layout>
|
||||||
</ModalContent>
|
</ModalContent>
|
||||||
|
|
||||||
<Modal bind:this={createVariableModal}>
|
|
||||||
<CreateEditVariableModal {save} />
|
|
||||||
</Modal>
|
|
||||||
|
|
Loading…
Reference in New Issue