fix: upload variables modal

This commit is contained in:
Arman committed 2025-03-03 12:02:08 +01:00
1 parent 627d04715a
commit 11eb8ed25c
2 files changed
+67 -44

No files matched your search

@@ -219,11 +219,22 @@
>.
{/if}
<svelte:fragment slot="aside">
<Layout.Stack justifyContent="space-between" direction="row" wrap="wrap">
<Button secondary on:click={() => (showVariablesModal = true)}>
<Icon size="s" icon={IconPlus} />
<span class="text">Create variable</span>
</Button>
<Layout.Stack gap="l">
<Layout.Stack direction="row">
<Layout.Stack direction="row" gap="s">
<Button secondary on:mousedown={() => (showEditorModal = true)}>
<Icon slot="start" icon={IconCode} /> Editor
</Button>
<Button secondary on:mousedown={() => (showVariablesUpload = true)}>
<Icon slot="start" icon={IconUpload} /> Import .env
</Button>
</Layout.Stack>
{#if variableList.total}
<Button secondary on:mousedown={() => (showVariablesModal = true)}>
<Icon slot="start" icon={IconPlus} /> Create variable
</Button>
{/if}
</Layout.Stack>
</Layout.Stack>
{@const sum = variableList.total}
{#if sum}
@@ -307,7 +318,7 @@
showVariablesModal = true;
toggle(e);
}}>
Edit
Update
</ActionMenu.Item.Button>
{#if !isGlobal}
<ActionMenu.Item.Button
@@ -322,6 +333,7 @@
</ActionMenu.Item.Button>
{/if}
<ActionMenu.Item.Button
status="danger"
trailingIcon={IconTrash}
on:click={async (e) => {
handleVariableDeleted(variable);
@@ -349,16 +361,6 @@
Create a {isGlobal ? 'global variable' : 'variable'} to get started
</Empty>
{/if}
<Layout.Stack direction="row" gap="s" wrap="wrap">
<Button secondary on:click={() => (showEditorModal = true)}>
<Icon size="s" icon={IconCode} />
<span class="text">Editor</span>
</Button>
<Button secondary on:click={() => (showVariablesUpload = true)}>
<Icon size="s" icon={IconUpload} />
<span class="text">Import .env file</span>
</Button>
</Layout.Stack>
</svelte:fragment>
</CardGrid>
@@ -4,22 +4,35 @@
import { Button } from '$lib/elements/forms';
import { addNotification } from '$lib/stores/notifications';
import type { Models } from '@appwrite.io/console';
import { Layout, Typography, Upload } from '@appwrite.io/pink-svelte';
import { IconInfo } from '@appwrite.io/pink-icons-svelte';
import {
Icon,
InlineCode,
Layout,
Selector,
Tooltip,
Typography,
Upload
} from '@appwrite.io/pink-svelte';
import { parse } from 'envfile';
export let isGlobal: boolean;
export let show = false;
export let variableList: Models.VariableList;
export let sdkCreateVariable: (key: string, value: string) => Promise<unknown>;
export let sdkCreateVariable: (
key: string,
value: string,
secret?: boolean
) => Promise<unknown>;
export let sdkUpdateVariable: (
variableId: string,
key: string,
value: string
value: string,
secret?: boolean
) => Promise<unknown>;
let files: FileList;
let secret = false;
let error: string;
export let product: 'function' | 'site' = 'function';
async function handleSubmit() {
try {
@@ -49,8 +62,8 @@
(variable) => variable.key === key
);
return found
? sdkUpdateVariable(found.$id, key, value)
: sdkCreateVariable(key, value);
? sdkUpdateVariable(found.$id, key, value, secret)
: sdkCreateVariable(key, value, secret);
})
);
@@ -64,36 +77,44 @@
error = e.message;
}
}
const title = `Import new ${isGlobal ? 'global' : 'environment'} variables`;
</script>
<Modal {title} bind:show bind:error onSubmit={handleSubmit}>
<div class="u-flex u-flex-vertical u-gap-24 u-margin-block-start-8">
<p>
{title} from
<span class="inline-code">.env</span>
file that will be passed to {!isGlobal
? `your ${product}`
: 'all functions and sites within your project'}.
</p>
{#if variableList.total > 0}
<Alert type="info">
Existing {isGlobal ? 'global' : 'environment'} variables will be updated. They will not
be deleted if they are not present in your .env file.
</Alert>
{/if}
</div>
<Modal title="Import variables" bind:show bind:error onSubmit={handleSubmit}>
<span slot="description">
Import new environment variables from <InlineCode code=".env" size="s" /> file.
</span>
<Upload.Dropzone bind:files>
<Layout.Stack alignItems="center" gap="s">
<Layout.Stack alignItems="center" justifyContent="center" direction="row" gap="s">
<Typography.Text variant="l-500">Upload a file</Typography.Text>
<Layout.Stack alignItems="center" gap="s">
<Layout.Stack alignItems="center" justifyContent="center" direction="row" gap="s">
<Typography.Text variant="l-500">
Drag and drop files here or click to upload
</Typography.Text>
<Tooltip>
<Layout.Stack alignItems="center" justifyContent="center" inline>
<Icon icon={IconInfo} size="s" />
</Layout.Stack>
<svelte:fragment slot="tooltip">Only .env files allowed</svelte:fragment>
</Tooltip>
</Layout.Stack>
<Typography.Caption variant="400">Up to 100 variables allowed</Typography.Caption>
</Layout.Stack>
</Layout.Stack>
</Upload.Dropzone>
{#if variableList.total > 0}
<Alert type="info">
This action can create and update variables but can not delete them.
</Alert>
{/if}
<Selector.Checkbox
size="s"
id="secret"
label="Secret"
bind:checked={secret}
description="If selected, you and your team won't be able to read the values after creation." />
<svelte:fragment slot="footer">
<Button text on:click={() => (show = false)}>Cancel</Button>
<Button submit disabled={!files?.length}>Import</Button>