Files
archie/ui/src/settings/ConnectionsPage.vue
T
sam 94f79177a2
deploy / gate (push) Successful in 4m53s
Quality / check (push) Successful in 6m42s
deploy / archied-image (push) Successful in 3m20s
deploy / agent-image (push) Successful in 11s
deploy / dist-zip (push) Skipped
fix(ui): adopt the type scale across components/ui and pages (#1758)
components/ui and the pages now use only the style.css scale:
text-[0.8rem]→text-label, text-[0.625rem]→text-micro, text-base/text-sm→
text-label (rows and controls), text-xs→text-caption (captions and
secondary text), text-lg/text-xl/text-2xl→text-title (panel and page
titles). Rendered markdown (ChatMarkdown/ChatInline/markdown.ts) keeps
Tailwind steps as the issue allows. 196 files, class-token swaps only.
2026-11-06 23:07:46 +11:00

132 lines
4.3 KiB
Vue

<script setup lang="ts">
import { Alert, AlertDescription } from "@/components/ui/alert";
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 { Badge } from "@/components/ui/badge";
import { Button } from "@/components/ui/button";
import { resourcesForPage, useSettingsStore } from "@/stores/settings";
import { useExtensionsStore } from "@/stores/extensions";
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);
const extensions = useExtensionsStore();
onMounted(() => {
void store.load();
void extensions.loadInstalled();
orgStore.watchIdentities();
});
const resources = computed(() => resourcesForPage(catalog.value, "connections"));
const form = computed(() => store.formFor(KIND));
const connections = computed(() => (store.draftValue(KIND) ?? []) as Connection[]);
const error = computed(() => store.pageErrorFor(KIND));
const open = ref("0");
// What stops a connection serving a repository, from what the page already
// holds. Nothing is claimed while the installed forges could not be read.
function connectionIssue(item: Connection): string {
if (item.type && !extensions.error && !extensions.forges.some((e) => e.name === item.type)) return "Forge not enabled";
if (!item.token?.key) return "No credential";
return "";
}
const unsaved = computed(() => store.changesFor(KIND).length > 0);
// Each edit writes a new array: the document is a root list, and the draft
// value is read-only outside the store.
function setConnections(next: Connection[]) {
store.setDraftValue(KIND, next);
}
function updateConnection(index: number, next: Connection) {
setConnections(connections.value.map((c, j) => (j === index ? next : c)));
}
function removeConnection(index: number) {
setConnections(connections.value.filter((_, j) => j !== index));
}
function addConnection() {
if (unsaved.value) return;
const used = new Set(connections.value.map((c) => c.id));
let id = "connection";
for (let n = 2; used.has(id); n++) id = `connection-${n}`;
const next = [
...connections.value,
{
id,
name: "",
type: "github",
host: "",
account: "",
token: { engine: "", key: "" },
permits: {},
},
];
setConnections(next);
open.value = String(next.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"
/>
<Alert v-if="catalogError || error" variant="destructive" class="mb-4"><AlertDescription>
{{ catalogError || error }}
</AlertDescription></Alert>
<template v-if="form">
<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-caption 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="removeConnection"
>
<template #aside="{ item }">
<Badge v-if="connectionIssue(item as Connection)" variant="warn">{{ connectionIssue(item as Connection) }}</Badge>
</template>
<template #default="slot">
<ConnectionCard
:model-value="slot.item"
:index="slot.index"
@update:model-value="(next: Connection) => updateConnection(slot.index, next)"
/>
</template>
</CardAccordion>
</template>
</div>
</template>