Skip to content

Commit

Permalink
Implement correct filter method for typeahead
Browse files Browse the repository at this point in the history
  • Loading branch information
lkleisa committed May 24, 2024
1 parent d5f0776 commit 4c6c28a
Showing 1 changed file with 22 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -311,14 +311,28 @@ export class ObjectiveFormComponent implements OnInit {

filter() {
let filterValue = this.input.nativeElement.value.toLowerCase();
this.alignmentPossibilities$.subscribe((value: AlignmentPossibility[]) => {
this.filteredOptions = value.filter((alignmentPossibility: AlignmentPossibility) => {
let teamMatch = alignmentPossibility.teamName.toLowerCase().includes(filterValue);
let objectMatch = alignmentPossibility.alignmentObjectDtos.some((obj) =>
obj.objectTitle.toLowerCase().includes(filterValue),
);
return teamMatch || objectMatch;
});
this.alignmentPossibilities$.subscribe((alignmentPossibilities: AlignmentPossibility[]) => {
let filteredObjects = alignmentPossibilities.flatMap(possibility =>
possibility.alignmentObjectDtos.filter(obj => obj.objectTitle.toLowerCase().includes(filterValue))
);

let matchingPossibilities = alignmentPossibilities.filter(possibility =>
filteredObjects.some(obj => possibility.alignmentObjectDtos.includes(obj))
);

let uniquePossibilities = [...new Set(matchingPossibilities)];

let finalList = uniquePossibilities.map(possibility => ({
...possibility,
alignmentObjectDtos: possibility.alignmentObjectDtos.filter(obj => filteredObjects.includes(obj)),
}));

if (finalList.length == 0) {
this.filteredOptions = alignmentPossibilities.filter(possibility =>
possibility.teamName.toLowerCase().includes(filterValue));
} else {
this.filteredOptions = finalList;
}
});
}

Expand Down

0 comments on commit 4c6c28a

Please sign in to comment.