fix(etcd): preserve raw key identity in browser actions
This commit is contained in:
69 files changed
+6577
-742
No files matched your search
@@ -1,15 +1,17 @@
|
||||
import type { KvKeySummary } from "@/lib/backend/api";
|
||||
import type { KvKeySummary, KvValue } from "@/lib/backend/api";
|
||||
|
||||
export interface KvKeyTreeLeafNode {
|
||||
kind: "leaf";
|
||||
id: string;
|
||||
label: string;
|
||||
key: string;
|
||||
keyIdentity?: string | null;
|
||||
keyBytes?: KvValue | null;
|
||||
pathSegments: string[];
|
||||
createRevision?: number | null;
|
||||
modRevision?: number | null;
|
||||
version?: number | null;
|
||||
lease?: number | null;
|
||||
createRevision?: string | number | null;
|
||||
modRevision?: string | number | null;
|
||||
version?: string | number | null;
|
||||
lease?: string | number | null;
|
||||
valueSize?: number | null;
|
||||
}
|
||||
|
||||
@@ -19,6 +21,14 @@ export interface KvKeyTreeGroupNode {
|
||||
label: string;
|
||||
pathSegments: string[];
|
||||
children: KvKeyTreeNode[];
|
||||
key?: string;
|
||||
keyIdentity?: string | null;
|
||||
keyBytes?: KvValue | null;
|
||||
createRevision?: string | number | null;
|
||||
modRevision?: string | number | null;
|
||||
version?: string | number | null;
|
||||
lease?: string | number | null;
|
||||
valueSize?: number | null;
|
||||
}
|
||||
|
||||
export type KvKeyTreeNode = KvKeyTreeLeafNode | KvKeyTreeGroupNode;
|
||||
@@ -36,8 +46,12 @@ function groupId(pathSegments: string[]): string {
|
||||
return `group:${pathSegments.join("\u0000")}`;
|
||||
}
|
||||
|
||||
function leafId(key: string): string {
|
||||
return `leaf:${key}`;
|
||||
function summaryIdentity(key: KvKeySummary): string {
|
||||
return key.keyIdentity ?? key.key;
|
||||
}
|
||||
|
||||
function leafId(key: KvKeySummary): string {
|
||||
return `leaf:${summaryIdentity(key)}`;
|
||||
}
|
||||
|
||||
function sortNodes(nodes: KvKeyTreeNode[]): KvKeyTreeNode[] {
|
||||
@@ -58,9 +72,11 @@ export function buildKvKeyTree(keys: KvKeySummary[]): KvKeyTreeNode[] {
|
||||
if (segments.length <= 1) {
|
||||
root.push({
|
||||
kind: "leaf",
|
||||
id: leafId(key.key),
|
||||
id: leafId(key),
|
||||
label: segments[0] || key.key || "/",
|
||||
key: key.key,
|
||||
keyIdentity: key.keyIdentity,
|
||||
keyBytes: key.keyBytes,
|
||||
pathSegments: segments,
|
||||
createRevision: key.createRevision,
|
||||
modRevision: key.modRevision,
|
||||
@@ -78,18 +94,49 @@ export function buildKvKeyTree(keys: KvKeySummary[]): KvKeyTreeNode[] {
|
||||
const id = groupId(groupSegments);
|
||||
let group = groups.get(id);
|
||||
if (!group) {
|
||||
group = { kind: "group", id, label: segment, pathSegments: [...groupSegments], children: [] };
|
||||
const leafIndex = current.findIndex((candidate) => candidate.kind === "leaf" && candidate.pathSegments.join("\u0000") === groupSegments.join("\u0000"));
|
||||
const existingLeaf = leafIndex >= 0 ? (current.splice(leafIndex, 1)[0] as KvKeyTreeLeafNode) : null;
|
||||
group = {
|
||||
kind: "group",
|
||||
id,
|
||||
label: segment,
|
||||
pathSegments: [...groupSegments],
|
||||
children: [],
|
||||
key: existingLeaf?.key,
|
||||
keyIdentity: existingLeaf?.keyIdentity,
|
||||
keyBytes: existingLeaf?.keyBytes,
|
||||
createRevision: existingLeaf?.createRevision,
|
||||
modRevision: existingLeaf?.modRevision,
|
||||
version: existingLeaf?.version,
|
||||
lease: existingLeaf?.lease,
|
||||
valueSize: existingLeaf?.valueSize,
|
||||
};
|
||||
groups.set(id, group);
|
||||
current.push(group);
|
||||
}
|
||||
current = group.children;
|
||||
}
|
||||
|
||||
const existingGroup = groups.get(groupId(segments));
|
||||
if (existingGroup) {
|
||||
existingGroup.key = key.key;
|
||||
existingGroup.keyIdentity = key.keyIdentity;
|
||||
existingGroup.keyBytes = key.keyBytes;
|
||||
existingGroup.createRevision = key.createRevision;
|
||||
existingGroup.modRevision = key.modRevision;
|
||||
existingGroup.version = key.version;
|
||||
existingGroup.lease = key.lease;
|
||||
existingGroup.valueSize = key.valueSize;
|
||||
continue;
|
||||
}
|
||||
|
||||
current.push({
|
||||
kind: "leaf",
|
||||
id: leafId(key.key),
|
||||
id: leafId(key),
|
||||
label: segments[segments.length - 1],
|
||||
key: key.key,
|
||||
keyIdentity: key.keyIdentity,
|
||||
keyBytes: key.keyBytes,
|
||||
pathSegments: segments,
|
||||
createRevision: key.createRevision,
|
||||
modRevision: key.modRevision,
|
||||
@@ -134,3 +181,22 @@ export function flattenVisibleKvKeyTree(nodes: KvKeyTreeNode[], expandedGroupIds
|
||||
}
|
||||
return rows;
|
||||
}
|
||||
|
||||
export function kvKeyTreeNodePath(node: KvKeyTreeNode): string {
|
||||
if (node.kind === "leaf") return node.key;
|
||||
if (node.key) return node.key;
|
||||
|
||||
const descendantKey = firstDescendantKey(node);
|
||||
const joined = node.pathSegments.join("/");
|
||||
return descendantKey?.startsWith("/") ? `/${joined}` : joined;
|
||||
}
|
||||
|
||||
function firstDescendantKey(node: KvKeyTreeGroupNode): string | null {
|
||||
for (const child of node.children) {
|
||||
if (child.kind === "leaf") return child.key;
|
||||
if (child.key) return child.key;
|
||||
const nested = firstDescendantKey(child);
|
||||
if (nested) return nested;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
Reference in new issue
Block a user