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

UI: Refactors the code-mirror linting #4866

Merged
merged 1 commit into from
Nov 6, 2018

Conversation

johncowen
Copy link
Contributor

Also see:

#4814 (comment)

This moves the extra code mirror linting functionality into a separate service so I'm not changing things I don't own.

I also noticed that when editing rules of legacy tokens the editor wasn't restricted to HCL only, so this adds an attribute to the component for that view to restrict the editor to HCL only.

I also considered moving the mode configuration into ember configuration, but decided against in the end as I don't want all of this configuration going in a meta tag attribute. There's still some nice work that could be done on top of this, but for now I'll at least wait until we revisit the look and feel also.

@johncowen johncowen added the theme/ui Anything related to the UI label Oct 29, 2018
@johncowen johncowen requested a review from a team October 29, 2018 12:00
@johncowen johncowen added this to the 1.4.0 milestone Oct 29, 2018
Copy link
Contributor

@pearkes pearkes left a comment

Choose a reason for hiding this comment

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

Looks good to me, minor feedback. Also should this be in 1.4.0 final? It’s tagged as such but not sure it should unless it is fixing a bug of some kind .

@@ -15,7 +15,7 @@
{{/if}}
<label class="type-text">
<span>Rules <a href="{{env 'CONSUL_DOCUMENTATION_URL'}}/guides/acl.html#rule-specification" rel="help noopener noreferrer" target="_blank">(HCL Format)</a></span>
{{code-editor class=(if item.error.Rules 'error') name='Rules' value=item.Rules onkeyup=(action 'change' 'Rules')}}
{{code-editor class=(if item.error.Rules 'error') name='Rules' syntax='hcl' value=item.Rules onkeyup=(action 'change' 'Rules')}}
Copy link
Contributor

Choose a reason for hiding this comment

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

I see we're doing a item.name.toLowerCase() == syntax.toLowerCase() on this syntax param. It caught me a bit by surprise given it wasn't an alias or a name (hcl) and I was wondering how it knew to select HCL. Maybe just worth making it an alias instead of doing that for readability?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You mean an ember alias yeah? Do you know how that would help here? I thought an alias was to point one property to another?

The toLowerCase was just good hygiene really, I took the mode specs from the code-mirror source and the properties/'syntax names' are in uppercase, and I didn't want to change that, so I thought there would always be the slight chance of confusion as to whether to say syntax="HCL" or syntax="hcl"

Actually looking at it I could at least use === not ==

Anyway, lemme know on the alias thing, maybe I've misunderstood what you meant.

Copy link
Contributor

Choose a reason for hiding this comment

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

Oh I meant https://github.com/hashicorp/consul/pull/4866/files/98acdadaf1a3597bd3e36247b6e321aa3b1826c3#diff-c79b0ce21a1201a8516d52bd57f5404bR17 one of those things. I might be really confused.

Just hygienic regardless so LGTM.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ahh, of course (sorry just realized what you meant now), you're not confused, I am!

This will end up going in post 1.4.0, but if you are interested in the background (more or less), here goes:

So, that JSON blob is taken directly from the codemirror modes.js file (I think its called that). That file is massive and contains a load of stuff I'll never need (it has ALL the different modes it supports). So I took the bits I need from it, but I want to leave it as close the original source as possible.

The HCL part of the blob is actually the 'ruby' one from codemirror, I just changed the name: but kept it uppercase to be consistent to the other names. So essentially HCL 'mode' is actually 'ruby' mode. I chose the syntax name for the attribute as it made sense to me, and I didn't want to use name as that means something else in HTML and mode didn't seem quite right as this is ruby mode..but hcl :S

To choose the syntax/mode, it just looks through the JSON blob, looking for 'HCL'.toLowerCase(). I could have just hardcoded the names in the JSON blob to be lowercase, but see above about wanting to change as little as possible.

@johncowen
Copy link
Contributor Author

Hey!

Thanks for having a look!

Looks good to me, minor feedback. Also should this be in 1.4.0 final? It’s tagged as such but not sure it should unless it is fixing a bug of some kind .

It addresses a tiny bug:

I also noticed that when editing rules of legacy tokens the editor wasn't restricted to HCL only, so this adds an attribute to the component for that view to restrict the editor to HCL only.

So if the linting editor is to go in 1.4.0 then this should also really.

John

@pearkes
Copy link
Contributor

pearkes commented Oct 30, 2018

@johncowen sounds good!

@johncowen johncowen removed this from the 1.4.0 milestone Nov 1, 2018
@johncowen johncowen changed the base branch from master to ui-staging November 2, 2018 09:56
@johncowen
Copy link
Contributor Author

Just for reference, the bug fix in here has been done in a separate PR, so this one can wait for merging for the moment - I'm changed the base branch also

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
theme/ui Anything related to the UI
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants