Skip to content

fix: display shard key in collection tooltip#670

Merged
tnaum-ms merged 4 commits into
microsoft:mainfrom
lte-z:dev/lte_z/shard-key-tooltip
May 27, 2026
Merged

fix: display shard key in collection tooltip#670
tnaum-ms merged 4 commits into
microsoft:mainfrom
lte-z:dev/lte_z/shard-key-tooltip

Conversation

@lte-z

@lte-z lte-z commented May 21, 2026

Copy link
Copy Markdown
Contributor

Fixes #661

Changes

This PR exposes shard key information for sharded collections in the tree view tooltip.

  • Extended CollectionItemModel to include optional shardKey field
  • Extracted shard key from MongoDB listCollections() response in ClustersClient
  • Rendered shard key in CollectionItem tooltip when present
  • Added localization entry for "Shard Key"

Behavior

  • Sharded collections now display their shard key in tooltip, e.g.:
Database: my-database
Documents: 5.2k
Shard Key: { userId: "hashed" }
  • Non-sharded collections are unaffected (no shard key section shown)

Notes

  • Handles missing or undefined shard key safely
  • Supports both numeric (1) and hashed shard key formats

Copilot AI review requested due to automatic review settings May 21, 2026 13:56
@lte-z lte-z requested a review from a team as a code owner May 21, 2026 13:56
@lte-z

lte-z commented May 21, 2026

Copy link
Copy Markdown
Contributor Author

@microsoft-github-policy-service agree

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Exposes sharding metadata in the DocumentDB tree UI by preserving the shard key from listCollections() and rendering it in the collection tooltip.

Changes:

  • Extend CollectionItemModel with an optional shardKey property populated from listCollections() results.
  • Update CollectionItem tooltip to conditionally display shard key details when present.
  • Add localization string for “Shard Key”.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

File Description
src/tree/documentdb/CollectionItem.ts Adds shard key section to the collection tooltip.
src/documentdb/ClustersClient.ts Extracts and stores shard key from listCollections() into the collection model.
l10n/bundle.l10n.json Adds localized string entry for “Shard Key”.

Comment thread src/tree/documentdb/CollectionItem.ts Outdated
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
@tnaum-ms

Copy link
Copy Markdown
Collaborator

@lte-z Thank you for your contribution and for addressing Copilot review. I'll review your PR tomorrow.

@tnaum-ms tnaum-ms added the on-hold Approved but not merging yet. Reason in comments. Remove + click Ready for review to release. label May 21, 2026
@tnaum-ms tnaum-ms added this to the 0.8.1 milestone May 27, 2026
Previously all entries were joined into a single backtick code span
with escapeMarkdown applied to each key and value. Markdown escaping
inside a code span is a no-op visually, so characters like underscores
were rendered with a literal backslash (e.g. user\_id).

Each entry is now its own inline code span, e.g.:
  Shard Key: `userId: 1`, `tenantId: "hashed"`

This avoids the escaping issue and makes multi-key shard keys easier
to read in the tooltip.
@tnaum-ms

tnaum-ms commented May 27, 2026

Copy link
Copy Markdown
Collaborator

I pushed one follow-up commit on top of yours.

What changed: The shard key entries are now each wrapped in their own inline code span instead of being joined into a single one. So a two-key shard key renders as:

userId: 1, tenantId: "hashed"

Why: The original code applied escapeMarkdown to key and value strings before placing them inside a backtick code span. Inside a code span the Markdown renderer never interprets special characters, so the escape backslashes were rendered literally (e.g. user\_id showed up as user\_id with a visible backslash). Wrapping each entry in its own code span removes the need for escaping entirely and also makes multi-key shard keys easier to scan.

@tnaum-ms

Copy link
Copy Markdown
Collaborator

Hey @lte-z, thanks for not just one, but the three PRs (#670, #674, #679) focused and quality contributions.

first-contribution

I'll have to work on the badges I use :)

@tnaum-ms tnaum-ms merged commit c65f004 into microsoft:main May 27, 2026
5 checks passed
@tnaum-ms tnaum-ms removed the on-hold Approved but not merging yet. Reason in comments. Remove + click Ready for review to release. label May 27, 2026
@lte-z

lte-z commented May 27, 2026

Copy link
Copy Markdown
Contributor Author

Thank you so much for the warm welcome and for merging this!

I also appreciate the follow-up commit and the explanation about the inline code spans. That makes sense to me now, especially for shard keys with underscores or multiple fields.

And thank you for the kind words about the three PRs. I’m really glad they were helpful, and I’d be happy to keep contributing to vscode-documentdb 🙂

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Show shard key in collection tooltip 🔑

3 participants