Skip to content

Commit 0b3b556

Browse files
committed
fix: disabled state missing on functions create.
1 parent 60e6dee commit 0b3b556

1 file changed

Lines changed: 61 additions & 36 deletions

File tree

  • src/routes/(console)/project-[region]-[project]/functions

src/routes/(console)/project-[region]-[project]/functions/+page.svelte

Lines changed: 61 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
<script lang="ts">
2-
import { base } from '$app/paths';
32
import { page } from '$app/state';
43
import { registerCommands, updateCommandGroupRanks } from '$lib/commandCenter';
54
import {
@@ -27,12 +26,21 @@
2726
import { goto } from '$app/navigation';
2827
import { Button } from '$lib/elements/forms';
2928
import Avatar from '$lib/components/avatar.svelte';
29+
import { resolveRoute, withPath } from '$lib/stores/navigation';
30+
import type { PageProps } from './$types';
3031
31-
export let data;
32+
const { data }: PageProps = $props();
3233
33-
let offset = 0;
34+
let offset = $state(0);
3435
35-
const project = page.params.project;
36+
const createFunctionsUrl = resolveRoute(
37+
'/(console)/project-[region]-[project]/functions/create-function',
38+
{
39+
...page.params
40+
}
41+
);
42+
43+
const isLimited = $derived(isServiceLimited('functions', $organization, data.functions.total));
3644
3745
onMount(async () => {
3846
const from = page.url.searchParams.get('from');
@@ -42,15 +50,18 @@
4250
case 'template': {
4351
const template = page.url.searchParams.get('template');
4452
const templateConfig = page.url.searchParams.get('templateConfig');
45-
goto(
46-
`${base}/project-${page.params.region}-${project}/functions/create-function/template-${template}?templateConfig=${templateConfig}`
53+
const templateUrl = resolveRoute(
54+
'/(console)/project-[region]-[project]/functions/create-function/template-[template]',
55+
{
56+
...page.params,
57+
template
58+
}
4759
);
60+
await goto(withPath(templateUrl, `?templateConfig=${templateConfig}`));
4861
break;
4962
}
5063
case 'cover':
51-
goto(
52-
`${base}/project-${page.params.region}-${project}/functions/create-function`
53-
);
64+
await goto(createFunctionsUrl);
5465
break;
5566
}
5667
}
@@ -60,32 +71,42 @@
6071
return toLocaleDateTime(parseExpression(func.schedule, { utc: true }).next().toString());
6172
}
6273
63-
$: $registerCommands([
64-
{
65-
label: 'Create function',
66-
callback: () =>
67-
goto(`${base}/project-${page.params.region}-${project}/functions/create-function`),
68-
keys: ['c'],
69-
disabled:
70-
$wizard.show ||
71-
isServiceLimited('functions', $organization, data.functions?.total) ||
72-
!$canWriteFunctions,
73-
icon: IconPlus,
74-
group: 'functions'
75-
}
76-
]);
74+
$effect(() => {
75+
$registerCommands([
76+
{
77+
label: 'Create function',
78+
callback: () => goto(createFunctionsUrl),
79+
keys: ['c'],
80+
disabled:
81+
$wizard.show ||
82+
isServiceLimited('functions', $organization, data.functions?.total) ||
83+
!$canWriteFunctions,
84+
icon: IconPlus,
85+
group: 'functions'
86+
}
87+
]);
88+
});
7789
78-
$updateCommandGroupRanks({ functions: 1000 });
90+
$effect(() => {
91+
$updateCommandGroupRanks({ functions: 1000 });
92+
});
7993
</script>
8094

8195
<Container>
8296
<Layout.Stack direction="row" justifyContent="space-between">
8397
<SearchQuery placeholder="Search by name or ID" />
8498

85-
<Button href={`${base}/project-${page.params.region}-${project}/functions/create-function`}>
86-
<Icon icon={IconPlus} slot="start" />
87-
Create function
88-
</Button>
99+
<Tooltip disabled={!isLimited}>
100+
<div>
101+
<Button disabled={isLimited} href={createFunctionsUrl}>
102+
<Icon icon={IconPlus} slot="start" />
103+
Create function
104+
</Button>
105+
</div>
106+
<svelte:fragment slot="tooltip">
107+
You have reached the maximum number of functions for your plan.
108+
</svelte:fragment>
109+
</Tooltip>
89110
</Layout.Stack>
90111

91112
{#if data.functions.total}
@@ -95,11 +116,16 @@
95116
event="functions"
96117
total={data.functions.total}
97118
service="functions"
98-
on:click={() =>
99-
goto(`${base}/project-${page.params.region}-${project}/functions/create-function`)}>
119+
on:click={() => goto(createFunctionsUrl)}>
100120
{#each data.functions.functions as func (func.$id)}
101121
<GridItem1
102-
href={`${base}/project-${page.params.region}-${project}/functions/function-${func.$id}`}>
122+
href={resolveRoute(
123+
'/(console)/project-[region]-[project]/functions/function-[function]',
124+
{
125+
...page.params,
126+
function: func.$id
127+
}
128+
)}>
103129
<svelte:fragment slot="title">
104130
<Layout.Stack gap="l" alignItems="center" direction="row" inline>
105131
<Avatar alt={func.name} size="m">
@@ -135,7 +161,9 @@
135161
<EmptySearch hidePages bind:search={data.search} target="functions">
136162
<Button
137163
secondary
138-
href={`${base}/project-${page.params.region}-${page.params.project}/functions`}>
164+
href={resolveRoute('/(console)/project-[region]-[project]/functions', {
165+
...page.params
166+
})}>
139167
Clear search
140168
</Button>
141169
</EmptySearch>
@@ -145,9 +173,6 @@
145173
allowCreate={$canWriteFunctions}
146174
href="https://appwrite.io/docs/products/functions"
147175
target="function"
148-
on:click={() =>
149-
goto(
150-
`${base}/project-${page.params.region}-${project}/functions/create-function`
151-
)} />
176+
on:click={() => goto(createFunctionsUrl)} />
152177
{/if}
153178
</Container>

0 commit comments

Comments
 (0)