Files
archie/ui/src/org/OrgOverviewPage.vue
T
sam 90e58a67e9 fix(ui): link user attribution to member records
(cherry picked from commit d30901653a181041b2424389baceb056f16ec7c9)
2026-11-27 15:51:34 +11:00

181 lines
6.6 KiB
Vue

<script setup lang="ts">
import { ArrowRight, Pencil } from "@lucide/vue";
import { computed, onMounted, ref } from "vue";
import PageHeader from "@/base/PageHeader.vue";
import { Alert, AlertDescription } from "@/components/ui/alert";
import { Button } from "@/components/ui/button";
import { Card, CardHeader, CardTitle } from "@/components/ui/card";
import {
Dialog,
DialogContent,
DialogFooter,
DialogHeader,
DialogTitle,
} from "@/components/ui/dialog";
import { Empty, EmptyHeader, EmptyTitle } from "@/components/ui/empty";
import { Input } from "@/components/ui/input";
import { ReadError } from "@/components/ui/read-error";
import { Section } from "@/components/ui/section";
import { Timestamp } from "@/components/ui/timestamp";
import { errors } from "@/copy/errors";
import { hiddenPaths } from "@/lib/nav";
import { ApiError, api, describeError } from "@/lib/api";
import { useOrgStore } from "@/stores/org";
import { useSessionStore } from "@/stores/session";
import type { OrgEvent } from "./org";
import UserReference from "./UserReference.vue";
/**
* The organisation home: where each kind of organisation configuration lives,
* linked, so an operator can reach the thing a run needs without guessing
* which page owns it, and the record of every name change so a rename is
* attributable without leaving the page.
*/
const allAreas = [
{ title: "Execution identities", to: "/org/agents" },
{ title: "Extensions", to: "/settings/extensions" },
{ title: "Workspaces", to: "/org/workspaces" },
{ title: "Models", to: "/settings/models" },
{ title: "Triggers", to: "/events?tab=triggers" },
{ title: "Members and access", to: "/org/members" },
];
const orgStore = useOrgStore();
const session = useSessionStore();
const areas = computed(() => {
const hidden = hiddenPaths(session.sections);
return allAreas.filter((area) => !hidden.includes(area.to.split("?")[0]!));
});
const org = computed(() => orgStore.org);
// The single binary reports a revision with every org and serves the rename
// routes and their history. A server without one has neither, so the controls
// stay hidden rather than calling an endpoint it does not have.
const renamesHere = computed(() => typeof org.value?.version === "number");
const canRename = computed(() => renamesHere.value && org.value?.role === "owner");
const history = ref<OrgEvent[]>([]);
const historyLoading = ref(true);
const historyError = ref("");
async function loadHistory(): Promise<void> {
if (!org.value || !renamesHere.value) return;
try {
history.value = (
await api.orgHistory<{ events: OrgEvent[] }>(org.value.id)
).events;
historyError.value = "";
} catch (cause) {
historyError.value = describeError(cause, errors.common.unknown);
}
}
onMounted(async () => {
try {
await orgStore.loadOrg();
await loadHistory();
} catch (cause) {
historyError.value = describeError(cause, errors.common.unknown);
} finally {
historyLoading.value = false;
}
});
const renameOpen = ref(false);
const draft = ref("");
const renameError = ref("");
const renaming = ref(false);
function openRename(): void {
draft.value = org.value?.name ?? "";
renameError.value = "";
renameOpen.value = true;
}
async function rename(): Promise<void> {
const name = draft.value.trim();
if (!name || renaming.value) return;
renaming.value = true;
renameError.value = "";
try {
await orgStore.renameOrg(name);
renameOpen.value = false;
await loadHistory();
} catch (cause) {
if (cause instanceof ApiError && cause.status === 409) {
// Another tab changed the name first. Show that name and keep the draft,
// so the operator can decide whether their name still wins.
await orgStore.loadOrg(true).catch(() => undefined);
renameError.value = errors.org.rename.conflict(org.value?.name ?? name);
} else {
renameError.value = describeError(cause, errors.common.unknown);
}
} finally {
renaming.value = false;
}
}
function describeChange(event: OrgEvent): string {
if (event.kind === "workspace") {
return `Renamed workspace “${event.old_name}” to “${event.new_name}”`;
}
return `Renamed the organisation from “${event.old_name}” to “${event.new_name}”`;
}
</script>
<template>
<div>
<PageHeader title="Organisation">
<Button v-if="canRename" variant="outline" @click="openRename">
<Pencil data-icon="inline-start" />Rename
</Button>
<Button as-child>
<RouterLink to="/tasks">Start a task<ArrowRight data-icon="inline-end" /></RouterLink>
</Button>
</PageHeader>
<div class="grid gap-3 sm:grid-cols-2">
<RouterLink v-for="area in areas" :key="area.to" :to="area.to" class="focus-visible:outline-2 focus-visible:outline-ring">
<Card size="sm" class="h-full transition-colors hover:border-primary/40">
<CardHeader>
<CardTitle>{{ area.title }}</CardTitle>
</CardHeader>
</Card>
</RouterLink>
</div>
<Section v-if="renamesHere" title="Name changes" class="mt-4">
<ReadError v-if="historyError" :message="historyError" retry-label="Retry" @retry="loadHistory" />
<p v-else-if="historyLoading" class="text-label text-fg-muted" role="status">Loading changes…</p>
<Empty v-else-if="!history.length">
<EmptyHeader>
<EmptyTitle>No name changes yet</EmptyTitle>
</EmptyHeader>
</Empty>
<ul v-else class="divide-y">
<li v-for="event in history" :key="event.id" class="flex flex-wrap items-baseline gap-x-2 gap-y-1 py-2 first:pt-0 last:pb-0">
<span class="text-label">{{ describeChange(event) }}</span>
<span class="text-caption text-fg-muted">by <UserReference :id="event.actor_id" :name="event.actor_name" :org-id="org?.id" /></span>
<Timestamp class="ml-auto text-caption text-fg-subtle" :at="event.at" />
</li>
</ul>
</Section>
<Dialog :open="renameOpen" @update:open="renameOpen = $event">
<DialogContent>
<DialogHeader>
<DialogTitle>Rename organisation</DialogTitle>
</DialogHeader>
<form id="rename-org" class="flex flex-col gap-3" @submit.prevent="rename">
<Input v-model="draft" maxlength="80" aria-label="Organisation name" required />
<Alert v-if="renameError" variant="destructive"><AlertDescription>{{ renameError }}</AlertDescription></Alert>
</form>
<DialogFooter>
<Button variant="outline" @click="renameOpen = false">Cancel</Button>
<Button type="submit" form="rename-org" :disabled="!draft.trim() || renaming">Save</Button>
</DialogFooter>
</DialogContent>
</Dialog>
</div>
</template>