FEATURE: Add Data Explorer Params to the URL on run (#128)
Co-authored-by: Mark VanLandingham <markvanlan@gmail.com>
This commit is contained in:
parent
0c9005513a
commit
286b5b5fe7
|
@ -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() {
|
||||
|
|
|
@ -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,
|
||||
|
@ -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"];
|
||||
|
@ -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() {
|
||||
|
@ -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") +
|
||||
|
|
|
@ -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}}
|
||||
|
|
|
@ -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";
|
||||
|
||||
|
@ -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);
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue