From 563fb57276d8cad5bf9b861394972aacfbc2a6c9 Mon Sep 17 00:00:00 2001 From: lte_z Date: Thu, 21 May 2026 21:48:36 +0800 Subject: [PATCH 1/2] fix: display shard key in collection tooltip --- l10n/bundle.l10n.json | 1 + src/documentdb/ClustersClient.ts | 10 +++++++++- src/tree/documentdb/CollectionItem.ts | 8 ++++++++ 3 files changed, 18 insertions(+), 1 deletion(-) diff --git a/l10n/bundle.l10n.json b/l10n/bundle.l10n.json index 2aae6dc5c..c7e134227 100644 --- a/l10n/bundle.l10n.json +++ b/l10n/bundle.l10n.json @@ -995,6 +995,7 @@ "sessionId is required for query optimization": "sessionId is required for query optimization", "Settings:": "Settings:", "Severe multikey expansion": "Severe multikey expansion", + "Shard Key": "Shard Key", "SHARD_MERGE · {0} shards": "SHARD_MERGE · {0} shards", "SHARD_MERGE · {0} shards · {1} docs · {2}ms": "SHARD_MERGE · {0} shards · {1} docs · {2}ms", "Shard: {0}": "Shard: {0}", diff --git a/src/documentdb/ClustersClient.ts b/src/documentdb/ClustersClient.ts index e7f965552..2a4795db2 100644 --- a/src/documentdb/ClustersClient.ts +++ b/src/documentdb/ClustersClient.ts @@ -71,6 +71,7 @@ export interface DatabaseItemModel { export interface CollectionItemModel { name: string; type?: string; + shardKey?: Record; } /** @@ -602,7 +603,14 @@ export class ClustersClient { } const rawCollections = await this._mongoClient.db(databaseName).listCollections().toArray(); - const collections: CollectionItemModel[] = rawCollections; + const collections: CollectionItemModel[] = rawCollections.map((c) => ({ + name: c.name, + type: c.type, + shardKey: + 'options' in c + ? (c.options as { shardKey?: Record } | undefined)?.shardKey + : undefined, + })); this._collectionsCache.set(databaseName, collections); diff --git a/src/tree/documentdb/CollectionItem.ts b/src/tree/documentdb/CollectionItem.ts index c5e79b427..c68aac43e 100644 --- a/src/tree/documentdb/CollectionItem.ts +++ b/src/tree/documentdb/CollectionItem.ts @@ -137,6 +137,14 @@ export class CollectionItem implements TreeElement, TreeElementWithExperience, T md.appendMarkdown(`**${l10n.t('Documents')}:** ${formatDocumentCount(this.documentCount)}\n\n`); } + // Shard key + if (this.collectionInfo.shardKey) { + const entries = Object.entries(this.collectionInfo.shardKey) + .map(([k, v]) => `${k}: ${typeof v === 'string' ? `"${v}"` : v}`) + .join(', '); + md.appendMarkdown(`**${l10n.t('Shard Key')}:** \`{ ${entries} }\`\n\n`); + } + return md; } } From 846809c3171f81d28bed53f711d9848168b2dd56 Mon Sep 17 00:00:00 2001 From: lte_z <56144340+lte-z@users.noreply.github.com> Date: Thu, 21 May 2026 22:12:03 +0800 Subject: [PATCH 2/2] fix: escape shard key tooltip markdown content Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com> --- src/tree/documentdb/CollectionItem.ts | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/src/tree/documentdb/CollectionItem.ts b/src/tree/documentdb/CollectionItem.ts index c68aac43e..bb293570b 100644 --- a/src/tree/documentdb/CollectionItem.ts +++ b/src/tree/documentdb/CollectionItem.ts @@ -139,10 +139,18 @@ export class CollectionItem implements TreeElement, TreeElementWithExperience, T // Shard key if (this.collectionInfo.shardKey) { - const entries = Object.entries(this.collectionInfo.shardKey) - .map(([k, v]) => `${k}: ${typeof v === 'string' ? `"${v}"` : v}`) - .join(', '); - md.appendMarkdown(`**${l10n.t('Shard Key')}:** \`{ ${entries} }\`\n\n`); + const shardKeyEntries = Object.entries(this.collectionInfo.shardKey); + if (shardKeyEntries.length > 0) { + const entries = shardKeyEntries + .map(([k, v]) => { + const escapedKey = escapeMarkdown(k); + const valueText = typeof v === 'string' ? `"${v}"` : String(v); + const escapedValue = escapeMarkdown(valueText); + return `${escapedKey}: ${escapedValue}`; + }) + .join(', '); + md.appendMarkdown(`**${l10n.t('Shard Key')}:** \`{ ${entries} }\`\n\n`); + } } return md;