refactor: format markdown files using prettier, fix spelling concerns, reduce Taskfile bloat
This commit is contained in:
608 files changed
+63317
-10219
No files matched your search
@@ -2,7 +2,13 @@
|
||||
import { useMediaQuery } from "@vueuse/core";
|
||||
import { computed, ref, watch } from "vue";
|
||||
|
||||
import { Card, CardContent, CardDescription, CardHeader, CardTitle } from "@/components/ui/card";
|
||||
import {
|
||||
Card,
|
||||
CardContent,
|
||||
CardDescription,
|
||||
CardHeader,
|
||||
CardTitle,
|
||||
} from "@/components/ui/card";
|
||||
import { Badge } from "@/components/ui/badge";
|
||||
import { ago } from "@/lib/format";
|
||||
import { captureSignature } from "./capture-signature";
|
||||
@@ -36,14 +42,22 @@ const pane = ref<HTMLElement | null>(null);
|
||||
// as CapturesPage, matched there in CSS and here in script.
|
||||
const stacked = useMediaQuery("(max-width: 1099px)");
|
||||
|
||||
const cap = computed(() => (stacked.value || !props.maxHeight ? undefined : `${props.maxHeight}px`));
|
||||
const cap = computed(() =>
|
||||
stacked.value || !props.maxHeight ? undefined : `${props.maxHeight}px`,
|
||||
);
|
||||
|
||||
const signature = computed(() => (selected.value ? captureSignature(selected.value) : null));
|
||||
const signature = computed(() =>
|
||||
selected.value ? captureSignature(selected.value) : null,
|
||||
);
|
||||
|
||||
const meta = computed(() => {
|
||||
const capture = selected.value;
|
||||
if (!capture) return "";
|
||||
return [ago(capture.received_at), capture.content_type || "no content type", capture.remote_addr]
|
||||
return [
|
||||
ago(capture.received_at),
|
||||
capture.content_type || "no content type",
|
||||
capture.remote_addr,
|
||||
]
|
||||
.filter(Boolean)
|
||||
.join(" · ");
|
||||
});
|
||||
@@ -60,7 +74,9 @@ watch(selected, () => {
|
||||
<CardHeader>
|
||||
<CardTitle class="flex items-center gap-2 font-mono">
|
||||
{{ selected.source || "Unknown source" }}
|
||||
<Badge v-if="signature" :variant="signature.kind">{{ signature.label }}</Badge>
|
||||
<Badge v-if="signature" :variant="signature.kind">{{
|
||||
signature.label
|
||||
}}</Badge>
|
||||
</CardTitle>
|
||||
<CardDescription>{{ meta }}</CardDescription>
|
||||
</CardHeader>
|
||||
@@ -68,7 +84,9 @@ watch(selected, () => {
|
||||
the way the task log does rather than letting one large payload
|
||||
become a ten-thousand-pixel page. Split, the page's cap is the bound
|
||||
and this one is lifted. -->
|
||||
<CardContent class="min-h-0 max-h-[62vh] overflow-y-auto min-[1100px]:max-h-none">
|
||||
<CardContent
|
||||
class="min-h-0 max-h-[62vh] overflow-y-auto min-[1100px]:max-h-none"
|
||||
>
|
||||
<div class="flex flex-col gap-5">
|
||||
<CapturePayload label="Payload" :raw="selected.body" />
|
||||
<CapturePayload label="Headers" :raw="selected.headers" />
|
||||
|
||||
@@ -15,7 +15,11 @@ const text = computed(() => prettyPrint(props.raw));
|
||||
|
||||
<template>
|
||||
<section class="min-w-0">
|
||||
<h3 class="mb-2 text-xs font-semibold tracking-[0.05em] text-fg-subtle uppercase">{{ label }}</h3>
|
||||
<h3
|
||||
class="mb-2 text-xs font-semibold tracking-[0.05em] text-fg-subtle uppercase"
|
||||
>
|
||||
{{ label }}
|
||||
</h3>
|
||||
<!--
|
||||
Wrap rather than scroll sideways: a captured payload is mostly long
|
||||
unbroken tokens (URLs, hashes, base64), and one of those on a single line
|
||||
@@ -25,7 +29,6 @@ const text = computed(() => prettyPrint(props.raw));
|
||||
<pre
|
||||
v-else
|
||||
class="rounded-sm border border-border-strong bg-muted p-3 font-mono text-xs whitespace-pre-wrap wrap-break-word"
|
||||
><HighlightedJson :text="text" /></pre
|
||||
>
|
||||
><HighlightedJson :text="text" /></pre>
|
||||
</section>
|
||||
</template>
|
||||
@@ -18,14 +18,19 @@ import { selected, type Capture } from "./state";
|
||||
*/
|
||||
const props = defineProps<{ capture: Capture }>();
|
||||
|
||||
const identity = computed(() => captureIdentity(props.capture, eventTypes.value));
|
||||
const identity = computed(() =>
|
||||
captureIdentity(props.capture, eventTypes.value),
|
||||
);
|
||||
|
||||
const signature = computed(() => captureSignature(props.capture));
|
||||
const isSelected = computed(() => selected.value?.id === props.capture.id);
|
||||
|
||||
// The name is set here because role="button" makes the cells presentational:
|
||||
// what a screen reader reads is this, not five unrelated columns.
|
||||
const label = computed(() => `Show the payload received from ${props.capture.source || "an unknown source"}`);
|
||||
const label = computed(
|
||||
() =>
|
||||
`Show the payload received from ${props.capture.source || "an unknown source"}`,
|
||||
);
|
||||
|
||||
function open(): void {
|
||||
selected.value = props.capture;
|
||||
@@ -44,8 +49,12 @@ function open(): void {
|
||||
@keydown.enter.prevent="open"
|
||||
@keydown.space.prevent="open"
|
||||
>
|
||||
<TableCell class="font-mono">{{ props.capture.source || "(unknown)" }}</TableCell>
|
||||
<TableCell :title="props.capture.received_at || ''">{{ ago(props.capture.received_at) }}</TableCell>
|
||||
<TableCell class="font-mono">{{
|
||||
props.capture.source || "(unknown)"
|
||||
}}</TableCell>
|
||||
<TableCell :title="props.capture.received_at || ''">{{
|
||||
ago(props.capture.received_at)
|
||||
}}</TableCell>
|
||||
<!-- An unidentified capture is never dispatched. -->
|
||||
<TableCell>
|
||||
<div class="flex items-center gap-1">
|
||||
@@ -55,7 +64,9 @@ function open(): void {
|
||||
<Badge :variant="signature.kind">{{ signature.label }}</Badge>
|
||||
</div>
|
||||
</TableCell>
|
||||
<TableCell class="font-mono">{{ props.capture.content_type || "—" }}</TableCell>
|
||||
<TableCell class="font-mono">{{
|
||||
props.capture.content_type || "—"
|
||||
}}</TableCell>
|
||||
<TableCell class="text-right">
|
||||
<ChevronRight class="size-4 text-fg-subtle" />
|
||||
</TableCell>
|
||||
|
||||
@@ -1,5 +1,11 @@
|
||||
<script setup lang="ts">
|
||||
import { Card, CardContent, CardDescription, CardHeader, CardTitle } from "@/components/ui/card";
|
||||
import {
|
||||
Card,
|
||||
CardContent,
|
||||
CardDescription,
|
||||
CardHeader,
|
||||
CardTitle,
|
||||
} from "@/components/ui/card";
|
||||
|
||||
import CapturesList from "./CapturesList.vue";
|
||||
|
||||
@@ -15,7 +21,10 @@ import CapturesList from "./CapturesList.vue";
|
||||
<Card>
|
||||
<CardHeader>
|
||||
<CardTitle>Recent captures</CardTitle>
|
||||
<CardDescription>Headers and payloads are redacted before they are stored.</CardDescription>
|
||||
<CardDescription
|
||||
>Headers and payloads are redacted before they are
|
||||
stored.</CardDescription
|
||||
>
|
||||
</CardHeader>
|
||||
<CardContent>
|
||||
<CapturesList />
|
||||
|
||||
@@ -2,9 +2,21 @@
|
||||
import { Inbox, TriangleAlert } from "@lucide/vue";
|
||||
|
||||
import { Alert, AlertDescription, AlertTitle } from "@/components/ui/alert";
|
||||
import { Empty, EmptyDescription, EmptyHeader, EmptyMedia, EmptyTitle } from "@/components/ui/empty";
|
||||
import {
|
||||
Empty,
|
||||
EmptyDescription,
|
||||
EmptyHeader,
|
||||
EmptyMedia,
|
||||
EmptyTitle,
|
||||
} from "@/components/ui/empty";
|
||||
import { Skeleton } from "@/components/ui/skeleton";
|
||||
import { Table, TableBody, TableHead, TableHeader, TableRow } from "@/components/ui/table";
|
||||
import {
|
||||
Table,
|
||||
TableBody,
|
||||
TableHead,
|
||||
TableHeader,
|
||||
TableRow,
|
||||
} from "@/components/ui/table";
|
||||
import CaptureRow from "./CaptureRow.vue";
|
||||
import { captures, enabled, error, loading } from "./state";
|
||||
|
||||
@@ -17,7 +29,8 @@ import { captures, enabled, error, loading } from "./state";
|
||||
// The receiver's path, held as a string rather than typed into the template:
|
||||
// its source segment is angle-bracketed, which a template parser reads as a
|
||||
// tag.
|
||||
const webhookHint = "Point a webhook at /webhooks/capture/<source> and it will show up here.";
|
||||
const webhookHint =
|
||||
"Point a webhook at /webhooks/capture/<source> and it will show up here.";
|
||||
</script>
|
||||
|
||||
<template>
|
||||
@@ -59,7 +72,11 @@ const webhookHint = "Point a webhook at /webhooks/capture/<source> and it will s
|
||||
</TableRow>
|
||||
</TableHeader>
|
||||
<TableBody>
|
||||
<CaptureRow v-for="capture in captures" :key="capture.id" :capture="capture" />
|
||||
<CaptureRow
|
||||
v-for="capture in captures"
|
||||
:key="capture.id"
|
||||
:capture="capture"
|
||||
/>
|
||||
</TableBody>
|
||||
</Table>
|
||||
</template>
|
||||
@@ -96,7 +96,9 @@ watch(selected, (capture) => {
|
||||
<div class="mb-4 flex flex-wrap items-center justify-end gap-2">
|
||||
<CaptureStatus />
|
||||
</div>
|
||||
<div class="grid min-w-0 items-start gap-4 min-[1100px]:grid-cols-[minmax(0,1fr)_minmax(0,1fr)]">
|
||||
<div
|
||||
class="grid min-w-0 items-start gap-4 min-[1100px]:grid-cols-[minmax(0,1fr)_minmax(0,1fr)]"
|
||||
>
|
||||
<div ref="listColumn" class="min-w-0">
|
||||
<CapturesCard />
|
||||
</div>
|
||||
|
||||
@@ -3,13 +3,26 @@ import { computed } from "vue";
|
||||
|
||||
import { Alert, AlertDescription } from "@/components/ui/alert";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { Dialog, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogTitle } from "@/components/ui/dialog";
|
||||
import {
|
||||
Dialog,
|
||||
DialogContent,
|
||||
DialogDescription,
|
||||
DialogFooter,
|
||||
DialogHeader,
|
||||
DialogTitle,
|
||||
} from "@/components/ui/dialog";
|
||||
import { Input } from "@/components/ui/input";
|
||||
import { Label } from "@/components/ui/label";
|
||||
import { Spinner } from "@/components/ui/spinner";
|
||||
import { Textarea } from "@/components/ui/textarea";
|
||||
import RuleEditor from "./RuleEditor.vue";
|
||||
import { closeDraft, draft, saveDraft, saveError, saving } from "./event-type-state";
|
||||
import {
|
||||
closeDraft,
|
||||
draft,
|
||||
saveDraft,
|
||||
saveError,
|
||||
saving,
|
||||
} from "./event-type-state";
|
||||
|
||||
/**
|
||||
* One event-type editing session: naming a proposed group, creating a type
|
||||
@@ -34,30 +47,55 @@ function onOpenChange(open: boolean) {
|
||||
|
||||
<template>
|
||||
<Dialog :open="draft !== null" @update:open="onOpenChange">
|
||||
<DialogContent v-if="draft" class="max-h-[85vh] overflow-y-auto sm:max-w-2xl">
|
||||
<DialogContent
|
||||
v-if="draft"
|
||||
class="max-h-[85vh] overflow-y-auto sm:max-w-2xl"
|
||||
>
|
||||
<DialogHeader>
|
||||
<DialogTitle>{{ title }}</DialogTitle>
|
||||
<DialogDescription>Events on {{ draft.source || "the source" }} that match no type are never dispatched.</DialogDescription>
|
||||
<DialogDescription
|
||||
>Events on {{ draft.source || "the source" }} that match no type are
|
||||
never dispatched.</DialogDescription
|
||||
>
|
||||
</DialogHeader>
|
||||
|
||||
<div class="flex flex-col gap-4">
|
||||
<div class="flex flex-col gap-2">
|
||||
<Label for="event-type-source">Source</Label>
|
||||
<Input id="event-type-source" v-model="draft.source" class="font-mono" :disabled="draft.mode !== 'paste'" />
|
||||
<Input
|
||||
id="event-type-source"
|
||||
v-model="draft.source"
|
||||
class="font-mono"
|
||||
:disabled="draft.mode !== 'paste'"
|
||||
/>
|
||||
</div>
|
||||
<div class="flex flex-col gap-2">
|
||||
<Label for="event-type-name">Name</Label>
|
||||
<Input id="event-type-name" v-model="draft.name" placeholder="pull_request.opened" />
|
||||
<Input
|
||||
id="event-type-name"
|
||||
v-model="draft.name"
|
||||
placeholder="pull_request.opened"
|
||||
/>
|
||||
</div>
|
||||
|
||||
<template v-if="draft.mode === 'paste'">
|
||||
<div class="flex flex-col gap-2">
|
||||
<Label for="event-type-headers">Headers</Label>
|
||||
<Textarea id="event-type-headers" v-model="draft.headersText" class="min-h-20 font-mono text-xs" placeholder="X-GitHub-Event: pull_request" />
|
||||
<Textarea
|
||||
id="event-type-headers"
|
||||
v-model="draft.headersText"
|
||||
class="min-h-20 font-mono text-xs"
|
||||
placeholder="X-GitHub-Event: pull_request"
|
||||
/>
|
||||
</div>
|
||||
<div class="flex flex-col gap-2">
|
||||
<Label for="event-type-body">Payload</Label>
|
||||
<Textarea id="event-type-body" v-model="draft.body" class="min-h-40 font-mono text-xs" placeholder="{ }" />
|
||||
<Textarea
|
||||
id="event-type-body"
|
||||
v-model="draft.body"
|
||||
class="min-h-40 font-mono text-xs"
|
||||
placeholder="{ }"
|
||||
/>
|
||||
</div>
|
||||
</template>
|
||||
<RuleEditor v-else v-model="draft.rule" />
|
||||
@@ -69,7 +107,10 @@ function onOpenChange(open: boolean) {
|
||||
|
||||
<DialogFooter>
|
||||
<Button variant="outline" @click="closeDraft">Cancel</Button>
|
||||
<Button :disabled="saving || !draft.name.trim() || !draft.source.trim()" @click="saveDraft">
|
||||
<Button
|
||||
:disabled="saving || !draft.name.trim() || !draft.source.trim()"
|
||||
@click="saveDraft"
|
||||
>
|
||||
<Spinner v-if="saving" />
|
||||
Save
|
||||
</Button>
|
||||
|
||||
@@ -1,5 +1,11 @@
|
||||
<script setup lang="ts">
|
||||
import { ClipboardPaste, Pencil, Tag, Trash2, TriangleAlert } from "@lucide/vue";
|
||||
import {
|
||||
ClipboardPaste,
|
||||
Pencil,
|
||||
Tag,
|
||||
Trash2,
|
||||
TriangleAlert,
|
||||
} from "@lucide/vue";
|
||||
|
||||
import { Alert, AlertDescription, AlertTitle } from "@/components/ui/alert";
|
||||
import {
|
||||
@@ -13,8 +19,21 @@ import {
|
||||
AlertDialogTitle,
|
||||
} from "@/components/ui/alert-dialog";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { Card, CardAction, CardContent, CardHeader, CardTitle } from "@/components/ui/card";
|
||||
import { Table, TableBody, TableCell, TableHead, TableHeader, TableRow } from "@/components/ui/table";
|
||||
import {
|
||||
Card,
|
||||
CardAction,
|
||||
CardContent,
|
||||
CardHeader,
|
||||
CardTitle,
|
||||
} from "@/components/ui/card";
|
||||
import {
|
||||
Table,
|
||||
TableBody,
|
||||
TableCell,
|
||||
TableHead,
|
||||
TableHeader,
|
||||
TableRow,
|
||||
} from "@/components/ui/table";
|
||||
import EventTypeDialog from "./EventTypeDialog.vue";
|
||||
import {
|
||||
confirmDelete,
|
||||
@@ -44,7 +63,9 @@ function fieldCount(schema: Record<string, string> | null | undefined): number {
|
||||
<CardHeader>
|
||||
<CardTitle>Event types</CardTitle>
|
||||
<CardAction>
|
||||
<Button variant="outline" size="sm" @click="pasteExample()"><ClipboardPaste /> From payload</Button>
|
||||
<Button variant="outline" size="sm" @click="pasteExample()"
|
||||
><ClipboardPaste /> From payload</Button
|
||||
>
|
||||
</CardAction>
|
||||
</CardHeader>
|
||||
<CardContent class="flex flex-col gap-6">
|
||||
@@ -61,17 +82,31 @@ function fieldCount(schema: Record<string, string> | null | undefined): number {
|
||||
<TableHead class="w-20 text-right">Events</TableHead>
|
||||
<TableHead class="w-20 text-right">Fields</TableHead>
|
||||
<TableHead>Rule</TableHead>
|
||||
<TableHead class="w-24"><span class="sr-only">Name</span></TableHead>
|
||||
<TableHead class="w-24"
|
||||
><span class="sr-only">Name</span></TableHead
|
||||
>
|
||||
</TableRow>
|
||||
</TableHeader>
|
||||
<TableBody>
|
||||
<TableRow v-for="p in proposals" :key="p.source + p.key">
|
||||
<TableCell class="font-mono">{{ p.source || "(unknown)" }}</TableCell>
|
||||
<TableCell class="font-mono">{{
|
||||
p.source || "(unknown)"
|
||||
}}</TableCell>
|
||||
<TableCell class="text-right tabular-nums">{{ p.count }}</TableCell>
|
||||
<TableCell class="text-right tabular-nums">{{ fieldCount(p.schema) }}</TableCell>
|
||||
<TableCell class="font-mono text-xs"><span class="block max-w-96 truncate" :title="ruleSummary(p.rule)">{{ ruleSummary(p.rule) }}</span></TableCell>
|
||||
<TableCell class="text-right tabular-nums">{{
|
||||
fieldCount(p.schema)
|
||||
}}</TableCell>
|
||||
<TableCell class="font-mono text-xs"
|
||||
><span
|
||||
class="block max-w-96 truncate"
|
||||
:title="ruleSummary(p.rule)"
|
||||
>{{ ruleSummary(p.rule) }}</span
|
||||
></TableCell
|
||||
>
|
||||
<TableCell class="text-right">
|
||||
<Button variant="outline" size="sm" @click="nameProposal(p)"><Tag /> Name</Button>
|
||||
<Button variant="outline" size="sm" @click="nameProposal(p)"
|
||||
><Tag /> Name</Button
|
||||
>
|
||||
</TableCell>
|
||||
</TableRow>
|
||||
</TableBody>
|
||||
@@ -83,37 +118,72 @@ function fieldCount(schema: Record<string, string> | null | undefined): number {
|
||||
<TableHead>Source</TableHead>
|
||||
<TableHead>Name</TableHead>
|
||||
<TableHead>Rule</TableHead>
|
||||
<TableHead class="w-20"><span class="sr-only">Actions</span></TableHead>
|
||||
<TableHead class="w-20"
|
||||
><span class="sr-only">Actions</span></TableHead
|
||||
>
|
||||
</TableRow>
|
||||
</TableHeader>
|
||||
<TableBody>
|
||||
<TableRow v-for="t in eventTypes" :key="t.id">
|
||||
<TableCell class="font-mono">{{ t.source }}</TableCell>
|
||||
<TableCell>{{ t.name }}</TableCell>
|
||||
<TableCell class="font-mono text-xs"><span class="block max-w-96 truncate" :title="ruleSummary(t.rule)">{{ ruleSummary(t.rule) }}</span></TableCell>
|
||||
<TableCell class="font-mono text-xs"
|
||||
><span
|
||||
class="block max-w-96 truncate"
|
||||
:title="ruleSummary(t.rule)"
|
||||
>{{ ruleSummary(t.rule) }}</span
|
||||
></TableCell
|
||||
>
|
||||
<TableCell class="text-right whitespace-nowrap">
|
||||
<Button variant="ghost" size="icon-sm" :aria-label="`Edit ${t.name}`" @click="editEventType(t)"><Pencil /></Button>
|
||||
<Button variant="ghost" size="icon-sm" :aria-label="`Delete ${t.name}`" @click="pendingDelete = t"><Trash2 /></Button>
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="icon-sm"
|
||||
:aria-label="`Edit ${t.name}`"
|
||||
@click="editEventType(t)"
|
||||
><Pencil
|
||||
/></Button>
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="icon-sm"
|
||||
:aria-label="`Delete ${t.name}`"
|
||||
@click="pendingDelete = t"
|
||||
><Trash2
|
||||
/></Button>
|
||||
</TableCell>
|
||||
</TableRow>
|
||||
</TableBody>
|
||||
</Table>
|
||||
|
||||
<p v-if="!proposals.length && !eventTypes.length" class="text-sm text-fg-muted">No event types or proposals.</p>
|
||||
<p
|
||||
v-if="!proposals.length && !eventTypes.length"
|
||||
class="text-sm text-fg-muted"
|
||||
>
|
||||
No event types or proposals.
|
||||
</p>
|
||||
</CardContent>
|
||||
</Card>
|
||||
<EventTypeDialog />
|
||||
<AlertDialog :open="pendingDelete !== null" @update:open="(open) => { if (!open) pendingDelete = null; }">
|
||||
<AlertDialog
|
||||
:open="pendingDelete !== null"
|
||||
@update:open="
|
||||
(open) => {
|
||||
if (!open) pendingDelete = null;
|
||||
}
|
||||
"
|
||||
>
|
||||
<AlertDialogContent>
|
||||
<AlertDialogHeader>
|
||||
<AlertDialogTitle>Delete this event type?</AlertDialogTitle>
|
||||
<AlertDialogDescription>
|
||||
Events matching "{{ pendingDelete?.name }}" will arrive unidentified and will not dispatch.
|
||||
Events matching "{{ pendingDelete?.name }}" will arrive unidentified
|
||||
and will not dispatch.
|
||||
</AlertDialogDescription>
|
||||
</AlertDialogHeader>
|
||||
<AlertDialogFooter>
|
||||
<AlertDialogCancel>Cancel</AlertDialogCancel>
|
||||
<AlertDialogAction variant="destructive" @click="confirmDelete">Delete</AlertDialogAction>
|
||||
<AlertDialogAction variant="destructive" @click="confirmDelete"
|
||||
>Delete</AlertDialogAction
|
||||
>
|
||||
</AlertDialogFooter>
|
||||
</AlertDialogContent>
|
||||
</AlertDialog>
|
||||
|
||||
@@ -4,7 +4,14 @@ import { Plus, X } from "@lucide/vue";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { Input } from "@/components/ui/input";
|
||||
import { Label } from "@/components/ui/label";
|
||||
import { Select, SelectContent, SelectGroup, SelectItem, SelectTrigger, SelectValue } from "@/components/ui/select";
|
||||
import {
|
||||
Select,
|
||||
SelectContent,
|
||||
SelectGroup,
|
||||
SelectItem,
|
||||
SelectTrigger,
|
||||
SelectValue,
|
||||
} from "@/components/ui/select";
|
||||
import type { PayloadCondition, Rule } from "./event-types";
|
||||
|
||||
/**
|
||||
@@ -30,24 +37,55 @@ function asOp(value: unknown): PayloadCondition["op"] {
|
||||
<div class="flex flex-col gap-4">
|
||||
<div class="flex flex-col gap-2">
|
||||
<Label>Headers</Label>
|
||||
<div v-for="(h, i) in rule.headers || []" :key="`h${i}`" class="flex items-center gap-2">
|
||||
<Input v-model="h.name" class="font-mono" aria-label="Header name" placeholder="X-GitHub-Event" />
|
||||
<div
|
||||
v-for="(h, i) in rule.headers || []"
|
||||
:key="`h${i}`"
|
||||
class="flex items-center gap-2"
|
||||
>
|
||||
<Input
|
||||
v-model="h.name"
|
||||
class="font-mono"
|
||||
aria-label="Header name"
|
||||
placeholder="X-GitHub-Event"
|
||||
/>
|
||||
<span class="text-fg-subtle">=</span>
|
||||
<Input v-model="h.value" class="font-mono" aria-label="Header value" />
|
||||
<Button variant="ghost" size="icon-sm" aria-label="Remove header condition" @click="headers().splice(i, 1)">
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="icon-sm"
|
||||
aria-label="Remove header condition"
|
||||
@click="headers().splice(i, 1)"
|
||||
>
|
||||
<X />
|
||||
</Button>
|
||||
</div>
|
||||
<Button variant="outline" size="sm" class="w-fit" @click="headers().push({ name: '', value: '' })">
|
||||
<Button
|
||||
variant="outline"
|
||||
size="sm"
|
||||
class="w-fit"
|
||||
@click="headers().push({ name: '', value: '' })"
|
||||
>
|
||||
<Plus /> Header
|
||||
</Button>
|
||||
</div>
|
||||
|
||||
<div class="flex flex-col gap-2">
|
||||
<Label>Payload</Label>
|
||||
<div v-for="(p, i) in rule.payload || []" :key="`p${i}`" class="flex items-center gap-2">
|
||||
<Input v-model="p.path" class="font-mono" aria-label="Payload path" placeholder="action" />
|
||||
<Select :model-value="p.op" @update:model-value="(value) => (p.op = asOp(value))">
|
||||
<div
|
||||
v-for="(p, i) in rule.payload || []"
|
||||
:key="`p${i}`"
|
||||
class="flex items-center gap-2"
|
||||
>
|
||||
<Input
|
||||
v-model="p.path"
|
||||
class="font-mono"
|
||||
aria-label="Payload path"
|
||||
placeholder="action"
|
||||
/>
|
||||
<Select
|
||||
:model-value="p.op"
|
||||
@update:model-value="(value) => (p.op = asOp(value))"
|
||||
>
|
||||
<SelectTrigger size="sm" class="w-28 shrink-0" aria-label="Condition">
|
||||
<SelectValue />
|
||||
</SelectTrigger>
|
||||
@@ -58,13 +96,28 @@ function asOp(value: unknown): PayloadCondition["op"] {
|
||||
</SelectGroup>
|
||||
</SelectContent>
|
||||
</Select>
|
||||
<Input v-if="p.op === 'equals'" v-model="p.value" class="font-mono" aria-label="Payload value" />
|
||||
<Input
|
||||
v-if="p.op === 'equals'"
|
||||
v-model="p.value"
|
||||
class="font-mono"
|
||||
aria-label="Payload value"
|
||||
/>
|
||||
<span v-else class="w-full" />
|
||||
<Button variant="ghost" size="icon-sm" aria-label="Remove payload condition" @click="payload().splice(i, 1)">
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="icon-sm"
|
||||
aria-label="Remove payload condition"
|
||||
@click="payload().splice(i, 1)"
|
||||
>
|
||||
<X />
|
||||
</Button>
|
||||
</div>
|
||||
<Button variant="outline" size="sm" class="w-fit" @click="payload().push({ path: '', op: 'equals', value: '' })">
|
||||
<Button
|
||||
variant="outline"
|
||||
size="sm"
|
||||
class="w-fit"
|
||||
@click="payload().push({ path: '', op: 'equals', value: '' })"
|
||||
>
|
||||
<Plus /> Payload condition
|
||||
</Button>
|
||||
</div>
|
||||
|
||||
@@ -8,7 +8,10 @@ export interface CaptureSignature {
|
||||
kind: "ok" | "warn" | "idle";
|
||||
}
|
||||
|
||||
export function captureSignature(capture: { authenticated?: boolean; unsigned?: boolean }): CaptureSignature {
|
||||
export function captureSignature(capture: {
|
||||
authenticated?: boolean;
|
||||
unsigned?: boolean;
|
||||
}): CaptureSignature {
|
||||
if (capture.unsigned) return { label: "Unsigned", kind: "warn" };
|
||||
if (capture.authenticated) return { label: "Signed", kind: "ok" };
|
||||
return { label: "Unverified", kind: "idle" };
|
||||
|
||||
@@ -2,7 +2,13 @@ import { ref } from "vue";
|
||||
|
||||
import { api } from "@/lib/api";
|
||||
import { captures } from "./state";
|
||||
import { cleanRule, parseHeaderLines, type EventType, type Proposal, type Rule } from "./event-types";
|
||||
import {
|
||||
cleanRule,
|
||||
parseHeaderLines,
|
||||
type EventType,
|
||||
type Proposal,
|
||||
type Rule,
|
||||
} from "./event-types";
|
||||
|
||||
/**
|
||||
* The inspector's event types: the named ones, and the groups of unidentified
|
||||
@@ -78,11 +84,29 @@ export function nameProposal(p: Proposal): void {
|
||||
}
|
||||
|
||||
export function pasteExample(source = ""): void {
|
||||
open({ mode: "paste", id: null, source, name: "", rule: { headers: [], payload: [] }, headersText: "", body: "", exampleHeaders: {} });
|
||||
open({
|
||||
mode: "paste",
|
||||
id: null,
|
||||
source,
|
||||
name: "",
|
||||
rule: { headers: [], payload: [] },
|
||||
headersText: "",
|
||||
body: "",
|
||||
exampleHeaders: {},
|
||||
});
|
||||
}
|
||||
|
||||
export function editEventType(t: EventType): void {
|
||||
open({ mode: "edit", id: t.id, source: t.source, name: t.name, rule: copyRule(t.rule), headersText: "", body: "", exampleHeaders: {} });
|
||||
open({
|
||||
mode: "edit",
|
||||
id: t.id,
|
||||
source: t.source,
|
||||
name: t.name,
|
||||
rule: copyRule(t.rule),
|
||||
headersText: "",
|
||||
body: "",
|
||||
exampleHeaders: {},
|
||||
});
|
||||
}
|
||||
|
||||
export function closeDraft(): void {
|
||||
@@ -95,9 +119,13 @@ export async function saveDraft(): Promise<void> {
|
||||
saving.value = true;
|
||||
try {
|
||||
if (d.mode === "edit" && d.id) {
|
||||
await api.eventTypeUpdate(d.id, { name: d.name, rule: cleanRule(d.rule) });
|
||||
await api.eventTypeUpdate(d.id, {
|
||||
name: d.name,
|
||||
rule: cleanRule(d.rule),
|
||||
});
|
||||
} else {
|
||||
const headers = d.mode === "paste" ? parseHeaderLines(d.headersText) : d.exampleHeaders;
|
||||
const headers =
|
||||
d.mode === "paste" ? parseHeaderLines(d.headersText) : d.exampleHeaders;
|
||||
await api.eventTypeCreate({
|
||||
source: d.source,
|
||||
name: d.name,
|
||||
|
||||
@@ -60,7 +60,10 @@ export function captureIdentity(
|
||||
}
|
||||
|
||||
/** eventTypeLabel names an event type by id as "source / name". */
|
||||
export function eventTypeLabel(id: string | undefined, types: EventType[]): string {
|
||||
export function eventTypeLabel(
|
||||
id: string | undefined,
|
||||
types: EventType[],
|
||||
): string {
|
||||
if (!id) return "No event type";
|
||||
const found = types.find((t) => t.id === id);
|
||||
return found ? `${found.source} / ${found.name}` : "Deleted type";
|
||||
@@ -70,7 +73,9 @@ export function eventTypeLabel(id: string | undefined, types: EventType[]): stri
|
||||
export function ruleSummary(rule: Rule): string {
|
||||
const parts = [
|
||||
...(rule.headers || []).map((h) => `${h.name} = ${h.value}`),
|
||||
...(rule.payload || []).map((p) => (p.op === "present" ? `${p.path} present` : `${p.path} = ${p.value ?? ""}`)),
|
||||
...(rule.payload || []).map((p) =>
|
||||
p.op === "present" ? `${p.path} present` : `${p.path} = ${p.value ?? ""}`,
|
||||
),
|
||||
];
|
||||
return parts.length ? parts.join(" · ") : "any event";
|
||||
}
|
||||
@@ -78,9 +83,15 @@ export function ruleSummary(rule: Rule): string {
|
||||
/** cleanRule drops the editor's blank rows, and a present condition's value. */
|
||||
export function cleanRule(rule: Rule): Rule {
|
||||
return {
|
||||
headers: (rule.headers || []).filter((h) => h.name.trim() !== "").map((h) => ({ name: h.name.trim(), value: h.value })),
|
||||
headers: (rule.headers || [])
|
||||
.filter((h) => h.name.trim() !== "")
|
||||
.map((h) => ({ name: h.name.trim(), value: h.value })),
|
||||
payload: (rule.payload || [])
|
||||
.filter((p) => p.path.trim() !== "")
|
||||
.map((p) => (p.op === "present" ? { path: p.path.trim(), op: p.op } : { path: p.path.trim(), op: p.op, value: p.value ?? "" })),
|
||||
.map((p) =>
|
||||
p.op === "present"
|
||||
? { path: p.path.trim(), op: p.op }
|
||||
: { path: p.path.trim(), op: p.op, value: p.value ?? "" },
|
||||
),
|
||||
};
|
||||
}
|
||||
Reference in new issue
Block a user