Skip to content

Commit a2667f8

Browse files
authored
Update Console to handle specifications for self-hosted (#2685)
Update Console to conditionally call listSpecifications only on Cloud - Modified functions layout loader to check isCloud before calling listSpecifications - Modified sites settings page loader to check isCloud before calling listSpecifications - Updated function create pages to handle empty specifications array safely - Updated updateResourceLimits components to handle empty specifications array safely - On self-hosted, specifications will be empty and not passed to backend, allowing default spec
1 parent 8838922 commit a2667f8

7 files changed

Lines changed: 16 additions & 10 deletions

File tree

src/routes/(console)/project-[region]-[project]/functions/+layout.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import Header from './header.svelte';
33
import { sdk } from '$lib/stores/sdk';
44
import { Query } from '@appwrite.io/console';
55
import { Dependencies } from '$lib/constants';
6+
import { isCloud } from '$lib/system';
67
import type { LayoutLoad } from './$types';
78

89
export const load: LayoutLoad = async ({ depends, params }) => {
@@ -13,7 +14,9 @@ export const load: LayoutLoad = async ({ depends, params }) => {
1314
sdk
1415
.forProject(params.region, params.project)
1516
.vcs.listInstallations({ queries: [Query.limit(100)] }),
16-
sdk.forProject(params.region, params.project).functions.listSpecifications()
17+
isCloud
18+
? sdk.forProject(params.region, params.project).functions.listSpecifications()
19+
: Promise.resolve({ specifications: [], total: 0 })
1720
]);
1821

1922
return {

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
return { value, label, leadingHtml };
3939
});
4040
41-
const specificationOptions = data.specificationsList.specifications.map((size) => ({
41+
const specificationOptions = (data.specificationsList?.specifications ?? []).map((size) => ({
4242
label:
4343
`${size.cpus} CPU, ${size.memory} MB RAM` +
4444
(!size.enabled ? ` (Upgrade to use this)` : ''),
@@ -58,7 +58,7 @@
5858
let roles: string[] = [];
5959
let variables: Partial<Models.Variable>[] = [];
6060
let files: FileList;
61-
let specification = specificationOptions[0].value;
61+
let specification = specificationOptions[0]?.value || '';
6262
6363
async function create() {
6464
try {

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
2626
export let data;
2727
28-
const specificationOptions = data.specificationsList.specifications.map((size) => ({
28+
const specificationOptions = (data.specificationsList?.specifications ?? []).map((size) => ({
2929
label:
3030
`${size.cpus} CPU, ${size.memory} MB RAM` +
3131
(!size.enabled ? ` (Upgrade to use this)` : ''),
@@ -55,7 +55,7 @@
5555
let rootDir = './';
5656
let variables: Partial<Models.Variable>[] = [];
5757
let silentMode = false;
58-
let specification = specificationOptions[0].value;
58+
let specification = specificationOptions[0]?.value || '';
5959
6060
let detectingRuntime = true;
6161

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
3535
export let data;
3636
37-
const specificationOptions = data.specificationsList.specifications.map((size) => ({
37+
const specificationOptions = (data.specificationsList?.specifications ?? []).map((size) => ({
3838
label:
3939
`${size.cpus} CPU, ${size.memory} MB RAM` +
4040
(!size.enabled ? ` (Upgrade to use this)` : ''),
@@ -65,7 +65,7 @@
6565
let selectedScopes: string[] = [];
6666
let execute = true;
6767
let variables: Partial<Models.TemplateVariable>[] = [];
68-
let specification = specificationOptions[0].value;
68+
let specification = specificationOptions[0]?.value || '';
6969
7070
onMount(async () => {
7171
if (!$installation?.$id) {

src/routes/(console)/project-[region]-[project]/functions/function-[function]/settings/updateResourceLimits.svelte

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@
6565
}
6666
}
6767
68-
const options = specs.specifications.map((spec) => ({
68+
const options = (specs?.specifications ?? []).map((spec) => ({
6969
label: `${spec.cpus} CPU, ${spec.memory} MB RAM`,
7070
value: spec.slug,
7171
disabled: !spec.enabled

src/routes/(console)/project-[region]-[project]/sites/site-[site]/settings/+page.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { sdk } from '$lib/stores/sdk';
22
import { Dependencies } from '$lib/constants';
3+
import { isCloud } from '$lib/system';
34

45
export const load = async ({ params, depends, parent }) => {
56
depends(Dependencies.VARIABLES);
@@ -14,7 +15,9 @@ export const load = async ({ params, depends, parent }) => {
1415
.sites.listVariables({ siteId: params.site }),
1516
sdk.forProject(params.region, params.project).sites.listFrameworks(),
1617
sdk.forProject(params.region, params.project).vcs.listInstallations(),
17-
sdk.forProject(params.region, params.project).sites.listSpecifications()
18+
isCloud
19+
? sdk.forProject(params.region, params.project).sites.listSpecifications()
20+
: Promise.resolve({ specifications: [], total: 0 })
1821
]);
1922

2023
// Conflicting variables first

src/routes/(console)/project-[region]-[project]/sites/site-[site]/settings/updateResourceLimits.svelte

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@
5858
}
5959
}
6060
61-
const options = specs.specifications.map((spec) => ({
61+
const options = (specs?.specifications ?? []).map((spec) => ({
6262
label: `${spec.cpus} CPU, ${spec.memory} MB RAM`,
6363
value: spec.slug,
6464
disabled: !spec.enabled

0 commit comments

Comments
 (0)