Skip to content

Commit

Permalink
Fixed a bug in the new search logic.
Browse files Browse the repository at this point in the history
It wasn't searching into elements of arrays
  • Loading branch information
ashleydavis committed Aug 4, 2024
1 parent c98eba7 commit c63ee50
Showing 1 changed file with 20 additions and 3 deletions.
23 changes: 20 additions & 3 deletions packages/user-interface/src/context/gallery-context.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -564,6 +564,23 @@ export function GalleryContextProvider({ children }: IGalleryContextProviderProp
return items.filter(item => !item.deleted);
}

//
// Determine if a field value matches the search text.
//
function valueMatches(fieldValue: any, searchTextLwr: string): boolean {
if (Array.isArray(fieldValue)) {
for (const elementValue of fieldValue) {
if (elementValue.toLowerCase().includes(searchTextLwr)) {
return true;
}
}
return false;
}
else {
return fieldValue.toLowerCase().includes(searchTextLwr);
}
}

//
// Search for assets based on text input.
//
Expand All @@ -578,7 +595,7 @@ export function GalleryContextProvider({ children }: IGalleryContextProviderProp
const searchFields = [ "location", "description", "labels", "origFileName", "origPath", "contentType" ];
const searchedItems: IGalleryItem[] = [];

const searchLwr = searchText.toLowerCase();
const searchTextLwr = searchText.toLowerCase();

for (const item of items) {
for (const fieldName of searchFields) {
Expand All @@ -587,10 +604,10 @@ export function GalleryContextProvider({ children }: IGalleryContextProviderProp
continue;
}

if (fieldValue.toLowerCase().includes(searchLwr)) {
if (valueMatches(fieldValue, searchTextLwr)) {
searchedItems.push(item);
break;
}
}
}
}

Expand Down

0 comments on commit c63ee50

Please sign in to comment.