@@ -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