Skip to content

Conversation

aaronzi
Copy link
Member

@aaronzi aaronzi commented Aug 30, 2025

Description of Changes

This PR adds a feature to the editor to copy a Submodel/SubmodelElement as JSON to the clipboard.

@aaronzi aaronzi requested a review from Copilot August 30, 2025 08:03
Copy link
Contributor

@Copilot Copilot AI left a comment

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 a "Copy as JSON" feature to the AAS web UI editor, allowing users to copy Submodel and SubmodelElement objects as JSON to the clipboard. The implementation includes UI integration in the treeview context menus and reuses existing JSON cleaning logic.

  • Adds new copyJsonToClipboard function with object cleaning capabilities
  • Integrates "Copy as JSON" menu items in both Submodel and SubmodelElement context menus
  • Refactors existing JSON view component to use shared cleaning logic

Reviewed Changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

File Description
ClipboardUtil.ts Adds copyJsonToClipboard function and cleanObjectRecursively helper for removing tree-specific properties
Treeview.vue Integrates new copy JSON functionality into context menus for both Submodels and SubmodelElements
SubmodelElementJSONView.vue Refactors to use shared cleaning logic from ClipboardUtil instead of local implementation

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

color: 'success',
btnColor: 'buttonText',
text:
(valueName.trim() !== '' ? valueName : "'" + JSON.stringify(cleanedValue) + "'") +
Copy link
Preview

Copilot AI Aug 30, 2025

Choose a reason for hiding this comment

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

The fallback message construction could result in double JSON stringification. If valueName is empty, cleanedValue is stringified twice - once here and once in line 39 where it's copied to clipboard. Consider using a simpler fallback like 'JSON' or the object's modelType property.

Suggested change
(valueName.trim() !== '' ? valueName : "'" + JSON.stringify(cleanedValue) + "'") +
(valueName.trim() !== ''
? valueName
: (typeof cleanedValue === 'object' && cleanedValue !== null && 'modelType' in cleanedValue
? (cleanedValue as { modelType?: string }).modelType || 'JSON'
: 'JSON')) +

Copilot uses AI. Check for mistakes.

iconReference.value = 'mdi-check';

// copy value to clipboard
navigator.clipboard.writeText(JSON.stringify(cleanedValue, null, 2));
Copy link
Preview

Copilot AI Aug 30, 2025

Choose a reason for hiding this comment

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

The clipboard write operation should handle potential errors. If the clipboard API fails (e.g., due to permissions or browser compatibility), the user will see the success message despite the operation failing.

Copilot uses AI. Check for mistakes.

@aaronzi aaronzi merged commit c9f7a2a into eclipse-basyx:main Aug 30, 2025
2 checks passed
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.

1 participant