feat: remove custom logic for appwrite variables

This commit is contained in:
Arman
2024-08-08 09:49:35 +02:00
parent 8de53cfc36
commit 66dbba3314
4 changed files with 29 additions and 93 deletions
@@ -1,39 +0,0 @@
<script lang="ts">
import { Box } from '$lib/components';
import { FormList, Helper, InputChoice, InputPassword } from '$lib/elements/forms';
import type { Variable } from '$lib/stores/marketplace';
import { templateConfig } from '../store';
export let appwriteVariable: Variable;
</script>
<Box radius="small" padding={16}>
<FormList>
<div>
<InputPassword
id={appwriteVariable.name}
label={appwriteVariable.name}
placeholder={appwriteVariable.placeholder ?? 'Enter value'}
showPasswordButton
required={appwriteVariable.required && !$templateConfig.generateKey}
bind:value={$templateConfig.appwriteApiKey}
disabled={!!$templateConfig.generateKey} />
<Helper type="neutral">
This API key will allow you to interact with the Appwrite server APIs. <a
href="https://appwrite.io/docs/advanced/platform/api-keys"
target="_blank"
rel="noopener noreferrer"
class="link">Learn more</a
>.
</Helper>
</div>
<InputChoice
bind:value={$templateConfig.generateKey}
id="generate"
label="Generate API key on completion"
disabled={!!$templateConfig.appwriteApiKey}>
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>
</Box>
@@ -16,7 +16,6 @@
import { Submit, trackError, trackEvent } from '$lib/actions/analytics';
import { base } from '$app/paths';
import { page } from '$app/stores';
import { scopes } from '$lib/constants';
import { isValueOfStringEnum } from '$lib/helpers/types';
import TemplateConfiguration from './steps/templateConfiguration.svelte';
import TemplatePermissions from './steps/templatePermissions.svelte';
@@ -33,16 +32,6 @@
const runtimeDetail = $template.runtimes.find(
(r) => r.name === $templateConfig.runtime
);
if ($templateConfig.appwriteApiKey) {
$templateConfig.variables['APPWRITE_API_KEY'] = $templateConfig.appwriteApiKey;
} else if ($templateConfig?.generateKey) {
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;
}
const response = await sdk.forProject.functions.create(
$templateConfig.$id || ID.unique(),
@@ -12,7 +12,6 @@
InputNumber
} from '$lib/elements/forms';
import { Card, Collapsible, CollapsibleItem } from '$lib/components';
import AppwriteVariable from '../components/appwriteVariable.svelte';
import type { SvelteComponent } from 'svelte';
async function beforeSubmit() {
@@ -20,10 +19,6 @@
if (!variable.required) {
continue;
}
if (variable.name === 'APPWRITE_API_KEY') {
if ($templateConfig.appwriteApiKey || $templateConfig.generateKey) continue;
else throw new Error(`Please set ${variable.name} variable or generate it.`);
}
if (!$templateConfig.variables[variable.name]) {
throw new Error(`Please set ${variable.name} variable.`);
}
@@ -72,25 +67,21 @@
<FormList>
{#each requiredVariables as variable}
{#if variable.name === 'APPWRITE_API_KEY'}
<AppwriteVariable appwriteVariable={variable} />
{:else}
<div>
<svelte:component
this={selectComponent(variable.type)}
id={variable.name}
label={variable.name}
placeholder={variable.placeholder ?? 'Enter value'}
required={variable.required}
autocomplete={false}
minlength={variable.type === 'password' ? 0 : null}
showPasswordButton={variable.type === 'password'}
bind:value={$templateConfig.variables[variable.name]} />
<Helper type="neutral">
{@html variable.description}
</Helper>
</div>
{/if}
<div>
<svelte:component
this={selectComponent(variable.type)}
id={variable.name}
label={variable.name}
placeholder={variable.placeholder ?? 'Enter value'}
required={variable.required}
autocomplete={false}
minlength={variable.type === 'password' ? 0 : null}
showPasswordButton={variable.type === 'password'}
bind:value={$templateConfig.variables[variable.name]} />
<Helper type="neutral">
{@html variable.description}
</Helper>
</div>
{/each}
</FormList>
</CollapsibleItem>
@@ -107,25 +98,21 @@
<FormList>
{#each optionalVariables as variable}
{#if variable.name === 'APPWRITE_API_KEY'}
<AppwriteVariable appwriteVariable={variable} />
{:else}
<div>
<svelte:component
this={selectComponent(variable.type)}
id={variable.name}
label={variable.name}
placeholder={variable.placeholder ?? 'Enter value'}
required={variable.required}
autocomplete={false}
showPasswordButton={variable.type === 'password'}
bind:value={$templateConfig.variables[variable.name]} />
<div>
<svelte:component
this={selectComponent(variable.type)}
id={variable.name}
label={variable.name}
placeholder={variable.placeholder ?? 'Enter value'}
required={variable.required}
autocomplete={false}
showPasswordButton={variable.type === 'password'}
bind:value={$templateConfig.variables[variable.name]} />
<Helper type="neutral">
{@html variable.description}
</Helper>
</div>
{/if}
<Helper type="neutral">
{@html variable.description}
</Helper>
</div>
{/each}
</FormList>
</CollapsibleItem>
-1
View File
@@ -14,7 +14,6 @@ export const templateConfig = writable<{
repositoryName?: string;
repositoryPrivate?: boolean;
repositoryId: string;
appwriteApiKey?: string;
generateKey?: boolean;
execute?: boolean;
scopes?: string[];