Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bugfix/FOUR-15004: PMQL in record list doesnt work with pm variables: #423

Closed
wants to merge 3 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
113 changes: 80 additions & 33 deletions src/components/FormSelectList.vue
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,11 @@ export default {
collectionOptions() {
return get(this.options, 'collectionOptions');
},
isDataConnector() {
return get(this.options, 'dataSource') === "dataConnector";
},
isCollection() {
return get(this.options, 'dataSource') === "collection"
return get(this.options, 'dataSource') === "collection";
},
mode() {
return this.$root.$children[0].mode;
Expand Down Expand Up @@ -227,7 +230,7 @@ export default {
}
}
}
},
}
},
methods: {
renderPmql(pmql) {
Expand All @@ -237,6 +240,7 @@ export default {
}
return "";
},

/**
* Load select list options from a data connector
*
Expand All @@ -246,57 +250,99 @@ export default {
async loadOptionsFromDataConnector(options) {
const { selectedEndPoint, selectedDataSource, dataName } = options;

// If no data source has been specified, do not make the api call
if (
selectedDataSource === null ||
typeof selectedDataSource === "undefined" ||
selectedDataSource.toString().trim().length === 0
) {
if (!this.shouldLoadOptionsFromDataConnector(selectedDataSource, selectedEndPoint)) {
return false;
}

// Do not run in standalone mode
if (!this.$dataProvider) {
const params = this.prepareParamsForDataConnector(selectedEndPoint);
const request = { selectedDataSource, params };

if (isEqual(this.lastRequest, request)) {
return false;
}

this.lastRequest = cloneDeep(request);

this.fetchDataSourceOptions(selectedDataSource, params, dataName);
},

shouldLoadOptionsFromDataConnector(selectedDataSource, selectedEndPoint) {
if (this.isEditorMode()) {
return false;
}

// If no data source has been specified, do not make the api call
if (this.isNoDataSourceSelected(selectedDataSource)) {
return false;
}

// If no endpoint has been specified, do not make the api call
if (
selectedEndPoint === null ||
typeof selectedEndPoint === "undefined" ||
selectedEndPoint.toString().trim().length === 0
) {
if (this.isNoEndpointSelected(selectedEndPoint)) {
return false;
}

// Do not run in standalone mode
if (this.isStandaloneMode()) {
return false;
}

return true;
},

isEditorMode() {
return this.mode === "editor";
},

isNoDataSourceSelected(dataSource) {
return dataSource === null || typeof dataSource === "undefined" || dataSource.toString().trim().length === 0;
},

isNoEndpointSelected(endpoint) {
return endpoint === null || typeof endpoint === "undefined" || endpoint.toString().trim().length === 0;
},

isStandaloneMode() {
return !this.$dataProvider;
},

prepareParamsForDataConnector(selectedEndPoint) {
const params = {
config: {
endpoint: selectedEndPoint
}
};

if (
typeof this.options.pmqlQuery !== "undefined" &&
this.options.pmqlQuery !== "" &&
this.options.pmqlQuery !== null
) {
const data = this.makeProxyData();
const pmql = Mustache.render(this.options.pmqlQuery, { data });
const pmql = this.renderPmql(this.options.pmqlQuery);

if (pmql) {
params.config.outboundConfig = [
{ type: "PARAM", key: "pmql", value: pmql }
{
type: "PARAM",
key: "pmql",
value: pmql
}
];
}
const request = { selectedDataSource, params };
if (isEqual(this.lastRequest, request)) {
return false;
}
this.lastRequest = cloneDeep(request);

return params;
},

async fetchDataSourceOptions(dataSource, params, dataName) {
try {
const response = await this.$dataProvider.getDataSource(
selectedDataSource,
params
);
let resolvedNonce = null;
let response = null;

// Nonce ensures we only use results from the latest request
this.nonce = Math.random();

[response, resolvedNonce] = await this.$dataProvider.getDataSource(dataSource, params, this.nonce);

if (resolvedNonce !== this.nonce) {
return;
}

this.nonce = null;

const list = dataName ? get(response.data, dataName) : response.data;
const transformedList = this.transformOptions(list);
this.$root.$emit("selectListOptionsUpdated", transformedList);
Expand All @@ -308,6 +354,7 @@ export default {
return false;
}
},

async loadOptionsFromCollection() {
if (this.mode === "editor") {
return false;
Expand Down Expand Up @@ -396,7 +443,7 @@ export default {
async getCollectionRecords(options) {
let data = { data : [] };
let resolvedNonce = null;

// Nonce ensures we only use results from the latest request
this.nonce = Math.random();

Expand Down
Loading