Skip to content

Commit e07f037

Browse files
Merge pull request #535 from appwrite/fix-deployment-activation
fix: deployments activation
2 parents 46c7f2f + ad9aa40 commit e07f037

3 files changed

Lines changed: 13 additions & 32 deletions

File tree

src/routes/console/project-[project]/functions/function-[function]/+layout.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@ export const load: LayoutLoad = async ({ params, depends }) => {
1414
return {
1515
header: Header,
1616
breadcrumbs: Breadcrumbs,
17-
function: sdk.forProject.functions.get(params.function),
18-
proxyRuleList: sdk.forProject.proxy.listRules([
17+
function: await sdk.forProject.functions.get(params.function),
18+
proxyRuleList: await sdk.forProject.proxy.listRules([
1919
Query.equal('resourceType', 'function'),
2020
Query.equal('resourceId', params.function),
2121
Query.limit(1)

src/routes/console/project-[project]/functions/function-[function]/+page.svelte

Lines changed: 4 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,9 @@
2929
import { Container } from '$lib/layout';
3030
import { app } from '$lib/stores/app';
3131
import { calculateSize, humanFileSize } from '$lib/helpers/sizeConvertion';
32-
import { Query, type Models } from '@appwrite.io/console';
32+
import type { Models } from '@appwrite.io/console';
3333
import Delete from './delete.svelte';
3434
import Create from './create.svelte';
35-
import { sdk } from '$lib/stores/sdk';
3635
import Activate from './activate.svelte';
3736
import { calculateTime } from '$lib/helpers/timeConversion';
3837
import { Pill } from '$lib/elements';
@@ -50,34 +49,10 @@
5049
let showAlert = true;
5150
5251
let selectedDeployment: Models.Deployment = null;
53-
let activeDeployment: Models.Deployment = null;
54-
55-
async function getActiveDeployment() {
56-
if (!$func?.deployment) return null;
57-
const list = await sdk.forProject.functions.listDeployments($page.params.function, [
58-
Query.equal('$id', $func.deployment)
59-
]);
60-
return list?.deployments?.[0];
61-
}
6252
6353
function handleActivate() {
6454
invalidate(Dependencies.DEPLOYMENTS);
6555
}
66-
67-
deploymentList.subscribe((list: Models.DeploymentList | null) => {
68-
if (list?.deployments) {
69-
let activeDep = list.deployments.find(
70-
(deployment) => deployment.$id === $func.deployment
71-
);
72-
if (!activeDep) {
73-
getActiveDeployment().then((deployment) => {
74-
activeDeployment = deployment;
75-
});
76-
} else {
77-
activeDeployment = activeDep;
78-
}
79-
}
80-
});
8156
</script>
8257

8358
<Container>
@@ -86,6 +61,7 @@
8661
<Create main />
8762
</div>
8863
{#if $deploymentList?.total}
64+
{@const activeDeployment = data.activeDeployment}
8965
<div class="common-section">
9066
<Heading tag="h3" size="7">Active</Heading>
9167
</div>
@@ -113,8 +89,8 @@
11389
<div class="u-grid-equal-row-size u-gap-4 u-line-height-1">
11490
<p><b>Deployment ID</b></p>
11591

116-
<Id value={$func.deployment}>
117-
{$func.deployment}
92+
<Id value={activeDeployment.$id}>
93+
{activeDeployment.$id}
11894
</Id>
11995
</div>
12096
</div>
@@ -197,7 +173,6 @@
197173
</div>
198174
</Empty>
199175
{/if}
200-
201176
<div class="common-section">
202177
<Heading tag="h3" size="7">All</Heading>
203178
</div>

src/routes/console/project-[project]/functions/function-[function]/+page.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { Dependencies, PAGE_LIMIT } from '$lib/constants';
55
import type { PageLoad } from './$types';
66

77
export const load: PageLoad = async ({ params, depends, url, route, parent }) => {
8-
await parent();
8+
const data = await parent();
99
depends(Dependencies.DEPLOYMENTS);
1010
const page = getPage(url);
1111
const limit = getLimit(url, route, PAGE_LIMIT);
@@ -14,6 +14,12 @@ export const load: PageLoad = async ({ params, depends, url, route, parent }) =>
1414
return {
1515
offset,
1616
limit,
17+
activeDeployment: data.function.deployment
18+
? await sdk.forProject.functions.getDeployment(
19+
params.function,
20+
data.function.deployment
21+
)
22+
: null,
1723
deploymentList: await sdk.forProject.functions.listDeployments(params.function, [
1824
Query.limit(limit),
1925
Query.offset(offset),

0 commit comments

Comments
 (0)