Skip to content

Commit 200bbd8

Browse files
committed
addressed code rabbit comment
1 parent c762927 commit 200bbd8

3 files changed

Lines changed: 42 additions & 78 deletions

File tree

  • src
    • lib/helpers
    • routes/(console)/project-[region]-[project]
      • functions/create-function/repository-[repository]
      • sites/create-site/repositories/repository-[repository]

src/lib/helpers/variables.ts

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import type { Models } from '@appwrite.io/console';
2+
3+
export type DetectedVariable = {
4+
key?: string;
5+
name?: string;
6+
value?: string;
7+
secret?: boolean;
8+
};
9+
10+
export function normalizeDetectedVariables(detected: DetectedVariable[] = []) {
11+
const normalized: Partial<Models.Variable>[] = [];
12+
detected.forEach((variable) => {
13+
const key = variable.key ?? variable.name;
14+
if (!key) {
15+
return;
16+
}
17+
normalized.push({
18+
key,
19+
value: variable.value ?? '',
20+
secret: variable.secret ?? false
21+
});
22+
});
23+
return normalized;
24+
}
25+
26+
export function mergeVariables(
27+
existing: Partial<Models.Variable>[],
28+
detected: Partial<Models.Variable>[]
29+
) {
30+
const map = new Map(existing.map((variable) => [variable.key, variable]));
31+
detected.forEach((variable) => {
32+
if (!variable.key) {
33+
return;
34+
}
35+
if (!map.has(variable.key)) {
36+
map.set(variable.key, variable);
37+
}
38+
});
39+
return Array.from(map.values());
40+
}

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

Lines changed: 1 addition & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import RepoCard from './repoCard.svelte';
2323
import { getIconFromRuntime } from '$lib/stores/runtimes';
2424
import { regionalConsoleVariables } from '$routes/(console)/project-[region]-[project]/store';
25+
import { normalizeDetectedVariables, mergeVariables } from '$lib/helpers/variables';
2526
2627
export let data;
2728
@@ -59,45 +60,6 @@
5960
6061
let detectingRuntime = true;
6162
62-
type DetectedVariable = {
63-
key?: string;
64-
name?: string;
65-
value?: string;
66-
secret?: boolean;
67-
};
68-
69-
function normalizeDetectedVariables(detected: DetectedVariable[] = []) {
70-
const normalized: Partial<Models.Variable>[] = [];
71-
detected.forEach((variable) => {
72-
const key = variable.key ?? variable.name;
73-
if (!key) {
74-
return;
75-
}
76-
normalized.push({
77-
key,
78-
value: variable.value ?? '',
79-
secret: variable.secret ?? false
80-
});
81-
});
82-
return normalized;
83-
}
84-
85-
function mergeVariables(
86-
existing: Partial<Models.Variable>[],
87-
detected: Partial<Models.Variable>[]
88-
) {
89-
const map = new Map(existing.map((variable) => [variable.key, variable]));
90-
detected.forEach((variable) => {
91-
if (!variable.key) {
92-
return;
93-
}
94-
if (!map.has(variable.key)) {
95-
map.set(variable.key, variable);
96-
}
97-
});
98-
return Array.from(map.values());
99-
}
100-
10163
onMount(async () => {
10264
installation.set(data.installation);
10365
repository.set(data.repository);

src/routes/(console)/project-[region]-[project]/sites/create-site/repositories/repository-[repository]/+page.svelte

Lines changed: 1 addition & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import Configuration from '../../configuration.svelte';
2828
import Domain from '../../domain.svelte';
2929
import { regionalConsoleVariables } from '$routes/(console)/project-[region]-[project]/store';
30+
import { normalizeDetectedVariables, mergeVariables } from '$lib/helpers/variables';
3031
3132
export let data;
3233
let showExitModal = false;
@@ -49,45 +50,6 @@
4950
let domainIsValid = true;
5051
let isVariablesLoading = true;
5152
52-
type DetectedVariable = {
53-
key?: string;
54-
name?: string;
55-
value?: string;
56-
secret?: boolean;
57-
};
58-
59-
function normalizeDetectedVariables(detected: DetectedVariable[] = []) {
60-
const normalized: Partial<Models.Variable>[] = [];
61-
detected.forEach((variable) => {
62-
const key = variable.key ?? variable.name;
63-
if (!key) {
64-
return;
65-
}
66-
normalized.push({
67-
key,
68-
value: variable.value ?? '',
69-
secret: variable.secret ?? false
70-
});
71-
});
72-
return normalized;
73-
}
74-
75-
function mergeVariables(
76-
existing: Partial<Models.Variable>[],
77-
detected: Partial<Models.Variable>[]
78-
) {
79-
const map = new Map(existing.map((variable) => [variable.key, variable]));
80-
detected.forEach((variable) => {
81-
if (!variable.key) {
82-
return;
83-
}
84-
if (!map.has(variable.key)) {
85-
map.set(variable.key, variable);
86-
}
87-
});
88-
return Array.from(map.values());
89-
}
90-
9153
onMount(async () => {
9254
installation.set(data.installation);
9355
repository.set(data.repository);

0 commit comments

Comments
 (0)