feat(xugu): show tablespace details in sidebar
This commit is contained in:
1 parent
2f4a72c4e9
commit
7e24f4007c
12 files changed
+305
-1
No files matched your search
@@ -1,5 +1,5 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { buildXuguTablespaceChildren, xuguDatafileDisplayName } from "@/lib/sidebar/xuguTablespaces";
|
||||
import { buildXuguTablespaceChildren, xuguDatafileDetailRows, xuguDatafileDisplayName, xuguTablespaceDetailRows } from "@/lib/sidebar/xuguTablespaces";
|
||||
|
||||
describe("Xugu tablespace tree", () => {
|
||||
it("uses the physical file basename while retaining the full path", () => {
|
||||
@@ -25,10 +25,62 @@ describe("Xugu tablespace tree", () => {
|
||||
id: "conn:storage:tablespace:7:files:1:/data/DATA1.DBF",
|
||||
type: "datafile",
|
||||
label: "DATA1.DBF",
|
||||
xuguDatafile: { node_id: "1", space_id: 7, path: "/data/DATA1.DBF", file_no: 1, curr_size: 1024 },
|
||||
xuguDatafilePath: "/data/DATA1.DBF",
|
||||
});
|
||||
});
|
||||
|
||||
it("builds tablespace details and derives chunk usage", () => {
|
||||
expect(
|
||||
xuguTablespaceDetailRows({
|
||||
node_id: "1",
|
||||
space_id: 7,
|
||||
space_name: "DATA1",
|
||||
datafile_num: 2,
|
||||
space_type: "DATA_SPACE",
|
||||
media_error: "F",
|
||||
total_chunk_num: 64,
|
||||
free_chunk_num: 16,
|
||||
datafiles: [],
|
||||
}),
|
||||
).toEqual([
|
||||
{ key: "name", value: "DATA1" },
|
||||
{ key: "nodeId", value: "1" },
|
||||
{ key: "spaceId", value: "7" },
|
||||
{ key: "spaceType", value: "DATA_SPACE" },
|
||||
{ key: "datafileCount", value: "2" },
|
||||
{ key: "totalChunks", value: "64" },
|
||||
{ key: "freeChunks", value: "16" },
|
||||
{ key: "usedChunks", value: "48" },
|
||||
{ key: "usage", value: "75.0%" },
|
||||
{ key: "mediaError", value: "F" },
|
||||
]);
|
||||
});
|
||||
|
||||
it("builds datafile details while preserving nullable size fields", () => {
|
||||
expect(
|
||||
xuguDatafileDetailRows({
|
||||
node_id: "1",
|
||||
space_id: 7,
|
||||
path: "/data/DATA1.DBF",
|
||||
file_no: 1,
|
||||
max_size: -1,
|
||||
step_size: 64,
|
||||
curr_size: 512,
|
||||
reserved1: null,
|
||||
}),
|
||||
).toEqual([
|
||||
{ key: "name", value: "DATA1.DBF" },
|
||||
{ key: "path", value: "/data/DATA1.DBF", multiline: true },
|
||||
{ key: "nodeId", value: "1" },
|
||||
{ key: "spaceId", value: "7" },
|
||||
{ key: "fileNo", value: "1" },
|
||||
{ key: "currentSize", value: "512" },
|
||||
{ key: "maxSize", value: "-1" },
|
||||
{ key: "stepSize", value: "64" },
|
||||
]);
|
||||
});
|
||||
|
||||
it("preserves expanded state on refresh", () => {
|
||||
const first = buildXuguTablespaceChildren({ id: "conn:storage", connectionId: "conn", database: "APP", children: [] }, [{ node_id: "1", space_id: 7, space_name: "DATA1", datafile_num: 0, space_type: "PERMANENT", datafiles: [] }]);
|
||||
first[0].isExpanded = true;
|
||||
|
||||
@@ -1,5 +1,54 @@
|
||||
import type { TreeNode, XuguTablespaceInfo } from "@/types/database";
|
||||
|
||||
export type XuguStorageDetailEntry = {
|
||||
key: string;
|
||||
value: string;
|
||||
multiline?: boolean;
|
||||
};
|
||||
|
||||
function detailValue(value: string | number | null | undefined): string {
|
||||
return value == null ? "" : String(value).trim();
|
||||
}
|
||||
|
||||
function detailEntries(entries: XuguStorageDetailEntry[]): XuguStorageDetailEntry[] {
|
||||
return entries.filter((entry) => entry.value.length > 0);
|
||||
}
|
||||
|
||||
/** Build the fields shown by the sidebar's Xugu tablespace detail popover. */
|
||||
export function xuguTablespaceDetailRows(tablespace: XuguTablespaceInfo): XuguStorageDetailEntry[] {
|
||||
const total = tablespace.total_chunk_num;
|
||||
const free = tablespace.free_chunk_num;
|
||||
const used = total != null && free != null ? Math.max(total - free, 0) : null;
|
||||
const usage = total != null && total > 0 && used != null ? `${((used / total) * 100).toFixed(1)}%` : "";
|
||||
return detailEntries([
|
||||
{ key: "name", value: detailValue(tablespace.space_name) },
|
||||
{ key: "nodeId", value: detailValue(tablespace.node_id) },
|
||||
{ key: "spaceId", value: detailValue(tablespace.space_id) },
|
||||
{ key: "spaceType", value: detailValue(tablespace.space_type) },
|
||||
{ key: "datafileCount", value: detailValue(tablespace.datafile_num) },
|
||||
{ key: "totalChunks", value: detailValue(total) },
|
||||
{ key: "freeChunks", value: detailValue(free) },
|
||||
{ key: "usedChunks", value: detailValue(used) },
|
||||
{ key: "usage", value: usage },
|
||||
{ key: "mediaError", value: detailValue(tablespace.media_error) },
|
||||
]);
|
||||
}
|
||||
|
||||
/** Build the fields shown by the sidebar's Xugu datafile detail popover. */
|
||||
export function xuguDatafileDetailRows(datafile: NonNullable<TreeNode["xuguDatafile"]>): XuguStorageDetailEntry[] {
|
||||
return detailEntries([
|
||||
{ key: "name", value: xuguDatafileDisplayName(datafile.path, datafile.file_no) },
|
||||
{ key: "path", value: detailValue(datafile.path), multiline: true },
|
||||
{ key: "nodeId", value: detailValue(datafile.node_id) },
|
||||
{ key: "spaceId", value: detailValue(datafile.space_id) },
|
||||
{ key: "fileNo", value: detailValue(datafile.file_no) },
|
||||
{ key: "currentSize", value: detailValue(datafile.curr_size) },
|
||||
{ key: "maxSize", value: detailValue(datafile.max_size) },
|
||||
{ key: "stepSize", value: detailValue(datafile.step_size) },
|
||||
{ key: "reserved", value: detailValue(datafile.reserved1) },
|
||||
]);
|
||||
}
|
||||
|
||||
export function xuguDatafileDisplayName(path: string, fileNo: number): string {
|
||||
const normalized = path.trim().replaceAll("\\", "/");
|
||||
const parts = normalized.split("/").filter(Boolean);
|
||||
@@ -21,6 +70,7 @@ export function buildXuguTablespaceChildren(parent: Pick<TreeNode, "id" | "conne
|
||||
connectionId: parent.connectionId,
|
||||
database: parent.database,
|
||||
objectName: file.path,
|
||||
xuguDatafile: file,
|
||||
xuguDatafilePath: file.path,
|
||||
comment: file.path,
|
||||
}));
|
||||
|
||||
Reference in new issue
Block a user