43 lines
2.3 KiB
Vue
43 lines
2.3 KiB
Vue
<script setup lang="ts">
|
|
import { computed, onMounted, ref } from "vue";
|
|
import PageHeader from "@/base/PageHeader.vue";
|
|
import { Button } from "@/components/ui/button";
|
|
import { Input } from "@/components/ui/input";
|
|
import { SettingRow } from "@/components/ui/setting-row";
|
|
import { useSettingsStore } from "@/stores/settings";
|
|
import ApplyStatusRows from "./ApplyStatusRows.vue";
|
|
import CardAccordion from "./CardAccordion.vue";
|
|
import HistoryLink from "./HistoryLink.vue";
|
|
import SecretRefField from "./SecretRefField.vue";
|
|
interface Binding { service: string; org?: string; secret: { engine: string; key: string } }
|
|
const KIND = "credential-bindings";
|
|
const store = useSettingsStore();
|
|
onMounted(store.load);
|
|
const bindings = computed(() => store.drafts[KIND]?.value as Binding[] | null);
|
|
const open = ref("");
|
|
const unsaved = computed(() => store.changesFor(KIND).length > 0);
|
|
function add() {
|
|
if (unsaved.value) return;
|
|
const draft = store.drafts[KIND];
|
|
if (!draft) return;
|
|
if (!draft.value) draft.value = [];
|
|
(draft.value as Binding[]).push({ service: "", org: "", secret: { engine: "", key: "" } });
|
|
open.value = String((draft.value as Binding[]).length - 1);
|
|
}
|
|
</script>
|
|
<template>
|
|
<div>
|
|
<PageHeader title="Credential bindings"><HistoryLink :kinds="[KIND]" /><Button :disabled="unsaved" @click="add">Add binding</Button></PageHeader>
|
|
<ApplyStatusRows :kind="KIND" class="mb-4" />
|
|
<p v-if="store.catalogError || store.pageErrorFor(KIND)" class="mb-4 text-sm text-destructive" role="alert">{{ store.catalogError || store.pageErrorFor(KIND) }}</p>
|
|
<p v-if="!bindings?.length" class="text-sm text-fg-muted">No credential bindings.</p>
|
|
<CardAccordion v-model:open="open" :items="bindings ?? []" :title="(b) => b.service || 'New binding'" remove-label="Remove" mono @remove="bindings!.splice($event, 1)">
|
|
<template #default="{ item: binding, index }">
|
|
<SettingRow label="Service" :for="`binding-${index}-service`"><Input :id="`binding-${index}-service`" v-model="binding.service" /></SettingRow>
|
|
<SettingRow label="Organisation" :for="`binding-${index}-org`" hint="Empty uses the default organisation."><Input :id="`binding-${index}-org`" v-model="binding.org" /></SettingRow>
|
|
<SettingRow label="Secret"><SecretRefField v-model="binding.secret" :id-prefix="`binding-${index}-secret`" /></SettingRow>
|
|
</template>
|
|
</CardAccordion>
|
|
</div>
|
|
</template>
|