fix: template variables

This commit is contained in:
Arman committed 2023-08-17 10:53:00 +02:00
1 parent 12abde796c
commit 3ffdd56683
6 files changed
+59 -100

No files matched your search

+1 -1
View File
@@ -10,7 +10,7 @@
"@analytics/google-tag-manager": "^0.5.3",
"@appwrite.io/console": "npm:matej-appwrite-console@7.1.125",
"@appwrite.io/pink": "0.0.7-next.1",
"@appwrite.io/pink-icons": "0.0.7-next.1",
"@appwrite.io/pink-icons": "^0.0.7-next.1",
"@popperjs/core": "^2.11.6",
"@sentry/svelte": "^7.44.2",
"@sentry/tracing": "^7.44.2",
+2 -2
View File
@@ -19,10 +19,10 @@
},
"dependencies": {
"@analytics/google-analytics": "^1.0.5",
"@analytics/google-tag-manager": "^0.5.3",
"@appwrite.io/console": "npm:matej-appwrite-console@7.1.125",
"@appwrite.io/pink": "0.0.7-next.1",
"@appwrite.io/pink-icons": "0.0.7-next.1",
"@analytics/google-tag-manager": "^0.5.3",
"@appwrite.io/pink-icons": "^0.0.7-next.1",
"@popperjs/core": "^2.11.6",
"@sentry/svelte": "^7.44.2",
"@sentry/tracing": "^7.44.2",
@@ -53,6 +53,29 @@
wizard.hide();
}
// async function generateApiKey() {
// try {
// const key = await sdk.forConsole.projects.createKey(
// $page.params.project,
// 'Generated for Template',
// scopes.map((scope) => scope.scope)
// );
// $templateConfig.variables['APPWRITE_API_KEY'] = key.secret;
// addNotification({
// type: 'success',
// message: 'Key generated successfully.'
// });
// } catch (error) {
// addNotification({
// type: 'error',
// message: error.message
// });
// } finally {
// generatingApiKey = false;
// }
// }
function resetState() {
wizard.hide();
templateConfig.set(null);
@@ -12,12 +12,6 @@
if (!$templateConfig.runtime) {
throw new Error('Please select a runtime.');
}
for (const variable of $template.variables) {
if (!variable.required) {
continue;
}
}
}
async function loadRuntimes() {
@@ -1,52 +1,10 @@
<script lang="ts">
import { page } from '$app/stores';
import Alert from '$lib/components/alert.svelte';
import Button from '$lib/elements/forms/button.svelte';
import InputText from '$lib/elements/forms/inputText.svelte';
import { WizardStep } from '$lib/layout';
import { sdk } from '$lib/stores/sdk';
import { template, templateConfig } from '../store';
import { scopes } from '$lib/constants';
import { addNotification } from '$lib/stores/notifications';
let generatingApiKey = false;
let showApiKeyCheck = false;
async function generateApiKey() {
if (generatingApiKey) {
return;
}
generatingApiKey = true;
try {
const key = await await sdk.forConsole.projects.createKey(
$page.params.project,
'Generated for Template',
scopes.map((scope) => scope.scope)
);
$templateConfig.variables['APPWRITE_API_KEY'] = key.secret;
showApiKeyCheck = true;
addNotification({
type: 'success',
message: 'Key generated successfully.'
});
} catch (error) {
addNotification({
type: 'error',
message: error.message
});
} finally {
generatingApiKey = false;
}
}
import { FormList, Helper, InputChoice } from '$lib/elements/forms';
async function beforeSubmit() {
if (!$templateConfig.runtime) {
throw new Error('Please select a runtime.');
}
for (const variable of $template.variables) {
if (!variable.required) {
continue;
@@ -66,65 +24,48 @@
runtime.
</svelte:fragment>
<div class="u-flex u-flex-vertical u-gap-24">
{#if $template.variables.length > 0}
{#if $template?.variables?.length}
<div class="u-flex u-flex-vertical u-gap-16">
<p class="text u-bold">Environment variables</p>
<div class="u-flex u-flex-vertical u-gap-16">
{#each $template.variables as variable}
<div>
{#if variable.name === 'APPWRITE_API_KEY'}
<Alert type="info">
<svelte:fragment slot="title">API key creation</svelte:fragment>
<p class="text">
By clicking generate button, an API key will be
automatically generated in the background, and filled into
input field. This API key will be granted all scopes and
will never expire.
</p>
</Alert>
{/if}
<div class="u-margin-block-start-12 u-flex u-gap-8 u-cross-end">
<div class="u-width-full-line">
{#each $template.variables as variable}
{#if variable.name === 'APPWRITE_API_KEY'}
<div
class="box"
style:--box-padding="1rem"
style:--box-border-radius="var(--border-radius-small)">
<FormList>
<div>
<InputText
id={variable.name}
label={variable.name}
placeholder={variable.placeholder ?? ''}
required={variable.required}
autocomplete={false}
bind:value={$templateConfig.variables[variable.name]} />
bind:value={$templateConfig.appwriteApiKey} />
<Helper type="neutral">
This API key will allow you to interact with the Appwrite
server APIs. <a
href="http://#"
target="_blank"
rel="noopener noreferrer"
class="link">Learn more</a
>.
</Helper>
</div>
{#if variable.name === 'APPWRITE_API_KEY'}
<Button
disabled={$templateConfig.variables[variable.name]
? true
: false}
secondary
on:click={generateApiKey}>
{#if showApiKeyCheck && ($templateConfig.variables[variable.name] ? true : false)}
<span class="icon-check" aria-hidden="true" />
{/if}
{#if generatingApiKey}
<span class="loader is-small" />
{:else if showApiKeyCheck && ($templateConfig.variables[variable.name] ? true : false)}
<span class="text">Generated</span>
{:else}
<span class="text">Generate</span>
{/if}
</Button>
{/if}
</div>
<div class="u-margin-block-start-4">
<p class="helper">
<span class="icon-info" aria-hidden="true" />
<span class="text">{@html variable.description}</span>
</p>
</div>
<InputChoice id="generate" label="Generate API key on completion">
The <code class="inline-code">APPWRITE_API_KEY</code> will be automatically
generated for your project and applied to this function once it's
created.
</InputChoice>
</FormList>
</div>
{/each}
</div>
{/if}
<Helper type="neutral">
{@html variable.description}
</Helper>
{/each}
</div>
{/if}
</div>
+1
View File
@@ -13,6 +13,7 @@ export const templateConfig = writable<{
repositoryName: string;
repositoryPrivate: boolean;
repositoryId: string;
appwriteApiKey?: string;
}>();
export const repository = writable<Models.ProviderRepository>();
export const installation = writable<Models.Installation>();