Merge pull request 'fix(ui): preview extensions and modal-edit policies' (#2133) from fix/ui-screen-consistency into main
Reviewed-on: #2133
This commit was merged in pull request #2133.
This commit is contained in:
commit
74deeb74d5
8 files changed
+267
-40
No files matched your search
@@ -10,6 +10,8 @@ repo=$(cd "$here/../.." && pwd)
|
||||
dir=/root/archie
|
||||
|
||||
version=$(git -C "$repo" describe --tags --always --dirty)
|
||||
# The dashboard is embedded in the binary; never build from a stale ui/dist.
|
||||
(cd "$repo" && task ui)
|
||||
CGO_ENABLED=0 GOOS=linux GOARCH=amd64 go build -C "$repo" -trimpath \
|
||||
-ldflags "-X github.com/samcharles93/archie-core/internal/buildinfo.Version=$version" \
|
||||
-o "$here/.build/archie" ./cmd/archie
|
||||
|
||||
@@ -8,6 +8,7 @@ import { computed, onMounted, ref } from "vue";
|
||||
|
||||
import { Badge } from "@/components/ui/badge";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { Dialog, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogTitle } from "@/components/ui/dialog";
|
||||
import { Section } from "@/components/ui/section";
|
||||
import { Input } from "@/components/ui/input";
|
||||
import {
|
||||
@@ -68,6 +69,7 @@ function newPolicy(): void {
|
||||
draft.value = blank();
|
||||
original.value = blank();
|
||||
editingExisting.value = false;
|
||||
saveError.value = "";
|
||||
editing.value = true;
|
||||
});
|
||||
}
|
||||
@@ -75,6 +77,9 @@ function newPolicy(): void {
|
||||
function cancel(): void {
|
||||
openForm(() => {
|
||||
draft.value = blank();
|
||||
original.value = blank();
|
||||
editingExisting.value = false;
|
||||
saveError.value = "";
|
||||
editing.value = false;
|
||||
});
|
||||
}
|
||||
@@ -125,6 +130,7 @@ function edit(p: Policy): void {
|
||||
draft.value = { ...p };
|
||||
original.value = { ...p };
|
||||
editingExisting.value = true;
|
||||
saveError.value = "";
|
||||
editing.value = true;
|
||||
});
|
||||
}
|
||||
@@ -197,44 +203,50 @@ onMounted(load);
|
||||
</div>
|
||||
</Section>
|
||||
|
||||
<Section v-if="editing" :title="draft.id ? draft.id : 'New policy'">
|
||||
<div class="flex flex-col gap-3">
|
||||
<div class="flex flex-wrap gap-2">
|
||||
<Input v-model="draft.id" :readonly="editingExisting" placeholder="policy id" aria-label="Policy id" class="w-56" />
|
||||
<Select v-model="draft.level">
|
||||
<SelectTrigger class="w-40" aria-label="Level"><SelectValue /></SelectTrigger>
|
||||
<SelectContent>
|
||||
<SelectItem value="instance">instance</SelectItem>
|
||||
<SelectItem value="org">org</SelectItem>
|
||||
<SelectItem value="workspace">workspace</SelectItem>
|
||||
<SelectItem value="object">object</SelectItem>
|
||||
</SelectContent>
|
||||
</Select>
|
||||
<Input
|
||||
v-if="draft.level === 'workspace'"
|
||||
v-model="draft.workspace_id"
|
||||
placeholder="workspace id"
|
||||
aria-label="Workspace id"
|
||||
class="w-48"
|
||||
<Dialog :open="editing" @update:open="(value: boolean) => { if (!value) cancel(); }">
|
||||
<DialogContent class="flex max-h-[90dvh] flex-col overflow-hidden sm:max-w-2xl">
|
||||
<DialogHeader>
|
||||
<DialogTitle>{{ draft.id || "New policy" }}</DialogTitle>
|
||||
<DialogDescription>Set the policy scope and Cedar expression.</DialogDescription>
|
||||
</DialogHeader>
|
||||
<form id="policy-editor" class="min-h-0 flex-1 space-y-3 overflow-y-auto pr-1" @submit.prevent="save">
|
||||
<div class="flex flex-wrap gap-2">
|
||||
<Input v-model="draft.id" :readonly="editingExisting" placeholder="policy id" aria-label="Policy id" class="w-56" />
|
||||
<Select v-model="draft.level">
|
||||
<SelectTrigger class="w-40" aria-label="Level"><SelectValue /></SelectTrigger>
|
||||
<SelectContent>
|
||||
<SelectItem value="instance">instance</SelectItem>
|
||||
<SelectItem value="org">org</SelectItem>
|
||||
<SelectItem value="workspace">workspace</SelectItem>
|
||||
<SelectItem value="object">object</SelectItem>
|
||||
</SelectContent>
|
||||
</Select>
|
||||
<Input
|
||||
v-if="draft.level === 'workspace'"
|
||||
v-model="draft.workspace_id"
|
||||
placeholder="workspace id"
|
||||
aria-label="Workspace id"
|
||||
class="w-48"
|
||||
/>
|
||||
<template v-if="draft.level === 'object'">
|
||||
<Input v-model="draft.object_kind" placeholder="kind (secret, source...)" aria-label="Object kind" class="w-48" />
|
||||
<Input v-model="draft.object_id" placeholder="object id (a source's id)" aria-label="Object id" class="w-48" />
|
||||
</template>
|
||||
</div>
|
||||
<Textarea
|
||||
v-model="draft.text"
|
||||
class="min-h-40 font-mono text-caption"
|
||||
aria-label="Cedar policy"
|
||||
placeholder='permit(principal, action == Archie::Action::"read", resource);'
|
||||
/>
|
||||
<template v-if="draft.level === 'object'">
|
||||
<Input v-model="draft.object_kind" placeholder="kind (secret, source...)" aria-label="Object kind" class="w-48" />
|
||||
<Input v-model="draft.object_id" placeholder="object id (a source's id)" aria-label="Object id" class="w-48" />
|
||||
</template>
|
||||
</div>
|
||||
<Textarea
|
||||
v-model="draft.text"
|
||||
class="min-h-40 font-mono text-caption"
|
||||
aria-label="Cedar policy"
|
||||
placeholder='permit(principal, action == Archie::Action::"read", resource);'
|
||||
/>
|
||||
<ReadError v-if="saveError" :message="saveError" class="mb-2" />
|
||||
<div class="flex gap-2">
|
||||
<Button :disabled="!canSave || saving" @click="save">Save</Button>
|
||||
<Button variant="outline" @click="cancel">Cancel</Button>
|
||||
</div>
|
||||
</div>
|
||||
</Section>
|
||||
<ReadError v-if="saveError" :message="saveError" class="mb-2" />
|
||||
</form>
|
||||
<DialogFooter>
|
||||
<Button type="submit" form="policy-editor" :disabled="!canSave || saving">Save</Button>
|
||||
<Button type="button" variant="outline" @click="cancel">Cancel</Button>
|
||||
</DialogFooter>
|
||||
</DialogContent>
|
||||
</Dialog>
|
||||
</div>
|
||||
<AlertDialog :open="discardConfirm" @update:open="(v: boolean) => { if (!v) closeDiscard(); }">
|
||||
<AlertDialogContent>
|
||||
|
||||
@@ -0,0 +1,107 @@
|
||||
<script setup lang="ts">
|
||||
import { computed, ref, watch } from "vue";
|
||||
|
||||
import { Badge } from "@/components/ui/badge";
|
||||
import { Dialog, DialogContent, DialogDescription, DialogHeader, DialogTitle } from "@/components/ui/dialog";
|
||||
import { MetadataList } from "@/components/ui/metadata-list";
|
||||
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "@/components/ui/select";
|
||||
import { SettingRow } from "@/components/ui/setting-row";
|
||||
import { grants, type CatalogueEntry } from "@/stores/extensions";
|
||||
import { previewVersion } from "./catalogue-preview";
|
||||
|
||||
const props = defineProps<{ entry: CatalogueEntry | null }>();
|
||||
const open = defineModel<boolean>("open", { required: true });
|
||||
|
||||
const version = ref("");
|
||||
watch(
|
||||
[
|
||||
open,
|
||||
() => props.entry?.name,
|
||||
() => props.entry?.default_version,
|
||||
() => props.entry?.latest,
|
||||
() => props.entry?.versions.map((item) => item.version).join("\u0000"),
|
||||
],
|
||||
([isOpen]) => {
|
||||
if (isOpen && props.entry) version.value = previewVersion(props.entry);
|
||||
},
|
||||
{ immediate: true },
|
||||
);
|
||||
|
||||
const selected = computed(() =>
|
||||
props.entry?.versions.find((item) => item.version === version.value),
|
||||
);
|
||||
const entryDetails = computed(() => {
|
||||
const entry = props.entry;
|
||||
if (!entry) return [];
|
||||
return [
|
||||
{ label: "Package", value: entry.name, mono: true },
|
||||
{ label: "Contract", value: entry.contract, mono: true },
|
||||
{ label: "Group", value: entry.group },
|
||||
{ label: "Latest", value: entry.latest, mono: true },
|
||||
...(entry.default_version && entry.default_version !== entry.latest ? [{ label: "Default", value: entry.default_version, mono: true }] : []),
|
||||
{ label: "Installed", value: entry.installed ? "Yes" : "No" },
|
||||
{ label: "Update", value: entry.update_available ? entry.latest : "None" },
|
||||
];
|
||||
});
|
||||
const versionDetails = computed(() => {
|
||||
const item = selected.value;
|
||||
return item
|
||||
? [
|
||||
{ label: "Digest", value: item.digest, mono: true },
|
||||
{ label: "Registered", value: item.registered ? "Yes" : "No" },
|
||||
]
|
||||
: [];
|
||||
});
|
||||
const authority = computed(() => grants(selected.value?.grants));
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<Dialog v-model:open="open">
|
||||
<DialogContent class="flex max-h-[90dvh] flex-col overflow-hidden sm:max-w-2xl">
|
||||
<DialogHeader>
|
||||
<DialogTitle>{{ entry?.display_name || entry?.name }}</DialogTitle>
|
||||
<DialogDescription>{{ entry?.description || "Manifest metadata and authority." }}</DialogDescription>
|
||||
</DialogHeader>
|
||||
|
||||
<div class="min-h-0 flex-1 space-y-5 overflow-y-auto pr-1">
|
||||
<MetadataList :rows="entryDetails" />
|
||||
|
||||
<SettingRow v-if="entry?.versions.length" label="Version" for="catalogue-preview-version">
|
||||
<Select v-model="version">
|
||||
<SelectTrigger id="catalogue-preview-version" class="w-full"><SelectValue /></SelectTrigger>
|
||||
<SelectContent>
|
||||
<SelectItem v-for="item in entry.versions" :key="item.version" :value="item.version">{{ item.version }}</SelectItem>
|
||||
</SelectContent>
|
||||
</Select>
|
||||
</SettingRow>
|
||||
|
||||
<MetadataList v-if="selected" :rows="versionDetails" />
|
||||
|
||||
<section v-if="selected" aria-labelledby="catalogue-preview-authority">
|
||||
<h3 id="catalogue-preview-authority" class="mb-2 text-label font-semibold">Authority</h3>
|
||||
<ul class="space-y-1 font-mono text-caption">
|
||||
<li v-for="line in authority" :key="line">{{ line }}</li>
|
||||
<li v-if="!authority.length" class="font-sans text-fg-muted">None declared</li>
|
||||
</ul>
|
||||
</section>
|
||||
|
||||
<section v-if="selected?.settings.length" aria-labelledby="catalogue-preview-settings">
|
||||
<h3 id="catalogue-preview-settings" class="mb-2 text-label font-semibold">Settings</h3>
|
||||
<ul class="divide-y divide-border">
|
||||
<li v-for="field in selected.settings" :key="field.key" class="space-y-1 py-2 first:pt-0 last:pb-0">
|
||||
<div class="flex flex-wrap items-center gap-2">
|
||||
<span class="font-medium">{{ field.label || field.key }}</span>
|
||||
<span class="font-mono text-caption text-fg-subtle">{{ field.key }}</span>
|
||||
<Badge v-if="field.required" variant="outline">Required</Badge>
|
||||
<Badge v-if="field.secret" variant="idle">Secret</Badge>
|
||||
<span v-if="field.type" class="text-caption text-fg-muted">{{ field.type }}</span>
|
||||
</div>
|
||||
<p v-if="field.description" class="text-caption text-fg-muted">{{ field.description }}</p>
|
||||
<p v-if="field.options?.length" class="text-caption text-fg-muted">Options: {{ field.options.join(", ") }}</p>
|
||||
</li>
|
||||
</ul>
|
||||
</section>
|
||||
</div>
|
||||
</DialogContent>
|
||||
</Dialog>
|
||||
</template>
|
||||
@@ -1,6 +1,6 @@
|
||||
<script setup lang="ts">
|
||||
import { computed, ref, type Component } from "vue";
|
||||
import { Package, Plus, Search, Workflow, Zap } from "@lucide/vue";
|
||||
import { Eye, Package, Plus, Search, Workflow, Zap } from "@lucide/vue";
|
||||
|
||||
import { Badge } from "@/components/ui/badge";
|
||||
import { Button } from "@/components/ui/button";
|
||||
@@ -14,7 +14,7 @@ import { useExtensionsStore, type CatalogueEntry } from "@/stores/extensions";
|
||||
* packages stay listed so the catalogue reads whole; they open their versions
|
||||
* when a newer one exists.
|
||||
*/
|
||||
const emit = defineEmits<{ install: [entry: CatalogueEntry]; versions: [name: string] }>();
|
||||
const emit = defineEmits<{ install: [entry: CatalogueEntry]; versions: [name: string]; preview: [entry: CatalogueEntry] }>();
|
||||
const store = useExtensionsStore();
|
||||
|
||||
// The server names each extension's group; these are its icons.
|
||||
@@ -68,6 +68,9 @@ const groups = computed(() => {
|
||||
<ItemDescription class="text-caption" :title="entry.description">{{ entry.description }}</ItemDescription>
|
||||
</ItemContent>
|
||||
<ItemActions class="self-center">
|
||||
<Button variant="ghost" size="sm" :aria-label="`Details for ${entry.display_name || entry.name}`" @click="emit('preview', entry)">
|
||||
<Eye data-icon="inline-start" />Details
|
||||
</Button>
|
||||
<Button v-if="entry.update_available" variant="outline" size="sm" :disabled="!!store.busy" @click="emit('versions', entry.name)"
|
||||
>Update to {{ entry.latest }}</Button
|
||||
>
|
||||
|
||||
@@ -42,6 +42,7 @@ import InstallationDialog from "./InstallationDialog.vue";
|
||||
import PackageList from "./PackageList.vue";
|
||||
import ExtensionsMarketplace from "./ExtensionsMarketplace.vue";
|
||||
import CatalogueInstallDialog from "./CatalogueInstallDialog.vue";
|
||||
import CataloguePreviewDialog from "./CataloguePreviewDialog.vue";
|
||||
import PackageVersionsDialog from "./PackageVersionsDialog.vue";
|
||||
|
||||
const route = useRoute();
|
||||
@@ -106,6 +107,13 @@ function openInstall(entry: CatalogueEntry): void {
|
||||
installOpen.value = true;
|
||||
}
|
||||
|
||||
const previewing = ref<CatalogueEntry | null>(null);
|
||||
const previewOpen = ref(false);
|
||||
function openPreview(entry: CatalogueEntry): void {
|
||||
previewing.value = entry;
|
||||
previewOpen.value = true;
|
||||
}
|
||||
|
||||
const versionsOf = ref("");
|
||||
const versionsOpen = ref(false);
|
||||
function openVersions(name: string): void {
|
||||
@@ -361,12 +369,13 @@ const active = computed(() => (kinds.data.value ?? []).find((kind) => kind.kind
|
||||
</CollapsibleContent>
|
||||
</Collapsible>
|
||||
<ReadError v-if="store.catalogueError" :message="store.catalogueError" retry-label="Retry" @retry="store.load()" />
|
||||
<ExtensionsMarketplace v-else @install="openInstall" @versions="openVersions" />
|
||||
<ExtensionsMarketplace v-else @install="openInstall" @versions="openVersions" @preview="openPreview" />
|
||||
</TabsContent>
|
||||
</Tabs>
|
||||
|
||||
<InstallationDialog v-model:open="installationOpen" :extension="installation" :packages="store.packages" :scopes="scopes" @saved="reload" />
|
||||
|
||||
<CataloguePreviewDialog v-model:open="previewOpen" :entry="previewing" />
|
||||
<CatalogueInstallDialog v-model:open="installOpen" :entry="installing" :scopes="scopes" />
|
||||
<PackageVersionsDialog v-model:open="versionsOpen" :name="versionsOf" />
|
||||
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
import type { CatalogueEntry } from "@/lib/api";
|
||||
|
||||
/** Selects a version that exists in the current catalogue snapshot. */
|
||||
export function previewVersion(entry: Pick<CatalogueEntry, "default_version" | "latest" | "versions">): string {
|
||||
const offered = new Set(entry.versions.map((item) => item.version));
|
||||
if (entry.default_version && offered.has(entry.default_version)) return entry.default_version;
|
||||
if (offered.has(entry.latest)) return entry.latest;
|
||||
return entry.versions[0]?.version ?? "";
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
import assert from "node:assert/strict";
|
||||
import test from "node:test";
|
||||
|
||||
test("extension preview chooses an offered version when catalogue defaults are stale", async () => {
|
||||
const { previewVersion } = await import("../src/settings/catalogue-preview.ts");
|
||||
const cases = [
|
||||
{
|
||||
name: "keeps an offered default ahead of latest",
|
||||
entry: { default_version: "1.1.0", latest: "1.2.0", versions: [{ version: "1.1.0" }, { version: "1.2.0" }] },
|
||||
expected: "1.1.0",
|
||||
},
|
||||
{
|
||||
name: "falls back to latest when default is no longer offered",
|
||||
entry: { default_version: "1.0.0", latest: "1.2.0", versions: [{ version: "1.2.0" }] },
|
||||
expected: "1.2.0",
|
||||
},
|
||||
{
|
||||
name: "falls back to the first offered version when both hints are stale",
|
||||
entry: { default_version: "1.0.0", latest: "1.2.0", versions: [{ version: "1.1.0" }] },
|
||||
expected: "1.1.0",
|
||||
},
|
||||
{
|
||||
name: "returns empty when no versions are offered",
|
||||
entry: { default_version: "1.0.0", latest: "1.2.0", versions: [] },
|
||||
expected: "",
|
||||
},
|
||||
];
|
||||
|
||||
for (const { name, entry, expected } of cases) {
|
||||
assert.equal(previewVersion(entry), expected, name);
|
||||
}
|
||||
});
|
||||
@@ -0,0 +1,53 @@
|
||||
import assert from "node:assert/strict";
|
||||
import { after, test } from "node:test";
|
||||
import { createSSRApp } from "vue";
|
||||
import { renderToString } from "vue/server-renderer";
|
||||
import { createPinia, setActivePinia } from "pinia";
|
||||
import { createServer } from "vite";
|
||||
import { fileURLToPath } from "node:url";
|
||||
|
||||
const server = await createServer({
|
||||
configFile: fileURLToPath(new URL("../vite.config.ts", import.meta.url)),
|
||||
server: { middlewareMode: true },
|
||||
appType: "custom",
|
||||
logLevel: "error",
|
||||
});
|
||||
|
||||
after(async () => server.close());
|
||||
|
||||
test("catalogue extensions expose a preview action separately from install", async () => {
|
||||
const { default: Marketplace } = await server.ssrLoadModule("/src/settings/ExtensionsMarketplace.vue");
|
||||
const pinia = createPinia();
|
||||
setActivePinia(pinia);
|
||||
const { useExtensionsStore } = await server.ssrLoadModule("/src/stores/extensions.ts");
|
||||
const store = useExtensionsStore();
|
||||
store.catalogue = [
|
||||
{
|
||||
name: "calendar",
|
||||
display_name: "Calendar",
|
||||
description: "Reads calendar events.",
|
||||
contract: "archie.connector.v1",
|
||||
group: "integration",
|
||||
latest: "1.2.0",
|
||||
versions: [
|
||||
{
|
||||
version: "1.2.0",
|
||||
digest: "sha256:abc123",
|
||||
grants: { egress: ["calendar.example"], env: ["CALENDAR_TOKEN"], credentials: ["calendar"] },
|
||||
settings: [{ key: "calendar_id", label: "Calendar ID", description: "Calendar to read.", required: true }],
|
||||
registered: false,
|
||||
},
|
||||
],
|
||||
installed: false,
|
||||
update_available: false,
|
||||
},
|
||||
];
|
||||
store.catalogueLoaded = true;
|
||||
|
||||
const app = createSSRApp(Marketplace);
|
||||
app.use(pinia);
|
||||
const html = await renderToString(app);
|
||||
|
||||
assert.ok(html.includes("Details"), "catalogue entry has no preview action");
|
||||
assert.ok(html.includes('aria-label="Details for Calendar"'), "preview action has no accessible name");
|
||||
});
|
||||
Reference in new issue
Block a user