Skip to content
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

Merged
merged 4 commits into from
May 6, 2021
Merged

Conversation

arnav28
Copy link
Contributor

@arnav28 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
@arnav28 arnav28 added the ui label Apr 29, 2021
@arnav28 arnav28 requested a review from hashishaw April 29, 2021 22:18
@ivana-mcconnell
Copy link

Would it be possible to see an example where there's help text included?

Copy link
Collaborator

@hashishaw hashishaw left a 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 };
Copy link
Collaborator

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

Copy link
Contributor Author

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.

Copy link
Collaborator

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>
Copy link
Collaborator

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

Copy link
Contributor Author

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.

Copy link
Collaborator

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

Copy link
Contributor Author

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
Copy link
Collaborator

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

Copy link
Contributor Author

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>
Copy link
Collaborator

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

Copy link
Contributor Author

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.

@arnav28
Copy link
Contributor Author

arnav28 commented May 4, 2021

Screen.Recording.2021-05-04.at.4.20.19.PM.mov

@ivana-mcconnell
Copy link

Thanks for the recording! I noticed a couple of things with the cursor hover behaviour. It's backwards in a couple of spots:

  • The hover on the "read" state is the text cursor at 0:05. The cursor's hover on the read state should be "default." This is also the case at 0:24, when viewing the policy. The cursor is "text" in the read state when hovering, and should be "default".
  • When looking at signing the SSH key (0:17), it seems like the cursor is "default" when hovering, but this is an edit state. In this case, the cursor should be "text"

Additionally, would it be possible to see an example of one of the code blocks with help text?

Copy link
Collaborator

@hashishaw hashishaw left a 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) {
Copy link
Collaborator

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?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

@ivana-mcconnell
Copy link

ivana-mcconnell commented May 5, 2021

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 text cursor. When it isn't hovering over text, the cursor is default. We'll keep this. The original reasoning for changing it was that users would get confused that the read-only code was editable. However, we've made other modifications which should help solve this problem. Those are:

  • Removing the 'flashing' cursor in the read-only mode. Previously, the user could click into the read-only version and see an 'editing' cursor (see image below). This gave the impression that editing was possible when it wasn't.
    image
  • We've removed the line numbering in the read-only view, which also contributes to the assumption that the code is editable.

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!

Copy link
Collaborator

@hashishaw hashishaw left a comment

Choose a reason for hiding this comment

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

Great work! 🚀

@arnav28 arnav28 merged commit a068cca into master May 6, 2021
@arnav28 arnav28 deleted the ui/ivycodemirror branch May 6, 2021 16:59
AndreyZamyslov pushed a commit to yandex-cloud/vault that referenced this pull request Jun 10, 2021
* Updated code mirror component for consistency

- Hide gutters, line number and selection while read only
- Show toolbar with copy functionality for all instances

* Moved toolbar and actions to json editor component

* Updated form-field-from-model template

* Added test for toolbar
jartek pushed a commit to jartek/vault that referenced this pull request Sep 11, 2021
* Updated code mirror component for consistency

- Hide gutters, line number and selection while read only
- Show toolbar with copy functionality for all instances

* Moved toolbar and actions to json editor component

* Updated form-field-from-model template

* Added test for toolbar
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants