feat(ui/controls): split the controls page into rules, guards and action classes (#2023)
This commit is contained in:
1 file changed
+39
-21
@@ -1,6 +1,6 @@
|
||||
<script setup lang="ts">
|
||||
import { onMounted, ref } from "vue";
|
||||
import { RouterLink } from "vue-router";
|
||||
import { computed, onMounted, ref } from "vue";
|
||||
import { RouterLink, useRoute, useRouter } from "vue-router";
|
||||
|
||||
import PageHeader from "@/base/PageHeader.vue";
|
||||
import { Badge } from "@/components/ui/badge";
|
||||
@@ -9,12 +9,13 @@ import { DropdownMenuItem } from "@/components/ui/dropdown-menu";
|
||||
import { Empty, EmptyHeader, EmptyTitle } from "@/components/ui/empty";
|
||||
import { MoreMenu } from "@/components/ui/more-menu";
|
||||
import { ReadError } from "@/components/ui/read-error";
|
||||
import { Section } from "@/components/ui/section";
|
||||
import { Skeleton } from "@/components/ui/skeleton";
|
||||
import { Tabs, TabsList, TabsTrigger } from "@/components/ui/tabs";
|
||||
import { Timestamp } from "@/components/ui/timestamp";
|
||||
import { errors } from "@/copy/errors";
|
||||
import { api, describeError, type ActionClass, type Judge } from "@/lib/api";
|
||||
import { useRead } from "@/lib/use-read";
|
||||
import { stateLabel } from "@/runs/state";
|
||||
import ActionClassDetail from "./ActionClassDetail.vue";
|
||||
import PolicyText from "./PolicyText.vue";
|
||||
|
||||
@@ -27,18 +28,28 @@ onMounted(() => {
|
||||
void classes.reload();
|
||||
});
|
||||
|
||||
const route = useRoute();
|
||||
const router = useRouter();
|
||||
const TABS = [
|
||||
{ id: "rules", label: "Rules" },
|
||||
{ id: "guards", label: "Guards" },
|
||||
{ id: "classes", label: "Action classes" },
|
||||
];
|
||||
const tab = computed(() => (TABS.some((t) => t.id === route.query.tab) ? String(route.query.tab) : "rules"));
|
||||
const show = (id: unknown) => void router.replace({ query: { ...route.query, tab: id === "rules" ? undefined : String(id) } });
|
||||
|
||||
const judgeColumns: DataTableColumn<Judge>[] = [
|
||||
{ id: "name", label: "Guard", fixed: true, sort: (j) => j.name },
|
||||
{ id: "mode", label: "Mode", fixed: true },
|
||||
{ id: "latest", label: "Last evaluation" },
|
||||
{ id: "name", label: "Guard", fixed: true, width: "16rem", sort: (j) => j.name },
|
||||
{ id: "mode", label: "Mode", fixed: true, width: "9rem" },
|
||||
{ id: "latest", label: "Last evaluation", width: "auto" },
|
||||
];
|
||||
const classColumns: DataTableColumn<ActionClass>[] = [
|
||||
{ id: "action", label: "Action", fixed: true, sort: (c) => `${c.connector}.${c.action}` },
|
||||
{ id: "target", label: "Target", sort: (c) => c.target_kind ?? "" },
|
||||
{ id: "level", label: "Level", fixed: true, sort: (c) => c.level },
|
||||
{ id: "count", label: "Approved in a row", sort: (c) => c.count },
|
||||
{ id: "decisions", label: "Decisions", hidden: true, sort: (c) => c.decisions },
|
||||
{ id: "last", label: "Last decided", sort: (c) => (c.last_decided_at ? Date.parse(c.last_decided_at) : 0) },
|
||||
{ id: "action", label: "Action", fixed: true, width: "auto", sort: (c) => `${c.connector}.${c.action}` },
|
||||
{ id: "target", label: "Target", width: "14rem", sort: (c) => c.target_kind ?? "" },
|
||||
{ id: "level", label: "Level", fixed: true, width: "16rem", sort: (c) => c.level },
|
||||
{ id: "count", label: "Approved in a row", width: "11rem", sort: (c) => c.count },
|
||||
{ id: "decisions", label: "Decisions", hidden: true, width: "7rem", sort: (c) => c.decisions },
|
||||
{ id: "last", label: "Last decided", width: "9rem", sort: (c) => (c.last_decided_at ? Date.parse(c.last_decided_at) : 0) },
|
||||
];
|
||||
|
||||
const resetError = ref("");
|
||||
@@ -56,9 +67,16 @@ async function reset(c: ActionClass): Promise<void> {
|
||||
<template>
|
||||
<div>
|
||||
<PageHeader title="Controls" />
|
||||
<PolicyText kind="hard-rules" title="Hard rules" />
|
||||
<PolicyText kind="change-request" title="Change-request rules" />
|
||||
<Section title="Guards">
|
||||
<Tabs :model-value="tab" class="mb-4" @update:model-value="show">
|
||||
<TabsList variant="line" class="w-full justify-start">
|
||||
<TabsTrigger v-for="t in TABS" :key="t.id" :value="t.id" class="flex-none px-3">{{ t.label }}</TabsTrigger>
|
||||
</TabsList>
|
||||
</Tabs>
|
||||
<template v-if="tab === 'rules'">
|
||||
<PolicyText kind="hard-rules" title="Hard rules" />
|
||||
<PolicyText kind="change-request" title="Change-request rules" />
|
||||
</template>
|
||||
<div v-else-if="tab === 'guards'">
|
||||
<ReadError v-if="judges.error.value" :message="judges.error.value" retry-label="Retry" @retry="judges.reload" />
|
||||
<Skeleton v-else-if="!judges.data.value" class="h-16 w-full" />
|
||||
<DataTable v-else :columns="judgeColumns" :rows="judges.data.value" :row-key="(j) => j.name" storage-key="judges">
|
||||
@@ -75,8 +93,8 @@ async function reset(c: ActionClass): Promise<void> {
|
||||
<template #empty><Empty><EmptyHeader><EmptyTitle>No guards</EmptyTitle></EmptyHeader></Empty></template>
|
||||
</DataTable>
|
||||
<p class="mt-2 text-caption text-fg-muted"><RouterLink class="underline" :to="{ path: '/settings/extensions', query: { kind: 'guards' } }">Manage guards</RouterLink></p>
|
||||
</Section>
|
||||
<Section title="Action classes">
|
||||
</div>
|
||||
<div v-else>
|
||||
<p v-if="resetError" role="alert" class="mb-2 text-caption text-danger">{{ resetError }}</p>
|
||||
<ReadError v-if="classes.error.value" :message="classes.error.value" retry-label="Retry" @retry="classes.reload" />
|
||||
<Skeleton v-else-if="!classes.data.value" class="h-16 w-full" />
|
||||
@@ -84,8 +102,8 @@ async function reset(c: ActionClass): Promise<void> {
|
||||
<template #cell-action="{ row }"><span class="font-mono text-caption">{{ row.connector }}.{{ row.action }}</span></template>
|
||||
<template #cell-target="{ row }">{{ row.target_kind }}<span v-if="row.environment" class="text-caption text-fg-muted"> · {{ row.environment }}</span></template>
|
||||
<template #cell-level="{ row }">
|
||||
<Badge variant="outline" :title="row.tightened_because || undefined">{{ row.level }}</Badge>
|
||||
<span v-if="row.level !== row.default" class="text-caption text-fg-muted"> from {{ row.default }}</span>
|
||||
<Badge variant="outline" :title="row.tightened_because || undefined">{{ stateLabel(row.level) }}</Badge>
|
||||
<span v-if="row.level !== row.default" class="text-caption text-fg-muted"> from {{ stateLabel(row.default) }}</span>
|
||||
</template>
|
||||
<template #cell-count="{ row }">{{ row.count }}</template>
|
||||
<template #cell-decisions="{ row }">{{ row.decisions }}</template>
|
||||
@@ -93,11 +111,11 @@ async function reset(c: ActionClass): Promise<void> {
|
||||
<template #detail="{ row }"><ActionClassDetail :id="row.id" /></template>
|
||||
<template #actions="{ row }">
|
||||
<MoreMenu :label="`${row.connector}.${row.action} actions`">
|
||||
<DropdownMenuItem :disabled="row.level === row.default" @select="reset(row)">Reset to {{ row.default }}</DropdownMenuItem>
|
||||
<DropdownMenuItem :disabled="row.level === row.default" @select="reset(row)">Reset to {{ stateLabel(row.default) }}</DropdownMenuItem>
|
||||
</MoreMenu>
|
||||
</template>
|
||||
<template #empty><Empty><EmptyHeader><EmptyTitle>No action classes</EmptyTitle></EmptyHeader></Empty></template>
|
||||
</DataTable>
|
||||
</Section>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
Reference in new issue
Block a user