Skip to content

Commit

Permalink
fix multiple word filtering
Browse files Browse the repository at this point in the history
Signed-off-by: R-Lawton <[email protected]>
  • Loading branch information
R-Lawton committed Nov 18, 2024
1 parent 7e9e2a9 commit b72f47f
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions src/components/ResourceList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -364,14 +364,18 @@ const ResourceList: React.FC<ResourceListProps> = ({
let data = allData;

if (filters) {
const search = filters.toLowerCase().trim().split(/\s+/); // Split by spaces
const search = filters.toLowerCase().trim().split(/\s+/).filter(Boolean);
data = data.filter((item) => {
return search.every(
const name = item.metadata?.name?.toLowerCase() || '';
const namespace = item.metadata?.namespace?.toLowerCase() || '';
const kind = item.kind?.toLowerCase() || '';
const matches = search.some(
(searchValue) =>
item.metadata?.name?.toLowerCase().includes(searchValue) ||
item.metadata?.namespace?.toLowerCase().includes(searchValue) ||
item.kind?.toLowerCase().includes(searchValue),
name.includes(searchValue) ||
namespace.includes(searchValue) ||
kind.includes(searchValue),
);
return matches;
});
}
setFilteredData(data);
Expand Down Expand Up @@ -526,11 +530,11 @@ const ResourceList: React.FC<ResourceListProps> = ({
)}
<div className="kuadrant-policy-list-body">
<ListPageBody>
<div className="kuadrant-filter-bar" style={{ marginBottom: '16px' , marginTop: '15px' }}>
<div className="kuadrant-filter-bar" style={{ marginBottom: '16px', marginTop: '15px' }}>
<SearchInput
placeholder="Search across name, namespace or resource type"
value={String(filters) || ''}
onChange={(_, value: string) => handleFilterChange(value)}
value={String(filters) || ''}
onChange={(_, value: string) => handleFilterChange(value)}
onClear={handleClear}
aria-label="Global search input"
style={{ marginRight: '8px', width: '350px' }}
Expand Down

0 comments on commit b72f47f

Please sign in to comment.