Commit a88b1d86 authored by Jaden's avatar Jaden Committed by Flavio TARSETTI
Browse files

[experiments][js] fix report URL construction

Now properly extracts the URL and prefix fragments to
handle an arbitrary or empty prefix, using a simple regex.

Closes #522
parent bb435ef6
Pipeline #30283 passed with stage
in 17 minutes and 10 seconds
......@@ -1913,12 +1913,16 @@ beat.experiments.utils.modal_add_to_report = function(names, report_list_url) {
var type = BootstrapDialog.TYPE_PRIMARY;
var title = '<i class="fa fa-check"></i> Report changes';
var btn_type = 'btn-primary';
let viewReportUrl = `${$.ajaxSettings.url.split(
'/experiments'
)[0]}${select
.val()
.replace('add/', '')
.replace(/api\/v.\//, '')}`;
// regex to extract the path to the report that the user
// added the experiment(s) to
// URL fragments are like "/platform/api/v1/reports/user/test/add/"
// format is "<part of prefix>/reports/<user>/<report name>/add/"
// we want "reports/<user>/<report name>"
const rReportFragment = /^.*(reports\/[^\/]+\/[^\/]+)\/add\/$/;
const reportUrlFragment = rReportFragment.exec(select.val())[1];
const currPrefix = $.ajaxSettings.url.split('/experiments')[0];
let viewReportUrl = `${currPrefix}/${reportUrlFragment}`;
if (successful == sent) {
description.text(
`Successfully added ${sent} experiment(s) to report`
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment