feat(ui): org switcher and new org for instance admins
This commit is contained in:
1 parent
2c447708e9
commit
0a80f21bcd
5 files changed
+249
-95
No files matched your search
+45
-10
@@ -1,9 +1,17 @@
|
||||
<script setup lang="ts">
|
||||
import { computed, onMounted, ref } from "vue";
|
||||
import { useRoute } from "vue-router";
|
||||
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 { loadOrg, org } from "./org";
|
||||
import NewOrgDialog from "./NewOrgDialog.vue";
|
||||
import { homeOrg, instanceAdmin, loadOrg, org, orgs, viewOrg } from "./org";
|
||||
|
||||
/**
|
||||
* The Org area's shared frame: the org it is about, and the tab strip that
|
||||
@@ -12,17 +20,29 @@ import { loadOrg, org } from "./org";
|
||||
*
|
||||
* The org name and id are a context bar rather than the page's heading: each
|
||||
* section states its own, and /org/access is a moved page that still carries
|
||||
* its own.
|
||||
* its own. An instance admin gets a switcher over every org in its place.
|
||||
*/
|
||||
const TABS = [
|
||||
{ path: "/org", label: "Members" },
|
||||
{ path: "/org/agents", label: "Agents" },
|
||||
{ path: "/org/workspaces", label: "Workspaces" },
|
||||
{ path: "/org/access", label: "Access" },
|
||||
{ path: "/org/tokens", label: "Tokens" },
|
||||
{ path: "/org/access", label: "Access", home: true },
|
||||
{ path: "/org/tokens", label: "Tokens", home: true },
|
||||
];
|
||||
|
||||
const route = useRoute();
|
||||
const router = useRouter();
|
||||
|
||||
// Access 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);
|
||||
const tabs = computed(() => TABS.filter((tab) => !(away.value && tab.home)));
|
||||
watch(away, (isAway) => {
|
||||
if (isAway && TABS.some((tab) => tab.home && route.path.startsWith(tab.path))) {
|
||||
void router.replace("/org");
|
||||
}
|
||||
});
|
||||
const error = ref("");
|
||||
|
||||
onMounted(async () => {
|
||||
@@ -40,14 +60,28 @@ const current = (path: string) =>
|
||||
|
||||
<template>
|
||||
<div>
|
||||
<div class="mb-4 flex flex-wrap items-baseline gap-x-3 gap-y-1">
|
||||
<div v-if="instanceAdmin" class="mb-4 flex flex-wrap items-center gap-2">
|
||||
<Select :model-value="org?.id" @update:model-value="(id) => viewOrg(String(id))">
|
||||
<SelectTrigger class="w-72" 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>
|
||||
<code v-if="org" class="text-xs text-fg-subtle">{{ org.id }}</code>
|
||||
<NewOrgDialog />
|
||||
</div>
|
||||
<div v-else class="mb-4 flex flex-wrap items-baseline gap-x-3 gap-y-1">
|
||||
<p class="text-lg font-semibold tracking-[-0.01em]">{{ org?.name ?? "Org" }}</p>
|
||||
<code v-if="org" class="text-xs text-fg-subtle">{{ org.id }}</code>
|
||||
</div>
|
||||
|
||||
<nav aria-label="Org" class="mb-6 flex flex-wrap items-center gap-1 border-b border-border">
|
||||
<RouterLink
|
||||
v-for="tab in TABS"
|
||||
v-for="tab in tabs"
|
||||
:key="tab.path"
|
||||
:to="tab.path"
|
||||
:aria-current="current(tab.path) ? 'page' : undefined"
|
||||
@@ -64,7 +98,8 @@ const current = (path: string) =>
|
||||
|
||||
<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. -->
|
||||
<RouterView v-if="org" />
|
||||
<!-- 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>
|
||||
Reference in new issue
Block a user