diff --git a/assets/javascripts/discourse/controllers/group-reports-show.js b/assets/javascripts/discourse/controllers/group-reports-show.js index 6f20e1de..8949ed91 100644 --- a/assets/javascripts/discourse/controllers/group-reports-show.js +++ b/assets/javascripts/discourse/controllers/group-reports-show.js @@ -15,14 +15,21 @@ import { bind } from "discourse-common/utils/decorators"; export default class GroupReportsShowController extends Controller { @service currentUser; @service modal; + @service router; @tracked showResults = false; @tracked loading = false; @tracked results = this.model.results; @tracked queryGroupBookmark = this.queryGroup?.bookmark; + queryParams = ["params"]; + explain = false; + get parsedParams() { + return this.params ? JSON.parse(this.params) : null; + } + get hasParams() { return this.model.param_info.length > 0; } @@ -52,12 +59,18 @@ export default class GroupReportsShowController extends Controller { this.showResults = false; try { + const stringifiedParams = JSON.stringify(this.model.params); + this.router.transitionTo({ + queryParams: { + params: this.model.params ? stringifiedParams : null, + }, + }); const response = await ajax( `/g/${this.get("group.name")}/reports/${this.model.id}/run`, { type: "POST", data: { - params: JSON.stringify(this.model.params), + params: stringifiedParams, explain: this.explain, }, } diff --git a/assets/javascripts/discourse/templates/group-reports-show.hbs b/assets/javascripts/discourse/templates/group-reports-show.hbs index 833c9b80..7a4ebb92 100644 --- a/assets/javascripts/discourse/templates/group-reports-show.hbs +++ b/assets/javascripts/discourse/templates/group-reports-show.hbs @@ -6,6 +6,7 @@ diff --git a/test/javascripts/acceptance/param-input-test.js b/test/javascripts/acceptance/param-input-test.js index fbdbb427..cd586f34 100644 --- a/test/javascripts/acceptance/param-input-test.js +++ b/test/javascripts/acceptance/param-input-test.js @@ -304,7 +304,18 @@ acceptance("Data Explorer Plugin | Param Input", function (needs) { await fillIn(".query-params input", monthsAgoValue); await click("form.query-run button"); - const searchParams = new URLSearchParams(currentURL()); + const searchParams = new URLSearchParams(currentURL().split("?")[1]); + const monthsAgoParam = JSON.parse(searchParams.get("params")).months_ago; + assert.equal(monthsAgoParam, monthsAgoValue); + }); + + test("it puts params for the query into the url for group reports", async function (assert) { + await visit("/g/discourse/reports/-8"); + const monthsAgoValue = "2"; + await fillIn(".query-params input", monthsAgoValue); + await click("form.query-run button"); + + const searchParams = new URLSearchParams(currentURL().split("?")[1]); const monthsAgoParam = JSON.parse(searchParams.get("params")).months_ago; assert.equal(monthsAgoParam, monthsAgoValue); }); @@ -315,6 +326,12 @@ acceptance("Data Explorer Plugin | Param Input", function (needs) { assert.ok(exists(".query-run .btn.btn-primary")); }); + test("it loads the page if one of the parameter is null for group reports", async function (assert) { + await visit('/g/discourse/reports/-8?params={"months_ago":null}'); + assert.ok(exists(".query-params input")); + assert.ok(exists(".query-run .btn.btn-primary")); + }); + test("it applies params when running a report", async function (assert) { await visit("/g/discourse/reports/-8"); const monthsAgoValue = "2";