Closed kamilkazmierczakMtab closed 1 month ago
+1
Thank you for the contribution! I will have another look at why the other error seems to come up.
In regards to the error in your second point, the logged error here seems to come from the call to focus the "Pizza" item in the story, but exandSubsequently
was just called on all items above that, with expandSubsequently(path.slice(0, path.length - 1))
it just expanded "root", "Meals" and "Europe", but then called the focus method on "Pizza" without waiting for it to be loaded in first.
As a dirty fix, it actually works fine when the target leaf is also included in the expandSubsequently
call with expandSubsequently(path)
, this will make the call wait until the Pizza leaf is loaded in as well. So something like this will fix it: https://github.com/lukasbach/react-complex-tree/commit/58e3ed9b3e372b0ec9e4f340eb0cc9bb2e106dea
This does have the disadvantage that the searched item will also be expanded if it is a folder, if this is not desired, some custom waiting would need to be implemented to make sure the item is loaded in before proceeding with doing things with it.
Issue solved:
expandSubsequently
does not wait to expand all items provided in argument. In rare cases it leads to errors.Additional info:
pizza
you will get errorCannot read properties of undefined (reading 'index')
this is similar to error that I was getting but my fix is not addressing that becauseEurope
item is not expanded before this function resolves - this is becauseonExpandItem
is not returning promise so I can't wait for it.@lukasbach