-
-
Notifications
You must be signed in to change notification settings - Fork 1.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
Move editing of shipment method and tracking into JS views and templates #2225
Move editing of shipment method and tracking into JS views and templates #2225
Conversation
9b2400e
to
05cccac
Compare
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.
Thanks. Poked around in the sandbox and it's working well.
Well, besides that we do not let users submit our Backbone views with the enter key. 😿
I described below in the comments how this can be easily achieved. By using the barely known magic form
attribute of button
s.
I will send a PR with the changes that are needed to make this work. A huge improvement to UX we should embrace for all our Backbone based forms.
/c @Mandily
model: Spree.Models.Shipment, | ||
|
||
url: function () { | ||
return Spree.routes.shipments_api; |
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.
This doesn’t have to be a function if we use a static property
"click .js-edit": "onEdit", | ||
"click .js-save": "onSave", | ||
"click .js-cancel": "onCancel", | ||
"change select": "onChange", |
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 indentation is a little off here.
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.
Just saw, that the onChange
function is not defined in this view.
patch: true, | ||
success: function() { | ||
// FIXME: should update page without reloading | ||
window.location.reload(); |
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.
What is the reason that we need a full page reload? Just curious
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.
Changing the shipping method may change the amount of the order, so the sidebar needs updating. This will eventually be done without a reload, but is outside the scope of this PR (which is the first step towards removing it).
This doesn't introduce the reload, it was moved from here
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.
Thanks for clarification
|
||
events: { | ||
"click .js-edit": "onEdit", | ||
"click .js-save": "onSave", |
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.
It's very inconvenient one can't submit all our Backbone views with Enter key. We should change that.
If we would listen to submit form
events instead and wrap the fields into a form
(and use that magic submit button trick shown below) we can have both behaviours (enter key and click on the button) with the same event handler.
I will submit a PR with the changes to your PR.
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.
👍
</th> | ||
<td colspan="4"> | ||
{{#if editing}} | ||
<input type="text" name="tracking" class="fullwidth" value="{{tracking}}"> |
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.
If we would wrap this in a form
we could use the submit
event instead.
<form id="tracking_form">
Notice that we need to have that id
to connect the "save" button with this form as it sits outside of the form. But there is this barely known attribute of submit buttons called form
.
Very handy for our use case!
</td> | ||
<td class="actions"> | ||
{{#if editing}} | ||
<button class="js-save fa fa-check no-text with-tip" data-action="save" title="{{ t "actions.save" }}"></button> |
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.
In order to use the same submit
event we need to add
<button type="submit" form="tracking_form">
the form
attribute is important here.
Just as a heads up. Besides the PR to this PR here I am working on updating all Backbone based views to also support submitting via enter key (where it’s appropriate) |
7cbf529
to
d7d0473
Compare
I believe I've addressed the suggestions here. The last 4 commits here are poorly named and will be squashed into earlier commits, but I have kept them separate to ease reviews. |
d7d0473
to
ab2a300
Compare
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.
YAY!
Previously, this spec used some error-prone DOM manipulation: within_row(1) worked when there were two shipments only because the first row of the second table was a hidden tr (for edit shipping method) Some specs required specific css classes and were tied to the editing implementation hiding/showing different rows. Both of these issues are improved by matching rows based on their text using within('tr', text: ...) This also fixes an issue where a second shipment was unintentionally created in some specs.
This doesn't handle pluralization yet, we can add that when it becomes necessary.
Hide shipments until data is available
In order to give users the same UX they know from form fields, we need to wrap the tracking input field into a form and use a submit button as save button. Because the submit buttons sits outside of the form and we can't wrap the whole table row in a form (HTML semantics) we need to use the barely known form attribute of submit buttons. Now we can use the form submit event instead of the save button click event and one can submit the form by clicking the save button or by hitting the enter key inside the form. Use form submit event for saving order shipment
ab2a300
to
72c116a
Compare
This is the first step towards future work on two separate goals:
For both of these, we need the editing of shipping methods to be renderable by JS (it was previously an ERB view). This also does the same to he tracking method, which made sense to do at the same time since they used to share code.
This creates a Shipment backbone model and collection, and fetches it from the order API endpoint when loading the shipments page.
Two new handlebars helpers were needed to allow this:
human_model_name
which works likemodel_name.human
in ruby (but only supports the singular translation for now), andformat_money
which gives access to the existingSpree.formatMoney
function.