feat: copy id or document to clipboard#419
Open
SethFalco wants to merge 1 commit intomongodb-js:mainfrom
Open
Conversation
addaleax
reviewed
May 30, 2022
Contributor
addaleax
left a comment
There was a problem hiding this comment.
Thank you for the PR! I think we’d need at least two things more, both for this one and for #420:
- They need tests :)
- And you need to sign the MongoDB Contributor’s Agreement if you haven’t already
| return false; | ||
| } | ||
|
|
||
| let body = JSON.stringify(documentId); |
Contributor
There was a problem hiding this comment.
What happens here if documentId contains non-JS bson datatypes, e.g. Binary() or similar? Should this be EJSON instead of JSON?
Comment on lines
+502
to
+504
| if (body.startsWith('"')) { | ||
| body = body.slice(1, body.length - 1); | ||
| } |
Contributor
There was a problem hiding this comment.
If the idea here is to leave string document ids as-is, it might be better to check e.g. if (typeof body !== 'string') { body = JSON.stringify(documentId); } instead, since this currently still leaves JSON escapes in body
| const tabSize = vscode.workspace | ||
| .getConfiguration('editor') | ||
| .get('tabSize', 2); | ||
| const body = JSON.stringify(document, undefined, tabSize); |
Member
|
Added view document and copy document in this pr: #445 - it'll be in the next release. No copy id, yet, though. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Adds 2 new context menu actions.
mdb.copyDocumentIdFromTree- To copy the ID of a document to the clipboard.mdb.copyDocumentFromTree- To copy the value of a document to the clipboard.Sometimes I can recognize an ID, or especially for small collections (i.e. during development) I know the document at the bottom is the one I need to interact with. It'd be nice to be able to just copy the ID directly from the tree view and just paste it in the playground.
body = body.slice(1, body.length - 1);Just to explain this particular line. Copies the
documentIdproperty, but if it's a string, which it is in most cases, I thought we should remove the quotes when copying.For any other type of ID (namely objects) the output doesn't start or end with quotes anyway.
Checklist
Motivation and Context
Dependents
Types of changes