101 lines
3.6 KiB
Vue
101 lines
3.6 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/tokens", label: "Tokens", home: true },
|
|
{ path: "/access/authentication", label: "Authentication", home: true, admin: 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 and tokens 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) => !(tab.admin && !instanceAdmin.value) && !(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>
|