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

Add UI Toolkit to the platform #11799

Closed
wants to merge 37 commits into from

Conversation

andy-armstrong
Copy link
Contributor

@openedx-webhooks
Copy link

PR Cover Letter

UITK-75

This adds the UI Toolkit to edx-platform, and then starts to convert the platform to use the new HtmlUtils class. I've primarily converted the Teams UI, along with the shared helper classes and Underscore templates that they depend upon.

In addition, the static path for the Pattern Library has been made /static/edx-pattern-library instead of just /static/pattern-library. This change was already made in the Pattern Library so it was made here too for consistency.

Note that this PR can't merge until Underscore.js has been upgraded by https://github.com/edx/edx-platform/pull/11631.

Sandbox

Testing

  • Unit, integration, acceptance tests as appropriate

Reviewers

If you've been tagged for review, please check your corresponding box once you've given the 👍.

FYI: @AlasdairSwan @dan-f @dsjen @bjacobel

Post-review

  • Squash commits

@andy-armstrong andy-armstrong force-pushed the andya/add-ui-toolkit branch 4 times, most recently from 5ce548c to 1028dd1 Compare March 14, 2016 04:27
'inProgress': '<i class="fa fa-spinner fa-pulse message-in-progress" aria-hidden="true"></i><span class="sr">' + gettext("In Progress") + '</span>',
'success': '<i class="fa fa-check message-success" aria-hidden="true"></i><span class="sr">' + gettext("Success") + '</span>',
'plus': '<i class="fa fa-plus placeholder" aria-hidden="true"></i><span class="sr">' + gettext("Placeholder")+ '</span>'
'canEdit': HtmlUtils.HTML(
Copy link
Contributor

Choose a reason for hiding this comment

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

  1. interpolateHtml so the getText() is escaped.
  2. Rename canEdit to canEditHtml if possible, or move to a template.

@andy-armstrong
Copy link
Contributor Author

Thanks for the thorough (and ongoing) review, @robrap and @cahrens.

One theme that keeps coming up is why I used HtmlUtils.interpolateHtml instead of StringUtils.interpolate for strings that don't have HTML. My thinking at the time was that the value was being passed to a field that accepts HTML, so it seemed logical to provide it as such. We have also discussed renaming all such fields to fooHtml to make it clearer that that the field supports HTML.

Reflecting on it more, we are saying that HTML fields will always allow raw strings to be passed, because the best practice says that templates will use a helper that will escape raw strings while passing HTML snippets through. Given this, I agree with you both that I should use StringUtils.interpolate whenever possible so that I am not escaping too early. It is up to each template to be responsible for escaping its values appropriately.

The naming convention of fooHtml should indicate that a template allows HTML to be passed in addition to raw strings. A client of a template shouldn't pass HTML snippets to a field that is not named fooHtml because the code could be using <%- to do its escaping and hence would double escape the HTML. This argues for being very strict about the naming convention, which I'm happy to go with if that's what folks think, but it would be an even more onerous change. If we don't do this, then developers can risk passing HTML snippets to fields that aren't named fooHtml, but then it is their responsibility to write tests that verify that the result isn't double escaped.

I'll make a second pass through this PR once you guys complete your reviews. Thanks.

@@ -183,13 +184,13 @@

showUploadInProgressMessage: function () {
this.$('.u-field-upload-button').css('opacity', 1);
this.$('.upload-button-icon').html(this.iconProgress);
this.$('.upload-button-icon').html(this.iconProgressHtml.toString());
Copy link
Contributor

Choose a reason for hiding this comment

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

Throwing out some ideas here:

this.$('.upload-button-icon').html(HtmlUtils.forJQuery(this.iconProgressHtml));

or

this.$('.upload-button-icon').html(HtmlUtils.for$(this.iconProgressHtml));

Again, these are just other alternative names for escape(), but maybe you'll like them more and we can have something consistent for the linter. For example, this could still work with interpolateHtml() as such...

this.$('.upload-button-icon').html(HtmlUtils.for$(HtmlUtils.interpolateHtml(...)));

Copy link
Contributor

Choose a reason for hiding this comment

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

Another possibility is:

this.$('.upload-button-icon').html(HtmlUtils.$html(this.iconProgressHtml));

Copy link

Choose a reason for hiding this comment

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

Does this mean that the toString method does some sort of escaping? I'm confused.

@robrap
Copy link
Contributor

robrap commented Mar 18, 2016

@andy-armstrong I doubt we will ever be able to be strict about naming, because the linting rules would get too complex, but we should have best practices. It sounds like you are proposing we use the name titleHtml for a variable the could be either HTML or plain text. I think that's fair. Again, I'm not sure that we'll be able to be strict about it.

Upgrade Underscore.js and Underscore.string.js
@cahrens
Copy link

cahrens commented Mar 18, 2016

@andy-armstrong I'm done with my pass, but there are still some pretty fundamental things that I don't understand about when/how to escape HTML (that should be HTML). I think I will need some intervention on Monday.

@robrap
Copy link
Contributor

robrap commented Mar 18, 2016

@andy-armstrong @cahrens @nedbat I put together a Confluence page because I wanted to collect my thoughts. We can discuss there as well, and adjust the page as necessary:
https://openedx.atlassian.net/wiki/display/TNL/HtmlUtils+Helpers+for+JavaScript

@andy-armstrong
Copy link
Contributor Author

Closing in favor of a new PR against master.

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.

None yet