Skip to content

feat(right-click): copy element and document as shell syntax COMPASS-10041#8245

Open
mabaasit wants to merge 10 commits into
mainfrom
crud-document-right-click
Open

feat(right-click): copy element and document as shell syntax COMPASS-10041#8245
mabaasit wants to merge 10 commits into
mainfrom
crud-document-right-click

Conversation

@mabaasit

@mabaasit mabaasit commented Jul 16, 2026

Copy link
Copy Markdown
Collaborator

Would be merged after Rhys's refactor PR is merged.

Description

Checklist

  • New tests and/or benchmarks are included
  • Documentation is changed or added
  • If this change updates the UI, screenshots/videos are added and a design review is requested
  • If this change could impact the load on the MongoDB cluster, please describe the expected and worst case impact
  • I have signed the MongoDB Contributor License Agreement (https://www.mongodb.com/legal/contributor-agreement)

Motivation and Context

  • Bugfix
  • New feature
  • Dependency update
  • Misc

Open Questions

Dependents

Types of changes

  • Backport Needed
  • Patch (non-breaking change which fixes an issue)
  • Minor (non-breaking change which adds functionality)
  • Major (fix or feature that would cause existing functionality to change)

Copilot AI review requested due to automatic review settings July 16, 2026 10:56
@mabaasit
mabaasit requested a review from a team as a code owner July 16, 2026 10:56
@mabaasit
mabaasit requested a review from gribnoysup July 16, 2026 10:56
@github-actions github-actions Bot added the feat label Jul 16, 2026

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

This PR adds “shell syntax” serialization/copying for documents and elements (intended for right-click / context-menu copy flows) and wires the chosen copy format into telemetry.

Changes:

  • Add toShellSyntax() serialization for Document/Element and use it for “copy as shell syntax” flows.
  • Extend document context menus to offer “Copy document as Shell Syntax” vs “Copy document as EJSON”, and record format in the “Document Copied” telemetry event.
  • Add/adjust unit tests for the new serialization and updated UI copy actions.

Code quality / risk notes (high level):

  • There are a couple of API/type-surface changes that can unintentionally break callers (Element serializer API parity, copyToClipboard typing) and should be addressed before merge.
  • Serializer fallback behavior should be consistent with existing toJSString() usage patterns in the repo to avoid returning/copying an empty string.

Reviewed changes

Copilot reviewed 18 out of 18 changed files in this pull request and generated 6 comments.

Show a summary per file
File Description
packages/hadron-document/test/element.test.ts Replaces element serialization tests with toShellSyntax coverage.
packages/hadron-document/test/document.test.ts Adds Document#toShellSyntax tests.
packages/hadron-document/src/utils.ts Introduces shell-syntax options type.
packages/hadron-document/src/element.ts Adds element shell-syntax serialization via toJSString.
packages/hadron-document/src/document.ts Adds document shell-syntax serialization via toJSString.
packages/hadron-document/package.json Adds mongodb-query-parser dependency for shell-syntax serialization.
packages/compass-telemetry/src/telemetry-events.ts Adds format field to “Document Copied” event schema.
packages/compass-crud/src/stores/crud-store.ts Updates clipboard copy action to support format + telemetry.
packages/compass-crud/src/stores/crud-store.spec.ts Adds tests for EJSON vs shell-syntax clipboard output.
packages/compass-crud/src/components/use-document-item-context-menu.tsx Adds context menu actions for copying as EJSON vs shell syntax.
packages/compass-crud/src/components/use-document-item-context-menu.spec.tsx Updates context menu tests for new copy items and format args.
packages/compass-crud/src/components/json-editor.tsx Updates copy behavior to explicitly copy as EJSON.
packages/compass-crud/src/components/editable-document.tsx Updates copy behavior to explicitly copy as EJSON.
packages/compass-crud/src/components/document-list-view-item.spec.tsx Updates expectations for new copy context menu labels.
packages/compass-crud/src/components/document-json-view-item.spec.tsx Updates expectations for new copy context menu labels.
packages/compass-components/src/components/document-list/element.tsx Adds “Copy value” and switches copy output to shell syntax.
packages/compass-components/src/components/document-list/element.spec.tsx Adds test for “Copy value” and updates quoting expectations.
packages/compass-components/src/components/context-menu.tsx Adjusts menu sizing to accommodate updated menu item labels.

Comment on lines 19 to 24
import type {
BSONArray,
BSONObject,
BSONValue,
HadronEJSONOptions,
HadronShellSyntaxOptions,
} from './utils';
Comment on lines 419 to 433
/**
* Generate the Extended JSON string representation of this element.
* Generate the Shell Syntax string representation of this element.
*
* @returns The Extended JSON string.
* @returns The Shell Syntax string.
*/
toEJSON(
toShellSyntax(
source: 'original' | 'current' = 'current',
options: HadronEJSONOptions = {}
options: HadronShellSyntaxOptions = {}
): string {
const generated =
source === 'original'
? this.generateOriginalObject()
: this.generateObject();
return objectToIdiomaticEJSON(generated, options);
return toJSString(generated, options.indent) ?? '{}';
}
Comment thread packages/hadron-document/src/document.ts
Comment thread packages/compass-crud/src/stores/crud-store.ts
Comment thread packages/hadron-document/test/document.test.ts Outdated
Comment thread packages/hadron-document/test/element.test.ts
@mabaasit
mabaasit force-pushed the crud-document-right-click branch from 5e160b9 to b3acf77 Compare July 16, 2026 11:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants