feat(etcd): multi-select tree keys for batch export and safe delete
This commit is contained in:
11 files changed
+497
-36
No files matched your search
@@ -1,13 +1,14 @@
|
||||
<script setup lang="ts">
|
||||
import { computed, nextTick, onBeforeUnmount, ref, watch } from "vue";
|
||||
import { Activity, AlertTriangle, ArrowRightLeft, ChevronDown, ChevronLeft, ChevronRight, Download, Eraser, KeyRound, Loader2, Search, Upload, Wrench } from "@lucide/vue";
|
||||
import { Activity, AlertTriangle, ArrowRightLeft, ChevronDown, ChevronLeft, ChevronRight, Download, Eraser, KeyRound, Loader2, Search, Trash2, Upload, Wrench } from "@lucide/vue";
|
||||
import { useI18n } from "vue-i18n";
|
||||
import KvKeyBrowser from "@/components/kv/KvKeyBrowser.vue";
|
||||
import EtcdAdminConsole from "@/components/etcd/EtcdAdminConsole.vue";
|
||||
import { Badge } from "@/components/ui/badge";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { Dialog, DialogContent, DialogFooter, DialogHeader, DialogTitle } from "@/components/ui/dialog";
|
||||
import { DropdownMenu, DropdownMenuContent, DropdownMenuItem, DropdownMenuTrigger } from "@/components/ui/dropdown-menu";
|
||||
import DangerConfirmDialog from "@/components/editor/DangerConfirmDialog.vue";
|
||||
import { DropdownMenu, DropdownMenuContent, DropdownMenuItem, DropdownMenuSeparator, DropdownMenuTrigger } from "@/components/ui/dropdown-menu";
|
||||
import { Input } from "@/components/ui/input";
|
||||
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "@/components/ui/select";
|
||||
import { useToast } from "@/composables/useToast";
|
||||
@@ -64,6 +65,13 @@ interface EtcdWatchPreset {
|
||||
scope: "key" | "prefix";
|
||||
}
|
||||
|
||||
interface EtcdMultiSelection {
|
||||
key: string;
|
||||
keyIdentity?: string | null;
|
||||
keyBytes?: api.KvValue | null;
|
||||
modRevision?: api.KvInt64 | null;
|
||||
}
|
||||
|
||||
interface TransferRow {
|
||||
id: string;
|
||||
displayKey: string;
|
||||
@@ -110,6 +118,9 @@ const watchKeySuggestions = computed(() => {
|
||||
return [...keyBytesByDisplay.entries()].flatMap(([key, values]) => [...values.values()].map((keyBytes) => ({ key, keyBytes })));
|
||||
});
|
||||
const fileInput = ref<HTMLInputElement>();
|
||||
const selectedTreeKeys = ref<EtcdMultiSelection[]>([]);
|
||||
const batchDeleteOpen = ref(false);
|
||||
const batchDeleting = ref(false);
|
||||
|
||||
const searchQuery = ref("");
|
||||
const searchPrefix = ref("");
|
||||
@@ -313,6 +324,8 @@ const labels = computed(() => ({
|
||||
leasePickerHint: t("etcd.leasePickerHint"),
|
||||
noLeasePickerHint: t("etcd.noLeasePickerHint"),
|
||||
registryWarning: t("etcd.registryWarning"),
|
||||
selectAll: t("etcd.selectAllLoaded"),
|
||||
deselectAll: t("etcd.deselectAll"),
|
||||
valueContent: t("etcd.valueContent"),
|
||||
savePreview: t("etcd.savePreview"),
|
||||
keyAlreadyExists: t("etcd.keyAlreadyExists"),
|
||||
@@ -479,6 +492,66 @@ function bundleFromSummaries(entries: api.KvKeySummary[], prefix: string, revisi
|
||||
};
|
||||
}
|
||||
|
||||
function updateTreeSelection(selection: EtcdMultiSelection[]) {
|
||||
selectedTreeKeys.value = selection;
|
||||
}
|
||||
|
||||
async function exportTreeSelection(format: EtcdExportFormat) {
|
||||
const selected = [...selectedTreeKeys.value];
|
||||
if (!selected.length) return;
|
||||
try {
|
||||
const entries = await mapWithConcurrency(selected, TARGET_LOOKUP_CONCURRENCY, async (item) => {
|
||||
const result = await api.etcdGet(props.connectionId, item.key, { keyBytes: item.keyBytes ?? undefined });
|
||||
if (!result.found || !result.value) throw new Error(t("etcd.notFound"));
|
||||
return {
|
||||
key: result.key || item.key,
|
||||
keyBytes: result.keyBytes ?? item.keyBytes ?? { encoding: "utf8", data: item.key },
|
||||
value: result.value,
|
||||
...result.metadata,
|
||||
};
|
||||
});
|
||||
const file = buildEtcdExportFile(entries, "", null, "selection", `dbx-etcd-selection-${Date.now()}`, format);
|
||||
const exported = await downloadExport(file);
|
||||
if (exported) toast(t("etcd.exported", { count: entries.length }), 2500);
|
||||
} catch (error) {
|
||||
toast(error instanceof Error ? error.message : String(error), 4000);
|
||||
}
|
||||
}
|
||||
|
||||
function selectedTreeKeyDetails(): string {
|
||||
return selectedTreeKeys.value.map((item) => item.key).join("\n");
|
||||
}
|
||||
|
||||
async function deleteSelectedTreeKeys() {
|
||||
const selected = [...selectedTreeKeys.value];
|
||||
if (!selected.length || readOnly.value) return;
|
||||
batchDeleting.value = true;
|
||||
const completed: EtcdMultiSelection[] = [];
|
||||
let deleted = 0;
|
||||
let failed = false;
|
||||
try {
|
||||
for (const item of selected) {
|
||||
const result = await api.etcdDelete(props.connectionId, item.key, {
|
||||
keyBytes: item.keyBytes ?? undefined,
|
||||
expectedModRevision: item.modRevision ?? undefined,
|
||||
});
|
||||
deleted += result.deleted;
|
||||
completed.push(item);
|
||||
}
|
||||
toast(t("etcd.batchDeleteSuccess", { count: deleted }), 3000);
|
||||
} catch (error) {
|
||||
failed = true;
|
||||
const message = error instanceof Error ? error.message : String(error);
|
||||
toast(t("etcd.batchDeletePartial", { count: deleted, error: message }), 5000);
|
||||
} finally {
|
||||
if (failed) browserRef.value?.clearMultiSelection();
|
||||
else browserRef.value?.removeMultiSelection(completed);
|
||||
batchDeleteOpen.value = false;
|
||||
batchDeleting.value = false;
|
||||
if (completed.length || failed) browserRef.value?.refresh();
|
||||
}
|
||||
}
|
||||
|
||||
function csvCell(value: string): string {
|
||||
return /[",\r\n]/.test(value) ? `"${value.replaceAll('"', '""')}"` : value;
|
||||
}
|
||||
@@ -970,12 +1043,19 @@ defineExpose({ focusSearch, refresh });
|
||||
<DropdownMenuTrigger as-child>
|
||||
<Button size="sm" variant="outline" class="h-8 gap-1.5"><Download class="h-3.5 w-3.5" /> {{ t("etcd.export") }} <ChevronDown class="h-3.5 w-3.5" /></Button>
|
||||
</DropdownMenuTrigger>
|
||||
<DropdownMenuContent align="end" class="w-40">
|
||||
<DropdownMenuItem @select="void exportAll('json')">JSON(可导入)</DropdownMenuItem>
|
||||
<DropdownMenuItem @select="void exportAll('csv')">表格(CSV)</DropdownMenuItem>
|
||||
<DropdownMenuItem @select="void exportAll('markdown')">Markdown</DropdownMenuItem>
|
||||
<DropdownMenuContent align="end" class="w-auto whitespace-nowrap">
|
||||
<DropdownMenuItem @select="void exportAll('json')">{{ t("etcd.exportAllJson") }}</DropdownMenuItem>
|
||||
<DropdownMenuItem @select="void exportAll('csv')">{{ t("etcd.exportAllCsv") }}</DropdownMenuItem>
|
||||
<DropdownMenuItem @select="void exportAll('markdown')">{{ t("etcd.exportAllMarkdown") }}</DropdownMenuItem>
|
||||
<template v-if="selectedTreeKeys.length">
|
||||
<DropdownMenuSeparator />
|
||||
<DropdownMenuItem @select="void exportTreeSelection('json')">{{ t("etcd.exportSelectionJson") }}</DropdownMenuItem>
|
||||
<DropdownMenuItem @select="void exportTreeSelection('csv')">{{ t("etcd.exportSelectionCsv") }}</DropdownMenuItem>
|
||||
<DropdownMenuItem @select="void exportTreeSelection('markdown')">{{ t("etcd.exportSelectionMarkdown") }}</DropdownMenuItem>
|
||||
</template>
|
||||
</DropdownMenuContent>
|
||||
</DropdownMenu>
|
||||
<Button size="sm" variant="destructive" class="h-8 gap-1.5" :disabled="readOnly || selectedTreeKeys.length === 0 || batchDeleting" @click="batchDeleteOpen = true"><Trash2 class="h-3.5 w-3.5" />{{ t("etcd.delete") }}</Button>
|
||||
<Button size="sm" variant="outline" class="h-8 gap-1.5" :disabled="readOnly" @click="fileInput?.click()"><Upload class="h-3.5 w-3.5" /> {{ t("etcd.import") }}</Button>
|
||||
<Button size="sm" variant="outline" class="h-8 gap-1.5" :disabled="etcdConnections.length < 2" @click="openSync"><ArrowRightLeft class="h-3.5 w-3.5" /> {{ t("etcd.sync") }}</Button>
|
||||
<input ref="fileInput" type="file" accept="application/json,.json" class="hidden" @change="onImportFile" />
|
||||
@@ -995,10 +1075,12 @@ defineExpose({ focusSearch, refresh });
|
||||
:safe-write="true"
|
||||
:allow-binary-edit="true"
|
||||
:read-only="readOnly"
|
||||
:enable-multi-select="true"
|
||||
:on-watch-key="openWatchForKey"
|
||||
:lease-options="leaseOptions"
|
||||
:on-lease-options-requested="refreshLeaseOptions"
|
||||
@refresh-requested="refreshTtlCapability"
|
||||
@selection-change="updateTreeSelection"
|
||||
/>
|
||||
|
||||
<div v-if="mode === 'search'" class="flex min-h-0 flex-1 flex-col">
|
||||
@@ -1253,5 +1335,15 @@ defineExpose({ focusSearch, refresh });
|
||||
</DialogFooter>
|
||||
</DialogContent>
|
||||
</Dialog>
|
||||
<DangerConfirmDialog
|
||||
v-model:open="batchDeleteOpen"
|
||||
:title="t('etcd.batchDeleteTitle')"
|
||||
:message="t('etcd.batchDeleteConfirm', { count: selectedTreeKeys.length })"
|
||||
:details="selectedTreeKeyDetails()"
|
||||
:confirm-label="t('etcd.batchDelete')"
|
||||
:loading="batchDeleting"
|
||||
:close-on-confirm="false"
|
||||
@confirm="deleteSelectedTreeKeys"
|
||||
/>
|
||||
</div>
|
||||
</template>
|
||||
+150
-11
@@ -47,7 +47,7 @@ vi.mock("@/components/kv/KvKeyBrowser.vue", () => ({
|
||||
supportsTtl: { type: Boolean, default: false },
|
||||
ttlCapabilityKnown: { type: Boolean, default: true },
|
||||
},
|
||||
emits: ["refreshRequested"],
|
||||
emits: ["refreshRequested", "selectionChange"],
|
||||
setup(props, { emit, expose }) {
|
||||
backend.capturedKvBrowserApi = props.api;
|
||||
expose({
|
||||
@@ -60,18 +60,88 @@ vi.mock("@/components/kv/KvKeyBrowser.vue", () => ({
|
||||
emit("refreshRequested");
|
||||
return true;
|
||||
},
|
||||
selectAllMultiSelection: () => undefined,
|
||||
clearMultiSelection: () => emit("selectionChange", []),
|
||||
removeMultiSelection: (selection: unknown[]) => {
|
||||
if (selection.length) emit("selectionChange", []);
|
||||
},
|
||||
});
|
||||
return () =>
|
||||
h(
|
||||
"button",
|
||||
{
|
||||
id: "kv-browser-stub",
|
||||
"data-supports-ttl": String(props.supportsTtl),
|
||||
"data-capability-known": String(props.ttlCapabilityKnown),
|
||||
onClick: () => emit("refreshRequested"),
|
||||
},
|
||||
"refresh",
|
||||
);
|
||||
h("div", [
|
||||
h(
|
||||
"button",
|
||||
{
|
||||
id: "kv-browser-stub",
|
||||
"data-supports-ttl": String(props.supportsTtl),
|
||||
"data-capability-known": String(props.ttlCapabilityKnown),
|
||||
onClick: () => emit("refreshRequested"),
|
||||
},
|
||||
"refresh",
|
||||
),
|
||||
h(
|
||||
"button",
|
||||
{
|
||||
id: "emit-tree-selection",
|
||||
onClick: () =>
|
||||
emit("selectionChange", [
|
||||
{
|
||||
key: "[base64:/w==]",
|
||||
keyIdentity: "ff",
|
||||
keyBytes: { encoding: "base64", data: "/w==" },
|
||||
modRevision: "7",
|
||||
},
|
||||
]),
|
||||
},
|
||||
"select",
|
||||
),
|
||||
]);
|
||||
},
|
||||
}),
|
||||
}));
|
||||
|
||||
vi.mock("@/components/editor/DangerConfirmDialog.vue", () => ({
|
||||
default: defineComponent({
|
||||
name: "DangerConfirmDialogStub",
|
||||
props: {
|
||||
open: { type: Boolean, default: false },
|
||||
},
|
||||
emits: ["confirm", "update:open"],
|
||||
setup(props, { emit }) {
|
||||
return () => (props.open ? h("button", { id: "confirm-batch-delete", onClick: () => emit("confirm") }, "confirm") : null);
|
||||
},
|
||||
}),
|
||||
}));
|
||||
|
||||
vi.mock("@/components/ui/dropdown-menu", () => ({
|
||||
DropdownMenu: defineComponent({
|
||||
name: "DropdownMenuStub",
|
||||
setup(_, { slots }) {
|
||||
return () => h("div", slots.default?.());
|
||||
},
|
||||
}),
|
||||
DropdownMenuTrigger: defineComponent({
|
||||
name: "DropdownMenuTriggerStub",
|
||||
setup(_, { slots }) {
|
||||
return () => h("div", slots.default?.());
|
||||
},
|
||||
}),
|
||||
DropdownMenuContent: defineComponent({
|
||||
name: "DropdownMenuContentStub",
|
||||
setup(_, { slots }) {
|
||||
return () => h("div", slots.default?.());
|
||||
},
|
||||
}),
|
||||
DropdownMenuItem: defineComponent({
|
||||
name: "DropdownMenuItemStub",
|
||||
emits: ["select"],
|
||||
setup(_, { emit, slots }) {
|
||||
return () => h("button", { type: "button", onClick: () => emit("select") }, slots.default?.());
|
||||
},
|
||||
}),
|
||||
DropdownMenuSeparator: defineComponent({
|
||||
name: "DropdownMenuSeparatorStub",
|
||||
setup() {
|
||||
return () => h("hr");
|
||||
},
|
||||
}),
|
||||
}));
|
||||
@@ -318,3 +388,72 @@ describe("EtcdKeyBrowser byte-identity routing", () => {
|
||||
root.remove();
|
||||
});
|
||||
});
|
||||
|
||||
describe("EtcdKeyBrowser tree batch operations", () => {
|
||||
it("requires confirmation before deleting selected keys with their raw bytes and selection-time revision", async () => {
|
||||
backend.etcdDelete.mockResolvedValue({ deleted: 1 });
|
||||
|
||||
await mountBrowser();
|
||||
root!.querySelector<HTMLButtonElement>("#emit-tree-selection")!.click();
|
||||
await flushUi();
|
||||
|
||||
const batchDelete = [...root!.querySelectorAll("button")].find((button) => button.textContent?.includes("etcd.delete"));
|
||||
expect(root!.querySelector("#confirm-batch-delete")).toBeNull();
|
||||
expect(backend.etcdDelete).not.toHaveBeenCalled();
|
||||
|
||||
batchDelete!.click();
|
||||
await flushUi();
|
||||
expect(root!.querySelector("#confirm-batch-delete")).toBeTruthy();
|
||||
expect(backend.etcdDelete).not.toHaveBeenCalled();
|
||||
|
||||
root!.querySelector<HTMLButtonElement>("#confirm-batch-delete")!.click();
|
||||
await flushUi();
|
||||
|
||||
expect(backend.etcdDelete).toHaveBeenCalledWith("etcd-1", "[base64:/w==]", {
|
||||
keyBytes: { encoding: "base64", data: "/w==" },
|
||||
expectedModRevision: "7",
|
||||
});
|
||||
});
|
||||
|
||||
it("shows selected exports only after selecting keys and exports with raw key bytes", async () => {
|
||||
backend.etcdGet.mockResolvedValue({
|
||||
found: true,
|
||||
key: "[base64:/w==]",
|
||||
keyBytes: { encoding: "base64", data: "/w==" },
|
||||
value: { encoding: "utf8", data: "value" },
|
||||
metadata: { modRevision: "7" },
|
||||
});
|
||||
|
||||
await mountBrowser();
|
||||
const selectedExports = () => [...root!.querySelectorAll("button")].filter((button) => button.textContent?.includes("etcd.exportSelection"));
|
||||
expect(selectedExports()).toHaveLength(0);
|
||||
|
||||
root!.querySelector<HTMLButtonElement>("#emit-tree-selection")!.click();
|
||||
await flushUi();
|
||||
|
||||
expect(selectedExports()).toHaveLength(3);
|
||||
selectedExports()[0]!.click();
|
||||
await flushUi();
|
||||
|
||||
expect(backend.etcdGet).toHaveBeenCalledWith("etcd-1", "[base64:/w==]", {
|
||||
keyBytes: { encoding: "base64", data: "/w==" },
|
||||
});
|
||||
});
|
||||
|
||||
it("clears the stale selection and refreshes after a batch delete fails", async () => {
|
||||
backend.etcdDelete.mockRejectedValue(new Error("ETCD_CAS_CONFLICT"));
|
||||
|
||||
await mountBrowser();
|
||||
root!.querySelector<HTMLButtonElement>("#emit-tree-selection")!.click();
|
||||
await flushUi();
|
||||
|
||||
const batchDelete = [...root!.querySelectorAll("button")].find((button) => button.textContent?.includes("etcd.delete"));
|
||||
batchDelete!.click();
|
||||
await flushUi();
|
||||
root!.querySelector<HTMLButtonElement>("#confirm-batch-delete")!.click();
|
||||
await flushUi();
|
||||
|
||||
const selectedExports = [...root!.querySelectorAll("button")].filter((button) => button.textContent?.includes("etcd.exportSelection"));
|
||||
expect(selectedExports).toHaveLength(0);
|
||||
});
|
||||
});
|
||||
@@ -4,7 +4,7 @@ import { useI18n } from "vue-i18n";
|
||||
import { Pane, Splitpanes } from "splitpanes";
|
||||
import "splitpanes/dist/splitpanes.css";
|
||||
import { useConnectionStore } from "@/stores/connectionStore";
|
||||
import { Activity, ChevronDown, ChevronRight, Clock3, Copy, Download, FolderClosed, FolderOpen, KeyRound, Loader2, Pencil, Plus, RefreshCw, Search, Trash2 } from "@lucide/vue";
|
||||
import { Activity, Check, ChevronDown, ChevronRight, Clock3, Copy, Download, FolderClosed, FolderOpen, KeyRound, Loader2, Pencil, Plus, RefreshCw, Search, Trash2 } from "@lucide/vue";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { Input } from "@/components/ui/input";
|
||||
import { Badge } from "@/components/ui/badge";
|
||||
@@ -102,6 +102,8 @@ interface KvKeyBrowserLabels {
|
||||
leasePickerHint?: string;
|
||||
noLeasePickerHint?: string;
|
||||
registryWarning?: string;
|
||||
selectAll?: string;
|
||||
deselectAll?: string;
|
||||
}
|
||||
|
||||
interface KvCreateModeOption {
|
||||
@@ -126,6 +128,10 @@ interface KvKeyRoute {
|
||||
keyBytes?: KvValue | null;
|
||||
}
|
||||
|
||||
interface KvMultiSelection extends KvKeyRoute {
|
||||
modRevision?: KvInt64 | null;
|
||||
}
|
||||
|
||||
type BrowserTreeNode = KvKeyTreeNode | LazyKvKeyTreeNode;
|
||||
type BrowserTreeRow = { type: "node"; node: BrowserTreeNode; depth: number } | LazyKvKeyTreeRow;
|
||||
type KvExpiryMode = "permanent" | "ttl" | "lease";
|
||||
@@ -160,6 +166,7 @@ const props = withDefaults(
|
||||
safeWrite?: boolean;
|
||||
allowBinaryEdit?: boolean;
|
||||
readOnly?: boolean;
|
||||
enableMultiSelect?: boolean;
|
||||
onWatchKey?: (route: KvKeyRoute) => void;
|
||||
leaseOptions?: Array<{ id: KvInt64; ttl: number; grantedTtl?: number }>;
|
||||
onLeaseOptionsRequested?: () => void;
|
||||
@@ -176,10 +183,15 @@ const props = withDefaults(
|
||||
safeWrite: false,
|
||||
allowBinaryEdit: false,
|
||||
readOnly: false,
|
||||
enableMultiSelect: false,
|
||||
leaseOptions: () => [],
|
||||
},
|
||||
);
|
||||
|
||||
const emit = defineEmits<{
|
||||
selectionChange: [selection: KvMultiSelection[]];
|
||||
}>();
|
||||
|
||||
const { t } = useI18n();
|
||||
const { toast } = useToast();
|
||||
const connectionStore = useConnectionStore();
|
||||
@@ -228,6 +240,7 @@ const showHistoryDiff = ref(false);
|
||||
const restoring = ref(false);
|
||||
const selectedCreateMode = ref<KvCreateMode>("persistent");
|
||||
const selectedPrettyValue = ref<string | null>(null);
|
||||
const multiSelectedKeys = ref<Map<string, KvMultiSelection>>(new Map());
|
||||
const lazyTreeState = reactive(createLazyKvKeyTreeState());
|
||||
const pageSize = 200;
|
||||
const metadataRefreshIntervalMs = 1000;
|
||||
@@ -257,6 +270,13 @@ function routeIdentity(route: KvKeyRoute): string {
|
||||
return route.keyIdentity ?? route.key;
|
||||
}
|
||||
|
||||
function multiSelectionFromSummary(summary: KvKeySummary): KvMultiSelection {
|
||||
return {
|
||||
...routeFromSummary(summary),
|
||||
modRevision: summary.modRevision == null ? null : String(summary.modRevision),
|
||||
};
|
||||
}
|
||||
|
||||
function routeFromKey(input: string | KvKeyRoute): KvKeyRoute {
|
||||
return typeof input === "string" ? { key: input } : input;
|
||||
}
|
||||
@@ -368,6 +388,7 @@ function closeKeySuggestions() {
|
||||
|
||||
function onPrefixInput(event: Event) {
|
||||
const value = (event.target as HTMLInputElement).value;
|
||||
clearMultiSelection();
|
||||
keySuggestionOpen.value = Boolean(value.trim());
|
||||
keySuggestionIndex.value = -1;
|
||||
}
|
||||
@@ -381,6 +402,7 @@ function moveKeySuggestion(delta: number) {
|
||||
function acceptKeySuggestion(index: number) {
|
||||
const suggestion = keySuggestions.value[index];
|
||||
if (!suggestion) return;
|
||||
clearMultiSelection();
|
||||
prefix.value = suggestion.key;
|
||||
closeKeySuggestions();
|
||||
void loadKeys(true);
|
||||
@@ -809,6 +831,61 @@ function onRowClick(node: BrowserTreeNode) {
|
||||
}
|
||||
}
|
||||
|
||||
function collectNodeMultiSelection(node: BrowserTreeNode): KvMultiSelection[] {
|
||||
if (node.kind === "lazy") return [{ key: node.key }];
|
||||
|
||||
const selected: KvMultiSelection[] = [];
|
||||
const collect = (candidate: KvKeyTreeNode) => {
|
||||
if (candidate.kind === "leaf" || candidate.key) {
|
||||
selected.push({
|
||||
key: kvKeyTreeNodePath(candidate),
|
||||
keyIdentity: candidate.keyIdentity,
|
||||
keyBytes: candidate.keyBytes,
|
||||
modRevision: candidate.modRevision == null ? null : String(candidate.modRevision),
|
||||
});
|
||||
}
|
||||
if (candidate.kind === "group") candidate.children.forEach(collect);
|
||||
};
|
||||
collect(node);
|
||||
return selected;
|
||||
}
|
||||
|
||||
function emitMultiSelection(next: Map<string, KvMultiSelection>) {
|
||||
multiSelectedKeys.value = next;
|
||||
emit("selectionChange", [...next.values()]);
|
||||
}
|
||||
|
||||
function setNodeMultiSelection(node: BrowserTreeNode, selected: boolean) {
|
||||
const next = new Map(multiSelectedKeys.value);
|
||||
for (const route of collectNodeMultiSelection(node)) {
|
||||
const identity = routeIdentity(route);
|
||||
if (selected) next.set(identity, route);
|
||||
else next.delete(identity);
|
||||
}
|
||||
emitMultiSelection(next);
|
||||
}
|
||||
|
||||
function nodeMultiSelectionState(node: BrowserTreeNode): { selected: boolean; indeterminate: boolean } {
|
||||
const candidates = collectNodeMultiSelection(node);
|
||||
if (!candidates.length) return { selected: false, indeterminate: false };
|
||||
const selectedCount = candidates.filter((route) => multiSelectedKeys.value.has(routeIdentity(route))).length;
|
||||
return { selected: selectedCount === candidates.length, indeterminate: selectedCount > 0 && selectedCount < candidates.length };
|
||||
}
|
||||
|
||||
function selectAllMultiSelection() {
|
||||
emitMultiSelection(new Map(keys.value.map((key) => [summaryIdentity(key), multiSelectionFromSummary(key)])));
|
||||
}
|
||||
|
||||
function clearMultiSelection() {
|
||||
if (multiSelectedKeys.value.size) emitMultiSelection(new Map());
|
||||
}
|
||||
|
||||
function removeMultiSelection(selection: KvMultiSelection[]) {
|
||||
const next = new Map(multiSelectedKeys.value);
|
||||
selection.forEach((route) => next.delete(routeIdentity(route)));
|
||||
emitMultiSelection(next);
|
||||
}
|
||||
|
||||
function onRowDoubleClick(node: BrowserTreeNode) {
|
||||
if (!nodeIsExpandable(node)) {
|
||||
void loadSelectedKey(routeFromNode(node)).then(() => openEditDialog());
|
||||
@@ -1329,6 +1406,7 @@ watch(
|
||||
async () => {
|
||||
stopKeyListRefresh();
|
||||
clearSelectedKey();
|
||||
clearMultiSelection();
|
||||
try {
|
||||
await connectionStore.ensureConnected(props.connectionId);
|
||||
} catch {
|
||||
@@ -1386,6 +1464,7 @@ onMounted(() => {
|
||||
|
||||
onBeforeUnmount(() => {
|
||||
clearSelectedKey();
|
||||
clearMultiSelection();
|
||||
stopKeyListRefresh();
|
||||
});
|
||||
defineExpose({
|
||||
@@ -1394,6 +1473,10 @@ defineExpose({
|
||||
selectKey: selectKeyFromNavigation,
|
||||
openCreate: (parentPath?: string) => openCreateDialog(parentPath),
|
||||
selection: () => ({ key: selectedKey.value, value: selectedValue.value }),
|
||||
multiSelection: () => [...multiSelectedKeys.value.values()],
|
||||
selectAllMultiSelection,
|
||||
clearMultiSelection,
|
||||
removeMultiSelection,
|
||||
});
|
||||
</script>
|
||||
|
||||
@@ -1435,6 +1518,10 @@ defineExpose({
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
<div v-if="enableMultiSelect && multiSelectedKeys.size" class="flex shrink-0 items-center gap-1.5">
|
||||
<Button size="sm" variant="outline" class="h-7 px-2 text-xs" @click="selectAllMultiSelection()">{{ labels.selectAll || "Select all" }}</Button>
|
||||
<Button size="sm" variant="outline" class="h-7 px-2 text-xs" @click="clearMultiSelection()">{{ labels.deselectAll || "Clear" }}</Button>
|
||||
</div>
|
||||
<Button size="sm" variant="outline" class="h-8 gap-1.5" :disabled="loading" @click="loadKeys(true, { preserveSelection: true })">
|
||||
<Loader2 v-if="loading" class="h-3.5 w-3.5 animate-spin" />
|
||||
<RefreshCw v-else class="h-3.5 w-3.5" />
|
||||
@@ -1459,28 +1546,43 @@ defineExpose({
|
||||
<div v-else class="h-full overflow-auto py-1 text-sm">
|
||||
<template v-for="row in visibleRows" :key="row.type === 'node' ? row.node.id : row.id">
|
||||
<CustomContextMenu v-if="row.type === 'node'" :items="nodeContextMenuItems(row.node)" v-slot="{ onContextMenu }">
|
||||
<button
|
||||
type="button"
|
||||
class="flex h-8 w-full items-center gap-1.5 px-2 text-left transition-colors hover:bg-accent"
|
||||
<div
|
||||
class="flex h-8 w-full items-center gap-1.5 pr-2 text-left transition-colors hover:bg-accent"
|
||||
:class="rowIsSelected(row.node) ? 'bg-primary/10 font-medium text-foreground shadow-[inset_3px_0_0_hsl(var(--primary))]' : ''"
|
||||
:style="{ paddingLeft: `${8 + row.depth * 18}px` }"
|
||||
@click="onRowClick(row.node)"
|
||||
@dblclick.stop.prevent="onRowDoubleClick(row.node)"
|
||||
@contextmenu="(event) => onRowContextMenu(event, row.node, onContextMenu)"
|
||||
>
|
||||
<template v-if="nodeIsExpandable(row.node)">
|
||||
<Loader2 v-if="nodeIsLoading(row.node)" class="h-3.5 w-3.5 shrink-0 animate-spin" />
|
||||
<ChevronDown v-else-if="nodeIsExpanded(row.node)" class="h-3.5 w-3.5 shrink-0" />
|
||||
<ChevronRight v-else class="h-3.5 w-3.5 shrink-0" />
|
||||
<FolderOpen v-if="nodeIsExpanded(row.node)" class="h-4 w-4 shrink-0 text-sky-500" />
|
||||
<FolderClosed v-else class="h-4 w-4 shrink-0 text-sky-500" />
|
||||
</template>
|
||||
<template v-else>
|
||||
<span class="w-3.5 shrink-0" />
|
||||
<KeyRound class="h-4 w-4 shrink-0 text-sky-500" />
|
||||
</template>
|
||||
<span class="truncate">{{ row.node.label }}</span>
|
||||
</button>
|
||||
<button
|
||||
v-if="enableMultiSelect"
|
||||
type="button"
|
||||
role="checkbox"
|
||||
class="flex h-5 w-5 shrink-0 items-center justify-center text-foreground"
|
||||
:aria-label="`${row.node.label}`"
|
||||
:aria-checked="nodeMultiSelectionState(row.node).indeterminate ? 'mixed' : nodeMultiSelectionState(row.node).selected"
|
||||
@click.stop
|
||||
@click="setNodeMultiSelection(row.node, !nodeMultiSelectionState(row.node).selected)"
|
||||
>
|
||||
<span v-if="nodeMultiSelectionState(row.node).selected" class="flex h-3.5 w-3.5 items-center justify-center rounded-[2px] bg-primary text-primary-foreground">
|
||||
<Check class="h-2.5 w-2.5 stroke-[3]" />
|
||||
</span>
|
||||
<span v-else-if="nodeMultiSelectionState(row.node).indeterminate" class="h-3.5 w-3.5 rounded-[2px] bg-primary" />
|
||||
<span v-else class="h-3.5 w-3.5 rounded-[2px] border border-muted-foreground/50" />
|
||||
</button>
|
||||
<button type="button" class="flex min-w-0 flex-1 items-center gap-1.5 text-left" @click="onRowClick(row.node)" @dblclick.stop.prevent="onRowDoubleClick(row.node)">
|
||||
<template v-if="nodeIsExpandable(row.node)">
|
||||
<Loader2 v-if="nodeIsLoading(row.node)" class="h-3.5 w-3.5 shrink-0 animate-spin" />
|
||||
<ChevronDown v-else-if="nodeIsExpanded(row.node)" class="h-3.5 w-3.5 shrink-0" />
|
||||
<ChevronRight v-else class="h-3.5 w-3.5 shrink-0" />
|
||||
<FolderOpen v-if="nodeIsExpanded(row.node)" class="h-4 w-4 shrink-0 text-sky-500" />
|
||||
<FolderClosed v-else class="h-4 w-4 shrink-0 text-sky-500" />
|
||||
</template>
|
||||
<template v-else>
|
||||
<span class="w-3.5 shrink-0" />
|
||||
<KeyRound class="h-4 w-4 shrink-0 text-sky-500" />
|
||||
</template>
|
||||
<span class="truncate">{{ row.node.label }}</span>
|
||||
</button>
|
||||
</div>
|
||||
</CustomContextMenu>
|
||||
<div v-else class="px-2 py-1" :style="{ paddingLeft: `${8 + row.depth * 18}px` }">
|
||||
<Button size="sm" variant="outline" class="h-7 w-full gap-1.5" :disabled="row.loading || loadingMore" @click="loadMoreLazyChildren(row.parentKey)">
|
||||
|
||||
Reference in new issue
Block a user