Open rliebz opened 10 years ago
I did some debugging of this. Following the events through the code, everything seems like it's working. The filtering on the collapsed folder returns back the proper structure, which makes sense because you can see it being correct in the view. I haven't quite gotten to the level of understanding with HGrid that I can tell what needs to be done that isn't being done, but I can poke around a bit more. @sloria would probably have a better idea.
In the picture below, if I collapse '3', I cannot drag 'c' into '2' or '4'. If I expand 3 again, they become valid targets.
What I think is happening is that Tree.prototype.collapse() is, first, not setting a default value for refresh, so if you don't explicitly set refresh to true, it doesn't do so. Probably that default should be set to true, so
Tree.prototype.collapse = function(hideSelf, refresh) {
if(typeof refresh === 'undefined'){
refresh = true;
}
Or similar (there's a quick JS way to do this, but I'm old fashioned). The next bit is that it looks like, even with the refresh, it's only updating the items contained by the folder, not getting the things that are under the folder at the same level or higher. So I think you need to start at the index of the folder, grab all the items below in the list, and update those items as well.
No, that wasn't it. Still exploring. The part where it all definitely goes wrong is in the rowmovemanager's handeDrag().
// The moved data items
var movedItems = dd.selectedRows.map(function(rowIdx) {
return _grid.getData().getItemByIdx(rowIdx);
});
dd.movedItems = movedItems;
The getItemByIdx is returning an index based on all rows regardless of visibility. The collapsed rows are still in the grid, but are not visible. The big question is why it's true there but not in other places, and I'm not sure if it's because other places in the code have access to the item rather than just the index, or…
getItemByIdx() gets items[i], but getLength() that is called by another function that updates is using rows[] instead of items[]. Rows is apparently updated to hide the hidden data unlike items. So perhaps getDataItem is what we want.
…aaaand it is! Yay.
There is a previously unnoticed other aspect to this that was documented in https://github.com/CenterForOpenScience/openscienceframework.org/issues/779.
For more information, see CenterForOpenScience/openscienceframework.org/issues/723