Open user2684 opened 2 years ago
+1 have the same issue
Same issue here!
Took a look myself as I had the same issue, .at(-1)
tends to get the blank space element so I grabbed the array in Console and found where config
is not present media-browser
is the next last array item.
Let me know if the below works for you as well (because I am not sure if media-browser is a default), this is a full drop in for the getSidebarItem function:
function getSidebarItem(root) {
if (window.$customSidebarV2.SidebarItemElement) {
return window.$customSidebarV2.SidebarItemElement;
}
if (!root || !root.children) {
return;
}
//return Array.from(root.children).at(-1)
//return Array.from(root.children).find((element) => {
// return (
// element.tagName == 'A' && element.getAttribute('data-panel') == 'config'
// );
// }
let lastdatapanel = Array.from(root.children).find((element) => {
return (
element.tagName == 'A' && element.getAttribute('data-panel') == 'config'
);
});
if (!lastdatapanel) {
lastpanel = Array.from(root.children).find((element) => {
return (
element.tagName == 'A' && element.getAttribute('data-panel') == 'media-browser'
);
});
}
return lastpanel;
}
Also logged a PR with the above, though it may need cleaning up this was a 5-second fix and could probably be cleaner 👍
Hi, first of all thanks for refactoring this plugin and make it working with the latest version of HA :-) I noticed everything works fine for admin users but not for non administrators. The issue seems related to
getSidebarItem()
when called upon startup returningundefined
since looking for "data-panel
" equals to "config
" which is not there for a non admin user (https://github.com/galloween/custom-sidebar-v2/blob/main/dist/custom-sidebar-v2.js#L145). As a workaround a tried picking up the latest element (e.g..at(-1)
) ofwindow.$customSidebarV2.SideBarElement
which works but I'm sure it breaks out other things. Thanks!