From 6e03fd28c0f1445b8284d51d22ce4e270886a2ee Mon Sep 17 00:00:00 2001 From: Torsten Dittmann Date: Mon, 28 Aug 2023 12:21:21 +0200 Subject: [PATCH] fix: functions loading --- .../functions/components/repositories.svelte | 148 +++++++++--------- src/lib/wizards/functions/cover.svelte | 74 ++++----- .../wizards/functions/steps/details.svelte | 6 +- .../steps/functionConfiguration.svelte | 5 +- .../steps/templateConfiguration.svelte | 6 +- src/lib/wizards/functions/store.ts | 5 + .../project-[project]/functions/+layout.ts | 1 + .../settings/updateRuntime.svelte | 2 +- .../functions/wizard/step1.svelte | 10 +- 9 files changed, 130 insertions(+), 127 deletions(-) diff --git a/src/lib/wizards/functions/components/repositories.svelte b/src/lib/wizards/functions/components/repositories.svelte index 9d3564186..568a075e6 100644 --- a/src/lib/wizards/functions/components/repositories.svelte +++ b/src/lib/wizards/functions/components/repositories.svelte @@ -17,9 +17,6 @@ export let hasInstallations = false; export let action: 'button' | 'select' = 'select'; - let offset = 0; - const limit = 5; - $: { hasInstallations = $installations?.total > 0; } @@ -74,8 +71,24 @@ {#if hasInstallations} {#await loadInstallations()} -
-
+
+
+ +
+
+ +
{:then installations}
@@ -103,86 +116,75 @@
{/await} - +

+ Manage organization configuration in your project settings. +

{#if selectedInstallation} -

- Manage organization configuration in your project settings. -

{#await loadRepositories(selectedInstallation, search)} -
-
-
- Loading repositories... -
+
+
{:then response} {#if response?.length}
    - {#each response as repo, i} - {#if i < offset + limit && i > offset - limit} -
  • -
    + {#each response as repo} +
  • +
    +
    + {#if action === 'select'} + repository.set(repo)} + value={repo.id} /> + {/if}
    - {#if action === 'select'} - repository.set(repo)} - value={repo.id} /> - {/if} -
    - {#if repo.runtime} - {repo.name} - {/if} -
    -
    - {repo.name} - {#if repo.private} -
    - {#if action === 'button'} -
    - -
    + class="avatar is-size-x-small" + style:--p-text-size="1.25rem" + class:is-color-empty={!repo.runtime}> + {#if repo.runtime} + {repo.name} {/if}
    +
    + {repo.name} + {#if repo.private} +
    + {#if action === 'button'} +
    + +
    + {/if}
    -
  • - {/if} +
+ {/each} - {:else if search}
diff --git a/src/lib/wizards/functions/cover.svelte b/src/lib/wizards/functions/cover.svelte index a32142d1a..399d541d6 100644 --- a/src/lib/wizards/functions/cover.svelte +++ b/src/lib/wizards/functions/cover.svelte @@ -32,9 +32,8 @@ import WizardCover from '$lib/layout/wizardCover.svelte'; import { app } from '$lib/stores/app'; import { wizard } from '$lib/stores/wizard'; - import { repository, templateConfig, template as templateStore } from './store'; + import { repository, runtimes, templateConfig, template as templateStore } from './store'; import { marketplace, type MarketplaceTemplate } from '$lib/stores/marketplace'; - import { sdk } from '$lib/stores/sdk'; import type { Models } from '@appwrite.io/console'; import Repositories from './components/repositories.svelte'; import CreateManual from './createManual.svelte'; @@ -52,11 +51,6 @@ repository.set(event.detail); wizard.start(CreateGit); } - - async function loadRuntimes() { - let runtimes = await sdk.forProject.functions.listRuntimes(); - return runtimes.runtimes; - } @@ -64,7 +58,7 @@
-
+
Connect Git repository

Create and deploy a function with a connected git repository. @@ -81,36 +75,34 @@ on:connect={connect} />

-

- You can also create a function - or using the CLI. - Learn more. -

-
+

Quick start

Use a starter templates to begin with the basics.

- - {#await loadRuntimes()} -
-
-
- {:then runtimes} -
    +
      + {#await $runtimes} + {#each Array(6) as _i} +
    • + +
    • + {/each} + {:then response} + {@const runtimes = response.runtimes} {#each quickStart.runtimes.filter((_template, index) => index < 6) as runtime} {@const runtimeDetail = runtimes.find( (r) => r.$id === runtime.name @@ -150,8 +142,8 @@ {/if} -
    - {/await} + {/await} +
@@ -183,12 +175,24 @@
+

+ You can also create a function + or using the CLI. + Learn more. +

diff --git a/src/lib/wizards/functions/steps/details.svelte b/src/lib/wizards/functions/steps/details.svelte index ea0361b35..78c0a4e5b 100644 --- a/src/lib/wizards/functions/steps/details.svelte +++ b/src/lib/wizards/functions/steps/details.svelte @@ -3,17 +3,15 @@ import { Pill } from '$lib/elements'; import { InputText, InputSelect, FormList } from '$lib/elements/forms'; import { WizardStep } from '$lib/layout'; - import { sdk } from '$lib/stores/sdk'; import { onMount } from 'svelte'; - import { createFunction } from '../store'; + import { createFunction, runtimes } from '../store'; let showCustomId = false; let options = []; onMount(async () => { - let runtimes = await sdk.forProject.functions.listRuntimes(); - options = runtimes.runtimes.map((runtime) => ({ + options = (await $runtimes).runtimes.map((runtime) => ({ label: `${runtime.name} - ${runtime.version}`, value: runtime.$id })); diff --git a/src/lib/wizards/functions/steps/functionConfiguration.svelte b/src/lib/wizards/functions/steps/functionConfiguration.svelte index c433d3994..c720e89d1 100644 --- a/src/lib/wizards/functions/steps/functionConfiguration.svelte +++ b/src/lib/wizards/functions/steps/functionConfiguration.svelte @@ -7,7 +7,7 @@ import { onMount } from 'svelte'; import { sdk } from '$lib/stores/sdk'; import Label from '$lib/elements/forms/label.svelte'; - import { choices, createFunction, installation, repository } from '../store'; + import { choices, createFunction, installation, repository, runtimes } from '../store'; let showCustomId = false; @@ -29,8 +29,7 @@ let options = []; onMount(async () => { - let runtimes = await sdk.forProject.functions.listRuntimes(); - options = runtimes.runtimes.map((runtime) => ({ + options = (await $runtimes).runtimes.map((runtime) => ({ label: `${runtime.name} - ${runtime.version}`, value: runtime.$id })); diff --git a/src/lib/wizards/functions/steps/templateConfiguration.svelte b/src/lib/wizards/functions/steps/templateConfiguration.svelte index 10e7406a9..53e97ecd3 100644 --- a/src/lib/wizards/functions/steps/templateConfiguration.svelte +++ b/src/lib/wizards/functions/steps/templateConfiguration.svelte @@ -3,8 +3,7 @@ import { Pill } from '$lib/elements'; import { FormList, InputSelect, InputText } from '$lib/elements/forms'; import { WizardStep } from '$lib/layout'; - import { sdk } from '$lib/stores/sdk'; - import { template, templateConfig } from '../store'; + import { runtimes, template, templateConfig } from '../store'; let showCustomId = false; @@ -15,8 +14,7 @@ } async function loadRuntimes() { - let runtimes = await sdk.forProject.functions.listRuntimes(); - const options = runtimes.runtimes + const options = (await $runtimes).runtimes .map((runtime) => ({ label: `${runtime.name} - ${runtime.version}`, value: runtime.$id diff --git a/src/lib/wizards/functions/store.ts b/src/lib/wizards/functions/store.ts index 878fbdcc5..afd6121c8 100644 --- a/src/lib/wizards/functions/store.ts +++ b/src/lib/wizards/functions/store.ts @@ -33,6 +33,11 @@ export const installations = derived( ($page) => $page.data.installations as Models.InstallationList ); +export const runtimes = derived( + page, + ($page) => $page.data.runtimes as Promise +); + const initialCreateFunction: Partial = { $id: null, name: null, diff --git a/src/routes/console/project-[project]/functions/+layout.ts b/src/routes/console/project-[project]/functions/+layout.ts index 7fb46f02c..2e4caca75 100644 --- a/src/routes/console/project-[project]/functions/+layout.ts +++ b/src/routes/console/project-[project]/functions/+layout.ts @@ -11,6 +11,7 @@ export const load: LayoutLoad = async ({ depends }) => { return { header: Header, breadcrumbs: Breadcrumbs, + runtimes: sdk.forProject.functions.listRuntimes(), installations: sdk.forProject.vcs.listInstallations([Query.limit(100)]) }; }; diff --git a/src/routes/console/project-[project]/functions/function-[function]/settings/updateRuntime.svelte b/src/routes/console/project-[project]/functions/function-[function]/settings/updateRuntime.svelte index 6464f80e7..504847e58 100644 --- a/src/routes/console/project-[project]/functions/function-[function]/settings/updateRuntime.svelte +++ b/src/routes/console/project-[project]/functions/function-[function]/settings/updateRuntime.svelte @@ -19,7 +19,7 @@ onMount(async () => { runtime ??= $func.runtime; - let runtimes = await sdk.forProject.functions.listRuntimes(); + let runtimes = await $page.data.runtimes; options = runtimes.runtimes.map((runtime) => ({ label: `${runtime.name} - ${runtime.version}`, value: runtime.$id diff --git a/src/routes/console/project-[project]/functions/wizard/step1.svelte b/src/routes/console/project-[project]/functions/wizard/step1.svelte index fd0c3a118..53c58e72e 100644 --- a/src/routes/console/project-[project]/functions/wizard/step1.svelte +++ b/src/routes/console/project-[project]/functions/wizard/step1.svelte @@ -3,17 +3,16 @@ import { Pill } from '$lib/elements'; import { InputText, InputSelect, FormList } from '$lib/elements/forms'; import { WizardStep } from '$lib/layout'; - import { sdk } from '$lib/stores/sdk'; import { onMount } from 'svelte'; import { createFunction } from './store'; + import { runtimes } from '$lib/wizards/functions/store'; let showCustomId = false; let options = []; onMount(async () => { - let runtimes = await sdk.forProject.functions.listRuntimes(); - options = runtimes.runtimes.map((runtime) => ({ + options = (await $runtimes).runtimes.map((runtime) => ({ label: `${runtime.name} - ${runtime.version}`, value: runtime.$id })); @@ -22,7 +21,7 @@ Create your function - Let’s create a function. + Let's create a function. - - - {#if !showCustomId}
(showCustomId = !showCustomId)}>