Skip to content

Commit

Permalink
Merge pull request #33 from soderlind/fix/search
Browse files Browse the repository at this point in the history
Bump version to 1.7.3 and update changelog for improved search functi…
  • Loading branch information
soderlind authored Jan 8, 2025
2 parents fdadfd0 + 86f4eab commit 7edf423
Show file tree
Hide file tree
Showing 9 changed files with 111 additions and 20 deletions.
28 changes: 28 additions & 0 deletions .github/workflows/manual-deploy-release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
name: Manual Deploy Release to WordPress.org
on:
workflow_dispatch:
inputs:
tag:
description: 'Tag to deploy'
required: true
type: string
default: ''
jobs:
tag:
name: New tag
runs-on: ubuntu-latest
steps:
- name: Install Subversion
run: sudo apt-get update && sudo apt-get install -y subversion

- name: Checkout code
uses: actions/checkout@v4
with:
ref: ${{ github.event.inputs.tag }}

- name: WordPress Plugin Deploy
uses: 10up/action-wordpress-plugin-deploy@stable
env:
SVN_PASSWORD: ${{ secrets.SVN_PASSWORD }}
SVN_USERNAME: ${{ secrets.SVN_USERNAME }}
SLUG: super-admin-all-sites-menu
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
# Changelog

### 1.7.3

- Fixed search functionality:
- Improved search performance with better indexing
- Added mutation observer to handle dynamically loaded sites
- Fixed event handling for search input
- Added improved error handling for search elements
- Better handling of empty search inputs

### 1.7.2

- Bump version to trigger a deploy to WordPress.org
Expand Down
2 changes: 1 addition & 1 deletion build/index.asset.php
Original file line number Diff line number Diff line change
@@ -1 +1 @@
<?php return array('dependencies' => array('wp-api-fetch', 'wp-i18n'), 'version' => '598e59804b1aee3f1164');
<?php return array('dependencies' => array('wp-api-fetch', 'wp-i18n'), 'version' => '6df7975b628e4eda2261');
4 changes: 2 additions & 2 deletions build/index.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "soderlind/super-admin-all-sites-menu",
"description": "For the super admin, replace WP Admin Bar My Sites menu with an All Sites menu.",
"version": "1.7.1",
"version": "1.7.3",
"keywords": [
"wordpress",
"multisite",
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "super-admin-all-sites-menu",
"version": "1.7.2",
"version": "1.7.3",
"description": "For the super admin, replace WP Admin Bar My Sites menu with an All Sites menu.",
"main": "index.js",
"scripts": {
Expand Down
10 changes: 9 additions & 1 deletion readme.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
=== Super Admin All Sites Menu ===
Stable tag: 1.7.2
Stable tag: 1.7.3
Requires at least: 5.6
Tested up to: 6.7
Requires PHP: 7.3
Expand Down Expand Up @@ -108,6 +108,14 @@ You can use the following filters to override the defaults:

== Changelog ==

= 1.7.3 =
* Fixed search functionality:
* Improved search performance with better indexing
* Added mutation observer to handle dynamically loaded sites
* Fixed event handling for search input
* Added improved error handling for search elements
* Better handling of empty search inputs

= 1.7.2 =

- Bump version to trigger a deploy to WordPress.org
Expand Down
70 changes: 58 additions & 12 deletions src/modules/search.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,28 +11,74 @@ const debounce = ( fn, delay ) => {
};
};

/**
* Add search functionality to the sites menu
* @returns {void}
*/
export function addSearch() {
// Use more specific selector and verify element exists
const search = document.querySelector( '#all-sites-search-text' );
if ( ! search ) return;
if ( ! search ) {
console.warn( 'Search input not found' );
return;
}

// Get the sites list container
const sitesContainer = document.querySelector(
'#wp-admin-bar-my-sites-list'
);
if ( ! sitesContainer ) {
console.warn( 'Sites container not found' );
return;
}

// Create search index on first load
const createSearchIndex = () => {
const menuItems =
sitesContainer.getElementsByClassName( 'menupop' ) || [];
return Array.from( menuItems ).map( ( li ) => ( {
element: li,
text:
li
.querySelector( '.ab-item' )
?.textContent?.toLowerCase()
.trim() || '',
} ) );
};

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

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

const performSearch = debounce( ( filter ) => {
const upperFilter = filter.toUpperCase();
// Show all items if search is empty
if ( ! filter ) {
searchIndex.forEach( ( { element } ) => {
element.style.display = '';
} );
return;
}

// Filter items
searchIndex.forEach( ( { element, text } ) => {
element.style.display = text.includes( upperFilter ) ? '' : 'none';
element.style.display = text.includes( filter ) ? '' : 'none';
} );
}, 150 );

search.addEventListener( 'keyup', ( e ) => {
// Add input event listener (catches all input changes)
search.addEventListener( 'input', ( e ) => {
e.preventDefault();
performSearch( e.target.value );
} );

// Re-index when new sites are loaded
const observer = new MutationObserver( () => {
searchIndex = createSearchIndex();
} );

observer.observe( sitesContainer, {
childList: true,
subtree: true,
} );
}
4 changes: 2 additions & 2 deletions super-admin-all-sites-menu.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
* Plugin URI: https://github.com/soderlind/super-admin-all-sites-menu
* GitHub Plugin URI: https://github.com/soderlind/super-admin-all-sites-menu
* Description: For the super admin, replace WP Admin Bar My Sites menu with an All Sites menu.
* Version: 1.7.2
* Version: 1.7.3
* Author: Per Soderlind
* Network: true
* Author URI: https://soderlind.no
Expand All @@ -31,7 +31,7 @@
* Default values for the plugin.
*/
const LOADINCREMENTS = 100; // Number of sites to load at a time.
const SEARCHTHRESHOLD = 20; // Number of sites before showing the search box.
const SEARCHTHRESHOLD = 2; // Number of sites before showing the search box.
const CACHE_EXPIRATION = DAY_IN_SECONDS; // Time to cache the site list.
const ORDERBY = 'name'; // Order by name.
const PLUGINS = [ 'restricted-site-access/restricted_site_access.php' ]; // Plugins triggering update local storages.
Expand Down

0 comments on commit 7edf423

Please sign in to comment.