@@ -119,8 +119,11 @@ export default {
119
119
collectionOptions () {
120
120
return get (this .options , ' collectionOptions' );
121
121
},
122
+ isDataConnector () {
123
+ return get (this .options , ' dataSource' ) === " dataConnector" ;
124
+ },
122
125
isCollection () {
123
- return get (this .options , ' dataSource' ) === " collection"
126
+ return get (this .options , ' dataSource' ) === " collection" ;
124
127
},
125
128
mode () {
126
129
return this .$root .$children [0 ].mode ;
@@ -227,7 +230,7 @@ export default {
227
230
}
228
231
}
229
232
}
230
- },
233
+ }
231
234
},
232
235
methods: {
233
236
renderPmql (pmql ) {
@@ -237,6 +240,7 @@ export default {
237
240
}
238
241
return " " ;
239
242
},
243
+
240
244
/**
241
245
* Load select list options from a data connector
242
246
*
@@ -246,57 +250,99 @@ export default {
246
250
async loadOptionsFromDataConnector (options ) {
247
251
const { selectedEndPoint , selectedDataSource , dataName } = options;
248
252
249
- // If no data source has been specified, do not make the api call
250
- if (
251
- selectedDataSource === null ||
252
- typeof selectedDataSource === " undefined" ||
253
- selectedDataSource .toString ().trim ().length === 0
254
- ) {
253
+ if (! this .shouldLoadOptionsFromDataConnector (selectedDataSource, selectedEndPoint)) {
255
254
return false ;
256
255
}
257
256
258
- // Do not run in standalone mode
259
- if (! this .$dataProvider ) {
257
+ const params = this .prepareParamsForDataConnector (selectedEndPoint);
258
+ const request = { selectedDataSource, params };
259
+
260
+ if (isEqual (this .lastRequest , request)) {
261
+ return false ;
262
+ }
263
+
264
+ this .lastRequest = cloneDeep (request);
265
+
266
+ this .fetchDataSourceOptions (selectedDataSource, params, dataName);
267
+ },
268
+
269
+ shouldLoadOptionsFromDataConnector (selectedDataSource , selectedEndPoint ) {
270
+ if (this .isEditorMode ()) {
271
+ return false ;
272
+ }
273
+
274
+ // If no data source has been specified, do not make the api call
275
+ if (this .isNoDataSourceSelected (selectedDataSource)) {
260
276
return false ;
261
277
}
262
278
263
279
// If no endpoint has been specified, do not make the api call
264
- if (
265
- selectedEndPoint === null ||
266
- typeof selectedEndPoint === " undefined" ||
267
- selectedEndPoint .toString ().trim ().length === 0
268
- ) {
280
+ if (this .isNoEndpointSelected (selectedEndPoint)) {
269
281
return false ;
270
282
}
271
283
284
+ // Do not run in standalone mode
285
+ if (this .isStandaloneMode ()) {
286
+ return false ;
287
+ }
288
+
289
+ return true ;
290
+ },
291
+
292
+ isEditorMode () {
293
+ return this .mode === " editor" ;
294
+ },
295
+
296
+ isNoDataSourceSelected (dataSource ) {
297
+ return dataSource === null || typeof dataSource === " undefined" || dataSource .toString ().trim ().length === 0 ;
298
+ },
299
+
300
+ isNoEndpointSelected (endpoint ) {
301
+ return endpoint === null || typeof endpoint === " undefined" || endpoint .toString ().trim ().length === 0 ;
302
+ },
303
+
304
+ isStandaloneMode () {
305
+ return ! this .$dataProvider ;
306
+ },
307
+
308
+ prepareParamsForDataConnector (selectedEndPoint ) {
272
309
const params = {
273
310
config: {
274
311
endpoint: selectedEndPoint
275
312
}
276
313
};
277
314
278
- if (
279
- typeof this .options .pmqlQuery !== " undefined" &&
280
- this .options .pmqlQuery !== " " &&
281
- this .options .pmqlQuery !== null
282
- ) {
283
- const data = this .makeProxyData ();
284
- const pmql = Mustache .render (this .options .pmqlQuery , { data });
315
+ const pmql = this .renderPmql (this .options .pmqlQuery );
316
+
317
+ if (pmql) {
285
318
params .config .outboundConfig = [
286
- { type: " PARAM" , key: " pmql" , value: pmql }
319
+ {
320
+ type: " PARAM" ,
321
+ key: " pmql" ,
322
+ value: pmql
323
+ }
287
324
];
288
325
}
289
- const request = { selectedDataSource, params };
290
- if (isEqual (this .lastRequest , request)) {
291
- return false ;
292
- }
293
- this .lastRequest = cloneDeep (request);
294
326
327
+ return params;
328
+ },
329
+
330
+ async fetchDataSourceOptions (dataSource , params , dataName ) {
295
331
try {
296
- const response = await this .$dataProvider .getDataSource (
297
- selectedDataSource,
298
- params
299
- );
332
+ let resolvedNonce = null ;
333
+ let response = null ;
334
+
335
+ // Nonce ensures we only use results from the latest request
336
+ this .nonce = Math .random ();
337
+
338
+ [response, resolvedNonce] = await this .$dataProvider .getDataSource (dataSource, params, this .nonce );
339
+
340
+ if (resolvedNonce !== this .nonce ) {
341
+ return ;
342
+ }
343
+
344
+ this .nonce = null ;
345
+
300
346
const list = dataName ? get (response .data , dataName) : response .data ;
301
347
const transformedList = this .transformOptions (list);
302
348
this .$root .$emit (" selectListOptionsUpdated" , transformedList);
@@ -308,6 +354,7 @@ export default {
308
354
return false ;
309
355
}
310
356
},
357
+
311
358
async loadOptionsFromCollection () {
312
359
if (this .mode === " editor" ) {
313
360
return false ;
@@ -396,7 +443,7 @@ export default {
396
443
async getCollectionRecords (options ) {
397
444
let data = { data : [] };
398
445
let resolvedNonce = null ;
399
-
446
+
400
447
// Nonce ensures we only use results from the latest request
401
448
this .nonce = Math .random ();
402
449
0 commit comments