Re-implement tag-editing component #5553
Conversation
@ErisDS I added the new |
@JohnONolan I was trying to get the input to work similar to pocket.co's tag input, but unfortunately I could not get it to work exactly like it. In the pocket.co version, the input is moved between tags as the user moves left and right with the arrow keys. Because we are using typeahead, doing that is not trivial and results in a lot of computational overhead. However, I did make it so that a user can traverse the current list of tags with the left and right arrow keys, with the currently selected one being highlighted. Because the user is able to traverse between the tags with the arrow keys, is it okay to remove the click-to-delete-tag functionality for the moment? It will allow me to implement the jqueryui drag-n-drop behavior in a much simpler fashion. It could perhaps be added back in once the css is fixed and the "x" icon is added back in. |
Sounds good to me - let's get it in, test it and see how it goes |
@acburdine Gave this a quick look.
|
@halfdan Fixed all that you suggested. As to tags not saving, they are saving for me just fine. The reason they are not showing up in Ember inspector is because the tag input bypasses the ember data store altogether in favor of direct api calls. |
There's an issue currently that @halfdan pointed out where the tags are not saving correctly when the post is saved. I tracked this down to the embedded tags relationship in the post model. The issue is that when the tag input component saves the list of tags, the post tags relationship does not get updated in the ember-data store, which results in the tags being overridden by whatever was in the post model on post save. I could, in theory, update the post model with the new updated tags after the tag input saves them, which would be the simplest option, however that would result in the same list of tags being saved twice, which I would think is unnecessary. There are a few other ways I can think of to solve this.
|
There is some discussion about this on the issue here. The major point being I have little-to-no idea what can or can't be done with ember and ember-data, and was looking for guidance from the people in the know to check the API design would work. The options from an API design perspective are: leave it as it is ( The major concern is ensuring that this is reliable because bugs like #4999 are the worst kind of bugs. |
@@ -305,6 +305,99 @@ posts = { | |||
|
|||
return deletedObj; | |||
}); | |||
}, | |||
|
|||
getTags: function getTags(options) { |
ErisDS
Jul 22, 2015
Member
The naming of these methods needs some consideration. Currently we use consistent 'BREAD' names like api.posts.read()
, not 100% sure at this moment how to extend that pattern to include nested relations. I'm thinking it ought to be something along the lines of: api.posts.tags.edit()
?
The naming of these methods needs some consideration. Currently we use consistent 'BREAD' names like api.posts.read()
, not 100% sure at this moment how to extend that pattern to include nested relations. I'm thinking it ought to be something along the lines of: api.posts.tags.edit()
?
acburdine
Jul 22, 2015
Author
Member
I would agree
I would agree
Okay. Given that comment thread I would think the best thing to do would be to switch the post model in Ember back to being a traditional async model instead of an embedded record. |
I think that the best way to move forward with this might be to revert back to something closer to the existing version, using the current API endpoint. The only reason for changing the endpoints was if it helped to make the ember code easier to write and more robust, whereas the change here seems to be causing more problems than it is solving. Having a robust, working version of the tag component with the same functionality as now (no drag and drop required), which lives inside the PSM and saves safely, is the priority for this issue. Drag and drop can be added later. |
Drag and drop is already working minus one function to re-order the tags on drop. Should I go ahead and complete dragndrop or no? |
I would focus on making sure everything else is 100% before looking to complete drag and drop. |
@ErisDS I hooked up the component directly to the post model instead of directly interacting with the API. That way, all data goes through the store and we don't get duplicate saves. That should finish up the main part of this. I will work on tests to get this finished. @jaswilli / @novaugust / @kevinansfield can you give this a once-over? I may re-order some of the functions in the tag component but all the functionality is there. |
@ErisDS about half-done with casper tests, should be able to finish those up tomorrow. |
I haven't had a chance to dig in too deeply yet but at first glance it seems that there may be some tight coupling between the tags input and the post model. Have you thought about making the input more focused on being a reusable input component and having the post-settings-menu controller deal with the post/tag specifics? Eg, something like:
If you tried this route were there any issues that you ran into? |
@kevinansfield I hadn't tried that, but IMO tight coupling between tags input and the post model is necessary in this situation. The primary reason I think is because of situations like #4999, because in the old tag input the tags were bound directly to the post model's tags. Another reason I think is that if it is bound directly to the post tags, and the post autosaves when the user has created new (but mistyped) tags, there is nothing to prevent those new tags from saving with the post. It also keeps the tag-input adding, deleting, and loading functions more cohesive. It wouldn't be hard to move the code out into the PSM controller, but I don't personally think it's necessary. If we need a re-usable input component in the future I can always abstract the necessary stuff out into a mixin. |
Cool, that's fair enough. My thinking behind that suggestion was that looking forward to apps it would be good to ensure that any core UI components are re-usable. There's a push to get zelda shipped so let's focus on functionality for now :) |
Ah okay I see your thinking now |
Hey @acburdine have taken this for a quick spin, at first, I couldn't seem to get an new tag to save. I think though it's something to do with the fact that clicking off of the tag component doesn't complete the last tag and there is no save triggered? |
I'm seeing a lot of bugs with this:
|
@ErisDS I'll try and get all of those fixed today. |
Reproduction steps for the 2 gnarly bugs: Create a new post with a brand new tag, and press save. Refresh and the tag is gone.Steps:
ghost tag on a new post
With the first one, the title should always have focus when opening a new post, when editing an existing post the focus is not meant to be on any input. With the second, making it so that defocusing the component results in the last tag being completed and saved, should help? |
@ErisDS I fixed all the bugs. I was getting a weird Casper error on local but maybe it was just me, will see what the Travis tests rustle up. |
bindKeys: function () { | ||
var self = this; | ||
|
||
key('enter, tab, ,', 'tags', function (event) { |
ErisDS
Aug 6, 2015
Member
Does this take into account that the comma is different in different locales? The original code was:
isComma = ','.localeCompare(String.fromCharCode(event.keyCode || event.charCode)) === 0;
This has regressed twice before, so I'm keen to avoid it happening again.
Does this take into account that the comma is different in different locales? The original code was:
isComma = ','.localeCompare(String.fromCharCode(event.keyCode || event.charCode)) === 0;
This has regressed twice before, so I'm keen to avoid it happening again.
acburdine
Aug 7, 2015
Author
Member
I think it's fixable, I'll have to play around with the keymaster library to see though.
I think it's fixable, I'll have to play around with the keymaster library to see though.
ErisDS
Aug 8, 2015
Member
Shall we have a separate issue to finish that off?
Shall we have a separate issue to finish that off?
This is now working much better @jaswilli @kevinansfield any code review comments? |
@ErisDS I added a check for the isComma behavior, and it seemed to work on my end, so all should be good now |
Eek there's a linting error |
refs #3800 - remove old tag editor code - reimplement tag editor as an ember component - add tag editor component to PSM
Re-implement tag-editing component
refs #3800
This PR re-implements the tag component into Zelda, as well as fixes a number of issues with the old one. The biggest change in this PR is the decision to implement a typeahead library to smooth over the autocomplete code.
While the styles will need to be fixed after this PR, the functionality will exist and work.
Task List: