Skip to content

Commit 2d2b02c

Browse files
authored
Merge pull request #424 from ProcessMaker/bugfix/FOUR-15004-b
Bugfix/FOUR-15004: PMQL in record list doesnt work with pm variables
2 parents e95987e + e8a61a3 commit 2d2b02c

File tree

1 file changed

+80
-33
lines changed

1 file changed

+80
-33
lines changed

src/components/FormSelectList.vue

Lines changed: 80 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -119,8 +119,11 @@ export default {
119119
collectionOptions() {
120120
return get(this.options, 'collectionOptions');
121121
},
122+
isDataConnector() {
123+
return get(this.options, 'dataSource') === "dataConnector";
124+
},
122125
isCollection() {
123-
return get(this.options, 'dataSource') === "collection"
126+
return get(this.options, 'dataSource') === "collection";
124127
},
125128
mode() {
126129
return this.$root.$children[0].mode;
@@ -227,7 +230,7 @@ export default {
227230
}
228231
}
229232
}
230-
},
233+
}
231234
},
232235
methods: {
233236
renderPmql(pmql) {
@@ -237,6 +240,7 @@ export default {
237240
}
238241
return "";
239242
},
243+
240244
/**
241245
* Load select list options from a data connector
242246
*
@@ -246,57 +250,99 @@ export default {
246250
async loadOptionsFromDataConnector(options) {
247251
const { selectedEndPoint, selectedDataSource, dataName } = options;
248252
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)) {
255254
return false;
256255
}
257256
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)) {
260276
return false;
261277
}
262278
263279
// 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)) {
269281
return false;
270282
}
271283
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) {
272309
const params = {
273310
config: {
274311
endpoint: selectedEndPoint
275312
}
276313
};
277314
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) {
285318
params.config.outboundConfig = [
286-
{ type: "PARAM", key: "pmql", value: pmql }
319+
{
320+
type: "PARAM",
321+
key: "pmql",
322+
value: pmql
323+
}
287324
];
288325
}
289-
const request = { selectedDataSource, params };
290-
if (isEqual(this.lastRequest, request)) {
291-
return false;
292-
}
293-
this.lastRequest = cloneDeep(request);
294326
327+
return params;
328+
},
329+
330+
async fetchDataSourceOptions(dataSource, params, dataName) {
295331
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+
300346
const list = dataName ? get(response.data, dataName) : response.data;
301347
const transformedList = this.transformOptions(list);
302348
this.$root.$emit("selectListOptionsUpdated", transformedList);
@@ -308,6 +354,7 @@ export default {
308354
return false;
309355
}
310356
},
357+
311358
async loadOptionsFromCollection() {
312359
if (this.mode === "editor") {
313360
return false;
@@ -396,7 +443,7 @@ export default {
396443
async getCollectionRecords(options) {
397444
let data = { data : [] };
398445
let resolvedNonce = null;
399-
446+
400447
// Nonce ensures we only use results from the latest request
401448
this.nonce = Math.random();
402449

0 commit comments

Comments
 (0)