Files
discourse-data-explorer/assets/javascripts/discourse/models/query.js
T
Isaac Janzen 556d12ac50 FIX: Maintain editing state after saving query changes (#223)
In the widget version of the data-explorer we would maintain the `editing` state after saving query changes. This was lost in upgrade to glimmer. 

# Current State
https://user-images.githubusercontent.com/50783505/217622464-79adaab6-84ed-4b64-93ae-c889aa8fb1bd.mp4

# Updated State
https://user-images.githubusercontent.com/50783505/217623475-1998fab6-0b70-42d2-923d-574efb9d5601.mov

# Other Changes
- `createProperties` was added back to the `query` model as it is being utilized in the creation of a new data explorer query. This was accidentally removed and was causing errors when trying to create a new query.
- Add new-query test
2023-02-08 13:40:53 -06:00

68 lines
1.5 KiB
JavaScript

import getURL from "discourse-common/lib/get-url";
import RestModel from "discourse/models/rest";
export default class Query extends RestModel {
static updatePropertyNames = [
"name",
"description",
"sql",
"user_id",
"created_at",
"group_ids",
"last_run_at",
];
params = {};
constructor() {
super(...arguments);
this.param_info?.resetParams();
}
get downloadUrl() {
return getURL(`/admin/plugins/explorer/queries/${this.id}.json?export=1`);
}
get hasParams() {
return this.param_info.length;
}
resetParams() {
const newParams = {};
const oldParams = this.params;
this.param_info.forEach((pinfo) => {
const name = pinfo.identifier;
if (oldParams[pinfo.identifier]) {
newParams[name] = oldParams[name];
} else if (pinfo["default"] !== null) {
newParams[name] = pinfo["default"];
} else if (pinfo["type"] === "boolean") {
newParams[name] = "false";
} else if (pinfo["type"] === "user_id") {
newParams[name] = null;
} else if (pinfo["type"] === "user_list") {
newParams[name] = null;
} else {
newParams[name] = "";
}
});
this.params = newParams;
}
updateProperties() {
const props = this.getProperties(Query.updatePropertyNames);
if (this.destroyed) {
props.id = this.id;
}
return props;
}
createProperties() {
if (this.sql) {
// Importing
return this.updateProperties();
}
return this.getProperties("name");
}
}