Inline error paragraphs become destructive Alerts, divided record lists become Item rows, the redirect URI box uses CodeView, and icon-button title hints use Tooltip. Native titles remain on truncated values and on disabled controls.
229 lines
10 KiB
Vue
229 lines
10 KiB
Vue
<script setup lang="ts">
|
|
import { Tooltip, TooltipContent, TooltipTrigger } from "@/components/ui/tooltip";
|
|
import { Item, ItemGroup } from "@/components/ui/item";
|
|
import { Alert, AlertDescription } from "@/components/ui/alert";
|
|
import { computed, onMounted, ref } from "vue";
|
|
import { ChevronRight, Plus, Trash2 } from "@lucide/vue";
|
|
|
|
import PageHeader from "@/base/PageHeader.vue";
|
|
import {
|
|
AlertDialog,
|
|
AlertDialogAction,
|
|
AlertDialogCancel,
|
|
AlertDialogContent,
|
|
AlertDialogDescription,
|
|
AlertDialogFooter,
|
|
AlertDialogHeader,
|
|
AlertDialogTitle,
|
|
} from "@/components/ui/alert-dialog";
|
|
import { Button } from "@/components/ui/button";
|
|
import { Collapsible, CollapsibleContent, CollapsibleTrigger } from "@/components/ui/collapsible";
|
|
import { Empty, EmptyHeader, EmptyTitle } from "@/components/ui/empty";
|
|
import { Input } from "@/components/ui/input";
|
|
import { Badge } from "@/components/ui/badge";
|
|
import { Switch } from "@/components/ui/switch";
|
|
import { Section } from "@/components/ui/section";
|
|
import { Tabs, TabsContent, TabsList, TabsTrigger } from "@/components/ui/tabs";
|
|
import { grants, stage, useExtensionsStore, type Extension } from "@/stores/extensions";
|
|
import ApplyStatusRows from "./ApplyStatusRows.vue";
|
|
import ExtensionsMarketplace from "./ExtensionsMarketplace.vue";
|
|
|
|
const KIND = "extension-settings";
|
|
const store = useExtensionsStore();
|
|
const loading = ref(true);
|
|
onMounted(async () => {
|
|
await store.load();
|
|
loading.value = false;
|
|
});
|
|
|
|
// The catalogue entry an installed package would move to on Update, when the
|
|
// catalogue pins a different digest than the one installed.
|
|
const updates = computed(() => {
|
|
const byName = new Map(store.catalogue.map((entry) => [entry.name, entry]));
|
|
return new Map(
|
|
store.extensions.flatMap((extension) => {
|
|
const entry = byName.get(extension.name);
|
|
return entry && entry.digest !== extension.digest ? [[extension.name, entry] as const] : [];
|
|
}),
|
|
);
|
|
});
|
|
|
|
const name = ref("");
|
|
const reference = ref("");
|
|
const digest = ref("");
|
|
async function install(): Promise<void> {
|
|
if (await store.install(name.value, reference.value, digest.value)) {
|
|
name.value = reference.value = digest.value = "";
|
|
}
|
|
}
|
|
|
|
// The dialog's action closes it before its click handler runs, so the
|
|
// target outlives the open flag rather than being cleared on close.
|
|
const accepting = ref<Extension | null>(null);
|
|
const acceptOpen = ref(false);
|
|
async function accept(): Promise<void> {
|
|
if (accepting.value) await store.accept(accepting.value.name);
|
|
}
|
|
const removing = ref<Extension | null>(null);
|
|
const removeOpen = ref(false);
|
|
async function remove(): Promise<void> {
|
|
if (removing.value) await store.remove(removing.value.name);
|
|
}
|
|
|
|
const tones = {
|
|
accept: { tone: "warn", label: "Authority not accepted" },
|
|
disabled: { tone: "idle", label: "Disabled" },
|
|
enabled: { tone: undefined, label: "" },
|
|
inert: { tone: "idle", label: "No extensions" },
|
|
} as const;
|
|
</script>
|
|
|
|
<template>
|
|
<div>
|
|
<PageHeader title="Extensions" />
|
|
|
|
<Alert v-if="store.error" variant="destructive" class="mb-4"><AlertDescription>{{ store.error }}</AlertDescription></Alert>
|
|
|
|
<Tabs default-value="installed" class="space-y-4">
|
|
<TabsList>
|
|
<TabsTrigger value="installed">Installed</TabsTrigger>
|
|
<TabsTrigger value="marketplace">Marketplace</TabsTrigger>
|
|
</TabsList>
|
|
<TabsContent value="installed">
|
|
<Section>
|
|
<ItemGroup aria-label="Extensions">
|
|
<Item v-for="extension in store.extensions" :key="extension.name" as="li" variant="outline">
|
|
<div class="min-w-0 w-full lg:w-auto lg:flex-1">
|
|
<p class="truncate text-sm font-medium">
|
|
{{ extension.display_name || extension.name }}
|
|
<span class="font-mono text-xs text-fg-subtle">{{ extension.version }}</span>
|
|
</p>
|
|
<p class="text-xs text-fg-subtle">{{ extension.description }}</p>
|
|
<p class="truncate font-mono text-xs text-fg-subtle">{{ extension.digest }}</p>
|
|
<Collapsible v-if="extension.accepted">
|
|
<CollapsibleTrigger as-child>
|
|
<Button variant="ghost" size="sm" class="-ml-2 h-6 px-2 text-xs font-normal text-fg-subtle">
|
|
<ChevronRight class="transition-transform group-data-[state=open]/button:rotate-90" />
|
|
Accepted authority
|
|
</Button>
|
|
</CollapsibleTrigger>
|
|
<CollapsibleContent>
|
|
<ul class="font-mono text-xs text-fg-subtle">
|
|
<li v-for="line in grants(extension.accepted)" :key="line">{{ line }}</li>
|
|
</ul>
|
|
</CollapsibleContent>
|
|
</Collapsible>
|
|
</div>
|
|
<Badge v-if="tones[stage(extension)].tone" :variant="tones[stage(extension)].tone">{{ tones[stage(extension)].label }}</Badge>
|
|
<div v-if="extension.pending" class="w-full rounded-md border border-border px-3 py-2">
|
|
<p class="text-xs font-medium">Update awaiting approval. It adds:</p>
|
|
<ul class="font-mono text-xs">
|
|
<li v-for="line in grants(extension.pending.added).filter((l) => !l.startsWith('network:'))" :key="line">{{ line }}</li>
|
|
</ul>
|
|
<Button size="sm" class="mt-2" :disabled="!!store.busy" @click="store.approveUpdate(extension.name)">Approve</Button>
|
|
</div>
|
|
<Button
|
|
v-if="updates.has(extension.name) && !extension.pending"
|
|
variant="outline"
|
|
size="sm"
|
|
:disabled="!!store.busy"
|
|
@click="store.update(extension.name)"
|
|
>Update to {{ updates.get(extension.name)?.version }}</Button
|
|
>
|
|
<Switch
|
|
:model-value="extension.update_policy === 'auto'"
|
|
:disabled="!!store.busy"
|
|
:aria-label="`Auto-update ${extension.name}`"
|
|
@update:model-value="(value: boolean) => store.setUpdatePolicy(extension.name, value ? 'auto' : 'manual')"
|
|
/>
|
|
<Button v-if="extension.can_rollback" variant="ghost" size="sm" :disabled="!!store.busy" @click="store.rollback(extension.name)"
|
|
>Roll back</Button
|
|
>
|
|
<Button
|
|
v-if="stage(extension) === 'accept'"
|
|
variant="ghost"
|
|
size="sm"
|
|
:disabled="!!store.busy"
|
|
@click="(accepting = extension), (acceptOpen = true)"
|
|
>Review authority</Button
|
|
>
|
|
<Switch
|
|
v-else-if="stage(extension) !== 'inert'"
|
|
:model-value="extension.enabled"
|
|
:disabled="!!store.busy"
|
|
:aria-label="`Enable ${extension.name}`"
|
|
@update:model-value="(value: boolean) => store.setEnabled(extension.name, value)"
|
|
/>
|
|
<Tooltip>
|
|
<TooltipTrigger as-child>
|
|
<Button
|
|
variant="ghost"
|
|
size="icon"
|
|
:aria-label="`Remove ${extension.name}`"
|
|
:disabled="!!store.busy"
|
|
@click="(removing = extension), (removeOpen = true)"
|
|
><Trash2
|
|
/></Button>
|
|
</TooltipTrigger>
|
|
<TooltipContent>Remove</TooltipContent>
|
|
</Tooltip>
|
|
</Item>
|
|
<li v-if="loading" class="py-3 text-sm text-fg-muted" role="status">Loading extensions…</li>
|
|
<li v-else-if="!store.extensions.length && !store.error">
|
|
<Empty class="py-6">
|
|
<EmptyHeader>
|
|
<EmptyTitle>Nothing installed</EmptyTitle>
|
|
</EmptyHeader>
|
|
</Empty>
|
|
</li>
|
|
</ItemGroup>
|
|
</Section>
|
|
|
|
<ApplyStatusRows :kind="KIND" class="mt-6 border-t border-border py-4" />
|
|
</TabsContent>
|
|
<TabsContent value="marketplace">
|
|
<p v-if="store.catalogueError" class="text-sm text-fg-muted">{{ store.catalogueError }}</p>
|
|
<ExtensionsMarketplace v-else :updates="updates" />
|
|
<Collapsible class="mt-3">
|
|
<CollapsibleTrigger class="cursor-pointer text-xs text-fg-muted">Install by reference</CollapsibleTrigger>
|
|
<CollapsibleContent><form class="mt-2 flex flex-wrap gap-2" @submit.prevent="install">
|
|
<Input v-model="name" class="max-w-40" placeholder="Name" aria-label="Name" required />
|
|
<Input v-model="reference" class="max-w-80 font-mono" placeholder="registry/repo:tag" aria-label="Reference" required />
|
|
<Input v-model="digest" class="max-w-96 font-mono" placeholder="sha256:…" aria-label="Digest" required />
|
|
<Button type="submit" size="sm" :disabled="!!store.busy"><Plus data-icon="inline-start" />Install</Button>
|
|
</form></CollapsibleContent>
|
|
</Collapsible>
|
|
</TabsContent>
|
|
</Tabs>
|
|
|
|
<AlertDialog v-model:open="acceptOpen">
|
|
<AlertDialogContent>
|
|
<AlertDialogHeader>
|
|
<AlertDialogTitle>Accept what {{ accepting?.name }} may use?</AlertDialogTitle>
|
|
<AlertDialogDescription>It runs as a process on this host and sees only these.</AlertDialogDescription>
|
|
</AlertDialogHeader>
|
|
<ul class="font-mono text-xs">
|
|
<li v-for="line in accepting ? grants(accepting.declared) : []" :key="line">{{ line }}</li>
|
|
</ul>
|
|
<AlertDialogFooter>
|
|
<AlertDialogCancel>Cancel</AlertDialogCancel>
|
|
<AlertDialogAction @click="accept">Accept</AlertDialogAction>
|
|
</AlertDialogFooter>
|
|
</AlertDialogContent>
|
|
</AlertDialog>
|
|
|
|
<AlertDialog v-model:open="removeOpen">
|
|
<AlertDialogContent>
|
|
<AlertDialogHeader>
|
|
<AlertDialogTitle>Remove {{ removing?.name }}?</AlertDialogTitle>
|
|
<AlertDialogDescription>Its process stops on the next sync.</AlertDialogDescription>
|
|
</AlertDialogHeader>
|
|
<AlertDialogFooter>
|
|
<AlertDialogCancel>Cancel</AlertDialogCancel>
|
|
<AlertDialogAction @click="remove">Remove</AlertDialogAction>
|
|
</AlertDialogFooter>
|
|
</AlertDialogContent>
|
|
</AlertDialog>
|
|
</div>
|
|
</template>
|