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

Add Data Explorer Params to the URL when user press run #128

Merged
merged 5 commits into from Sep 14, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 9 additions & 0 deletions assets/javascripts/discourse/components/param-input.js.es6
Expand Up @@ -43,6 +43,15 @@ export default Ember.Component.extend({
{ name: I18n.t("explorer.types.bool.false"), id: "N" },
{ name: I18n.t("explorer.types.bool.null_"), id: "#null" },
],
initialValues: null,

init() {
this._super(...arguments);

if (this.initialValues && this.info.identifier in this.initialValues) {
this.set("value", this.initialValues[this.info.identifier]);
}
},

value: Ember.computed("params", "info.identifier", {
get() {
Expand Down
Expand Up @@ -12,7 +12,7 @@ import { Promise } from "rsvp";
const NoQuery = Query.create({ name: "No queries", fake: true, group_ids: [] });

export default Ember.Controller.extend({
queryParams: { selectedQueryId: "id" },
queryParams: { selectedQueryId: "id", params: "params" },
selectedQueryId: null,
editDisabled: false,
showResults: false,
Expand All @@ -32,6 +32,11 @@ export default Ember.Controller.extend({
sortBy: ["last_run_at:desc"],
sortedQueries: Ember.computed.sort("model", "sortBy"),

@computed("params")
parsedParams(params) {
return params ? JSON.parse(params) : null;
},

@computed
acceptedImportFileTypes() {
return ["application/json"];
Expand Down Expand Up @@ -207,10 +212,12 @@ export default Ember.Controller.extend({
order: null,
showResults: false,
editDisabled: false,
showRecentQueries: true,
selectedQueryId: null,
params: null,
sortBy: ["last_run_at:desc"],
});
this.transitionToRoute({ queryParams: { id: null } });
this.transitionToRoute({ queryParams: { id: null, params: null } });
},

showHelpModal() {
Expand Down Expand Up @@ -303,7 +310,11 @@ export default Ember.Controller.extend({
return;
}

this.setProperties({ loading: true, showResults: false });
this.setProperties({
loading: true,
showResults: false,
params: JSON.stringify(this.selectedItem.params),
});
ajax(
"/admin/plugins/explorer/queries/" +
this.get("selectedItem.id") +
Expand Down
Expand Up @@ -149,7 +149,11 @@
{{#if selectedItem.hasParams}}
<div class="query-params">
{{#each selectedItem.param_info as |pinfo|}}
{{param-input params=selectedItem.params info=pinfo}}
{{param-input
params=selectedItem.params
initialValues=parsedParams
info=pinfo
}}
{{/each}}
</div>
{{/if}}
Expand Down
12 changes: 12 additions & 0 deletions test/javascripts/acceptance/run-query-test.js.es6
Expand Up @@ -4,6 +4,7 @@ import {
query,
queryAll,
} from "discourse/tests/helpers/qunit-helpers";
import { click, fillIn, visit } from "@ember/test-helpers";
import { clearPopupMenuOptionsCallback } from "discourse/controllers/composer";
import I18n from "I18n";

Expand Down Expand Up @@ -188,4 +189,15 @@ acceptance("Data Explorer Plugin | Run Query", function (needs) {

assert.ok(exists("canvas"), "the chart was rendered");
});

test("it puts params for the query into the url", async function (assert) {
await visit("admin/plugins/explorer?id=-6");
const monthsAgoValue = "2";
await fillIn(".query-params input", monthsAgoValue);
await click("form.query-run button");

let searchParams = new URLSearchParams(currentURL());
let paramsMonthsAgo = JSON.parse(searchParams.get("params")).months_ago;
assert.equal(paramsMonthsAgo, monthsAgoValue);
});
});