Skip to content
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

WebUI: Replace getElements & getChildren #22220

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

skomerko
Copy link
Contributor

This PR further reduces Mootools usage.

@skomerko skomerko changed the title WebUI: Replace getElements WebUI: Replace getElements & getChildren Jan 30, 2025
for (let i = 0; i < trs.length; ++i) {
if (trs[i].rowId === rowId)
return trs[i];
for (const tr of this.getTrs()) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you can use Array.find() instead. And with special handling to the undefined case.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Collection returned by getTrs is not an Array - it's a NodeList and we can't use Array.find() and others without for e.g converting it first. Should I do it in all reviewed cases or keep everything as is?

@@ -490,7 +490,9 @@ window.addEventListener("DOMContentLoaded", () => {
const categoryList = document.getElementById("categoryFilterList");
if (!categoryList)
return;
categoryList.getChildren().each(c => c.destroy());

for (const category of categoryList.querySelectorAll("li"))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Won't this be fragile? Also it looks like it will get grandchildren too.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment on lines 638 to 640
for (let i = 0; i < columns.length; ++i) {
if (columns[i].textContent === "Enabled")
return i;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be possible to use Array.findIndex().

Comment on lines +947 to +950
for (const tr of this.getTrs()) {
if (!tr.classList.contains("invisible") && (tr.style.display !== "none"))
visibleRows.push(tr);
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems you can use Array.filter().

Comment on lines +972 to +976
const visibleRows = [];
for (const tr of this.getTrs()) {
if (!tr.classList.contains("invisible") && (tr.style.display !== "none"))
visibleRows.push(tr);
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems you can use Array.filter().

@Chocobo1 Chocobo1 added the WebUI WebUI-related issues/changes label Jan 30, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
WebUI WebUI-related issues/changes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants