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

Add ability to filter the container list #2390

Merged
merged 1 commit into from
Jul 27, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 10 additions & 0 deletions src/css/popup.css
Original file line number Diff line number Diff line change
Expand Up @@ -2374,3 +2374,13 @@ tr:hover > td > .trash-button {
.overflow .panel.onboarding {
margin-block: auto;
}

/* Searchbar */
.searchbar {
margin-block: 4px -4px;
padding-inline: 16px;
}

.searchbar input {
inline-size: 100%;
}
19 changes: 18 additions & 1 deletion src/js/popup.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ async function getExtensionInfo() {
return extensionInfo;
}


// This object controls all the panels, identities and many other things.
const Logic = {
_identities: [],
Expand Down Expand Up @@ -465,6 +464,23 @@ const Logic = {
default:
break;
}
},

filterContainerList() {
const pattern = /^\s+|\s+$/g;
const list = Array.from(document.querySelectorAll("#identities-list tr"));
const search = document.querySelector("#search-terms").value.replace(pattern, "").toLowerCase();

for (const i in list) {
const text = list[i].querySelector("td div span");

if (text.innerText.replace(pattern, "").toLowerCase().includes(search) ||
!search) {
list[i].style.display = "block";
} else {
list[i].style.display = "none";
}
}
}
};

Expand Down Expand Up @@ -847,6 +863,7 @@ Logic.registerPanel(P_CONTAINERS_LIST, {

document.addEventListener("keydown", Logic.keyboardNavListener);
document.addEventListener("keydown", Logic.shortcutListener);
document.addEventListener("input", Logic.filterContainerList);

MozillaVPN.handleContainerList(identities);

Expand Down
12 changes: 12 additions & 0 deletions src/popup.html
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,18 @@ <h4 class="moz-vpn-logotype vpn-status-container-list display-none">Mozilla VPN
</h4>
</div>
<div class="scrollable identities-list">
<div class="searchbar">
<label for="search-terms"
class="hide-label"
data-i18n-message-id="filterInputLabel">
Copy link
Collaborator

Choose a reason for hiding this comment

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

I don't see this (Filter container list by name:) in the GIF. How is this used?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The label is for screen reader only.

</label>
<input type="text"
id="search-terms"
name="search-terms"
placeholder="Search container name"
data-i18n-attribute="placeholder"
data-i18n-attribute-message-id="filterInputPlaceholder">
</div>
<table class="menu" id="identities-list">
<tr class="menu-item hover-highlight">
<td>
Expand Down