-
Notifications
You must be signed in to change notification settings - Fork 18
Adds editor option copy as JSON #684
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
There was a problem hiding this 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) + "'") + |
There was a problem hiding this comment.
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.
(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)); |
There was a problem hiding this comment.
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.
Description of Changes
This PR adds a feature to the editor to copy a Submodel/SubmodelElement as JSON to the clipboard.