refactor(redis): keep keys out of sidebar tree

This commit is contained in:
t8y2
2026-04-30 14:29:25 +08:00
parent 2ae954e7a3
commit 5490ed007e
5 changed files with 6 additions and 73 deletions
+5 -16
View File
@@ -66,8 +66,6 @@ function getIconInfo(node: TreeNode): { icon: any; colorClass: string } | null {
return { icon: Zap, colorClass: "text-orange-300" };
case "redis-db":
return { icon: Database, colorClass: "text-red-400" };
case "redis-key":
return { icon: Key, colorClass: "text-red-300" };
case "mongo-db":
return { icon: Database, colorClass: "text-green-500" };
case "mongo-collection":
@@ -77,7 +75,7 @@ function getIconInfo(node: TreeNode): { icon: any; colorClass: string } | null {
}
}
const leafTypes: Set<TreeNodeType> = new Set(["column", "index", "fkey", "trigger", "redis-key"]);
const leafTypes: Set<TreeNodeType> = new Set(["column", "index", "fkey", "trigger", "redis-db"]);
const groupTypes: Set<TreeNodeType> = new Set(["group-columns", "group-indexes", "group-fkeys", "group-triggers"]);
function isGroupLabel(node: TreeNode): boolean {
@@ -101,7 +99,6 @@ async function toggle() {
} else if (node.type === "redis-db" && node.connectionId && node.database) {
const tabTitle = `${connectionStore.getConfig(node.connectionId)?.name || "Redis"}:db${node.database}`;
queryStore.createTab(node.connectionId, node.database, tabTitle, "redis");
await connectionStore.loadRedisKeys(node.connectionId, Number(node.database), node.id);
} else if (node.type === "mongo-db" && node.connectionId && node.database) {
await connectionStore.loadMongoCollections(node.connectionId, node.database);
} else if (node.type === "mongo-collection" && node.connectionId && node.database) {
@@ -135,6 +132,8 @@ function onClick() {
if (node.type === "table" || node.type === "view") {
openData();
toggle();
} else if (node.type === "redis-db") {
toggle();
} else if (canExpand) {
toggle();
}
@@ -180,8 +179,6 @@ async function refresh() {
const node = props.node;
node.isExpanded = false;
node.children = [];
node.scanCursor = undefined;
node.hasMore = undefined;
await toggle();
}
@@ -241,9 +238,7 @@ const visibleChildren = computed(() => {
return props.node.children.slice(0, displayLimit.value);
});
const hasMoreChildren = computed(() =>
(props.node.children?.length ?? 0) > displayLimit.value || !!props.node.hasMore
);
const hasMoreChildren = computed(() => (props.node.children?.length ?? 0) > displayLimit.value);
const remainingCount = computed(() =>
(props.node.children?.length ?? 0) - displayLimit.value
@@ -252,12 +247,6 @@ const remainingCount = computed(() =>
async function showMore() {
if ((props.node.children?.length ?? 0) > displayLimit.value) {
displayLimit.value += CHILDREN_PAGE_SIZE;
return;
}
if (props.node.type === "redis-db" && props.node.connectionId && props.node.database && props.node.hasMore) {
await connectionStore.loadMoreRedisKeys(props.node.connectionId, Number(props.node.database), props.node.id);
displayLimit.value += CHILDREN_PAGE_SIZE;
}
}
</script>
@@ -292,7 +281,7 @@ async function showMore() {
@click="showMore"
>
<Loader2 v-if="node.isLoading" class="w-3 h-3 shrink-0 animate-spin" />
<span>{{ node.hasMore && remainingCount <= 0 ? t('sidebar.loadMore') : t('sidebar.showMore', { count: Math.min(CHILDREN_PAGE_SIZE, remainingCount) }) }}</span>
<span>{{ t('sidebar.showMore', { count: Math.min(CHILDREN_PAGE_SIZE, remainingCount) }) }}</span>
</div>
</template>
</div>
-1
View File
@@ -14,7 +14,6 @@ export default {
import: "Import Connections",
export: "Export Connections",
showMore: "Show {count} more...",
loadMore: "Load more...",
},
connection: {
title: "New Connection",
-1
View File
@@ -14,7 +14,6 @@ export default {
import: "导入连接",
export: "导出连接",
showMore: "加载更多 ({count})...",
loadMore: "继续加载...",
},
connection: {
title: "新建连接",
-52
View File
@@ -161,56 +161,6 @@ export const useConnectionStore = defineStore("connection", () => {
}
}
async function loadRedisKeys(connectionId: string, db: number, nodeId: string) {
const node = findNode(treeNodes.value, nodeId);
if (!node) return;
node.isLoading = true;
try {
const result = await api.redisScanKeys(connectionId, db, 0, "*", 200);
node.scanCursor = result.cursor;
node.hasMore = result.cursor !== 0;
node.children = result.keys.map((k) => ({
id: `${nodeId}:${k.key}`,
label: `${k.key} [${k.key_type}]${k.ttl > 0 ? ` TTL:${k.ttl}` : ""}`,
type: "redis-key" as const,
connectionId,
database: String(db),
isExpanded: false,
}));
node.isExpanded = true;
} finally {
node.isLoading = false;
}
}
async function loadMoreRedisKeys(connectionId: string, db: number, nodeId: string) {
const node = findNode(treeNodes.value, nodeId);
if (!node || node.isLoading || !node.hasMore) return;
node.isLoading = true;
try {
const result = await api.redisScanKeys(connectionId, db, node.scanCursor ?? 0, "*", 200);
const existingIds = new Set((node.children ?? []).map((child) => child.id));
const moreChildren = result.keys
.filter((k) => !existingIds.has(`${nodeId}:${k.key}`))
.map((k) => ({
id: `${nodeId}:${k.key}`,
label: `${k.key} [${k.key_type}]${k.ttl > 0 ? ` TTL:${k.ttl}` : ""}`,
type: "redis-key" as const,
connectionId,
database: String(db),
isExpanded: false,
}));
node.scanCursor = result.cursor;
node.hasMore = result.cursor !== 0;
node.children = [...(node.children ?? []), ...moreChildren];
} finally {
node.isLoading = false;
}
}
async function loadMongoDatabases(connectionId: string) {
const node = findNode(treeNodes.value, connectionId);
if (!node) return;
@@ -506,8 +456,6 @@ export const useConnectionStore = defineStore("connection", () => {
initFromDisk,
loadDatabases,
loadRedisDatabases,
loadRedisKeys,
loadMoreRedisKeys,
loadMongoDatabases,
loadMongoCollections,
loadSchemas,
+1 -3
View File
@@ -72,7 +72,7 @@ export type TreeNodeType =
| "connection" | "database" | "schema" | "table" | "view"
| "group-columns" | "group-indexes" | "group-fkeys" | "group-triggers"
| "column" | "index" | "fkey" | "trigger"
| "redis-db" | "redis-key"
| "redis-db"
| "mongo-db" | "mongo-collection";
export interface TreeNode {
@@ -82,8 +82,6 @@ export interface TreeNode {
children?: TreeNode[];
isLoading?: boolean;
isExpanded?: boolean;
scanCursor?: number;
hasMore?: boolean;
connectionId?: string;
database?: string;
schema?: string;