feat: delete and cancel deployments

This commit is contained in:
loks0n committed 2024-06-28 22:33:04 +01:00
1 parent 351ae381a0
commit 50c76c121f
4 files changed
+205 -72

No files matched your search

+1
View File
@@ -232,6 +232,7 @@ export enum Submit {
DeploymentCreate = 'submit_deployment_create',
DeploymentDelete = 'submit_deployment_delete',
DeploymentUpdate = 'submit_deployment_update',
DeploymentCancel = 'submit_deployment_cancel',
ExecutionCreate = 'submit_execution_create',
VariableCreate = 'submit_variable_create',
VariableDelete = 'submit_variable_delete',
@@ -0,0 +1,51 @@
<script lang="ts">
import { invalidate } from '$app/navigation';
import { Submit, trackEvent, trackError } from '$lib/actions/analytics';
import { Modal } from '$lib/components';
import { Dependencies } from '$lib/constants';
import { Button } from '$lib/elements/forms';
import { addNotification } from '$lib/stores/notifications';
import { sdk } from '$lib/stores/sdk';
import type { Models } from '@appwrite.io/console';
export let showCancel = false;
export let selectedDeployment: Models.Deployment = null;
async function handleSubmit() {
try {
// TODO: update SDK
// @ts-expect-error
await sdk.forProject.functions.cancelDeployment(
selectedDeployment.resourceId,
selectedDeployment.$id
);
await invalidate(Dependencies.FUNCTION);
showCancel = false;
addNotification({
type: 'success',
message: `Deployment has been deleted`
});
trackEvent(Submit.DeploymentCancel);
} catch (error) {
addNotification({
type: 'error',
message: error.message
});
trackError(error, Submit.DeploymentCancel);
}
}
</script>
<Modal
title="Cancel deployment"
bind:show={showCancel}
onSubmit={handleSubmit}
icon="exclamation"
state="warning"
headerDivider={false}>
<p data-private>Are you sure you want to cancel this deployment?</p>
<svelte:fragment slot="footer">
<Button text on:click={() => (showCancel = false)}>Cancel</Button>
<Button secondary submit>Continue</Button>
</svelte:fragment>
</Modal>
@@ -1,6 +1,6 @@
<script lang="ts">
import { base } from '$app/paths';
import { Card, CardGrid, Id } from '$lib/components';
import { CardGrid, Id } from '$lib/components';
import { Pill } from '$lib/elements';
import { Button } from '$lib/elements/forms';
import { humanFileSize } from '$lib/helpers/sizeConvertion';
@@ -14,14 +14,27 @@
import { page } from '$app/stores';
import { invalidate } from '$app/navigation';
import { Dependencies } from '$lib/constants';
import { timer } from '$lib/actions/timer';
import DeploymentSource from '../deploymentSource.svelte';
import { deployment } from './store';
import DeploymentCreatedBy from '../deploymentCreatedBy.svelte';
import DeploymentDomains from '../deploymentDomains.svelte';
import { tooltip } from '$lib/actions/tooltip';
import Heading from '$lib/components/heading.svelte';
import BoxAvatar from '$lib/components/boxAvatar.svelte';
import { toLocaleDateTime } from '$lib/helpers/date';
import Delete from '../delete.svelte';
import Activate from '../activate.svelte';
import Cancel from '../cancel.svelte';
export let data;
let logs = '';
let showDelete = false;
let showCancel = false;
let showActivate = false;
function handleActivate() {
invalidate(Dependencies.DEPLOYMENTS);
}
onMount(() => {
logs = $deployment.buildLogs;
@@ -64,80 +77,141 @@
<svelte:fragment slot="aside">
{@const status = $deployment.status}
{@const fileSize = humanFileSize($deployment.size)}
<div class="u-flex u-main-space-between">
<div class="u-grid-equal-row-size u-gap-4 u-line-height-1">
<p>
<b>Build time:</b>
{#if ['processing', 'building'].includes($deployment.status)}
<span use:timer={{ start: $deployment.$createdAt }} />
{:else}
{calculateTime($deployment.buildTime)}
{/if}
</p>
<p><b>Updated:</b> <DeploymentCreatedBy deployment={$deployment} /></p>
<p>
<b>Size:</b>
{fileSize.value + fileSize.unit}
<span
class="icon-info"
aria-hidden="true"
style="font-size: var(--icon-size-small)"
use:tooltip={{
content:
'Build size is the size of your code that will run. If your code has been transpiled, it will include your library source code. If it has been compiled, it will include your build output file.'
}} />
</p>
<p class="u-flex u-gap-4 u-cross-center">
<b>Source:</b>
<DeploymentSource deployment={$deployment} />
</p>
{#if $proxyRuleList?.rules?.length}
<p class="u-flex u-gap-4 u-cross-center">
<b>Domains:</b>
<DeploymentDomains domain={$proxyRuleList} />
</p>
{/if}
</div>
<div class="u-flex u-flex-vertical u-cross-end">
<div class="stats-grid-box">
<div>
<p class="u-color-text-offline">Status</p>
<Pill
danger={status === 'failed'}
warning={status === 'building'}
info={status === 'ready'}>
<span class="text u-trim">{$deployment.status}</span>
warning={status === 'processing'}
success={status === 'ready'}
info={status === 'building'}>
{#if data.activeDeployment}
<span class="icon-lightning-bolt" aria-hidden="true" />
{:else if $deployment.status === 'canceled'}
<span class="icon-x-circle" aria-hidden="true" />
{/if}
<span class="text u-trim">
{data.activeDeployment ? 'active' : $deployment.status}
</span>
</Pill>
</div>
<div>
<p class="u-color-text-offline">Build time</p>
<p class="u-line-height-2">
{calculateTime($deployment.buildTime)}
</p>
</div>
<div>
<p class="u-color-text-offline">Build size</p>
<p class="u-line-height-2">
{fileSize.value + fileSize.unit}
</p>
</div>
<div>
<p class="u-color-text-offline">Updated</p>
<p class="u-line-height-2">
<DeploymentCreatedBy deployment={$deployment} />
</p>
</div>
</div>
<div class="u-flex u-flex-vertical u-gap-4">
<p class="u-color-text-offline">Source</p>
<div>
<DeploymentSource deployment={$deployment} />
</div>
</div>
{#if $proxyRuleList?.rules?.length}
<div class="u-flex u-flex-vertical u-gap-4">
<p class="u-color-text-offline">Domains</p>
<DeploymentDomains domain={$proxyRuleList} />
</div>
{/if}
</svelte:fragment>
<svelte:fragment slot="actions">
<div class="u-flex u-flex-wrap">
{#if $deployment.status === 'processing'}
<Button
text
class="u-margin-inline-end-16"
on:click={() => {
showCancel = true;
}}>Cancel</Button>
{/if}
<Button
secondary
disabled={data.activeDeployment}
on:click={() => {
showDelete = true;
}}>Activate</Button>
</div>
</svelte:fragment>
</CardGrid>
<Card>
<div class="u-stretch u-overflow-hidden">
<section class="code-panel">
<header
class="code-panel-header u-flex u-main-space-between u-width-full-line u-flex-wrap u-gap-16">
<div class="u-flex u-flex-vertical">
<h4 class="u-bold">Build {$func.name}</h4>
{#if $deployment.status === 'building'}
<span>Building...</span>
{:else}
<span class="u-capitalize">{$deployment.status}</span>
{/if}
</div>
<div class="u-flex u-gap-16">
<!-- TODO: add button once function is implemented -->
<!-- <Button disabled text>
<span class="icon-external-link" aria-hidden="true" /> Raw data</Button> -->
<Button
secondary
on:click={() => window.scrollTo({ top: 0, behavior: 'smooth' })}>
<span class="icon-arrow-sm-up" aria-hidden="true" /> Scroll to top</Button>
</div>
</header>
<div class="code-panel-content">
<pre><code>{logs}</code></pre>
<div class="u-stretch u-overflow-hidden u-padding-block-start-24">
<section class="code-panel" style="border-radius: var(--border-radius-medium);">
<header
class="code-panel-header u-flex u-main-space-between u-width-full-line u-flex-wrap u-gap-16">
<div class="u-flex u-flex-vertical">
<h4 class="u-bold">Build {$func.name}</h4>
{#if $deployment.status === 'building'}
<span>Building...</span>
{:else}
<span class="u-capitalize">{$deployment.status}</span>
{/if}
</div>
</section>
</div>
</Card>
<div class="u-flex u-gap-16">
<!-- TODO: add button once function is implemented -->
<!-- <Button disabled text>
<span class="icon-external-link" aria-hidden="true" /> Raw data</Button> -->
<Button
secondary
on:click={() => window.scrollTo({ top: 0, behavior: 'smooth' })}>
<span class="icon-arrow-sm-up" aria-hidden="true" /> Scroll to top</Button>
</div>
</header>
<div class="code-panel-content">
<pre><code>{logs}</code></pre>
</div>
</section>
</div>
{#if !data.activeDeployment}
<CardGrid danger>
<Heading tag="h6" size="7">Delete deployment</Heading>
<p>
The deployment will be permanently deleted, including all data associated with it.
This action is irreversible.
</p>
<svelte:fragment slot="aside">
<BoxAvatar>
<p>Last updated: {toLocaleDateTime($func.$updatedAt)}</p>
</BoxAvatar>
</svelte:fragment>
<svelte:fragment slot="actions">
<Button secondary on:click={() => (showDelete = true)}>Delete</Button>
</svelte:fragment>
</CardGrid>
{/if}
</Container>
<Delete selectedDeployment={$deployment} bind:showDelete />
<Cancel selectedDeployment={$deployment} bind:showCancel />
<Activate selectedDeployment={$deployment} bind:showActivate on:activated={handleActivate} />
<style lang="scss">
@import '@appwrite.io/pink/src/abstract/variables/_devices.scss';
.stats-grid-box {
display: grid;
gap: px2rem(16);
grid-template-columns: repeat(2, 1fr);
}
@media #{$break3open} {
.stats-grid-box {
grid-template-columns: repeat(4, 1fr);
}
}
</style>
@@ -2,10 +2,17 @@ import { sdk } from '$lib/stores/sdk';
import { Dependencies } from '$lib/constants';
import type { PageLoad } from './$types';
export const load: PageLoad = async ({ params, depends }) => {
export const load: PageLoad = async ({ params, depends, parent }) => {
const data = await parent();
depends(Dependencies.DEPLOYMENT);
const deployment = await sdk.forProject.functions.getDeployment(
params.function,
params.deployment
);
return {
deployment: await sdk.forProject.functions.getDeployment(params.function, params.deployment)
deployment,
activeDeployment: data.function.deployment === params.deployment ? true : false
};
};