Skip to content

Commit

Permalink
refactor(LibraryComponent): Clean up isSearchMatch() (#1425)
Browse files Browse the repository at this point in the history
  • Loading branch information
hirokiterashima authored Sep 21, 2023
1 parent 4f607ea commit 449e662
Showing 1 changed file with 20 additions and 28 deletions.
48 changes: 20 additions & 28 deletions src/app/modules/library/library/library.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ export abstract class LibraryComponent implements OnInit {
this.peValue = this.filterValues.peValue;
for (let project of this.projects) {
let filterMatch = false;
let searchMatch = this.isSearchMatch(project, this.searchValue);
const searchMatch = this.isSearchMatch(project, this.searchValue);
if (searchMatch) {
filterMatch = this.isFilterMatch(project);
}
Expand All @@ -108,36 +108,28 @@ export abstract class LibraryComponent implements OnInit {
);
}

isSearchMatch(project: LibraryProject, searchValue: string): boolean {
if (searchValue) {
let data: any = project.metadata;
data.id = project.id;
return Object.keys(data).some((prop) => {
// only check for match in specific metadata fields
if (
prop != 'title' &&
prop != 'summary' &&
prop != 'keywords' &&
prop != 'features' &&
prop != 'standardsAddressed' &&
prop != 'id'
) {
return false;
} else {
let value = data[prop];
private isSearchMatch(project: LibraryProject, searchValue: string): boolean {
const metadata: any = project.metadata;
metadata.id = project.id;
return (
!searchValue ||
Object.keys(metadata)
.filter((prop) =>
// only check for match in specific metadata fields
['title', 'summary', 'keywords', 'features', 'standardsAddressed', 'id'].includes(prop)
)
.some((prop) => {
let value = metadata[prop];
if (prop === 'standardsAddressed') {
value = JSON.stringify(value);
}
if (typeof value === 'undefined' || value === null) {
return false;
} else {
return value.toString().toLocaleLowerCase().indexOf(searchValue) !== -1;
}
}
});
} else {
return true;
}
return (
typeof value !== 'undefined' &&
value != null &&
value.toString().toLocaleLowerCase().indexOf(searchValue) !== -1
);
})
);
}

isFilterMatch(project: LibraryProject): boolean {
Expand Down

0 comments on commit 449e662

Please sign in to comment.