Files
archie/ui/src/org/OrgWorkspacesPage.vue
T

129 lines
4.0 KiB
Vue
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<script setup lang="ts">
import PageHeader from "@/base/PageHeader.vue";
import { Section } from "@/components/ui/section";
import { storeToRefs } from "pinia";
import { onMounted, ref } from "vue";
import { Plus } from "@lucide/vue";
import { Button } from "@/components/ui/button";
import { Empty, EmptyHeader, EmptyTitle } from "@/components/ui/empty";
import { Input } from "@/components/ui/input";
import {
Table,
TableBody,
TableCell,
TableHead,
TableHeader,
TableRow,
} from "@/components/ui/table";
import { api } from "@/lib/api";
import { useOrgStore } from "@/stores/org";
import type { OrgWorkspace } from "./org";
/**
* The org's workspaces: the division policies and records are scoped to.
*/
const orgStore = useOrgStore();
const { org } = storeToRefs(orgStore);
const workspaces = ref<OrgWorkspace[]>([]);
const id = ref("");
const name = ref("");
const environment = ref("");
const error = ref("");
const loading = ref(true);
const busy = ref(false);
async function load(): Promise<void> {
if (!org.value) return;
try {
workspaces.value = (
await api.orgWorkspaces<{ workspaces: OrgWorkspace[] }>(org.value.id)
).workspaces;
error.value = "";
} catch (cause) {
error.value = String((cause as Error).message || cause);
}
}
onMounted(async () => {
try {
await orgStore.loadOrg();
await load();
} catch (cause) {
error.value = String((cause as Error).message || cause);
} finally {
loading.value = false;
}
});
async function create(): Promise<void> {
if (!org.value || !id.value.trim() || !name.value.trim()) return;
busy.value = true;
try {
await api.createOrgWorkspace(org.value.id, {
id: id.value.trim(),
name: name.value.trim(),
environment: environment.value.trim(),
});
id.value = "";
name.value = "";
environment.value = "";
error.value = "";
await load();
} catch (cause) {
error.value = String((cause as Error).message || cause);
} finally {
busy.value = false;
}
}
</script>
<template>
<div>
<PageHeader title="Workspaces" />
<p v-if="error" role="alert" class="mb-4 text-sm text-danger">{{ error }}</p>
<Section>
<Table>
<TableHeader>
<TableRow>
<TableHead class="w-56">ID</TableHead>
<TableHead class="w-full">Name</TableHead>
<TableHead class="w-44">Environment</TableHead>
</TableRow>
</TableHeader>
<TableBody>
<TableRow v-for="workspace in workspaces" :key="workspace.id">
<TableCell class="font-mono text-xs">{{ workspace.id }}</TableCell>
<TableCell class="font-medium">{{ workspace.name }}</TableCell>
<TableCell class="text-fg-subtle">{{ workspace.environment || "–" }}</TableCell>
</TableRow>
<TableRow v-if="loading">
<TableCell colspan="3" class="text-sm text-fg-muted" role="status">Loading workspaces…</TableCell>
</TableRow>
<TableRow v-else-if="!workspaces.length && !error">
<TableCell colspan="3">
<Empty class="py-6">
<EmptyHeader>
<EmptyTitle>No workspaces yet</EmptyTitle>
</EmptyHeader>
</Empty>
</TableCell>
</TableRow>
</TableBody>
</Table>
</Section>
<Section title="New workspace">
<form class="flex flex-wrap items-center gap-2" @submit.prevent="create">
<Input v-model="id" class="w-40 font-mono" placeholder="id" aria-label="Workspace id" required />
<Input v-model="name" class="w-56" placeholder="Name" aria-label="Workspace name" required />
<Input v-model="environment" class="w-40" placeholder="Environment" aria-label="Environment" />
<Button type="submit" size="sm" :disabled="!id.trim() || !name.trim() || busy">
<Plus data-icon="inline-start" /> Create</Button>
</form>
</Section>
</div>
</template>