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.false"), id: "N" },
|
||||||
{ name: I18n.t("explorer.types.bool.null_"), id: "#null" },
|
{ 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", {
|
value: Ember.computed("params", "info.identifier", {
|
||||||
get() {
|
get() {
|
||||||
|
|
|
@ -12,7 +12,7 @@ import { Promise } from "rsvp";
|
||||||
const NoQuery = Query.create({ name: "No queries", fake: true, group_ids: [] });
|
const NoQuery = Query.create({ name: "No queries", fake: true, group_ids: [] });
|
||||||
|
|
||||||
export default Ember.Controller.extend({
|
export default Ember.Controller.extend({
|
||||||
queryParams: { selectedQueryId: "id" },
|
queryParams: { selectedQueryId: "id", params: "params" },
|
||||||
selectedQueryId: null,
|
selectedQueryId: null,
|
||||||
editDisabled: false,
|
editDisabled: false,
|
||||||
showResults: false,
|
showResults: false,
|
||||||
|
@ -32,6 +32,11 @@ export default Ember.Controller.extend({
|
||||||
sortBy: ["last_run_at:desc"],
|
sortBy: ["last_run_at:desc"],
|
||||||
sortedQueries: Ember.computed.sort("model", "sortBy"),
|
sortedQueries: Ember.computed.sort("model", "sortBy"),
|
||||||
|
|
||||||
|
@computed("params")
|
||||||
|
parsedParams(params) {
|
||||||
|
return params ? JSON.parse(params) : null;
|
||||||
|
},
|
||||||
|
|
||||||
@computed
|
@computed
|
||||||
acceptedImportFileTypes() {
|
acceptedImportFileTypes() {
|
||||||
return ["application/json"];
|
return ["application/json"];
|
||||||
|
@ -207,10 +212,12 @@ export default Ember.Controller.extend({
|
||||||
order: null,
|
order: null,
|
||||||
showResults: false,
|
showResults: false,
|
||||||
editDisabled: false,
|
editDisabled: false,
|
||||||
|
showRecentQueries: true,
|
||||||
selectedQueryId: null,
|
selectedQueryId: null,
|
||||||
|
params: null,
|
||||||
sortBy: ["last_run_at:desc"],
|
sortBy: ["last_run_at:desc"],
|
||||||
});
|
});
|
||||||
this.transitionToRoute({ queryParams: { id: null } });
|
this.transitionToRoute({ queryParams: { id: null, params: null } });
|
||||||
},
|
},
|
||||||
|
|
||||||
showHelpModal() {
|
showHelpModal() {
|
||||||
|
@ -303,7 +310,11 @@ export default Ember.Controller.extend({
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
this.setProperties({ loading: true, showResults: false });
|
this.setProperties({
|
||||||
|
loading: true,
|
||||||
|
showResults: false,
|
||||||
|
params: JSON.stringify(this.selectedItem.params),
|
||||||
|
});
|
||||||
ajax(
|
ajax(
|
||||||
"/admin/plugins/explorer/queries/" +
|
"/admin/plugins/explorer/queries/" +
|
||||||
this.get("selectedItem.id") +
|
this.get("selectedItem.id") +
|
||||||
|
|
|
@ -149,7 +149,11 @@
|
||||||
{{#if selectedItem.hasParams}}
|
{{#if selectedItem.hasParams}}
|
||||||
<div class="query-params">
|
<div class="query-params">
|
||||||
{{#each selectedItem.param_info as |pinfo|}}
|
{{#each selectedItem.param_info as |pinfo|}}
|
||||||
{{param-input params=selectedItem.params info=pinfo}}
|
{{param-input
|
||||||
|
params=selectedItem.params
|
||||||
|
initialValues=parsedParams
|
||||||
|
info=pinfo
|
||||||
|
}}
|
||||||
{{/each}}
|
{{/each}}
|
||||||
</div>
|
</div>
|
||||||
{{/if}}
|
{{/if}}
|
||||||
|
|
|
@ -4,6 +4,7 @@ import {
|
||||||
query,
|
query,
|
||||||
queryAll,
|
queryAll,
|
||||||
} from "discourse/tests/helpers/qunit-helpers";
|
} from "discourse/tests/helpers/qunit-helpers";
|
||||||
|
import { click, fillIn, visit } from "@ember/test-helpers";
|
||||||
import { clearPopupMenuOptionsCallback } from "discourse/controllers/composer";
|
import { clearPopupMenuOptionsCallback } from "discourse/controllers/composer";
|
||||||
import I18n from "I18n";
|
import I18n from "I18n";
|
||||||
|
|
||||||
|
@ -188,4 +189,15 @@ acceptance("Data Explorer Plugin | Run Query", function (needs) {
|
||||||
|
|
||||||
assert.ok(exists("canvas"), "the chart was rendered");
|
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