-
Notifications
You must be signed in to change notification settings - Fork 214
feat: auto-fill detected env variables for sites/functions #2851
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
HarshMN2345
wants to merge
6
commits into
main
Choose a base branch
from
feat-detection-vars
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
2f31744
feat: auto-fill detected env variables for sites/functions
HarshMN2345 c762927
fix responsiveness
HarshMN2345 200bbd8
addressed code rabbit comment
HarshMN2345 73da136
addressed comments
HarshMN2345 5438663
addressed more comments
HarshMN2345 4dfee7b
code rabbit
HarshMN2345 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
271 changes: 271 additions & 0 deletions
271
src/lib/components/variables/environmentVariables.svelte
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. svelte 5 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,271 @@ | ||
| <script lang="ts"> | ||
| import { Empty, Paginator } from '$lib/components'; | ||
| import { Button } from '$lib/elements/forms'; | ||
| import { | ||
| ActionMenu, | ||
| Accordion, | ||
| Badge, | ||
| InteractiveText, | ||
| Icon, | ||
| Layout, | ||
| Popover, | ||
| Skeleton, | ||
| Table, | ||
| Tooltip, | ||
| Button as PinkButton | ||
| } from '@appwrite.io/pink-svelte'; | ||
| import { | ||
| IconDotsHorizontal, | ||
| IconCode, | ||
| IconUpload, | ||
| IconPlus, | ||
| IconTrash, | ||
| IconEyeOff, | ||
| IconPencil | ||
| } from '@appwrite.io/pink-icons-svelte'; | ||
| import type { Models } from '@appwrite.io/console'; | ||
| import VariableEditorModal from './variableEditorModal.svelte'; | ||
| import SecretVariableModal from './secretVariableModal.svelte'; | ||
| import ImportVariablesModal from './importVariablesModal.svelte'; | ||
| import CreateVariableModal, { type ProductLabel } from './createVariableModal.svelte'; | ||
| import DeleteVariableModal from './deleteVariableModal.svelte'; | ||
| import UpdateVariableModal from './updateVariableModal.svelte'; | ||
| import { Click, trackEvent } from '$lib/actions/analytics'; | ||
|
|
||
| const DOCS_LINKS: Record<ProductLabel, string> = { | ||
| site: 'https://appwrite.io/docs/products/sites/develop#accessing-environment-variables', | ||
| function: 'https://appwrite.io/docs/products/functions/develop#environment-variables' | ||
| }; | ||
|
|
||
| let { | ||
| variables = $bindable([]), | ||
| productLabel = 'site', | ||
| analyticsSource = 'site_configuration', | ||
| analyticsCreateSource = 'site_settings', | ||
| isLoading = false | ||
| }: { | ||
| variables: Partial<Models.Variable>[]; | ||
| productLabel?: ProductLabel; | ||
| analyticsSource?: string; | ||
| analyticsCreateSource?: string; | ||
| isLoading?: boolean; | ||
| } = $props(); | ||
|
|
||
| let showEditorModal = $state(false); | ||
| let showImportModal = $state(false); | ||
| let showSecretModal = $state(false); | ||
| let showCreate = $state(false); | ||
| let showUpdate = $state(false); | ||
| let showDelete = $state(false); | ||
| let currentVariable = $state<Partial<Models.Variable>>(undefined); | ||
|
|
||
| const createSource = $derived(analyticsCreateSource || analyticsSource); | ||
| const docsLink = $derived(DOCS_LINKS[productLabel]); | ||
|
|
||
| const tableColumns = [ | ||
| { id: 'key', width: { min: 300 } }, | ||
| { id: 'value', width: { min: 280 } }, | ||
| { id: 'actions', width: 40 } | ||
| ]; | ||
| </script> | ||
|
|
||
| <Accordion title="Environment variables" badge="Optional" hideDivider> | ||
| <Layout.Stack gap="xl"> | ||
| Set up environment variables to securely manage keys and settings for your project. | ||
| <Layout.Stack gap="l"> | ||
| <Layout.Stack direction="row"> | ||
| <Layout.Stack direction="row" gap="s"> | ||
| <Button | ||
| secondary | ||
| size="s" | ||
| on:click={() => { | ||
| showEditorModal = true; | ||
| trackEvent(Click.VariablesUpdateClick, { | ||
| source: analyticsSource | ||
| }); | ||
| }}> | ||
| <Icon slot="start" icon={IconCode} /> Editor | ||
| </Button> | ||
| <Button | ||
| secondary | ||
| size="s" | ||
| on:click={() => { | ||
| showImportModal = true; | ||
| trackEvent(Click.VariablesImportClick, { | ||
| source: analyticsSource | ||
| }); | ||
| }}> | ||
| <Icon slot="start" icon={IconUpload} /> Import .env | ||
| </Button> | ||
| </Layout.Stack> | ||
| {#if variables?.length} | ||
| <Button | ||
| secondary | ||
| size="s" | ||
| on:click={() => { | ||
| showCreate = true; | ||
| trackEvent(Click.VariablesCreateClick, { | ||
| source: createSource | ||
| }); | ||
| }}> | ||
| <Icon slot="start" icon={IconPlus} /> Create variable | ||
| </Button> | ||
| {/if} | ||
| </Layout.Stack> | ||
|
|
||
| {#if isLoading && !variables?.length} | ||
| <Table.Root class="responsive-table" let:root columns={tableColumns}> | ||
| <svelte:fragment slot="header" let:root> | ||
| <Table.Header.Cell column="key" {root}>Key</Table.Header.Cell> | ||
| <Table.Header.Cell column="value" {root}>Value</Table.Header.Cell> | ||
| <Table.Header.Cell column="actions" {root}></Table.Header.Cell> | ||
| </svelte:fragment> | ||
| {#each Array(3) as _} | ||
| <Table.Row.Base {root}> | ||
| <Table.Cell column="key" {root}> | ||
| <Skeleton variant="line" width={120} height={14} /> | ||
| </Table.Cell> | ||
| <Table.Cell column="value" {root}> | ||
| <Skeleton variant="line" width="100%" height={14} /> | ||
| </Table.Cell> | ||
| <Table.Cell column="actions" {root}> | ||
| <Skeleton variant="line" width={24} height={14} /> | ||
| </Table.Cell> | ||
| </Table.Row.Base> | ||
| {/each} | ||
| </Table.Root> | ||
| {:else if variables?.length} | ||
| <Paginator items={variables} limit={6} hideFooter={variables.length <= 6}> | ||
| {#snippet children(paginatedItems)} | ||
| <Table.Root let:root columns={tableColumns}> | ||
| <svelte:fragment slot="header" let:root> | ||
| <Table.Header.Cell column="key" {root}>Key</Table.Header.Cell> | ||
| <Table.Header.Cell column="value" {root}>Value</Table.Header.Cell> | ||
| <Table.Header.Cell column="actions" {root}></Table.Header.Cell> | ||
| </svelte:fragment> | ||
| {#each paginatedItems as variable} | ||
| <Table.Row.Base {root}> | ||
| <Table.Cell column="key" {root}>{variable.key}</Table.Cell> | ||
| <Table.Cell column="value" {root}> | ||
| <!-- TODO: fix max width --> | ||
| <div style="max-width: 100%"> | ||
| {#if variable.secret} | ||
| <Tooltip maxWidth="26rem"> | ||
| <Badge | ||
| content="Secret" | ||
| variant="secondary" | ||
| size="s" /> | ||
| <svelte:fragment slot="tooltip"> | ||
| This value is secret, you cannot see its | ||
| value. | ||
| </svelte:fragment> | ||
| </Tooltip> | ||
| {:else} | ||
| <InteractiveText | ||
| variant="secret" | ||
| isVisible={true} | ||
| text={variable.value} /> | ||
| {/if} | ||
| </div> | ||
| </Table.Cell> | ||
| <Table.Cell column="actions" {root}> | ||
| <div style="margin-inline-start: auto"> | ||
| <Popover | ||
| padding="none" | ||
| placement="bottom-end" | ||
| let:toggle> | ||
| <PinkButton.Button | ||
| icon | ||
| variant="text" | ||
| size="s" | ||
| aria-label="More options" | ||
| onclick={(e) => { | ||
| e.preventDefault(); | ||
| toggle(e); | ||
| }}> | ||
| <Icon icon={IconDotsHorizontal} size="s" /> | ||
| </PinkButton.Button> | ||
|
|
||
| <svelte:fragment slot="tooltip" let:toggle> | ||
| <ActionMenu.Root> | ||
| {#if !variable?.secret} | ||
| <ActionMenu.Item.Button | ||
| leadingIcon={IconPencil} | ||
| onclick={(e) => { | ||
| toggle(e); | ||
| currentVariable = variable; | ||
| showUpdate = true; | ||
| }}> | ||
| Update | ||
| </ActionMenu.Item.Button> | ||
| {/if} | ||
| {#if !variable?.secret} | ||
| <ActionMenu.Item.Button | ||
| leadingIcon={IconEyeOff} | ||
| onclick={(e) => { | ||
| toggle(e); | ||
| currentVariable = variable; | ||
| showSecretModal = true; | ||
| }}> | ||
| Secret | ||
| </ActionMenu.Item.Button> | ||
| {/if} | ||
| <ActionMenu.Item.Button | ||
| status="danger" | ||
| leadingIcon={IconTrash} | ||
| onclick={(e) => { | ||
| toggle(e); | ||
| currentVariable = variable; | ||
| showDelete = true; | ||
| }}> | ||
| Delete | ||
| </ActionMenu.Item.Button> | ||
| </ActionMenu.Root> | ||
| </svelte:fragment> | ||
| </Popover> | ||
| </div> | ||
| </Table.Cell> | ||
| </Table.Row.Base> | ||
| {/each} | ||
| </Table.Root> | ||
| {/snippet} | ||
| </Paginator> | ||
| {:else} | ||
| <Empty | ||
| on:click={() => { | ||
| showCreate = true; | ||
| trackEvent(Click.VariablesCreateClick, { | ||
| source: createSource | ||
| }); | ||
| }}>Create variables to get started</Empty> | ||
| {/if} | ||
| </Layout.Stack> | ||
| </Layout.Stack> | ||
| </Accordion> | ||
|
|
||
| {#if showEditorModal} | ||
| <VariableEditorModal bind:variables bind:showEditor={showEditorModal} {docsLink} /> | ||
| {/if} | ||
|
|
||
| {#if showSecretModal} | ||
| <SecretVariableModal bind:show={showSecretModal} bind:currentVariable bind:variables /> | ||
| {/if} | ||
|
|
||
| {#if showImportModal} | ||
| <ImportVariablesModal bind:show={showImportModal} bind:variables /> | ||
| {/if} | ||
|
|
||
| {#if showCreate} | ||
| <CreateVariableModal bind:show={showCreate} bind:variables {productLabel} /> | ||
| {/if} | ||
| {#if showUpdate} | ||
| <UpdateVariableModal | ||
| bind:show={showUpdate} | ||
| bind:variables | ||
| bind:selectedVar={currentVariable} | ||
| {productLabel} /> | ||
| {/if} | ||
|
|
||
| {#if showDelete} | ||
| <DeleteVariableModal bind:show={showDelete} bind:variables bind:currentVariable /> | ||
| {/if} |
File renamed without changes.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| export { default as CreateVariableModal, type ProductLabel } from './createVariableModal.svelte'; | ||
| export { default as DeleteVariableModal } from './deleteVariableModal.svelte'; | ||
| export { default as EnvironmentVariables } from './environmentVariables.svelte'; | ||
| export { default as ImportVariablesModal } from './importVariablesModal.svelte'; | ||
| export { default as SecretVariableModal } from './secretVariableModal.svelte'; | ||
| export { default as UpdateVariableModal } from './updateVariableModal.svelte'; | ||
| export { default as VariableEditorModal } from './variableEditorModal.svelte'; |
File renamed without changes.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
productLabelshould have proper union type,site | function | global.