From 275c99d29a4cfb2b25445da1359cc1d772328a75 Mon Sep 17 00:00:00 2001 From: Torsten Dittmann Date: Mon, 17 Jul 2023 15:59:15 +0200 Subject: [PATCH] fix: create deployment --- package-lock.json | 6 + package.json | 1 + src/lib/helpers/date.ts | 12 + .../function-[function]/+page.svelte | 88 ++++--- .../function-[function]/create.svelte | 223 ++---------------- .../function-[function]/createCli.svelte | 123 ++++++++++ .../function-[function]/createGit.svelte | 22 ++ .../function-[function]/createManual.svelte | 85 +++++++ .../executions/+page.svelte | 10 +- 9 files changed, 316 insertions(+), 254 deletions(-) create mode 100644 src/routes/console/project-[project]/functions/function-[function]/createCli.svelte create mode 100644 src/routes/console/project-[project]/functions/function-[function]/createGit.svelte create mode 100644 src/routes/console/project-[project]/functions/function-[function]/createManual.svelte diff --git a/package-lock.json b/package-lock.json index f356f9f6b..4a6aeb3f4 100644 --- a/package-lock.json +++ b/package-lock.json @@ -13,6 +13,7 @@ "@sentry/svelte": "^7.44.2", "@sentry/tracing": "^7.44.2", "analytics": "^0.8.1", + "dayjs": "^1.11.9", "dotenv": "^16.0.3", "echarts": "^5.4.1", "logrocket": "^3.0.1", @@ -3450,6 +3451,11 @@ "node": ">=14" } }, + "node_modules/dayjs": { + "version": "1.11.9", + "resolved": "https://registry.npmjs.org/dayjs/-/dayjs-1.11.9.tgz", + "integrity": "sha512-QvzAURSbQ0pKdIye2txOzNaHmxtUBXerpY0FJsFXUMKbIZeFm5ht1LS/jFsrncjnmtv8HsG0W2g6c0zUjZWmpA==" + }, "node_modules/debug": { "version": "4.3.4", "resolved": "https://registry.npmjs.org/debug/-/debug-4.3.4.tgz", diff --git a/package.json b/package.json index 061dd1082..2fc132c5e 100644 --- a/package.json +++ b/package.json @@ -25,6 +25,7 @@ "@sentry/svelte": "^7.44.2", "@sentry/tracing": "^7.44.2", "analytics": "^0.8.1", + "dayjs": "^1.11.9", "dotenv": "^16.0.3", "echarts": "^5.4.1", "logrocket": "^3.0.1", diff --git a/src/lib/helpers/date.ts b/src/lib/helpers/date.ts index 8558f315f..1ad196ecd 100644 --- a/src/lib/helpers/date.ts +++ b/src/lib/helpers/date.ts @@ -1,3 +1,11 @@ +import { browser } from '$app/environment'; +import dayjs from 'dayjs'; +import relativeTime from 'dayjs/plugin/relativeTime'; + +if (browser) { + dayjs.extend(relativeTime); +} + export const toLocaleDate = (datetime: string) => { const date = new Date(datetime); const options: Intl.DateTimeFormatOptions = { @@ -39,3 +47,7 @@ export const diffDays = (date1: Date, date2: Date) => { const diffTime = Math.abs(date2.getTime() - date1.getTime()); return Math.floor(diffTime / (1000 * 60 * 60 * 24)); }; + +export function timeFromNow(datetime: string): string { + return dayjs().to(dayjs(datetime)); +} diff --git a/src/routes/console/project-[project]/functions/function-[function]/+page.svelte b/src/routes/console/project-[project]/functions/function-[function]/+page.svelte index 46cb680e8..edabd86aa 100644 --- a/src/routes/console/project-[project]/functions/function-[function]/+page.svelte +++ b/src/routes/console/project-[project]/functions/function-[function]/+page.svelte @@ -5,10 +5,10 @@ DropList, DropListItem, Empty, - Status, Heading, PaginationWithLimit, - Id + Id, + Alert } from '$lib/components'; import { TableHeader, @@ -19,19 +19,18 @@ TableCellText, TableScroll } from '$lib/elements/table'; - import { execute, func } from './store'; + import { func } from './store'; import { Container } from '$lib/layout'; import { base } from '$app/paths'; import { app } from '$lib/stores/app'; - import { calculateSize } from '$lib/helpers/sizeConvertion'; - import { toLocaleDateTime } from '$lib/helpers/date'; + import { calculateSize, humanFileSize } from '$lib/helpers/sizeConvertion'; + import { timeFromNow } from '$lib/helpers/date'; import { log } from '$lib/stores/logs'; import { invalidate } from '$app/navigation'; import { Dependencies } from '$lib/constants'; import type { Models } from '@appwrite.io/console'; import type { PageData } from './$types'; import Delete from './delete.svelte'; - import Create from './create.svelte'; import Activate from './activate.svelte'; import { browser } from '$app/environment'; import { sdk } from '$lib/stores/sdk'; @@ -39,7 +38,8 @@ import { timer } from '$lib/actions/timer'; import { addNotification } from '$lib/stores/notifications'; import { Submit, trackError, trackEvent } from '$lib/actions/analytics'; - import Alert from '$lib/components/alert.svelte'; + import { Pill } from '$lib/elements'; + import Create from './create.svelte'; export let data: PageData; @@ -105,10 +105,7 @@
Deployments - +
{#if data.deployments.total}
@@ -116,7 +113,7 @@
{#if activeDeployment && !$func.live}
- + Some configuration options are not live yet. Redeploy your function to apply latest changes. @@ -134,12 +131,10 @@
-

Function ID:

- {$func.$id} +

Deployment ID

-

Deployment ID:

{$func.deployment} @@ -147,29 +142,28 @@
+ {@const status = activeDeployment.status} + {@const fileSize = humanFileSize(activeDeployment.size)}
-

Created at: {toLocaleDateTime($func.$createdAt)}

-

Updated at: {toLocaleDateTime($func.$updatedAt)}

-

Entrypoint: {activeDeployment?.entrypoint}

+

Build time: {calculateTime(activeDeployment.buildTime)}

+

Created: {timeFromNow(activeDeployment.$createdAt)}

+

Size: {fileSize.value + fileSize.unit}

+

Source: Git

- - {activeDeployment.status} - -

- {calculateTime(activeDeployment.buildTime)} -

+ + {activeDeployment.status} +
- - - - - + + {:else} @@ -200,8 +194,9 @@ Deployment ID - Created Status + Source + Created Build Time Size @@ -209,19 +204,24 @@ {#each data.deployments.deployments as deployment, index} {#if deployment.$id !== $func.deployment} + {@const status = deployment.status} {deployment.$id} - - {toLocaleDateTime(deployment.$createdAt)} - - - - {deployment.status} - + + {status} + + Git + + {timeFromNow(deployment.$createdAt)} + {#if ['processing', 'building'].includes(deployment.status)} @@ -312,9 +312,7 @@ text event="empty_documentation" ariaLabel={`create {target}`}>Documentation - + {/if} @@ -330,8 +328,6 @@
- - {#if selectedDeployment} diff --git a/src/routes/console/project-[project]/functions/function-[function]/create.svelte b/src/routes/console/project-[project]/functions/function-[function]/create.svelte index 7b0e7f048..9c6d6963c 100644 --- a/src/routes/console/project-[project]/functions/function-[function]/create.svelte +++ b/src/routes/console/project-[project]/functions/function-[function]/create.svelte @@ -1,208 +1,27 @@ - - Create Deployment - - (mode = Mode.CLI)} selected={mode === Mode.CLI} event="deploy_cli"> - CLI - - (mode = Mode.Github)} - selected={mode === Mode.Github} - event="deploy_github"> - GitHub - (Soon) - - (mode = Mode.Manual)} - selected={mode === Mode.Manual} - event="deploy_manual">Manual - - {#if mode === Mode.CLI} -

- You can deploy your function from the Appwrite CLI using Unix, CMD, or PowerShell. Check - out our Documentation to learn more about deploying your functions, or how to install and use the - Appwrite CLI. -

- - {#each ['Unix', 'CMD', 'PowerShell'] as category, i} - - {category} - - - {/each} - - {:else if mode === Mode.Github} -
- {#if $app.themeInUse === 'dark'} - github - {:else} - github - {/if} -
-

Coming Soon!

-

- Creating deployments will be easier than ever with our upcoming Git Integration. - Just set up a repository and we'll do the rest. -

-
-
- {:else if mode === Mode.Manual} - - - - This deployment will be activated after the build is completed. - - {/if} - - {#if mode === Mode.Manual} - - - {:else} - - {/if} + + + + (showCreateGit = true)}>Git + (showCreateCli = true)}>CLI + (showCreateManual = true)}>Manual -
+ + + + diff --git a/src/routes/console/project-[project]/functions/function-[function]/createCli.svelte b/src/routes/console/project-[project]/functions/function-[function]/createCli.svelte new file mode 100644 index 000000000..e57864cba --- /dev/null +++ b/src/routes/console/project-[project]/functions/function-[function]/createCli.svelte @@ -0,0 +1,123 @@ + + + + Create Deployment +

+ You can deploy your function from the Appwrite CLI using Unix, CMD, or PowerShell. Check out + our Documentation to learn more about deploying your functions, or how to install and use the + Appwrite CLI. +

+ + {#each ['Unix', 'CMD', 'PowerShell'] as category, i} + + {category} + + + {/each} + + + + +
diff --git a/src/routes/console/project-[project]/functions/function-[function]/createGit.svelte b/src/routes/console/project-[project]/functions/function-[function]/createGit.svelte new file mode 100644 index 000000000..7aa7ce1a2 --- /dev/null +++ b/src/routes/console/project-[project]/functions/function-[function]/createGit.svelte @@ -0,0 +1,22 @@ + + + + Create Deployment +

+ Deploy your function from the Git provider of your choice. When you push to a connected + repository, your function will be deployed. Learn more about function deployments. +

+ + + +
diff --git a/src/routes/console/project-[project]/functions/function-[function]/createManual.svelte b/src/routes/console/project-[project]/functions/function-[function]/createManual.svelte new file mode 100644 index 000000000..550ec92c3 --- /dev/null +++ b/src/routes/console/project-[project]/functions/function-[function]/createManual.svelte @@ -0,0 +1,85 @@ + + + + Create Deployment + + + + + + Build commands + (optional) + + + + + + + This deployment will be activated after the build is completed. + + + + + + diff --git a/src/routes/console/project-[project]/functions/function-[function]/executions/+page.svelte b/src/routes/console/project-[project]/functions/function-[function]/executions/+page.svelte index 07ee79d30..3feece93c 100644 --- a/src/routes/console/project-[project]/functions/function-[function]/executions/+page.svelte +++ b/src/routes/console/project-[project]/functions/function-[function]/executions/+page.svelte @@ -1,6 +1,6 @@