Skip to content

Commit 5d0f1ee

Browse files
committed
keep loading until selected item is found?
Signed-off-by: Abhishek Kumar <[email protected]>
1 parent fec2dfb commit 5d0f1ee

File tree

2 files changed

+36
-5
lines changed

2 files changed

+36
-5
lines changed

ui/src/components/header/ProjectMenu.vue

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
resourceType="project"
2626
:defaultOption="defaultOption"
2727
defaultIcon="project-outlined"
28+
:pageSize="100"
2829
@change-option="changeProject" />
2930
</span>
3031
</template>

ui/src/components/widgets/InfiniteScrollSelect.vue

Lines changed: 35 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -75,33 +75,47 @@ export default {
7575
defaultIcon: {
7676
type: String,
7777
default: 'cloud-outlined'
78+
},
79+
pageSize: {
80+
type: Number,
81+
default: null
7882
}
7983
},
8084
data () {
8185
return {
8286
options: [],
8387
page: 1,
84-
pageSize: 50,
8588
totalCount: null,
8689
loading: false,
8790
searchQuery: '',
88-
scrollHandlerAttached: false
91+
scrollHandlerAttached: false,
92+
preselectedOptionId: null,
93+
successiveFetches: 0
8994
}
9095
},
9196
created () {
9297
this.addDefaultOptionIfNeeded(true)
9398
},
9499
mounted () {
100+
this.preselectedOptionId = this.$attrs.value
95101
this.fetchItems()
96102
},
103+
computed: {
104+
maxSuccessiveFetches () {
105+
return 10
106+
},
107+
computedPageSize () {
108+
return this.pageSize || this.$store.getters.defaultListViewPageSize
109+
}
110+
},
97111
emits: ['change-option'],
98112
methods: {
99113
async fetchItems () {
100-
if (this.loading) return
114+
if (this.successiveFetches === 0 && this.loading) return
101115
this.loading = true
102116
const params = {
103117
page: this.page,
104-
pagesize: this.pageSize,
118+
pagesize: this.computedPageSize,
105119
keyword: this.searchQuery,
106120
listall: true
107121
}
@@ -113,10 +127,25 @@ export default {
113127
const newOpts = response[this.resourceType] || []
114128
this.options = this.options.concat(newOpts)
115129
this.page++
130+
131+
if (this.preselectedOptionId && this.successiveFetches < this.maxSuccessiveFetches) {
132+
const match = this.options.find(entry => entry.id === this.preselectedOptionId)
133+
if (!match) {
134+
this.successiveFetches++
135+
this.fetchItems()
136+
} else {
137+
this.preselectedOptionId = null
138+
this.successiveFetches = 0
139+
}
140+
} else {
141+
this.successiveFetches = 0
142+
}
116143
}).catch(error => {
117144
this.$notifyError(error)
118145
}).finally(() => {
119-
this.loading = false
146+
if (this.successiveFetches === 0) {
147+
this.loading = false
148+
}
120149
})
121150
},
122151
addDefaultOptionIfNeeded () {
@@ -142,6 +171,7 @@ export default {
142171
}
143172
},
144173
onChange (id) {
174+
this.preselectedOptionId = null
145175
const match = this.options.find(entry => entry.id === id)
146176
if (match) {
147177
this.$emit('change-option', match)

0 commit comments

Comments
 (0)