Skip to content

Commit e4b6ac7

Browse files
vishesh92dhslove
authored andcommitted
UI: Prevent extra API calls in search filter on scrolling (apache#12553)
1 parent 9c41bfa commit e4b6ac7

2 files changed

Lines changed: 36 additions & 32 deletions

File tree

ui/src/components/view/SearchFilter.vue

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,17 @@
11
// Licensed to the Apache Software Foundation (ASF) under one
2-
// or more contributor license agreements. See the NOTICE file
2+
// or more contributor license agreements. See the NOTICE file
33
// distributed with this work for additional information
4-
// regarding copyright ownership. The ASF licenses this file
4+
// regarding copyright ownership. The ASF licenses this file
55
// to you under the Apache License, Version 2.0 (the
66
// "License"); you may not use this file except in compliance
7-
// with the License. You may obtain a copy of the License at
7+
// with the License. You may obtain a copy of the License at
88
//
9-
// http://www.apache.org/licenses/LICENSE-2.0
9+
// http://www.apache.org/licenses/LICENSE-2.0
1010
//
1111
// Unless required by applicable law or agreed to in writing,
1212
// software distributed under the License is distributed on an
1313
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14-
// KIND, either express or implied. See the License for the
14+
// KIND, either express or implied. See the License for the
1515
// specific language governing permissions and limitations
1616
// under the License.
1717

@@ -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
@@ -157,7 +157,7 @@
157157
style="min-height: 36px; padding-top: 12px; padding-left: 12px;"
158158
>
159159
<search-filter
160-
:filters="getActiveFilters()"
160+
:filters="activeFiltersList"
161161
:apiName="apiName"
162162
@removeFilter="removeFilter"
163163
/>
@@ -1130,9 +1130,36 @@ export default {
11301130
}
11311131
},
11321132
computed: {
1133+
activeFiltersList () {
1134+
const queryParams = Object.assign({}, this.$route.query)
1135+
const activeFilters = []
1136+
for (const filter in queryParams) {
1137+
if (this.$route.name === 'host' && filter === 'type') {
1138+
continue
1139+
}
1140+
if (!filter.startsWith('tags[')) {
1141+
activeFilters.push({
1142+
key: filter,
1143+
value: queryParams[filter],
1144+
isTag: false
1145+
})
1146+
} else if (filter.endsWith('].key')) {
1147+
const tagIdx = filter.split('[')[1].split(']')[0]
1148+
const tagKey = queryParams[`tags[${tagIdx}].key`]
1149+
const tagValue = queryParams[`tags[${tagIdx}].value`]
1150+
activeFilters.push({
1151+
key: tagKey,
1152+
value: tagValue,
1153+
isTag: true,
1154+
tagIdx: tagIdx
1155+
})
1156+
}
1157+
}
1158+
return activeFilters
1159+
},
11331160
showSearchFilters () {
11341161
const excludedKeys = ['page', 'pagesize', 'q', 'keyword', 'tags', 'projectid']
1135-
return !this.dataView && this.$config.showSearchFilters && this.getActiveFilters().some(f => !excludedKeys.includes(f.key))
1162+
return !this.dataView && this.$config.showSearchFilters && this.activeFiltersList.some(f => !excludedKeys.includes(f.key))
11361163
},
11371164
hasSelected () {
11381165
return this.selectedRowKeys.length > 0
@@ -1690,30 +1717,6 @@ export default {
16901717
eventBus.emit('action-closing', { action: this.currentAction })
16911718
this.closeAction()
16921719
},
1693-
getActiveFilters () {
1694-
const queryParams = Object.assign({}, this.$route.query)
1695-
const activeFilters = []
1696-
for (const filter in queryParams) {
1697-
if (!filter.startsWith('tags[')) {
1698-
activeFilters.push({
1699-
key: filter,
1700-
value: queryParams[filter],
1701-
isTag: false
1702-
})
1703-
} else if (filter.endsWith('].key')) {
1704-
const tagIdx = filter.split('[')[1].split(']')[0]
1705-
const tagKey = queryParams[`tags[${tagIdx}].key`]
1706-
const tagValue = queryParams[`tags[${tagIdx}].value`]
1707-
activeFilters.push({
1708-
key: tagKey,
1709-
value: tagValue,
1710-
isTag: true,
1711-
tagIdx: tagIdx
1712-
})
1713-
}
1714-
}
1715-
return activeFilters
1716-
},
17171720
removeFilter (filter) {
17181721
const queryParams = Object.assign({}, this.$route.query)
17191722
if (filter.isTag) {

0 commit comments

Comments
 (0)