Conversation
Testing GuidelinesHi @senadir , Apart from reviewing the code changes, please make sure to review the testing instructions (Guide) and verify that relevant tests (E2E, Unit, Integration, etc.) have been added or updated as needed. Reminder: PR reviewers are required to document testing performed. This includes:
|
📝 WalkthroughWalkthroughThis patch consolidates numeric customer ID filters across name/email/username into unified include/exclude params, adds a new Changes
Sequence Diagram(s)mermaid Estimated code review effort🎯 4 (Complex) | ⏱️ ~45 minutes 🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
🧪 Generate unit tests (beta)
No actionable comments were generated in the recent review. 🎉 Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Test using WordPress PlaygroundThe changes in this pull request can be previewed and tested using a WordPress Playground instance. Test this pull request with WordPress Playground. Note that this URL is valid for 30 days from when this comment was last updated. You can update it by closing/reopening the PR or pushing a new commit. |
|
Wondering why this went undiscovered for so long? was it not being used anywhere in the UI? |
|
@senadir after seeing the test fail and further investigation, it looks like at some point the UI switched to an ID based approach, so |
|
fix it in v4 |
|
@senadir This isn't part of the v4 API, its analytics. Claude was able to fix the client pretty easily and tests are passing. I think we should see if anyone is more familiar with admin/analytics to make the final call on this. I'm updating the PR description if the client changes now. |
|
Size Change: -11 B (0%) Total Size: 5.98 MB |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Fix all issues with AI agents
In `@packages/js/components/src/search/autocompleters/customers.tsx`:
- Around line 82-87: Customer names with commas can be split by the backend's
explode(',', ...) on the name_includes param; update getOptionCompletion to stop
emitting raw names as the key used in filtering and instead return a stable
identifier (e.g., customer.id as the key) while keeping customer.name as the
label, and then ensure the code that builds the name_includes filter uses the
option.key (id) rather than option.label (name); this avoids sending
comma-containing names to the backend — alternatively, if you must send names,
encode/quote commas consistently before building name_includes, but prefer
switching to IDs via getOptionCompletion and downstream consumers.
🧹 Nitpick comments (1)
plugins/woocommerce/client/admin/client/analytics/report/customers/config.js (1)
128-137: Consider extracting the repeatedgetLabelspattern into a shared helper.The same comma-split-trim-filter-map logic is duplicated three times (for name, username, and email). A small helper would reduce duplication:
♻️ Suggested refactor
const getStringLabels = async ( value ) => value .split( ',' ) .map( ( v ) => v.trim() ) .filter( Boolean ) .map( ( item ) => ( { key: item, label: item } ) );Then reference
getLabels: getStringLabelsin each input config.Also applies to: 236-245, 287-296
|
I don't want to invest too much time in this now that I know we can use IDs but there were some other options here:
|
6404260 to
5904ba2
Compare
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Fix all issues with AI agents
In `@plugins/woocommerce/src/Admin/API/Reports/Customers/Controller.php`:
- Around line 120-154: consolidate_customer_id_filters currently overwrites any
pre-existing customers/customers_exclude and treats an empty include
intersection as "no filter" (which returns all customers); update
consolidate_customer_id_filters to merge consolidated IDs with any existing
$args['customers'] and $args['customers_exclude'] instead of overwriting: parse
any existing $args['customers']/$args['customers_exclude'] via wp_parse_id_list
and when merging apply the same semantics as the consolidation (if $match ===
'all' use array_intersect between the consolidated ids and the existing ids,
otherwise array_unique(array_merge(...))); additionally, when $match === 'all'
and the computed include intersection is empty, set $args['customers'] to a
single invalid ID (e.g., [0]) to force a no-results filter rather than leaving
an empty array that DataStore treats as "no filter".
🧹 Nitpick comments (3)
plugins/woocommerce/src/Admin/API/Reports/Customers/Controller.php (2)
156-176:is_numeric()is broader than integer IDs — consider tightening.
is_numeric()accepts floats (1.5), negative numbers (-1), and scientific notation (1e2). Whilewp_parse_id_listdownstream will coerce these viaabsint, this makes the detection less precise. For example,email_includes=1e2would be treated as customer ID 100.A stricter check like
ctype_digit(trim((string) $v))would only match non-negative integer strings, which is the actual intent.Suggested tightening
foreach ( $values as $v ) { - if ( ! is_numeric( trim( $v ) ) ) { + if ( ! ctype_digit( trim( (string) $v ) ) ) { return false; } }
106-119: Missing@sinceannotation on public method.
consolidate_customer_id_filtersis apublic staticmethod and should include a@sincetag with the current WooCommerce version. As per coding guidelines: "Use@sinceannotations in PHP code with the current version fromincludes/class-woocommerce.php, removing any-devsuffix."plugins/woocommerce/tests/php/includes/admin/class-wc-admin-reports-customers-controller-test.php (1)
643-981: Good coverage of the new functionality.The tests cover string-based exact-match filtering, numeric ID consolidation, and match semantics well. Two test gaps worth noting — both relate to the bugs flagged in
consolidate_customer_id_filters:
- No test for
match=allintersection producing an empty set (e.g.,name_includes=1&email_includes=2where 1 and 2 are disjoint). This is the scenario where the current code would return all customers instead of none.- No test for when the
customersparam is already populated alongside numericemail_includes/name_includes, verifying the values are merged rather than overwritten.Adding these would lock down the edge cases.
…y `customer_id` (#63232) * Update datastore to look at correct columns * Expand test coverage * Add changefile(s) from automation for the following project(s): woocommerce * Make client search by strings rather than client ids * Allow for either strings or IDs when using includes/excludes filter * Add changefile(s) from automation for the following project(s): woocommerce * Fix customer ID merging --------- Co-authored-by: woocommercebot <woocommercebot@users.noreply.github.com>
…y `customer_id` (#63232) * Update datastore to look at correct columns * Expand test coverage * Add changefile(s) from automation for the following project(s): woocommerce * Make client search by strings rather than client ids * Allow for either strings or IDs when using includes/excludes filter * Add changefile(s) from automation for the following project(s): woocommerce * Fix customer ID merging --------- Co-authored-by: woocommercebot <woocommercebot@users.noreply.github.com>
Submission Review Guidelines
Changes proposed in this Pull Request
This PR fixes two related bugs in the Customers Reports advanced filters:
DataStore column mapping bug (commit
4cda1bfd6c): Theexact_match_paramsin the DataStore were previously mappingemail_includes,username_includes, andname_includesto thecustomer_idcolumn instead of their respective columns (email,username,CONCAT_WS(' ', first_name, last_name)). This was fixed by changing the mapping to an associative array keyed by column expression.Frontend autocompleters send customer IDs, not strings: The frontend autocompleters for email, username, and name filters send customer IDs (integers) via params like
email_includes=5,12. After fixing the DataStore to match against actual column values, these numeric IDs would be matched against strings (e.g.,WHERE email IN ('5','12')), which returns nothing.The fix: Controller-level ID consolidation
Rather than changing the frontend autocompleters, the Controller now consolidates numeric customer IDs from
name_includes,email_includes, andusername_includes(and their_excludesvariants) into thecustomers/customers_excludeparams before they reach the DataStore. This way:customers/customers_excludeand filtered bycustomer_idThe consolidation respects the
matchparameter:match=all: include sets are intersected, exclude sets are unionedmatch=any: include sets are unioned, exclude sets are intersectedNew
customers_excludeparam: Added to both the Customers and Stats controllers/DataStore to support exclusion by customer ID.Files changed:
src/Admin/API/Reports/Customers/Controller.phpconsolidate_customer_id_filters(),is_id_list(),customers_excludeREST param and mappingsrc/Admin/API/Reports/Customers/Stats/Controller.phpcustomers_excludeREST param and mappingsrc/Admin/API/Reports/Customers/DataStore.phpcustomers_excludeNOT IN clausetests/.../class-wc-admin-reports-customers-controller-test.phpcustomers_excludeScreenshots or screen recordings
N/A - No visual UI changes.
How to test the changes in this Pull Request
Using the WooCommerce Testing Instructions Guide, include your detailed testing instructions:
GET /wc-analytics/reports/customers?email_includes=<known-email>— should return only the matching customer.GET /wc-analytics/reports/customers?email_excludes=<known-email>— should exclude the matching customer.username_includes/username_excludesandname_includes/name_excludes.GET /wc-analytics/reports/customers?customers_exclude=<customer-id>— should exclude the customer with that ID.Testing that has already taken place
wp-envDocker environment (PHP 8.1, PHPUnit 9.6.29).WC_Admin_Reports_Customers_Controller_Testpass (23 existing + 8 new).lint:php:changes).Milestone
Changelog entry
Changelog Entry Details
Significance
Type
Message
Fix Customers Reports advanced filters (email, username, name) by consolidating autocompleter customer IDs into customers/customers_exclude params in the Controller, and add customers_exclude support.
Changelog Entry Comment
Comment