feat: set up wizard

This commit is contained in:
Arman committed 2022-09-22 11:46:18 +02:00
1 parent 102d85a532
commit d6fc882186
8 files changed
+234 -2

No files matched your search

@@ -5,7 +5,7 @@
import { Empty, EmptyGridItem, Pagination, Copy, GridItem1 } from '$lib/components';
import { Pill } from '$lib/elements';
import type { Models } from '@aw-labs/appwrite-console';
import Create from './_create.svelte';
import Create from './createFunction.svelte';
import { Container } from '$lib/layout';
import { base } from '$app/paths';
import { tooltip } from '$lib/actions/tooltip';
@@ -13,6 +13,7 @@
import { toLocaleDateTime } from '$lib/helpers/date';
import { app } from '$lib/stores/app';
import { onMount } from 'svelte';
import { wizard } from '$lib/stores/wizard';
let showCreate = false;
let search = '';
@@ -31,6 +32,10 @@
await goto(`${base}/console/project-${project}/functions/function/${event.detail.$id}`);
};
function openWizard() {
wizard.start(Create);
}
$: functionList.load(search, limit, offset ?? 0);
</script>
@@ -38,7 +43,7 @@
<div class="u-flex u-gap-12 common-section u-main-space-between">
<h2 class="heading-level-5">Functions</h2>
<Button on:click={() => (showCreate = true)}>
<Button on:click={openWizard}>
<span class="icon-plus" aria-hidden="true" /> <span class="text">Create function</span>
</Button>
</div>
@@ -0,0 +1,70 @@
<script lang="ts">
import { Wizard } from '$lib/layout';
import { functionList } from './store';
import { sdkForProject } from '$lib/stores/sdk';
import { onDestroy } from 'svelte';
import { addNotification } from '$lib/stores/notifications';
import { wizard } from '$lib/stores/wizard';
import Step1 from './wizard/step1.svelte';
import Step2 from './wizard/step2.svelte';
import Step3 from './wizard/step3.svelte';
import Step4 from './wizard/step4.svelte';
import Step5 from './wizard/step5.svelte';
import { createFunction } from './wizard/store';
import type { WizardStepsType } from '$lib/layout/wizard.svelte';
const create = async () => {
try {
await sdkForProject.functions.create(
$createFunction.id ?? 'unique()',
$createFunction.name,
$createFunction.execute,
$createFunction.runtime,
$createFunction.vars,
$createFunction.events,
$createFunction.schedule,
$createFunction.timeout
);
addNotification({
message: 'Document has been created',
type: 'success'
});
functionList.load('', 12, 0);
wizard.hide();
} catch (error) {
addNotification({
message: error.message,
type: 'error'
});
}
};
onDestroy(() => {
$createFunction.execute = [];
$createFunction.events = [];
});
const stepsComponents: WizardStepsType = new Map();
stepsComponents.set(1, {
label: 'Function Details',
component: Step1
});
stepsComponents.set(2, {
label: 'Execute access',
component: Step2
});
stepsComponents.set(3, {
label: 'Events',
component: Step3
});
stepsComponents.set(4, {
label: 'Scheduling',
component: Step4
});
stepsComponents.set(5, {
label: 'Variables',
component: Step5
});
</script>
<Wizard title="Create Function" steps={stepsComponents} on:finish={create} />
@@ -0,0 +1,76 @@
<script lang="ts">
import { InnerModal } from '$lib/components';
import { Pill } from '$lib/elements';
import { InputText, InputSelect } from '$lib/elements/forms';
import FormList from '$lib/elements/forms/formList.svelte';
import { WizardStep } from '$lib/layout';
import { createFunction } from './store';
let showCustomId = false;
let options = [
{ label: 'Node.js 16.0', value: 'nodejs' },
{ label: 'PHP 8.0', value: 'php' },
{ label: 'Ruby 3.0', value: 'ruby' },
{ label: 'Python 3.9', value: 'python' }
];
</script>
<WizardStep>
<svelte:fragment slot="title">Create your function</svelte:fragment>
<svelte:fragment slot="subtitle">Let’s create a function.</svelte:fragment>
<FormList>
<InputText
label="Name"
id="name"
placeholder="Function name"
bind:value={$createFunction.name}
required />
<InputSelect
label="Runtimes"
id="runtimes"
placeholder="Select runtime"
bind:value={$createFunction.runtime}
{options}
required />
<ul class="form-list">
{#if !showCustomId}
<div>
<Pill button on:click={() => (showCustomId = !showCustomId)}>
<span class="icon-pencil" aria-hidden="true" /><span class="text">
Function ID
</span>
</Pill>
</div>
{:else}
<InnerModal bind:show={showCustomId}>
<svelte:fragment slot="title">Function ID</svelte:fragment>
Enter a custom function ID. Leave blank for a randomly generated one.
<svelte:fragment slot="content">
<div class="form">
<InputText
id="id"
label="Custom ID"
showLabel={false}
placeholder="Enter ID"
autofocus={true}
bind:value={$createFunction.id} />
<div class="u-flex u-gap-4 u-margin-block-start-8 u-small">
<span
class="icon-info u-cross-center u-margin-block-start-2 u-line-height-1 u-icon-small"
aria-hidden="true" />
<span class="text u-line-height-1-5">
Allowed characters: alphanumeric, hyphen, non-leading
underscore, period
</span>
</div>
</div>
</svelte:fragment>
</InnerModal>
{/if}
</ul>
</FormList>
</WizardStep>
@@ -0,0 +1,16 @@
<script lang="ts">
import { WizardStep } from '$lib/layout';
// import { createFunction } from './store';
</script>
<WizardStep>
<svelte:fragment slot="title">Execute access (optional)</svelte:fragment>
<svelte:fragment slot="subtitle">
Choose who can execute this function using the client API. Check out our documentation for
more on <a href="#/" target="_blank" rel="noopener noreferrer" class="link">
Permissions</a
>.
</svelte:fragment>
ROLE
</WizardStep>
@@ -0,0 +1,13 @@
<script lang="ts">
import { WizardStep } from '$lib/layout';
// import { createFunction } from './store';
</script>
<WizardStep>
<svelte:fragment slot="title">Events (optional)</svelte:fragment>
<svelte:fragment slot="subtitle">
Set the events that will trigger your function. Maximum 100 events allowed.
</svelte:fragment>
EVENT
</WizardStep>
@@ -0,0 +1,18 @@
<script lang="ts">
import { WizardStep } from '$lib/layout';
// import { createFunction } from './store';
</script>
<WizardStep>
<svelte:fragment slot="title">Scheduling (optional)</svelte:fragment>
<svelte:fragment slot="subtitle">
Set a CRON schedule to trigger your function. Leave blank for no schedule. <a
href="#/"
target="_blank"
rel="noopener noreferrer"
class="link">More details on CRON syntax here</a
>.
</svelte:fragment>
EVENT
</WizardStep>
@@ -0,0 +1,13 @@
<script lang="ts">
import { WizardStep } from '$lib/layout';
// import { createFunction } from './store';
</script>
<WizardStep>
<svelte:fragment slot="title">Variables (optional)</svelte:fragment>
<svelte:fragment slot="subtitle">
Create a variable (or secret key) that will be passed to your function at runtime.
</svelte:fragment>
EVENT
</WizardStep>
@@ -0,0 +1,21 @@
import { writable } from 'svelte/store';
export const createFunction = writable<{
id?: string;
name: string;
execute: string[];
runtime: string;
vars?: object;
events?: string[];
schedule?: string;
timeout?: number;
}>({
id: null,
name: null,
execute: [],
runtime: null,
vars: {},
events: [],
schedule: null,
timeout: null
});