DataViews: Allow searching over array fieldtypes#70785
Conversation
|
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message. To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
|
Size Change: +22 B (0%) Total Size: 1.89 MB
ℹ️ View Unchanged
|
Searching over array fieldtypes with `enableGlobalSearch: true` threw a TypeError because the `normalizeSearchInput` function expected a string but received an array. This change fixes that by treating every value as an array and adapting the logic to match, before entering `normalizeSearchInput`.
This shows off that the search works over array fields too.
Also changed the second test so it's not just returning all results so it's clear that it is actually searching.
ca9f8e4 to
1dfdec6
Compare
|
Flaky tests detected in 46a8d4b. 🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/16464801606
|
| const { data: result } = filterSortAndPaginate( | ||
| data, | ||
| { | ||
| search: 'Moon', |
There was a problem hiding this comment.
title and description also have global search enabled, so this can give false positives because the 3 items (Europa, Io, Moon) have "moon" in the title or description. Perhaps change the search to Satellite?
… on title / description
|
Whoops, forgot to copy the props into the commit message 😬, sorry about that. |
|
Ah, I forgot to mention something: this needs a changelog update :) |
Searching over array fieldtypes with `enableGlobalSearch: true` threw a TypeError because the `normalizeSearchInput` function expected a string but received an array. This change fixes that by treating every value as an array and adapting the logic to match, before entering `normalizeSearchInput`.
It was missed when merging WordPress#70785 originally. Co-authored-by: dsas <dsas@git.wordpress.org> Co-authored-by: Mamaduka <mamaduka@git.wordpress.org>
What?
Closes #70782
Fixing a bug with searching over DataView fields that have the array field types.
Also updating the DataViews storybook to demonstrate that it works.
Why?
This fixes a bug with searching over DataView fields that have the array fieldtype. Previously they would crash with TypeError: input.trim is not a function
How?
Treats every value as an array before normalising and searching over every value in that array.
Testing Instructions
I've added some tests, to test manually:
Testing Instructions for Keyboard