Skip to content

Commit c27ccb9

Browse files
committed
UI: Prevent extra API calls in search filter on scrolling
1 parent 45d623e commit c27ccb9

File tree

2 files changed

+31
-27
lines changed

2 files changed

+31
-27
lines changed

ui/src/components/view/SearchFilter.vue

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,9 +189,10 @@ export default {
189189
resolve()
190190
} else {
191191
this.getSearchFilters(filter.key, filter.value).then((value) => {
192+
const displayValue = (value !== undefined && value !== null && value !== '') ? value : filter.value
192193
clonedFilters[idx] = {
193194
key: filter.key,
194-
value: value,
195+
value: displayValue,
195196
isTag: filter.isTag
196197
}
197198
resolve()

ui/src/views/AutogenView.vue

Lines changed: 29 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@
114114
style="min-height: 36px; padding-top: 12px; padding-left: 12px;"
115115
>
116116
<search-filter
117-
:filters="getActiveFilters()"
117+
:filters="activeFiltersList"
118118
:apiName="apiName"
119119
@removeFilter="removeFilter"
120120
/>
@@ -690,9 +690,36 @@ export default {
690690
}
691691
},
692692
computed: {
693+
activeFiltersList () {
694+
const queryParams = Object.assign({}, this.$route.query)
695+
const activeFilters = []
696+
for (const filter in queryParams) {
697+
if (this.$route.name === 'host' && filter === 'type') {
698+
continue
699+
}
700+
if (!filter.startsWith('tags[')) {
701+
activeFilters.push({
702+
key: filter,
703+
value: queryParams[filter],
704+
isTag: false
705+
})
706+
} else if (filter.endsWith('].key')) {
707+
const tagIdx = filter.split('[')[1].split(']')[0]
708+
const tagKey = queryParams[`tags[${tagIdx}].key`]
709+
const tagValue = queryParams[`tags[${tagIdx}].value`]
710+
activeFilters.push({
711+
key: tagKey,
712+
value: tagValue,
713+
isTag: true,
714+
tagIdx: tagIdx
715+
})
716+
}
717+
}
718+
return activeFilters
719+
},
693720
showSearchFilters () {
694721
const excludedKeys = ['page', 'pagesize', 'q', 'keyword', 'tags', 'projectid']
695-
return !this.dataView && this.$config.showSearchFilters && this.getActiveFilters().some(f => !excludedKeys.includes(f.key))
722+
return !this.dataView && this.$config.showSearchFilters && this.activeFiltersList.some(f => !excludedKeys.includes(f.key))
696723
},
697724
hasSelected () {
698725
return this.selectedRowKeys.length > 0
@@ -1145,30 +1172,6 @@ export default {
11451172
eventBus.emit('action-closing', { action: this.currentAction })
11461173
this.closeAction()
11471174
},
1148-
getActiveFilters () {
1149-
const queryParams = Object.assign({}, this.$route.query)
1150-
const activeFilters = []
1151-
for (const filter in queryParams) {
1152-
if (!filter.startsWith('tags[')) {
1153-
activeFilters.push({
1154-
key: filter,
1155-
value: queryParams[filter],
1156-
isTag: false
1157-
})
1158-
} else if (filter.endsWith('].key')) {
1159-
const tagIdx = filter.split('[')[1].split(']')[0]
1160-
const tagKey = queryParams[`tags[${tagIdx}].key`]
1161-
const tagValue = queryParams[`tags[${tagIdx}].value`]
1162-
activeFilters.push({
1163-
key: tagKey,
1164-
value: tagValue,
1165-
isTag: true,
1166-
tagIdx: tagIdx
1167-
})
1168-
}
1169-
}
1170-
return activeFilters
1171-
},
11721175
removeFilter (filter) {
11731176
const queryParams = Object.assign({}, this.$route.query)
11741177
if (filter.isTag) {

0 commit comments

Comments
 (0)