Skip to content

Commit 732e574

Browse files
fix(console): correct query parsing for parentheses and AND/OR logic for filter logs
1 parent aecdede commit 732e574

File tree

3 files changed

+37
-6
lines changed

3 files changed

+37
-6
lines changed

gravitee-apim-console-webui/src/components/logs/logs-filters.controller.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -245,10 +245,12 @@ class LogsFiltersController {
245245
.map((x) => x.trim());
246246
switch (k) {
247247
case 'api':
248-
this.filters.api = v;
248+
// Spread v to avoid nested arrays - v is already an array from split('OR')
249+
this.filters.api.push(...v);
249250
break;
250251
case 'application':
251-
this.filters.application = v;
252+
// Spread v to avoid nested arrays - v is already an array from split('OR')
253+
this.filters.application.push(...v);
252254
break;
253255
case 'path': {
254256
const value = v[0].replace(/\\"/g, '');
@@ -272,7 +274,8 @@ class LogsFiltersController {
272274
this.filters.method = v;
273275
break;
274276
case 'status':
275-
this.filters.status.push(v);
277+
// Spread v to avoid nested arrays - v is already an array from split('OR')
278+
this.filters.status.push(...v);
276279
break;
277280
case '_id':
278281
this.filters.id = v[0];

gravitee-apim-console-webui/src/components/logs/search-and-select/search-and-select.controller.ts

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,20 +59,48 @@ export class SearchAndSelectController {
5959
}
6060

6161
async $onInit() {
62+
63+
if (this.selectModel && Array.isArray(this.selectModel)) {
64+
const flattened = this.flattenArray(this.selectModel);
65+
if (flattened.length !== this.selectModel.length || JSON.stringify(flattened) !== JSON.stringify(this.selectModel)) {
66+
this.selectModel = flattened;
67+
}
68+
}
69+
6270
if (this.init) {
6371
const options = await this.init();
6472
this.selector.updateOptions(options);
6573
}
6674
this.select();
6775
}
6876

77+
/**
78+
* Recursively flattens nested arrays
79+
* Example: [[1], [2]] -> [1, 2]
80+
*/
81+
private flattenArray(arr: any[]): string[] {
82+
const result: string[] = [];
83+
for (const item of arr) {
84+
if (Array.isArray(item)) {
85+
result.push(...this.flattenArray(item));
86+
} else if (item !== null && item !== undefined) {
87+
result.push(item);
88+
}
89+
}
90+
return result;
91+
}
92+
6993
async onSearch() {
7094
const options = await this.search({ term: this.searchTerm });
7195
this.selector.updateOptions(options);
7296
}
7397

7498
select() {
75-
this.selector.updateSelection(this.selectModel, () => this.onSearch());
99+
// Normalize selectModel before using it (defensive check)
100+
const normalizedModel =
101+
this.selectModel && Array.isArray(this.selectModel) ? this.flattenArray(this.selectModel) : this.selectModel || [];
102+
103+
this.selector.updateSelection(normalizedModel, () => this.onSearch());
76104
this.onSelect({ selection: this.selection });
77105
}
78106

gravitee-apim-console-webui/src/components/logs/search-and-select/search-and-select.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
data-md-container-class="selectdemoSelectHeader"
2222
md-on-open="$ctrl.onSearch()"
2323
multiple
24-
ng-change="$ctrl.select(item)"
24+
ng-change="$ctrl.select()"
2525
>
2626
<md-select-header class="demo-select-header">
2727
<input
@@ -34,7 +34,7 @@
3434
/>
3535
</md-select-header>
3636

37-
<md-option ng-if="$ctrl.api === null" disabled>Loading...</md-option>
37+
<md-option ng-if="$ctrl.options.length === 0 && !$ctrl.searchTerm" disabled>No options available</md-option>
3838

3939
<md-option ng-value="item.id" ng-repeat="item in $ctrl.options track by item.id">{{ item.name }}</md-option>
4040

0 commit comments

Comments
 (0)