From c4331ea10dce0cbf403cae9aec8273f2d003ba2e Mon Sep 17 00:00:00 2001 From: Arman Date: Tue, 15 Aug 2023 22:47:02 +0200 Subject: [PATCH] feat: new design wizard --- .../wizards/functions/createTemplate.svelte | 11 +- .../steps/templateConfiguration.svelte | 142 +++--------------- .../functions/steps/templateVariables.svelte | 131 ++++++++++++++++ 3 files changed, 160 insertions(+), 124 deletions(-) create mode 100644 src/lib/wizards/functions/steps/templateVariables.svelte diff --git a/src/lib/wizards/functions/createTemplate.svelte b/src/lib/wizards/functions/createTemplate.svelte index dca6b544f..5d9fe8a18 100644 --- a/src/lib/wizards/functions/createTemplate.svelte +++ b/src/lib/wizards/functions/createTemplate.svelte @@ -14,6 +14,7 @@ import TemplateConfiguration from './steps/templateConfiguration.svelte'; import RepositoryBehaviour from './steps/repositoryBehaviour.svelte'; import CreateRepository from './steps/createRepository.svelte'; + import TemplateVariables from './steps/templateVariables.svelte'; async function create() { const runtimeDetail = $template.runtimes.find((r) => r.name === $templateConfig.runtime); @@ -60,18 +61,22 @@ const stepsComponents: WizardStepsType = new Map(); stepsComponents.set(1, { - label: 'Function configuration', + label: 'Template configuration', component: TemplateConfiguration }); stepsComponents.set(2, { + label: 'Variables', + component: TemplateVariables + }); + stepsComponents.set(3, { label: 'Repository behaviour', component: RepositoryBehaviour }); - stepsComponents.set(3, { + stepsComponents.set(4, { label: 'Select repository', component: CreateRepository }); - stepsComponents.set(4, { + stepsComponents.set(5, { label: 'Git configuration', component: GitConfiguration }); diff --git a/src/lib/wizards/functions/steps/templateConfiguration.svelte b/src/lib/wizards/functions/steps/templateConfiguration.svelte index 048bc67d4..e5a5f950b 100644 --- a/src/lib/wizards/functions/steps/templateConfiguration.svelte +++ b/src/lib/wizards/functions/steps/templateConfiguration.svelte @@ -10,42 +10,8 @@ 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 showCustomId = false; - 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; - } - } async function beforeSubmit() { if (!$templateConfig.runtime) { @@ -56,10 +22,6 @@ if (!variable.required) { continue; } - - if (!$templateConfig.variables[variable.name]) { - throw new Error(`Please set ${variable.name} variable.`); - } } } @@ -84,30 +46,13 @@ {$template.tagline} -
- - - {#if !showCustomId} -
- (showCustomId = !showCustomId)}> - -
- {:else} - - {/if} -
- + + {#await loadRuntimes()}
@@ -121,67 +66,22 @@ {options} required /> {/await} + - {#if $template.variables.length > 0} -
-

Environment variables

- -
- {#each $template.variables as variable} -
- {#if variable.name === 'APPWRITE_API_KEY'} - - API key creation -

- 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. -

-
- {/if} -
-
- -
- - {#if variable.name === 'APPWRITE_API_KEY'} - - {/if} -
-
-

-

-
-
- {/each} -
+
+ {#if !showCustomId} +
+ (showCustomId = !showCustomId)}> +
+ {:else} + {/if}
diff --git a/src/lib/wizards/functions/steps/templateVariables.svelte b/src/lib/wizards/functions/steps/templateVariables.svelte new file mode 100644 index 000000000..52a5a05da --- /dev/null +++ b/src/lib/wizards/functions/steps/templateVariables.svelte @@ -0,0 +1,131 @@ + + + + Environment variables + + Edit the values of the environment variables that will be passed to your function at + runtime. + +
+ {#if $template.variables.length > 0} +
+

Environment variables

+ +
+ {#each $template.variables as variable} +
+ {#if variable.name === 'APPWRITE_API_KEY'} + + API key creation +

+ 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. +

+
+ {/if} +
+
+ +
+ + {#if variable.name === 'APPWRITE_API_KEY'} + + {/if} +
+
+

+

+
+
+ {/each} +
+
+ {/if} +
+