Files
archie/ui/src/org/OrgShell.vue
T
sam d8569f26f5 fix(controlplane): name a migrated connection for its host
The seeded root connection was called "Instance forge", which names two
archie concepts an operator never chose. Name it for the host it points at
instead.
2026-10-17 08:59:57 +11:00

98 lines
3.4 KiB
Vue

<script setup lang="ts">
import PageHeader from "@/base/PageHeader.vue";
import { storeToRefs } from "pinia";
import { computed, onMounted, ref, watch } from "vue";
import { useRoute, useRouter } from "vue-router";
import {
Select,
SelectContent,
SelectItem,
SelectTrigger,
SelectValue,
} from "@/components/ui/select";
import { cn } from "@/lib/utils";
import NewOrgDialog from "./NewOrgDialog.vue";
import { useOrgStore } from "@/stores/org";
const TABS = [
{ path: "/access", label: "Accounts" },
{ path: "/access/policies", label: "Policies", home: true },
{ path: "/access/agents", label: "Agents" },
{ path: "/access/workspaces", label: "Workspaces" },
{ path: "/access/models", label: "Models", home: true, member: true },
];
const route = useRoute();
const router = useRouter();
const orgStore = useOrgStore();
const { homeOrg, instanceAdmin, org, orgs } = storeToRefs(orgStore);
// Policies act on the caller's own org server-side, so they are hidden while
// an instance admin views another org rather than editing the wrong one.
const away = computed(() => !!org.value && org.value.id !== homeOrg.value);
// Models is an org's own; the system org configures models in Settings.
const tabs = computed(() =>
TABS.filter((tab) => !(away.value && tab.home) && !(tab.member && homeOrg.value === "org-sys")),
);
watch([away, () => route.path], ([isAway]) => {
if (isAway && TABS.some((tab) => tab.home && route.path.startsWith(tab.path))) {
void router.replace("/access");
}
});
const error = ref("");
onMounted(async () => {
try {
await orgStore.loadOrg();
} catch (cause) {
error.value = String((cause as Error).message || cause);
}
});
const currentPath = computed(() => route.path);
const current = (path: string) =>
path === "/access" ? currentPath.value === "/access" : currentPath.value.startsWith(path);
</script>
<template>
<div>
<PageHeader title="Access">
<span class="text-sm text-muted-foreground">{{ org?.name }}</span>
<template v-if="instanceAdmin">
<Select :model-value="org?.id" @update:model-value="(id) => orgStore.viewOrg(String(id))">
<SelectTrigger class="w-60" aria-label="Org">
<SelectValue placeholder="Org" />
</SelectTrigger>
<SelectContent>
<SelectItem v-for="o in orgs" :key="o.id" :value="o.id">{{ o.name }}</SelectItem>
</SelectContent>
</Select>
<NewOrgDialog />
</template>
</PageHeader>
<nav aria-label="Access sections" class="mb-4 flex flex-wrap items-center gap-1 border-b border-border">
<RouterLink
v-for="tab in tabs"
:key="tab.path"
:to="tab.path"
:aria-current="current(tab.path) ? 'page' : undefined"
:class="
cn(
'-mb-px border-b-2 border-transparent px-3 py-2 text-sm text-muted-foreground transition-colors hover:text-foreground focus-visible:outline-2 focus-visible:outline-ring',
current(tab.path) && 'border-primary font-medium text-foreground',
)
"
>{{ tab.label }}</RouterLink
>
</nav>
<p v-if="error" role="alert" class="mb-4 text-sm text-danger">{{ error }}</p>
<!-- The sections need the org id, so they wait for the one read; keying on
it remounts the open section when an instance admin switches org. -->
<RouterView v-if="org" :key="org.id" />
</div>
</template>