-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
Updated code mirror component for consistency #11500
Conversation
arnav28
commented
Apr 29, 2021
- Hide gutters, line number and selection while read only
- Show toolbar with copy functionality for all instances
- Hide gutters, line number and selection while read only - Show toolbar with copy functionality for all instances
Would it be possible to see an example where there's help text included? |
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.
A few things to revise, and since the previous component was just an extension of a third party library we didn't have any tests for it. We should add tests for this one since we're doing custom logic (esp to make sure the options join with the defaults correctly, show or don't show the toolbar, etc)
}, this); | ||
init() { | ||
this._super(...arguments); | ||
this.options = { ...JSON_EDITOR_DEFAULTS, ...this.options }; |
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.
Are you trying to set it to the passed in options
here? That would be this.args.options
I believe
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.
options is a param on this component. Line 25 will merge the object properties from options passed in the child component with the default ones defined in JSON_EDITOR_DEFAULTS.
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.
Oh my bad, I was thinking this was a glimmer component 👍
Secret data | ||
{{/if}} | ||
</label> | ||
<Toolbar> |
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.
Could we have this toolbar as part of this new component, maybe an optional piece? Or it could be a separate component <ToolbarJsonEditor>
or something. That will make it easier to keep the behavior and look consistent between instances
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.
I did that but later realized we have a comment with an additional action for the upload file as well. Need to come up with a better design so we can create a separate ToolbarJsonEditor component with support for custom actions.
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.
Since the actions for each button will need to be passed in anyway, you could have the JSON component take "children" that get yielded within the toolbar. Or, if we know we want a discreet number of options (probably not) we could to a contextual component. Passing in the yielded content would be simpler, but it does depend on the developer using the correct class names for consistency in styling
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.
Done. Moved the Toolbar to json-editor component itself and added a yield block for custom actions.
<JsonEditor | ||
@valueUpdated={{action (mut input)}} | ||
@options={{hash | ||
lineNumbers=true |
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.
On these instances where we're swapping out IvyCodemirror for the JsonEditor component, we can simplify the options passed since many of these are in the default settings for the JsonEditor component
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.
Good point will fix it.
@@ -223,6 +241,7 @@ | |||
theme=(or attr.options.theme 'hashi') | |||
}} | |||
/> | |||
<p class="sub-text">{{ attr.options.helpText }}</p> |
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.
We should only show this if attr.options.helpText
exists. This also might error out if there are no options passed, so I would double check that
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.
True, will add defensive checks.
Screen.Recording.2021-05-04.at.4.20.19.PM.mov |
Thanks for the recording! I noticed a couple of things with the cursor hover behaviour. It's backwards in a couple of spots:
Additionally, would it be possible to see an example of one of the code blocks with help text? |
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.
Looking great! I think we should just add one more test, and I'll pull it down and play with it in the meantime
assert.equal(component.canEdit, true, 'json editor is in read only mode'); | ||
}); | ||
|
||
test('it renders in read only mode', async function(assert) { |
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.
Can we add one more test that ensures the toolbar shows only when showToolbar = true?
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.
Done.
After a chat with @arnav28 to clarify cursor behaviour, we've decided to leave them as they are. The current behaviour is consistent with how the cursor behaves in the browser: when hovering over text, it's the
The hope is that these visual changes will be enough to prevent customers assuming that the read-only code component is editable. There's no need to change cursor behaviour. If there's still confusion, we can look at making more visual changes to the code display in read-only mode. This looks good to me now! |
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.
Great work! 🚀