Merge branch 'feat-pink-v2' of https://github.com/appwrite/console into feat-pink-v2

This commit is contained in:
Torsten Dittmann committed 2025-01-30 21:13:43 +01:00
commit 6b3afff77a
10 files changed
+329 -111

No files matched your search

+2 -1
View File
@@ -15,6 +15,7 @@
};
export let title = '';
export let hideFooter = false;
export let submitOnEnter = true;
let alert: HTMLElement;
let formComponent: Form;
@@ -24,7 +25,7 @@
});
function handleKeydown(event: KeyboardEvent) {
if (event.key === 'Enter') {
if (event.key === 'Enter' && submitOnEnter) {
event.preventDefault();
if (show) {
formComponent.triggerSubmit();
+3 -1
View File
@@ -1,7 +1,7 @@
<script lang="ts">
import { Input } from '@appwrite.io/pink-svelte';
export let label: string;
export let label = '';
export let id: string;
export let name: string = id;
export let value = '';
@@ -12,6 +12,7 @@
export let readonly = false;
export let autofocus = false;
export let maxlength: number = null;
export let rows = 3;
let error: string;
@@ -39,6 +40,7 @@
{maxlength}
{label}
{nullable}
{rows}
autofocus={autofocus || undefined}
helper={error}
state={error ? 'error' : 'default'}
@@ -1,13 +1,14 @@
<script lang="ts">
import { Submit, trackError, trackEvent } from '$lib/actions/analytics';
import { SecondaryTabs, SecondaryTabsItem } from '$lib/components';
import Copy from '$lib/components/copy.svelte';
import Modal from '$lib/components/modal.svelte';
import Button from '$lib/elements/forms/button.svelte';
import { addNotification } from '$lib/stores/notifications';
import type { Models } from '@appwrite.io/console';
import { parse } from 'envfile';
import { Tooltip } from '@appwrite.io/pink-svelte';
import { Icon, Layout, Tabs } from '@appwrite.io/pink-svelte';
import { InputTextarea } from '$lib/elements/forms';
import { IconDownload, IconDuplicate } from '@appwrite.io/pink-icons-svelte';
export let isGlobal: boolean;
export let showEditor = false;
@@ -42,7 +43,6 @@
}
let tab: 'env' | 'json' = 'env';
let copyParent: HTMLElement;
async function handleSubmit() {
try {
@@ -111,84 +111,69 @@
window.URL.revokeObjectURL(url);
}
function handleKeydown(event: KeyboardEvent) {
if (event.key === 'Enter') {
if (tab === 'env') {
envCode += '\n';
} else {
jsonCode += '\n';
}
}
}
$: isButtonDisabled =
(tab === 'env' && baseEnvCode === envCode) || (tab === 'json' && baseJsonCode === jsonCode);
</script>
<Modal title="Editor" bind:show={showEditor} onSubmit={handleSubmit} bind:error>
<p>
<svelte:window on:keydown={handleKeydown} />
<Modal
title="Editor"
bind:show={showEditor}
onSubmit={handleSubmit}
bind:error
submitOnEnter={false}>
<p slot="description">
Edit {isGlobal ? 'global' : 'environment'} variables below or download as a
<span class="inline-code">.{tab}</span> file.
</p>
<div class="editor-border">
<SecondaryTabs large class="u-sep-block-end u-padding-8">
<SecondaryTabsItem
stretch
fullWidth
center
on:click={() => (tab = 'env')}
disabled={tab === 'env'}>
<Layout.Stack gap="s">
<Tabs.Root stretch>
<Tabs.Item.Button on:click={() => (tab = 'env')} active={tab === 'env'}>
ENV
</SecondaryTabsItem>
<SecondaryTabsItem
stretch
fullWidth
center
on:click={() => (tab = 'json')}
disabled={tab === 'json'}>
</Tabs.Item.Button>
<Tabs.Item.Button on:click={() => (tab = 'json')} active={tab === 'json'}>
JSON
</SecondaryTabsItem>
</SecondaryTabs>
</Tabs.Item.Button>
</Tabs.Root>
<div class="input-text-wrapper">
{#if tab === 'env'}
<textarea
placeholder={`SECRET_KEY=dQw4w9WgXcQ...`}
class="input-text u-border-width-0"
bind:value={envCode}
style:--amount-of-buttons={0.25}
style:border-radius="var(--border-radius-small)" />
{:else if tab === 'json'}
<textarea
placeholder={`{\n "SECRET_KEY": "dQw4w9WgXcQ..."\n}`}
class="input-text u-border-width-0"
bind:value={jsonCode}
style:--amount-of-buttons={0.25}
style:border-radius="var(--border-radius-small)" />
{/if}
<ul
class="buttons-list u-gap-8 u-cross-center u-position-absolute d u-inset-block-end-1 u-inset-inline-end-1 u-padding-block-8 u-padding-inline-12"
style="border-end-end-radius:0.0625rem;">
<li class="buttons-list-item">
<Tooltip>
<button
on:click={() => downloadVariables()}
type="button"
class="button is-small is-text is-only-icon"
aria-label={`Download .${tab} file`}>
<span class="icon-download" aria-hidden="true" />
</button>
<p slot="tooltip">Download .{tab} file</p>
</Tooltip>
</li>
<li class="buttons-list-item">
<div bind:this={copyParent}>
{#key copyParent}
<Copy value={tab == 'json' ? jsonCode : envCode}>
<button
type="button"
class="button is-small is-text is-only-icon"
aria-label="Click to copy">
<span class="icon-duplicate" aria-hidden="true" />
</button>
</Copy>
{/key}
</div>
</li>
</ul>
</div>
</div>
{#if tab === 'env'}
<InputTextarea
id="variables"
bind:value={envCode}
rows={10}
placeholder={`SECRET_KEY=dQw4w9WgXcQ...`} />
{:else if tab === 'json'}
<InputTextarea
id="variables"
bind:value={jsonCode}
rows={10}
placeholder={`{\n "SECRET_KEY": "dQw4w9WgXcQ..."\n}`} />
{/if}
<Layout.Stack direction="row" gap="xs">
<Button on:click={() => downloadVariables()} text>
<Icon icon={IconDownload} />
Download
</Button>
<Copy value={tab == 'json' ? jsonCode : envCode}>
<Button text>
<Icon icon={IconDuplicate} />
Copy
</Button>
</Copy>
</Layout.Stack>
</Layout.Stack>
<svelte:fragment slot="footer">
<Button secondary on:click={() => (showEditor = false)}>Cancel</Button>
@@ -3,7 +3,7 @@
import { base } from '$app/paths';
import { page } from '$app/stores';
import { Submit, trackError, trackEvent } from '$lib/actions/analytics';
import { Button, Form } from '$lib/elements/forms';
import { Button, Form, Label } from '$lib/elements/forms';
import { Wizard } from '$lib/layout';
import { addNotification } from '$lib/stores/notifications';
import { sdk } from '$lib/stores/sdk';
@@ -98,7 +98,22 @@
undefined
);
trackEvent(Submit.SiteCreate, {});
trackEvent(Submit.SiteCreate, {
source: 'manual',
framework: framework.key
});
//Add variables
await Promise.all(
Object.keys(variables).map(async (key) => {
await sdk.forProject.sites.createVariable(
site.$id,
key,
variables[key].value,
variables[key].secret
);
})
);
const { deployments } = await sdk.forProject.sites.listDeployments(site.$id, [
Query.limit(1)
@@ -129,26 +144,29 @@
confirmExit>
<Form bind:this={formComponent} onSubmit={create} bind:isSubmitting>
<Layout.Stack gap="xl">
<Upload.Dropzone folder bind:files on:change={handleChange}>
<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>
<Icon icon={IconInfo} size="s" />
<svelte:fragment slot="tooltip">
Only PNG, JPEG, PDF files allowed
</svelte:fragment>
</Tooltip>
<Layout.Stack gap="xxs">
<Label>Files or folder</Label>
<Upload.Dropzone folder bind:files on:change={handleChange}>
<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>
<Icon icon={IconInfo} size="s" />
<svelte:fragment slot="tooltip">
Only PNG, JPEG, PDF files allowed
</svelte:fragment>
</Tooltip>
</Layout.Stack>
<Typography.Caption variant="400">Max file size: 10MB</Typography.Caption>
</Layout.Stack>
<Typography.Caption variant="400">Max file size: 10MB</Typography.Caption>
</Layout.Stack>
</Upload.Dropzone>
</Upload.Dropzone>
</Layout.Stack>
<Details bind:name bind:id />
<Configuration
@@ -1,7 +1,36 @@
<script lang="ts">
import { Card } from '$lib/components';
import { Button, InputSelect } from '$lib/elements/forms';
import { IconDownload } from '@appwrite.io/pink-icons-svelte';
import { Icon, Image, Layout, Typography } from '@appwrite.io/pink-svelte';
let framework: 'react' | 'vue' | 'angular' | 'svelte' | 'web' = 'web';
</script>
<Card padding="xs">
<slot />
<Layout.Stack gap="xxs">
<Typography.Text variant="m-500">Don't have a site yet?</Typography.Text>
<Typography.Text variant="m-400">
Download our starter kit, and deploy in seconds.
</Typography.Text>
</Layout.Stack>
<Layout.Stack>
<InputSelect
id="framework"
options={[
{ label: 'React', value: 'react' },
{ label: 'Vue', value: 'vue' },
{ label: 'Angular', value: 'angular' },
{ label: 'Svelte', value: 'svelte' },
{ label: 'Web', value: 'web' }
]}
bind:value={framework} />
<Image src="https://placehold.co/349x201/111/bbb?text=Preview&font=inter" alt="preview" />
<Button size="s" fullWidth secondary href="#">
<Icon icon={IconDownload} /> Starter kit
</Button>
</Layout.Stack>
</Card>
@@ -24,6 +24,7 @@
import SecretVariableModal from '../secretVariableModal.svelte';
import ImportSiteVariablesModal from '../importSiteVariablesModal.svelte';
import type { Models } from '@appwrite.io/console';
import VariableEditorModal from '../variableEditorModal.svelte';
export let frameworks: Models.Framework[];
export let selectedFramework: Models.Framework;
@@ -206,13 +207,7 @@
</Fieldset>
{#if showEditorModal}
<!-- <RawVariableEditor
{isGlobal}
{sdkCreateVariable}
{sdkUpdateVariable}
{sdkDeleteVariable}
{variableList}
bind:showEditor={showEditorModal} /> -->
<VariableEditorModal bind:variables bind:showEditor={showEditorModal} />
{/if}
{#if showSecretModal}
@@ -83,8 +83,22 @@
silentMode,
rootDir
);
trackEvent(Submit.SiteCreate, {
source: 'repository',
framework: framework.key
});
trackEvent(Submit.SiteCreate, {});
//Add variables
await Promise.all(
Object.keys(variables).map(async (key) => {
await sdk.forProject.sites.createVariable(
site.$id,
key,
variables[key].value,
variables[key].secret
);
})
);
const { deployments } = await sdk.forProject.sites.listDeployments(site.$id, [
Query.limit(1)
@@ -26,6 +26,7 @@
import type { Models } from '@appwrite.io/console';
import { getFrameworkIcon } from '../../../store';
import { iconPath } from '$lib/stores/app';
import VariableEditorModal from '../../variableEditorModal.svelte';
export let frameworks: Models.Framework[];
export let selectedFramework: Models.Framework;
@@ -212,13 +213,7 @@
</Fieldset>
{#if showEditorModal}
<!-- <RawVariableEditor
{isGlobal}
{sdkCreateVariable}
{sdkUpdateVariable}
{sdkDeleteVariable}
{variableList}
bind:showEditor={showEditorModal} /> -->
<VariableEditorModal bind:variables bind:showEditor={showEditorModal} />
{/if}
{#if showSecretModal}
@@ -147,9 +147,23 @@
);
trackEvent(Submit.SiteCreate, {
source: 'template'
source: 'template',
framework: framework.key,
template: data.template.name
});
//Add variables
await Promise.all(
Object.keys(variables).map(async (key) => {
await sdk.forProject.sites.createVariable(
site.$id,
key,
variables[key].value,
variables[key].secret
);
})
);
const { deployments } = await sdk.forProject.sites.listDeployments(site.$id, [
Query.limit(1)
]);
@@ -0,0 +1,165 @@
<script lang="ts">
import { Submit, trackError, trackEvent } from '$lib/actions/analytics';
import Copy from '$lib/components/copy.svelte';
import Modal from '$lib/components/modal.svelte';
import Button from '$lib/elements/forms/button.svelte';
import { addNotification } from '$lib/stores/notifications';
import { parse } from 'envfile';
import { Icon, Layout, Tabs } from '@appwrite.io/pink-svelte';
import { IconDownload, IconDuplicate } from '@appwrite.io/pink-icons-svelte';
import { InputTextarea } from '$lib/elements/forms';
import type { Models } from '@appwrite.io/console';
export let showEditor = false;
export let variables: Partial<Models.Variable>[];
let error = '';
let envCode = variables.map((variable) => `${variable.key}=${variable.value}`).join('\n');
let jsonCode = JSON.stringify(
JSON.parse(
`{${variables
.map((variable) => `"${variable.key}":"${variable.value.split('"').join('\\"')}"`)
.join(',')}}`
),
null,
2
);
const baseEnvCode = envCode;
const baseJsonCode = jsonCode;
if (jsonCode === '{}') {
jsonCode = '';
}
let tab: 'env' | 'json' = 'env';
async function handleSubmit() {
try {
const vars = tab === 'env' ? parse(envCode) : JSON.parse(jsonCode ? jsonCode : '{}');
const entries = Object.entries(vars);
for (const [key, value] of entries) {
if (('' + value).length > 8192) {
throw new Error(`Variable ${key} is longer than 8192 allowed characters`);
}
}
variables.map((variable) => {
const newValue = vars[variable.key] ?? null;
if (newValue === null) {
variables = variables.filter((v) => v.key !== variable.key);
} else if (newValue !== variable.value) {
variable.value = newValue;
variables = [...variables];
}
delete vars[variable.key];
});
Object.keys(vars).map(async (key) => {
const value = vars[key];
variables.push({ key, value });
});
showEditor = false;
addNotification({
type: 'success',
message: `Variables have been updated.`
});
trackEvent(Submit.VariableEditor);
} catch (e) {
error = e.message;
trackError(e, Submit.VariableEditor);
}
}
function downloadVariables() {
const content = tab === 'json' ? jsonCode : envCode;
const fileName = tab === 'json' ? 'vars.json' : '.env';
const type = tab === 'json' ? 'application/json' : 'application/x-envoy';
const file = new File([content], fileName, {
type
});
const link = document.createElement('a');
const url = URL.createObjectURL(file);
link.href = url;
link.download = file.name;
document.body.appendChild(link);
link.click();
document.body.removeChild(link);
window.URL.revokeObjectURL(url);
}
function handleKeydown(event: KeyboardEvent) {
if (event.key === 'Enter') {
if (tab === 'env') {
envCode += '\n';
} else {
jsonCode += '\n';
}
}
}
$: isButtonDisabled =
(tab === 'env' && baseEnvCode === envCode) || (tab === 'json' && baseJsonCode === jsonCode);
</script>
<svelte:window on:keydown={handleKeydown} />
<Modal
title="Editor"
bind:show={showEditor}
onSubmit={handleSubmit}
bind:error
submitOnEnter={false}>
<p slot="description">Add, edit, or delete environment variables using a raw editor.</p>
<Layout.Stack gap="s">
<Tabs.Root stretch>
<Tabs.Item.Button on:click={() => (tab = 'env')} active={tab === 'env'}>
ENV
</Tabs.Item.Button>
<Tabs.Item.Button on:click={() => (tab = 'json')} active={tab === 'json'}>
JSON
</Tabs.Item.Button>
</Tabs.Root>
{#if tab === 'env'}
<InputTextarea
id="variables"
bind:value={envCode}
rows={10}
placeholder={`SECRET_KEY=dQw4w9WgXcQ...`} />
{:else if tab === 'json'}
<InputTextarea
id="variables"
bind:value={jsonCode}
rows={10}
placeholder={`{\n "SECRET_KEY": "dQw4w9WgXcQ..."\n}`} />
{/if}
<Layout.Stack direction="row" gap="xs">
<Button on:click={() => downloadVariables()} text>
<Icon icon={IconDownload} />
Download
</Button>
<Copy value={tab == 'json' ? jsonCode : envCode}>
<Button text>
<Icon icon={IconDuplicate} />
Copy
</Button>
</Copy>
</Layout.Stack>
</Layout.Stack>
<svelte:fragment slot="footer">
<Button secondary on:click={() => (showEditor = false)}>Cancel</Button>
<Button submit disabled={isButtonDisabled}>Save</Button>
</svelte:fragment>
</Modal>