Skip to content

Commit 948149e

Browse files
committed
feat: implement search functionality for fields in condition item component
Signed-off-by: Manuel Abascal <mjabascal10@gmail.com>
1 parent b516f51 commit 948149e

2 files changed

Lines changed: 23 additions & 2 deletions

File tree

frontend/src/app/incident-response/shared/component/condition-item/condition-item.component.html

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,11 +59,12 @@
5959
<ng-select
6060
class="input-sm"
6161
[clearable]="false"
62-
[items]="fields"
62+
[items]="filteredFields"
6363
bindLabel="name"
6464
bindValue="name"
6565
placeholder="Select field"
6666
formControlName="field"
67+
(search)="onSearch($event)"
6768
(change)="getValuesForField($event.name)">
6869
</ng-select>
6970
</div>

frontend/src/app/incident-response/shared/component/condition-item/condition-item.component.ts

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ export class ConditionItemComponent implements OnInit {
2121
@Input() index: number;
2222
@Input() fields: ElasticSearchFieldInfoType[];
2323
@Output() delete: EventEmitter<number> = new EventEmitter();
24+
filteredFields: ElasticSearchFieldInfoType[] = [];
25+
protected readonly operatorEnum = ElasticOperatorsEnum;
2426
selectableOperators = [ElasticOperatorsEnum.IS_ONE_OF,
2527
ElasticOperatorsEnum.IS_NOT_ONE_OF,
2628
ElasticOperatorsEnum.CONTAIN_ONE_OF,
@@ -40,6 +42,7 @@ export class ConditionItemComponent implements OnInit {
4042
private operatorsService: OperatorService) { }
4143

4244
ngOnInit() {
45+
this.filteredFields = this.fields.filter(field => field.name && !field.name.includes('.keyword'));
4346
}
4447

4548
onScroll() {
@@ -133,5 +136,22 @@ export class ConditionItemComponent implements OnInit {
133136
this.isMultipleSelectValue();
134137
}
135138

136-
protected readonly operatorEnum = ElasticOperatorsEnum;
139+
onSearch(term: { term: string }) {
140+
this.filteredFields = this.fields.filter(field => field.name && !field.name.includes('.keyword'));
141+
if (!term.term) {
142+
return;
143+
}
144+
145+
const searchTerm = term.term.toLowerCase();
146+
this.filteredFields = this.filteredFields
147+
.filter(field => field.name.toLowerCase().includes(searchTerm))
148+
.sort((a, b) => {
149+
const aStarts = a.name.toLowerCase().startsWith(searchTerm);
150+
const bStarts = b.name.toLowerCase().startsWith(searchTerm);
151+
152+
if (aStarts && !bStarts) { return -1; }
153+
if (!aStarts && bStarts) { return 1; }
154+
return a.name.localeCompare(b.name);
155+
});
156+
}
137157
}

0 commit comments

Comments
 (0)