95 lines
2.9 KiB
Vue
95 lines
2.9 KiB
Vue
<script setup lang="ts">
|
|
import { Empty, EmptyHeader, EmptyTitle } from "@/components/ui/empty";
|
|
import ApplyStatusRows from "./ApplyStatusRows.vue";
|
|
import { computed, onMounted, ref } from "vue";
|
|
import { storeToRefs } from "pinia";
|
|
import { Plus } from "@lucide/vue";
|
|
|
|
import PageHeader from "@/base/PageHeader.vue";
|
|
import { Button } from "@/components/ui/button";
|
|
import { resourcesForPage, useSettingsStore } from "@/stores/settings";
|
|
import { useOrgStore } from "@/stores/org";
|
|
import CardAccordion from "./CardAccordion.vue";
|
|
import ConnectionCard from "./ConnectionCard.vue";
|
|
import HistoryLink from "./HistoryLink.vue";
|
|
import type { Connection } from "./connection";
|
|
|
|
const KIND = "forge-connections";
|
|
|
|
const store = useSettingsStore();
|
|
const orgStore = useOrgStore();
|
|
const { catalog, catalogError } = storeToRefs(store);
|
|
onMounted(() => {
|
|
void store.load();
|
|
orgStore.watchIdentities();
|
|
});
|
|
|
|
const resources = computed(() => resourcesForPage(catalog.value, "connections"));
|
|
const draft = computed(() => store.drafts[KIND]);
|
|
const connections = computed(() => (draft.value?.value ?? []) as Connection[]);
|
|
const error = computed(() => store.pageErrorFor(KIND));
|
|
const open = ref("0");
|
|
const unsaved = computed(() => store.changesFor(KIND).length > 0);
|
|
|
|
function addConnection() {
|
|
if (unsaved.value) return;
|
|
draft.value.value ??= [];
|
|
const used = new Set(connections.value.map((c) => c.id));
|
|
let id = "connection";
|
|
for (let n = 2; used.has(id); n++) id = `connection-${n}`;
|
|
connections.value.push({
|
|
id,
|
|
name: "",
|
|
type: "github",
|
|
host: "",
|
|
account: "",
|
|
token: { engine: "", key: "" },
|
|
permits: {},
|
|
});
|
|
open.value = String(connections.value.length - 1);
|
|
}
|
|
</script>
|
|
|
|
<template>
|
|
<div>
|
|
<PageHeader title="Connections">
|
|
<HistoryLink :kinds="resources.map((r) => r.kind)" />
|
|
</PageHeader>
|
|
<ApplyStatusRows
|
|
v-for="resource in resources"
|
|
:key="resource.kind"
|
|
:kind="resource.kind"
|
|
class="mb-4"
|
|
/>
|
|
|
|
<p v-if="catalogError || error" class="mb-4 text-sm text-danger" role="alert">
|
|
{{ catalogError || error }}
|
|
</p>
|
|
|
|
<template v-if="draft">
|
|
<div class="mb-4 flex flex-wrap items-center gap-2">
|
|
<Button size="sm" :disabled="unsaved" @click="addConnection">
|
|
<Plus data-icon="inline-start" />Add connection
|
|
</Button>
|
|
<span v-if="unsaved" class="text-xs text-fg-muted">Save the current changes first.</span>
|
|
</div>
|
|
|
|
<Empty v-if="!connections.length"><EmptyHeader><EmptyTitle>No connections</EmptyTitle></EmptyHeader></Empty>
|
|
|
|
<CardAccordion
|
|
v-model:open="open"
|
|
:items="connections"
|
|
:title="(item) => item.name || item.id"
|
|
remove-label="Remove"
|
|
mono
|
|
@remove="connections.splice($event, 1)"
|
|
>
|
|
<template #default="slot">
|
|
<ConnectionCard :connection="slot.item" :index="slot.index" />
|
|
</template>
|
|
</CardAccordion>
|
|
|
|
</template>
|
|
</div>
|
|
</template>
|