wowowowowo
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
<script setup>
|
||||
<script setup lang="ts">
|
||||
import InputError from "@/components/InputError.vue";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { Input } from "@/components/ui/input";
|
||||
@@ -7,24 +7,13 @@ import AppLayout from "@/layouts/AppLayout.vue";
|
||||
import { Head, useForm } from "@inertiajs/vue3";
|
||||
import { computed, watch } from "vue";
|
||||
|
||||
const props = defineProps({
|
||||
application: {
|
||||
type: Object,
|
||||
required: true,
|
||||
},
|
||||
environment: {
|
||||
type: Object,
|
||||
required: true,
|
||||
},
|
||||
services: {
|
||||
type: Array,
|
||||
required: true,
|
||||
},
|
||||
roles: {
|
||||
type: Array,
|
||||
required: true,
|
||||
},
|
||||
});
|
||||
const props = defineProps<{
|
||||
application: Record<string, any>;
|
||||
environment: Record<string, any>;
|
||||
services: Record<string, any>[];
|
||||
roles: string[];
|
||||
compatibility: Record<string, string[]>;
|
||||
}>();
|
||||
|
||||
const form = useForm({
|
||||
service_id: props.services[0]?.id ?? null,
|
||||
@@ -32,18 +21,16 @@ const form = useForm({
|
||||
name: "",
|
||||
env_prefix: "",
|
||||
is_primary: true,
|
||||
domain: "",
|
||||
path_prefix: "/",
|
||||
tls_enabled: true,
|
||||
});
|
||||
|
||||
const compatibleServices = computed(() => {
|
||||
const roleTypes = {
|
||||
database: ["postgres"],
|
||||
cache: ["valkey"],
|
||||
queue: ["valkey"],
|
||||
gateway: ["caddy"],
|
||||
};
|
||||
|
||||
return props.services.filter((service) =>
|
||||
(roleTypes[form.role] ?? props.services.map((item) => item.type)).includes(service.type),
|
||||
(props.compatibility[form.role] ?? props.services.map((item) => item.type)).includes(
|
||||
service.type,
|
||||
),
|
||||
);
|
||||
});
|
||||
|
||||
@@ -66,6 +53,34 @@ const generatedSliceType = computed(() => {
|
||||
return "service link";
|
||||
});
|
||||
|
||||
const envPrefix = computed(() => form.env_prefix || form.role.toUpperCase());
|
||||
const variablePreview = computed(() => {
|
||||
if (form.role === "database") {
|
||||
return [
|
||||
`${envPrefix.value}_HOST`,
|
||||
`${envPrefix.value}_PORT`,
|
||||
`${envPrefix.value}_DATABASE`,
|
||||
`${envPrefix.value}_USERNAME`,
|
||||
`${envPrefix.value}_PASSWORD`,
|
||||
];
|
||||
}
|
||||
|
||||
if (["cache", "queue"].includes(form.role)) {
|
||||
return [
|
||||
`${envPrefix.value}_HOST`,
|
||||
`${envPrefix.value}_PORT`,
|
||||
`${envPrefix.value}_DATABASE`,
|
||||
`${envPrefix.value}_PASSWORD`,
|
||||
];
|
||||
}
|
||||
|
||||
if (form.role === "gateway") {
|
||||
return ["APP_URL", "KEYSTONE_ROUTE_HOST", "KEYSTONE_ROUTE_PORT", "KEYSTONE_ROUTE_TLS"];
|
||||
}
|
||||
|
||||
return [`${envPrefix.value}_HOST`, `${envPrefix.value}_PORT`];
|
||||
});
|
||||
|
||||
watch(
|
||||
compatibleServices,
|
||||
(services) => {
|
||||
@@ -142,6 +157,19 @@ watch(
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="rounded-md border bg-muted/30 p-3 text-sm">
|
||||
<div class="font-medium">Environment variables preview</div>
|
||||
<div class="mt-2 flex flex-wrap gap-2">
|
||||
<code
|
||||
v-for="variable in variablePreview"
|
||||
:key="variable"
|
||||
class="rounded bg-background px-2 py-1 text-xs"
|
||||
>
|
||||
{{ variable }}
|
||||
</code>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="grid gap-2">
|
||||
<Label for="role">Role</Label>
|
||||
<select
|
||||
@@ -180,9 +208,31 @@ watch(
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div v-if="form.role === 'gateway'" class="grid gap-4 rounded-md border p-3 md:grid-cols-3">
|
||||
<div class="grid gap-2">
|
||||
<Label for="domain">Domain</Label>
|
||||
<Input id="domain" v-model="form.domain" type="text" placeholder="app.example.com" />
|
||||
<InputError :message="form.errors.domain" />
|
||||
</div>
|
||||
<div class="grid gap-2">
|
||||
<Label for="path_prefix">Path prefix</Label>
|
||||
<Input id="path_prefix" v-model="form.path_prefix" type="text" placeholder="/" />
|
||||
<InputError :message="form.errors.path_prefix" />
|
||||
</div>
|
||||
<label class="flex items-center gap-2 pt-7 text-sm">
|
||||
<input v-model="form.tls_enabled" type="checkbox" class="size-4" />
|
||||
TLS enabled
|
||||
</label>
|
||||
</div>
|
||||
|
||||
<label class="flex items-center gap-2 text-sm">
|
||||
<input v-model="form.is_primary" type="checkbox" class="size-4" />
|
||||
Primary attachment
|
||||
<span>
|
||||
Primary attachment
|
||||
<span class="block text-muted-foreground">
|
||||
Primary attachments provide the default unprefixed variables for this role.
|
||||
</span>
|
||||
</span>
|
||||
</label>
|
||||
|
||||
<div class="flex items-center justify-end">
|
||||
|
||||
Reference in New Issue
Block a user