feat(eda): name and delete capture sources; an armed binding blocks the delete
This commit is contained in:
22 files changed
+1103
-592
No files matched your search
@@ -336,6 +336,10 @@ export const api = {
|
||||
request<T>(`/api/sources/${encodeURIComponent(path)}/approve-unsigned`, {
|
||||
method: "POST",
|
||||
}),
|
||||
sourceName: <T = unknown>(path: string, name: string) =>
|
||||
request<T>(`/api/sources/${encodeURIComponent(path)}/name`, { method: "PUT", body: { name } }),
|
||||
sourceDelete: (path: string) =>
|
||||
request<void>(`/api/sources/${encodeURIComponent(path)}`, { method: "DELETE", parse: false }),
|
||||
sourceSecret: <T = unknown>(path: string) =>
|
||||
request<T>(`/api/sources/${encodeURIComponent(path)}/secret`, {
|
||||
method: "POST",
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
<script setup lang="ts">
|
||||
import { Check, Copy, KeyRound, Lock, LockOpen, Plus } from "@lucide/vue";
|
||||
import { Check, Copy, KeyRound, Lock, LockOpen, Plus, Trash2 } from "@lucide/vue";
|
||||
import { onMounted, ref } from "vue";
|
||||
|
||||
import { Alert, AlertDescription, AlertTitle } from "@/components/ui/alert";
|
||||
@@ -46,6 +46,8 @@ const {
|
||||
requestUnsigned,
|
||||
requireSigning,
|
||||
approveUnsigned,
|
||||
rename,
|
||||
remove,
|
||||
refusals,
|
||||
} = useSources();
|
||||
|
||||
@@ -111,7 +113,14 @@ function url(source: Source): string {
|
||||
<TableCell
|
||||
class="max-w-0 truncate font-mono text-fg-muted"
|
||||
:title="url(source)"
|
||||
>{{ source.path }}
|
||||
><input
|
||||
class="block w-full bg-transparent font-sans text-sm text-foreground outline-none placeholder:text-fg-subtle focus:underline"
|
||||
:value="source.name ?? ''"
|
||||
placeholder="Name this source"
|
||||
:aria-label="`Name of source ${source.path}`"
|
||||
:disabled="busy"
|
||||
@change="rename(source, ($event.target as HTMLInputElement).value)"
|
||||
/>{{ source.path }}
|
||||
<div
|
||||
v-if="refusals[source.path]"
|
||||
class="text-xs font-sans text-destructive"
|
||||
@@ -185,6 +194,20 @@ function url(source: Source): string {
|
||||
<Lock data-icon="inline-start" />
|
||||
Require signing
|
||||
</Button>
|
||||
<Tooltip>
|
||||
<TooltipTrigger as-child>
|
||||
<Button
|
||||
variant="ghost"
|
||||
size="icon-sm"
|
||||
aria-label="Delete source"
|
||||
:disabled="busy"
|
||||
@click="remove(source)"
|
||||
>
|
||||
<Trash2 />
|
||||
</Button>
|
||||
</TooltipTrigger>
|
||||
<TooltipContent>Delete source</TooltipContent>
|
||||
</Tooltip>
|
||||
</div>
|
||||
</TableCell>
|
||||
</TableRow>
|
||||
|
||||
@@ -6,6 +6,8 @@
|
||||
|
||||
export interface Source {
|
||||
path: string;
|
||||
/** The operator's label; the path stays the source's identity. */
|
||||
name?: string;
|
||||
signing?: string;
|
||||
/** Present only on create and on a new secret. */
|
||||
secret?: string;
|
||||
|
||||
@@ -64,5 +64,10 @@ export function useSources() {
|
||||
run(() => api.sourceSigning<Source>(source.path, true)),
|
||||
approveUnsigned: (source: Source) =>
|
||||
run(() => api.sourceApproveUnsigned<Source>(source.path)),
|
||||
rename: (source: Source, name: string) =>
|
||||
run(() => api.sourceName<Source>(source.path, name.trim())),
|
||||
// An armed binding on the source refuses the delete; the refusal shows
|
||||
// as the panel's failure.
|
||||
remove: (source: Source) => run(() => api.sourceDelete(source.path)),
|
||||
};
|
||||
}
|
||||
@@ -39,6 +39,8 @@ const inputs = computed(() =>
|
||||
const repository = computed(() => takesRepository({ id: "", name: "", repository: String(workflowField(props.yaml, "repository") ?? "") || undefined }));
|
||||
|
||||
const sources = ref<string[]>([]);
|
||||
// The operator's label for each source path, where one is set.
|
||||
const sourceNames = ref<Record<string, string>>({});
|
||||
const captures = ref<Capture[]>([]);
|
||||
const eventTypes = ref<EventType[]>([]);
|
||||
const mappings = ref<Mapping[]>([]);
|
||||
@@ -64,13 +66,14 @@ async function loadCaptures(): Promise<void> {
|
||||
|
||||
onMounted(async () => {
|
||||
const [listed, types, mapped, bound] = await Promise.all([
|
||||
api.sources<{ sources?: { path: string }[] }>().catch(() => null),
|
||||
api.sources<{ sources?: { path: string; name?: string }[] }>().catch(() => null),
|
||||
api.eventTypes<{ event_types?: EventType[] }>().catch(() => null),
|
||||
api.mappings<{ mappings?: Mapping[] }>().catch(() => null),
|
||||
api.bindings<{ bindings?: Binding[] }>().catch(() => null),
|
||||
loadCaptures(),
|
||||
]);
|
||||
sources.value = (listed?.sources ?? []).map((s) => s.path);
|
||||
sourceNames.value = Object.fromEntries((listed?.sources ?? []).filter((s) => s.name).map((s) => [s.path, s.name!]));
|
||||
eventTypes.value = types?.event_types ?? [];
|
||||
mappings.value = mapped?.mappings ?? [];
|
||||
bindings.value = bound?.bindings ?? [];
|
||||
@@ -235,7 +238,7 @@ const resume = () => transition(api.bindingResume, "pending_approval");
|
||||
<label for="bind-source" class="text-xs font-medium text-muted-foreground">Source</label>
|
||||
<select id="bind-source" v-model="source" class="h-8 w-full rounded-md border border-input bg-background px-2 text-[13px]" :disabled="!!binding">
|
||||
<option value="" disabled>Pick a source</option>
|
||||
<option v-for="path in sources" :key="path" :value="path">{{ path }}</option>
|
||||
<option v-for="path in sources" :key="path" :value="path">{{ sourceNames[path] ? `${sourceNames[path]} (${path})` : path }}</option>
|
||||
<option :value="NEW_SOURCE">New source…</option>
|
||||
</select>
|
||||
<input
|
||||
|
||||
Reference in new issue
Block a user