Skip to content

Commit 7edf423

Browse files
authored
Merge pull request #33 from soderlind/fix/search
Bump version to 1.7.3 and update changelog for improved search functi…
2 parents fdadfd0 + 86f4eab commit 7edf423

File tree

9 files changed

+111
-20
lines changed

9 files changed

+111
-20
lines changed
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
name: Manual Deploy Release to WordPress.org
2+
on:
3+
workflow_dispatch:
4+
inputs:
5+
tag:
6+
description: 'Tag to deploy'
7+
required: true
8+
type: string
9+
default: ''
10+
jobs:
11+
tag:
12+
name: New tag
13+
runs-on: ubuntu-latest
14+
steps:
15+
- name: Install Subversion
16+
run: sudo apt-get update && sudo apt-get install -y subversion
17+
18+
- name: Checkout code
19+
uses: actions/checkout@v4
20+
with:
21+
ref: ${{ github.event.inputs.tag }}
22+
23+
- name: WordPress Plugin Deploy
24+
uses: 10up/action-wordpress-plugin-deploy@stable
25+
env:
26+
SVN_PASSWORD: ${{ secrets.SVN_PASSWORD }}
27+
SVN_USERNAME: ${{ secrets.SVN_USERNAME }}
28+
SLUG: super-admin-all-sites-menu

CHANGELOG.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,14 @@
11
# Changelog
22

3+
### 1.7.3
4+
5+
- Fixed search functionality:
6+
- Improved search performance with better indexing
7+
- Added mutation observer to handle dynamically loaded sites
8+
- Fixed event handling for search input
9+
- Added improved error handling for search elements
10+
- Better handling of empty search inputs
11+
312
### 1.7.2
413

514
- Bump version to trigger a deploy to WordPress.org

build/index.asset.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
<?php return array('dependencies' => array('wp-api-fetch', 'wp-i18n'), 'version' => '598e59804b1aee3f1164');
1+
<?php return array('dependencies' => array('wp-api-fetch', 'wp-i18n'), 'version' => '6df7975b628e4eda2261');

build/index.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "soderlind/super-admin-all-sites-menu",
33
"description": "For the super admin, replace WP Admin Bar My Sites menu with an All Sites menu.",
4-
"version": "1.7.1",
4+
"version": "1.7.3",
55
"keywords": [
66
"wordpress",
77
"multisite",

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "super-admin-all-sites-menu",
3-
"version": "1.7.2",
3+
"version": "1.7.3",
44
"description": "For the super admin, replace WP Admin Bar My Sites menu with an All Sites menu.",
55
"main": "index.js",
66
"scripts": {

readme.txt

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
=== Super Admin All Sites Menu ===
2-
Stable tag: 1.7.2
2+
Stable tag: 1.7.3
33
Requires at least: 5.6
44
Tested up to: 6.7
55
Requires PHP: 7.3
@@ -108,6 +108,14 @@ You can use the following filters to override the defaults:
108108

109109
== Changelog ==
110110

111+
= 1.7.3 =
112+
* Fixed search functionality:
113+
* Improved search performance with better indexing
114+
* Added mutation observer to handle dynamically loaded sites
115+
* Fixed event handling for search input
116+
* Added improved error handling for search elements
117+
* Better handling of empty search inputs
118+
111119
= 1.7.2 =
112120

113121
- Bump version to trigger a deploy to WordPress.org

src/modules/search.js

Lines changed: 58 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,28 +11,74 @@ const debounce = ( fn, delay ) => {
1111
};
1212
};
1313

14+
/**
15+
* Add search functionality to the sites menu
16+
* @returns {void}
17+
*/
1418
export function addSearch() {
19+
// Use more specific selector and verify element exists
1520
const search = document.querySelector( '#all-sites-search-text' );
16-
if ( ! search ) return;
21+
if ( ! search ) {
22+
console.warn( 'Search input not found' );
23+
return;
24+
}
25+
26+
// Get the sites list container
27+
const sitesContainer = document.querySelector(
28+
'#wp-admin-bar-my-sites-list'
29+
);
30+
if ( ! sitesContainer ) {
31+
console.warn( 'Sites container not found' );
32+
return;
33+
}
34+
35+
// Create search index on first load
36+
const createSearchIndex = () => {
37+
const menuItems =
38+
sitesContainer.getElementsByClassName( 'menupop' ) || [];
39+
return Array.from( menuItems ).map( ( li ) => ( {
40+
element: li,
41+
text:
42+
li
43+
.querySelector( '.ab-item' )
44+
?.textContent?.toLowerCase()
45+
.trim() || '',
46+
} ) );
47+
};
1748

18-
const ul = document.querySelector( '#wp-admin-bar-my-sites-list' );
19-
const menuItems = ul?.getElementsByClassName( 'menupop' ) || [];
49+
let searchIndex = createSearchIndex();
2050

21-
// Create index for faster searching
22-
const searchIndex = Array.from( menuItems ).map( ( li ) => ( {
23-
element: li,
24-
text: li.querySelector( '.ab-item' )?.textContent?.toUpperCase() || '',
25-
} ) );
51+
// Perform search with improved filtering
52+
const performSearch = debounce( ( searchTerm ) => {
53+
const filter = searchTerm.toLowerCase().trim();
2654

27-
const performSearch = debounce( ( filter ) => {
28-
const upperFilter = filter.toUpperCase();
55+
// Show all items if search is empty
56+
if ( ! filter ) {
57+
searchIndex.forEach( ( { element } ) => {
58+
element.style.display = '';
59+
} );
60+
return;
61+
}
62+
63+
// Filter items
2964
searchIndex.forEach( ( { element, text } ) => {
30-
element.style.display = text.includes( upperFilter ) ? '' : 'none';
65+
element.style.display = text.includes( filter ) ? '' : 'none';
3166
} );
3267
}, 150 );
3368

34-
search.addEventListener( 'keyup', ( e ) => {
69+
// Add input event listener (catches all input changes)
70+
search.addEventListener( 'input', ( e ) => {
3571
e.preventDefault();
3672
performSearch( e.target.value );
3773
} );
74+
75+
// Re-index when new sites are loaded
76+
const observer = new MutationObserver( () => {
77+
searchIndex = createSearchIndex();
78+
} );
79+
80+
observer.observe( sitesContainer, {
81+
childList: true,
82+
subtree: true,
83+
} );
3884
}

super-admin-all-sites-menu.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
* Plugin URI: https://github.com/soderlind/super-admin-all-sites-menu
1313
* GitHub Plugin URI: https://github.com/soderlind/super-admin-all-sites-menu
1414
* Description: For the super admin, replace WP Admin Bar My Sites menu with an All Sites menu.
15-
* Version: 1.7.2
15+
* Version: 1.7.3
1616
* Author: Per Soderlind
1717
* Network: true
1818
* Author URI: https://soderlind.no
@@ -31,7 +31,7 @@
3131
* Default values for the plugin.
3232
*/
3333
const LOADINCREMENTS = 100; // Number of sites to load at a time.
34-
const SEARCHTHRESHOLD = 20; // Number of sites before showing the search box.
34+
const SEARCHTHRESHOLD = 2; // Number of sites before showing the search box.
3535
const CACHE_EXPIRATION = DAY_IN_SECONDS; // Time to cache the site list.
3636
const ORDERBY = 'name'; // Order by name.
3737
const PLUGINS = [ 'restricted-site-access/restricted_site_access.php' ]; // Plugins triggering update local storages.

0 commit comments

Comments
 (0)