|
@@ -2,6 +2,7 @@
|
|
|
import {
|
|
import {
|
|
|
state as _state,
|
|
state as _state,
|
|
|
createEnvironment,
|
|
createEnvironment,
|
|
|
|
|
+ deleteEnvVariable,
|
|
|
insertEnvVariable,
|
|
insertEnvVariable,
|
|
|
selectEnvironment,
|
|
selectEnvironment,
|
|
|
updateEnvironment,
|
|
updateEnvironment,
|
|
@@ -9,13 +10,16 @@
|
|
|
} from "$lib/state.svelte";
|
|
} from "$lib/state.svelte";
|
|
|
import * as Select from "$lib/components/ui/select";
|
|
import * as Select from "$lib/components/ui/select";
|
|
|
import { Input } from "$lib/components/ui/input";
|
|
import { Input } from "$lib/components/ui/input";
|
|
|
- import { Label } from "$lib/components/ui/label";
|
|
|
|
|
import Button from "./ui/button/button.svelte";
|
|
import Button from "./ui/button/button.svelte";
|
|
|
import Editable from "./Editable.svelte";
|
|
import Editable from "./Editable.svelte";
|
|
|
import type { EnvVariable } from "$lib/types";
|
|
import type { EnvVariable } from "$lib/types";
|
|
|
|
|
+ import { Plus, Trash } from "@lucide/svelte";
|
|
|
|
|
|
|
|
let placeholderKey = $state("");
|
|
let placeholderKey = $state("");
|
|
|
let placeholderVal = $state("");
|
|
let placeholderVal = $state("");
|
|
|
|
|
+ let error = $state(false);
|
|
|
|
|
+ let errorMessage = $state("");
|
|
|
|
|
+ let showTooltip = $state(false);
|
|
|
|
|
|
|
|
async function handlePlaceholder() {
|
|
async function handlePlaceholder() {
|
|
|
if (placeholderKey && placeholderVal) {
|
|
if (placeholderKey && placeholderVal) {
|
|
@@ -29,8 +33,14 @@
|
|
|
);
|
|
);
|
|
|
placeholderKey = "";
|
|
placeholderKey = "";
|
|
|
placeholderVal = "";
|
|
placeholderVal = "";
|
|
|
- } catch (e) {
|
|
|
|
|
|
|
+ error = false;
|
|
|
|
|
+ showTooltip = false;
|
|
|
|
|
+ } catch (e: any) {
|
|
|
console.error("cannot insert env var", e);
|
|
console.error("cannot insert env var", e);
|
|
|
|
|
+ errorMessage = e;
|
|
|
|
|
+
|
|
|
|
|
+ error = true;
|
|
|
|
|
+ showTooltip = true;
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
@@ -41,38 +51,6 @@
|
|
|
</script>
|
|
</script>
|
|
|
|
|
|
|
|
<main class="w-full space-y-6 p-4">
|
|
<main class="w-full space-y-6 p-4">
|
|
|
- <!-- Environment selector -->
|
|
|
|
|
- <div class="flex items-center gap-4">
|
|
|
|
|
- <Label>Environment</Label>
|
|
|
|
|
-
|
|
|
|
|
- <Select.Root type="single" value={_state.environment?.id.toString() || "-"}>
|
|
|
|
|
- <Select.Trigger class="w-64">
|
|
|
|
|
- {_state.environment?.name || "-"}
|
|
|
|
|
- </Select.Trigger>
|
|
|
|
|
-
|
|
|
|
|
- <Select.Content>
|
|
|
|
|
- <Select.Item value={"-"} onclick={() => selectEnvironment(null)}>
|
|
|
|
|
- -
|
|
|
|
|
- </Select.Item>
|
|
|
|
|
- {#each _state.environments as env}
|
|
|
|
|
- <Select.Item
|
|
|
|
|
- value={env.id.toString()}
|
|
|
|
|
- onclick={() => selectEnvironment(env.id)}
|
|
|
|
|
- >
|
|
|
|
|
- {env.name}
|
|
|
|
|
- </Select.Item>
|
|
|
|
|
- {/each}
|
|
|
|
|
- </Select.Content>
|
|
|
|
|
- </Select.Root>
|
|
|
|
|
-
|
|
|
|
|
- <Button
|
|
|
|
|
- class="w-8 h-8"
|
|
|
|
|
- onclick={() => {
|
|
|
|
|
- createEnvironment(_state.workspace!!.id, "New environment");
|
|
|
|
|
- }}>+</Button
|
|
|
|
|
- >
|
|
|
|
|
- </div>
|
|
|
|
|
-
|
|
|
|
|
{#if _state.environment}
|
|
{#if _state.environment}
|
|
|
<!-- Environment name -->
|
|
<!-- Environment name -->
|
|
|
<Editable
|
|
<Editable
|
|
@@ -89,43 +67,68 @@
|
|
|
</Editable>
|
|
</Editable>
|
|
|
|
|
|
|
|
<!-- Variables -->
|
|
<!-- Variables -->
|
|
|
- <div class="space-y-3">
|
|
|
|
|
|
|
+ <div class="grid grid-cols-[1fr_1fr_auto] items-center gap-3">
|
|
|
{#each _state.environment.variables as v}
|
|
{#each _state.environment.variables as v}
|
|
|
- <div class="grid grid-cols-2 gap-3">
|
|
|
|
|
- <Input
|
|
|
|
|
- class="font-mono"
|
|
|
|
|
- bind:value={v.name}
|
|
|
|
|
- oninput={() => handleUpdate(v)}
|
|
|
|
|
- />
|
|
|
|
|
- <Input
|
|
|
|
|
- class="font-mono"
|
|
|
|
|
- bind:value={v.value}
|
|
|
|
|
- oninput={() => handleUpdate(v)}
|
|
|
|
|
- />
|
|
|
|
|
- </div>
|
|
|
|
|
|
|
+ <Input
|
|
|
|
|
+ class="font-mono"
|
|
|
|
|
+ bind:value={v.name}
|
|
|
|
|
+ oninput={() => handleUpdate(v)}
|
|
|
|
|
+ />
|
|
|
|
|
+ <Input
|
|
|
|
|
+ class="font-mono"
|
|
|
|
|
+ bind:value={v.value}
|
|
|
|
|
+ oninput={() => handleUpdate(v)}
|
|
|
|
|
+ />
|
|
|
|
|
+ <Trash
|
|
|
|
|
+ class="h-4 w-4 cursor-pointer text-muted-foreground hover:text-destructive"
|
|
|
|
|
+ onclick={() => deleteEnvVariable(v.id)}
|
|
|
|
|
+ />
|
|
|
{/each}
|
|
{/each}
|
|
|
</div>
|
|
</div>
|
|
|
|
|
|
|
|
- <p class="w-full border-b">Add</p>
|
|
|
|
|
- <div class="grid grid-cols-2 gap-3">
|
|
|
|
|
|
|
+ <p class="opacity-75 border-b pointer-events-none">Add variable</p>
|
|
|
|
|
+
|
|
|
|
|
+ <div
|
|
|
|
|
+ class={`p-2 relative grid grid-cols-2 gap-3 ${
|
|
|
|
|
+ error ? "border rounded-2xl border-red-500 ring-red-400" : ""
|
|
|
|
|
+ }`}
|
|
|
|
|
+ >
|
|
|
|
|
+ <!-- ADD KEY -->
|
|
|
|
|
+
|
|
|
<Input
|
|
<Input
|
|
|
class="font-mono"
|
|
class="font-mono"
|
|
|
bind:value={placeholderKey}
|
|
bind:value={placeholderKey}
|
|
|
onkeypress={(e) => {
|
|
onkeypress={(e) => {
|
|
|
- if (e.key === "Enter") {
|
|
|
|
|
- handlePlaceholder();
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ error = false;
|
|
|
|
|
+ showTooltip = false;
|
|
|
|
|
+ if (e.key === "Enter") handlePlaceholder();
|
|
|
}}
|
|
}}
|
|
|
/>
|
|
/>
|
|
|
|
|
+
|
|
|
|
|
+ <!-- ADD VALUE -->
|
|
|
|
|
+
|
|
|
<Input
|
|
<Input
|
|
|
class="font-mono"
|
|
class="font-mono"
|
|
|
bind:value={placeholderVal}
|
|
bind:value={placeholderVal}
|
|
|
onkeypress={(e) => {
|
|
onkeypress={(e) => {
|
|
|
- if (e.key === "Enter") {
|
|
|
|
|
- handlePlaceholder();
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ error = false;
|
|
|
|
|
+ showTooltip = false;
|
|
|
|
|
+ if (e.key === "Enter") handlePlaceholder();
|
|
|
}}
|
|
}}
|
|
|
/>
|
|
/>
|
|
|
|
|
+
|
|
|
|
|
+ <Plus
|
|
|
|
|
+ class="border p-1 rounded-2xl mx-auto col-span-2 cursor-pointer"
|
|
|
|
|
+ onclick={() => handlePlaceholder()}
|
|
|
|
|
+ />
|
|
|
|
|
+
|
|
|
|
|
+ <!-- ERROR TOOLTIP -->
|
|
|
|
|
+
|
|
|
|
|
+ {#if error && showTooltip}
|
|
|
|
|
+ <div class="w-max bg-red-600 text-white text-sm px-2 rounded shadow-md">
|
|
|
|
|
+ {errorMessage}
|
|
|
|
|
+ </div>
|
|
|
|
|
+ {/if}
|
|
|
</div>
|
|
</div>
|
|
|
{/if}
|
|
{/if}
|
|
|
</main>
|
|
</main>
|