Skip to content

A platform for community discussion. Free, open, simple.

UX: Apply new admin plugin show route and UI to Data Explorer (#37910)

Martin Brennane14af1c251c6
diff --git a/app/assets/stylesheets/common/components/d-page-header.scss b/app/assets/stylesheets/common/components/d-page-header.scss
index 9d0f640b3e0..aae03467f6b 100644
--- a/app/assets/stylesheets/common/components/d-page-header.scss
+++ b/app/assets/stylesheets/common/components/d-page-header.scss
@@ -18,7 +18,8 @@ $mobile-breakpoint: 700px;
font-size: var(--font-up-2);
}
- .d-page-header__actions {
+ .d-page-header__actions,
+ .d-page-subheader__actions {
display: flex;
align-items: center;
justify-content: flex-end;
diff --git a/frontend/discourse/admin/components/admin-filter-controls.gjs b/frontend/discourse/admin/components/admin-filter-controls.gjs
index 35217f384bb..dbc5bf17c70 100644
--- a/frontend/discourse/admin/components/admin-filter-controls.gjs
+++ b/frontend/discourse/admin/components/admin-filter-controls.gjs
@@ -230,6 +230,8 @@ export default class AdminFilterControls extends Component {
}
<template>
+ {{yield to="aboveFilters"}}
+
{{#if this.showFilters}}
<div
class={{concatClass
diff --git a/frontend/discourse/app/components/pick-files-button.gjs b/frontend/discourse/app/components/pick-files-button.gjs
index bd38ab37ab6..1a23ee4f874 100644
--- a/frontend/discourse/app/components/pick-files-button.gjs
+++ b/frontend/discourse/app/components/pick-files-button.gjs
@@ -6,6 +6,7 @@ import { service } from "@ember/service";
import { isBlank } from "@ember/utils";
import { classNames } from "@ember-decorators/component";
import DButton from "discourse/components/d-button";
+import concatClass from "discourse/helpers/concat-class";
import noop from "discourse/helpers/noop";
import discourseComputed, { bind } from "discourse/lib/decorators";
import {
@@ -131,6 +132,7 @@ export default class PickFilesButton extends Component {
@action={{this.openSystemFilePicker}}
@label={{this.label}}
@icon={{this.icon}}
+ class={{concatClass this.class "btn-default"}}
/>
{{/if}}
{{#if this.acceptsAllFormats}}
diff --git a/plugins/chat/spec/system/plugin_admin_interface_compatibility_spec.rb b/plugins/chat/spec/system/plugin_admin_interface_compatibility_spec.rb
new file mode 100644
index 00000000000..2a23e409a29
--- /dev/null
+++ b/plugins/chat/spec/system/plugin_admin_interface_compatibility_spec.rb
@@ -0,0 +1,47 @@
+# frozen_string_literal: true
+
+RSpec.describe "Plugin admin interface compatibility", type: :system do
+ fab!(:current_user, :admin)
+
+ before do
+ sign_in(current_user)
+ SiteSetting.data_explorer_enabled = true
+ SiteSetting.discourse_automation_enabled = true
+ SiteSetting.chat_enabled = true
+ SiteSetting.discourse_ai_enabled = true
+ end
+
+ it "plugin admin interfaces do not bleed between plugins" do
+ visit("/admin/plugins/discourse-ai")
+ within(".admin-plugin-config-area") do
+ expect(page).to have_css(".ai-features")
+ expect(page).to have_no_css(".discourse-data-explorer-query-list")
+ expect(page).to have_no_css(".discourse-automations-table")
+ expect(page).to have_no_css(".discourse-chat-incoming-webhooks")
+ end
+
+ visit("/admin/plugins/discourse-data-explorer")
+ within(".admin-plugin-config-area") do
+ expect(page).to have_css(".discourse-data-explorer-query-list")
+ expect(page).to have_no_css(".ai-features")
+ expect(page).to have_no_css(".discourse-automations-table")
+ expect(page).to have_no_css(".discourse-chat-incoming-webhooks")
+ end
+
+ visit("/admin/plugins/automation")
+ within(".admin-plugin-config-area") do
+ expect(page).to have_css(".discourse-automations-table")
+ expect(page).to have_no_css(".ai-features")
+ expect(page).to have_no_css(".discourse-data-explorer-query-list")
+ expect(page).to have_no_css(".discourse-chat-incoming-webhooks")
+ end
+
+ visit("/admin/plugins/chat")
+ within(".admin-plugin-config-area") do
+ expect(page).to have_css(".discourse-chat-incoming-webhooks")
+ expect(page).to have_no_css(".ai-features")
+ expect(page).to have_no_css(".discourse-data-explorer-query-list")
+ expect(page).to have_no_css(".discourse-automations-table")
+ end
+ end
+end
diff --git a/plugins/discourse-data-explorer/app/controllers/discourse_data_explorer/query_controller.rb b/plugins/discourse-data-explorer/app/controllers/discourse_data_explorer/query_controller.rb
index 1313c2d152c..c1e35159a47 100644
--- a/plugins/discourse-data-explorer/app/controllers/discourse_data_explorer/query_controller.rb
+++ b/plugins/discourse-data-explorer/app/controllers/discourse_data_explorer/query_controller.rb
@@ -13,20 +13,30 @@ module DiscourseDataExplorer
only: %i[group_reports_index group_reports_show group_reports_run public_run]
def index
- queries = Query.where(hidden: false).order(:last_run_at, :name).includes(:groups).to_a
-
- Queries.default.each do |params|
+ queries =
+ DiscourseDataExplorer::Query
+ .where(hidden: false)
+ .order(:last_run_at, :name)
+ .includes(:groups)
+ .to_a
+
+ DiscourseDataExplorer::Queries.default.each do |params|
attributes = params.last
- query = Query.new
- query.id = attributes["id"]
- query.sql = attributes["sql"]
- query.name = attributes["name"]
- query.description = attributes["description"]
+ persisted = queries.find { |q| q.id == attributes["id"] }
+
+ # Once a default query has been run, it is also saved in the local db
+ # so we can skip creating a "fake" query for the UI here, and this also
+ # avoids double-ups of the default query in the UI.
+ next if persisted.present?
+
+ query =
+ DiscourseDataExplorer::Query.new(attributes.slice("id", "sql", "name", "description"))
query.user_id = Discourse::SYSTEM_USER_ID.to_s
+
queries << query
end
- render_serialized queries, QuerySerializer, root: "queries"
+ render_serialized(queries, QuerySerializer, root: "queries")
end
def show
diff --git a/plugins/discourse-data-explorer/app/serializers/discourse_data_explorer/query_serializer.rb b/plugins/discourse-data-explorer/app/serializers/discourse_data_explorer/query_serializer.rb
index 0ba23d5386a..4f19cd336dd 100644
--- a/plugins/discourse-data-explorer/app/serializers/discourse_data_explorer/query_serializer.rb
+++ b/plugins/discourse-data-explorer/app/serializers/discourse_data_explorer/query_serializer.rb
@@ -2,7 +2,7 @@
module DiscourseDataExplorer
class QuerySerializer < ActiveModel::Serializer
- attributes :id, :name, :description, :username, :group_ids, :last_run_at, :user_id
+ attributes :id, :name, :description, :username, :group_ids, :last_run_at, :user_id, :is_default
def username
object&.user&.username
@@ -11,5 +11,9 @@ module DiscourseDataExplorer
def group_ids
object.groups.map(&:id)
end
+
+ def is_default
+ object.id < 0
+ end
end
end
diff --git a/plugins/discourse-data-explorer/assets/javascripts/admin/adapters/query.js b/plugins/discourse-data-explorer/assets/javascripts/admin/adapters/query.js
index 2cc55d4ad74..90bc2a0743b 100644
--- a/plugins/discourse-data-explorer/assets/javascripts/admin/adapters/query.js
+++ b/plugins/discourse-data-explorer/assets/javascripts/admin/adapters/query.js
@@ -5,5 +5,5 @@ const buildPluginAdapter = optionalRequire(
);
export default buildPluginAdapter
- ? buildPluginAdapter("explorer").extend({})
+ ? buildPluginAdapter("discourse-data-explorer").extend({})
: null; // Not logged in as admin, the adapter isn't needed
diff --git a/plugins/discourse-data-explorer/assets/javascripts/discourse/components/param-input-form.gjs b/plugins/discourse-data-explorer/assets/javascripts/discourse/components/param-input-form.gjs
index a6465d29741..31290fc5d82 100644
--- a/plugins/discourse-data-explorer/assets/javascripts/discourse/components/param-input-form.gjs
+++ b/plugins/discourse-data-explorer/assets/javascripts/discourse/components/param-input-form.gjs
@@ -441,7 +441,7 @@ export default class ParamInputForm extends Component {
as |form|
>
{{#each this.paramInfo as |info|}}
- <div class="param">
+ <div class="param" data-test-param-name={{info.identifier}}>
<form.Field
@name={{info.identifier}}
@title={{info.identifier}}
diff --git a/plugins/discourse-data-explorer/assets/javascripts/discourse/components/query-result.gjs b/plugins/discourse-data-explorer/assets/javascripts/discourse/components/query-result.gjs
index b75340a70af..ee315b7edfa 100644
--- a/plugins/discourse-data-explorer/assets/javascripts/discourse/components/query-result.gjs
+++ b/plugins/discourse-data-explorer/assets/javascripts/discourse/components/query-result.gjs
@@ -253,7 +253,7 @@ export default class QueryResult extends Component {
_download_url() {
return this.args.group
? `/g/${this.args.group.name}/reports/`
- : "/admin/plugins/explorer/queries/";
+ : "/admin/plugins/discourse-data-explorer/queries/";
}
_downloadResult(format) {
@@ -361,7 +361,7 @@ export default class QueryResult extends Component {
@datasetName={{this.chartDatasetName}}
/>
{{else}}
- <table>
+ <table class="query-results-table">
<thead>
<tr class="headers">
{{#each this.columnNames as |col|}}
diff --git a/plugins/discourse-data-explorer/assets/javascripts/discourse/components/query-row-content.gjs b/plugins/discourse-data-explorer/assets/javascripts/discourse/components/query-row-content.gjs
index bf7e4767fd2..f67ad7b3ee8 100644
--- a/plugins/discourse-data-explorer/assets/javascripts/discourse/components/query-row-content.gjs
+++ b/plugins/discourse-data-explorer/assets/javascripts/discourse/components/query-row-content.gjs
@@ -54,9 +54,9 @@ export default class QueryRowContent extends Component {
}
<template>
- <tr>
+ <tr class="query-result-row">
{{#each this.results as |result|}}
- <td>
+ <td class="query-result-cell">
<result.component
@ctx={{result.ctx}}
@params={{result.params}}
diff --git a/plugins/discourse-data-explorer/assets/javascripts/discourse/controllers/admin-plugins/explorer.js b/plugins/discourse-data-explorer/assets/javascripts/discourse/controllers/admin-plugins/show/explorer.js
similarity index 100%
rename from plugins/discourse-data-explorer/assets/javascripts/discourse/controllers/admin-plugins/explorer.js
rename to plugins/discourse-data-explorer/assets/javascripts/discourse/controllers/admin-plugins/show/explorer.js
diff --git a/plugins/discourse-data-explorer/assets/javascripts/discourse/controllers/admin-plugins/explorer/queries/details.js b/plugins/discourse-data-explorer/assets/javascripts/discourse/controllers/admin-plugins/show/explorer/details.js
similarity index 94%
rename from plugins/discourse-data-explorer/assets/javascripts/discourse/controllers/admin-plugins/explorer/queries/details.js
rename to plugins/discourse-data-explorer/assets/javascripts/discourse/controllers/admin-plugins/show/explorer/details.js
index 767aa97bf0d..b3d6879a364 100644
--- a/plugins/discourse-data-explorer/assets/javascripts/discourse/controllers/admin-plugins/explorer/queries/details.js
+++ b/plugins/discourse-data-explorer/assets/javascripts/discourse/controllers/admin-plugins/show/explorer/details.js
@@ -44,7 +44,7 @@ export default class PluginsExplorerController extends Controller {
}
get editDisabled() {
- return parseInt(this.model.id, 10) < 0 ? true : false;
+ return this.model.is_default;
}
get groupOptions() {
@@ -172,7 +172,7 @@ export default class PluginsExplorerController extends Controller {
@action
goHome() {
- this.router.transitionTo("adminPlugins.explorer");
+ this.router.transitionTo("adminPlugins.show.explorer");
}
@action
@@ -266,13 +266,18 @@ export default class PluginsExplorerController extends Controller {
params: JSON.stringify(params),
});
- ajax("/admin/plugins/explorer/queries/" + this.model.id + "/run", {
- type: "POST",
- data: {
- params: JSON.stringify(params),
- explain: this.explain,
- },
- })
+ ajax(
+ "/admin/plugins/discourse-data-explorer/queries/" +
+ this.model.id +
+ "/run",
+ {
+ type: "POST",
+ data: {
+ params: JSON.stringify(params),
+ explain: this.explain,
+ },
+ }
+ )
.then((result) => {
this.results = result;
if (!result.success) {
diff --git a/plugins/discourse-data-explorer/assets/javascripts/discourse/controllers/admin-plugins/explorer/index.js b/plugins/discourse-data-explorer/assets/javascripts/discourse/controllers/admin-plugins/show/explorer/index.js
similarity index 85%
rename from plugins/discourse-data-explorer/assets/javascripts/discourse/controllers/admin-plugins/explorer/index.js
rename to plugins/discourse-data-explorer/assets/javascripts/discourse/controllers/admin-plugins/show/explorer/index.js
index da9eac7b4d6..354e6b4e89a 100644
--- a/plugins/discourse-data-explorer/assets/javascripts/discourse/controllers/admin-plugins/explorer/index.js
+++ b/plugins/discourse-data-explorer/assets/javascripts/discourse/controllers/admin-plugins/show/explorer/index.js
@@ -12,12 +12,12 @@ export default class PluginsExplorerController extends Controller {
@service dialog;
@service appEvents;
@service router;
+ @service toasts;
@tracked sortByProperty = "last_run_at";
@tracked sortDescending = true;
@tracked params;
- @tracked search;
- @tracked newQueryName;
+ @tracked createFormData = { name: "" };
@tracked showCreate;
@tracked loading = false;
@@ -38,23 +38,9 @@ export default class PluginsExplorerController extends Controller {
return this.params ? JSON.parse(this.params) : null;
}
- get filteredContent() {
- const regexp = new RegExp(this.search, "i");
- return this.sortedQueries.filter(
- (result) => regexp.test(result.name) || regexp.test(result.description)
- );
- }
-
- get createDisabled() {
- return (this.newQueryName || "").trim().length === 0;
- }
-
addCreatedRecord(record) {
this.model.content.push(record);
- this.router.transitionTo(
- "adminPlugins.explorer.queries.details",
- record.id
- );
+ this.router.transitionTo("adminPlugins.show.explorer.details", record.id);
}
async _importQuery(file) {
@@ -151,6 +137,12 @@ export default class PluginsExplorerController extends Controller {
@action
displayCreate() {
this.showCreate = true;
+ this.createFormData = { name: "" };
+ }
+
+ @action
+ hideCreate() {
+ this.showCreate = false;
}
@action
@@ -164,12 +156,17 @@ export default class PluginsExplorerController extends Controller {
}
@action
- async create() {
+ async create({ name }) {
try {
- const name = this.newQueryName.trim();
this.loading = true;
+ const result = await this.store
+ .createRecord("query", { name: name.trim() })
+ .save();
+ this.toasts.success({
+ data: { message: i18n("explorer.query_created") },
+ });
this.showCreate = false;
- const result = await this.store.createRecord("query", { name }).save();
+ this.createFormData = { name: "" };
this.addCreatedRecord(result.target);
} catch (error) {
popupAjaxError(error);
@@ -177,14 +174,4 @@ export default class PluginsExplorerController extends Controller {
this.loading = false;
}
}
-
- @action
- updateSearch(value) {
- this.search = value;
- }
-
- @action
- updateNewQueryName(value) {
- this.newQueryName = value;
- }
}
diff --git a/plugins/discourse-data-explorer/assets/javascripts/discourse/explorer-legacy-route-map.js b/plugins/discourse-data-explorer/assets/javascripts/discourse/explorer-legacy-route-map.js
new file mode 100644
index 00000000000..d3f3cddb9e9
--- /dev/null
+++ b/plugins/discourse-data-explorer/assets/javascripts/discourse/explorer-legacy-route-map.js
@@ -0,0 +1,9 @@
+export default {
+ resource: "admin.adminPlugins",
+ path: "/plugins",
+ map() {
+ this.route("explorer", function () {
+ this.route("details", { path: "/:query_id" });
+ });
+ },
+};
diff --git a/plugins/discourse-data-explorer/assets/javascripts/discourse/explorer-route-map.js b/plugins/discourse-data-explorer/assets/javascripts/discourse/explorer-route-map.js
index 8b793f78f8f..a696b1cee71 100644
--- a/plugins/discourse-data-explorer/assets/javascripts/discourse/explorer-route-map.js
+++ b/plugins/discourse-data-explorer/assets/javascripts/discourse/explorer-route-map.js
@@ -1,11 +1,9 @@
export default {
- resource: "admin.adminPlugins",
+ resource: "admin.adminPlugins.show",
path: "/plugins",
map() {
- this.route("explorer", function () {
- this.route("queries", function () {
- this.route("details", { path: "/:query_id" });
- });
+ this.route("explorer", { path: "queries" }, function () {
+ this.route("details", { path: "/:query_id" });
});
},
};
diff --git a/plugins/discourse-data-explorer/assets/javascripts/discourse/initializers/data-explorer-admin-plugin-configuration-nav.js b/plugins/discourse-data-explorer/assets/javascripts/discourse/initializers/data-explorer-admin-plugin-configuration-nav.js
index aa55849e0e3..6eb5dc350f3 100644
--- a/plugins/discourse-data-explorer/assets/javascripts/discourse/initializers/data-explorer-admin-plugin-configuration-nav.js
+++ b/plugins/discourse-data-explorer/assets/javascripts/discourse/initializers/data-explorer-admin-plugin-configuration-nav.js
@@ -13,6 +13,12 @@ export default {
withPluginApi((api) => {
api.setAdminPluginIcon(PLUGIN_ID, "chart-line");
+ api.addAdminPluginConfigurationNav(PLUGIN_ID, [
+ {
+ label: "explorer.title",
+ route: "adminPlugins.show.explorer",
+ },
+ ]);
});
},
};
diff --git a/plugins/discourse-data-explorer/assets/javascripts/discourse/models/query.js b/plugins/discourse-data-explorer/assets/javascripts/discourse/models/query.js
index b57fd41d93e..3e63e39b6be 100644
--- a/plugins/discourse-data-explorer/assets/javascripts/discourse/models/query.js
+++ b/plugins/discourse-data-explorer/assets/javascripts/discourse/models/query.js
@@ -21,7 +21,9 @@ export default class Query extends RestModel {
}
get downloadUrl() {
- return getURL(`/admin/plugins/explorer/queries/${this.id}.json?export=1`);
+ return getURL(
+ `/admin/plugins/discourse-data-explorer/queries/${this.id}.json?export=1`
+ );
}
@computed("param_info", "updating")
diff --git a/plugins/discourse-data-explorer/assets/javascripts/discourse/routes/admin-plugins/explorer.js b/plugins/discourse-data-explorer/assets/javascripts/discourse/routes/admin-plugins/explorer.js
index 57afbfcba99..270243b132f 100644
--- a/plugins/discourse-data-explorer/assets/javascripts/discourse/routes/admin-plugins/explorer.js
+++ b/plugins/discourse-data-explorer/assets/javascripts/discourse/routes/admin-plugins/explorer.js
@@ -1,3 +1,3 @@
import Route from "@ember/routing/route";
-export default class extends Route {}
+export default class AdminPluginsExplorerRoute extends Route {}
diff --git a/plugins/discourse-data-explorer/assets/javascripts/discourse/routes/admin-plugins/explorer/details.js b/plugins/discourse-data-explorer/assets/javascripts/discourse/routes/admin-plugins/explorer/details.js
new file mode 100644
index 00000000000..7bd954b7e93
--- /dev/null
+++ b/plugins/discourse-data-explorer/assets/javascripts/discourse/routes/admin-plugins/explorer/details.js
@@ -0,0 +1,17 @@
+import Route from "@ember/routing/route";
+import { service } from "@ember/service";
+
+const PLUGIN_ID = "discourse-data-explorer";
+
+export default class AdminPluginsExplorerQueriesDetailsRoute extends Route {
+ @service router;
+
+ beforeModel(transition) {
+ this.router.transitionTo(
+ "adminPlugins.show.explorer.details",
+ PLUGIN_ID,
+ transition.to.params.query_id,
+ { queryParams: transition.to.queryParams }
+ );
+ }
+}
diff --git a/plugins/discourse-data-explorer/assets/javascripts/discourse/routes/admin-plugins/explorer/index.js b/plugins/discourse-data-explorer/assets/javascripts/discourse/routes/admin-plugins/explorer/index.js
index 90a2e9b60ea..6e8af457c58 100644
--- a/plugins/discourse-data-explorer/assets/javascripts/discourse/routes/admin-plugins/explorer/index.js
+++ b/plugins/discourse-data-explorer/assets/javascripts/discourse/routes/admin-plugins/explorer/index.js
@@ -1,47 +1,25 @@
+import Route from "@ember/routing/route";
import { service } from "@ember/service";
-import { ajax } from "discourse/lib/ajax";
-import DiscourseRoute from "discourse/routes/discourse";
-export default class AdminPluginsExplorerIndex extends DiscourseRoute {
+const PLUGIN_ID = "discourse-data-explorer";
+
+export default class AdminPluginsExplorerIndexRoute extends Route {
@service router;
beforeModel(transition) {
- // Redirect old /explorer?id=123 route to /explorer/queries/123
- if (transition.to.queryParams.id) {
+ const { id, ...queryParams } = transition.to.queryParams;
+ if (id) {
this.router.transitionTo(
- "adminPlugins.explorer.queries.details",
- transition.to.queryParams.id
+ "adminPlugins.show.explorer.details",
+ PLUGIN_ID,
+ id,
+ { queryParams }
);
- }
- }
-
- model() {
- if (!this.currentUser.admin) {
- // display "Only available to admins" message
- return { model: null, schema: null, disallow: true, groups: null };
+ return;
}
- const groupPromise = ajax("/admin/plugins/explorer/groups.json");
- const queryPromise = this.store.findAll("query");
-
- return groupPromise.then((groups) => {
- let groupNames = {};
- groups.forEach((g) => {
- groupNames[g.id] = g.name;
- });
- return queryPromise.then((model) => {
- model.content.forEach((query) => {
- query.set(
- "group_names",
- (query.group_ids || []).map((id) => groupNames[id])
- );
- });
- return { model, groups };
- });
+ this.router.transitionTo("adminPlugins.show.explorer", PLUGIN_ID, {
+ queryParams,
});
}
-
- setupController(controller, model) {
- controller.setProperties(model);
- }
}
diff --git a/plugins/discourse-data-explorer/assets/javascripts/discourse/routes/admin-plugins/show/explorer.js b/plugins/discourse-data-explorer/assets/javascripts/discourse/routes/admin-plugins/show/explorer.js
new file mode 100644
index 00000000000..57afbfcba99
--- /dev/null
+++ b/plugins/discourse-data-explorer/assets/javascripts/discourse/routes/admin-plugins/show/explorer.js
@@ -0,0 +1,3 @@
+import Route from "@ember/routing/route";
+
+export default class extends Route {}
diff --git a/plugins/discourse-data-explorer/assets/javascripts/discourse/routes/admin-plugins/explorer/queries/details.js b/plugins/discourse-data-explorer/assets/javascripts/discourse/routes/admin-plugins/show/explorer/details.js
similarity index 83%
rename from plugins/discourse-data-explorer/assets/javascripts/discourse/routes/admin-plugins/explorer/queries/details.js
rename to plugins/discourse-data-explorer/assets/javascripts/discourse/routes/admin-plugins/show/explorer/details.js
index 9fd0b59e35c..934e4606ff1 100644
--- a/plugins/discourse-data-explorer/assets/javascripts/discourse/routes/admin-plugins/explorer/queries/details.js
+++ b/plugins/discourse-data-explorer/assets/javascripts/discourse/routes/admin-plugins/show/explorer/details.js
@@ -15,10 +15,15 @@ export default class AdminPluginsExplorerQueriesDetails extends DiscourseRoute {
return { model: null, schema: null, disallow: true, groups: null };
}
- const groupPromise = ajax("/admin/plugins/explorer/groups.json");
- const schemaPromise = ajax("/admin/plugins/explorer/schema.json", {
- cache: true,
- });
+ const groupPromise = ajax(
+ "/admin/plugins/discourse-data-explorer/groups.json"
+ );
+ const schemaPromise = ajax(
+ "/admin/plugins/discourse-data-explorer/schema.json",
+ {
+ cache: true,
+ }
+ );
const queryPromise = this.store.find("query", params.query_id);
return groupPromise.then((groups) => {
diff --git a/plugins/discourse-data-explorer/assets/javascripts/discourse/routes/admin-plugins/show/explorer/index.js b/plugins/discourse-data-explorer/assets/javascripts/discourse/routes/admin-plugins/show/explorer/index.js
new file mode 100644
index 00000000000..64cde4ca9eb
--- /dev/null
+++ b/plugins/discourse-data-explorer/assets/javascripts/discourse/routes/admin-plugins/show/explorer/index.js
@@ -0,0 +1,45 @@
+import { service } from "@ember/service";
+import { ajax } from "discourse/lib/ajax";
+import DiscourseRoute from "discourse/routes/discourse";
+
+export default class AdminPluginsExplorerIndex extends DiscourseRoute {
+ @service router;
+
+ beforeModel(transition) {
+ // Redirect old `?id=123` URLs to query details.
+ const { id, ...queryParams } = transition.to.queryParams;
+ if (id) {
+ this.router.transitionTo("adminPlugins.show.explorer.details", id, {
+ queryParams,
+ });
+ }
+ }
+
+ async model() {
+ if (!this.currentUser.admin) {
+ // display "Only available to admins" message
+ return { model: null, schema: null, disallow: true, groups: null };
+ }
+
+ const [groups, model] = await Promise.all([
+ ajax("/admin/plugins/discourse-data-explorer/groups.json"),
+ this.store.findAll("query"),
+ ]);
+
+ const groupNames = {};
+ groups.forEach((g) => {
+ groupNames[g.id] = g.name;
+ });
+ model.content.forEach((query) => {
+ query.set(
+ "group_names",
+ (query.group_ids || []).map((id) => groupNames[id])
+ );
+ });
+ return { model, groups };
+ }
+
+ setupController(controller, model) {
+ controller.setProperties(model);
+ }
+}
diff --git a/plugins/discourse-data-explorer/assets/javascripts/discourse/templates/admin-plugins/explorer/index.gjs b/plugins/discourse-data-explorer/assets/javascripts/discourse/templates/admin-plugins/explorer/index.gjs
deleted file mode 100644
index fbe15e3ad59..00000000000
--- a/plugins/discourse-data-explorer/assets/javascripts/discourse/templates/admin-plugins/explorer/index.gjs
+++ /dev/null
@@ -1,181 +0,0 @@
-import { fn } from "@ember/helper";
-import { on } from "@ember/modifier";
-import ConditionalLoadingSpinner from "discourse/components/conditional-loading-spinner";
-import DButton from "discourse/components/d-button";
-import PickFilesButton from "discourse/components/pick-files-button";
-import TableHeaderToggle from "discourse/components/table-header-toggle";
-import TextField from "discourse/components/text-field";
-import ageWithTooltip from "discourse/helpers/age-with-tooltip";
-import icon from "discourse/helpers/d-icon";
-import { not } from "discourse/truth-helpers";
-import { i18n } from "discourse-i18n";
-import ShareReport from "../../../components/share-report";
-
-export default <template>
- {{#if @controller.disallow}}
- <h1>{{i18n "explorer.admins_only"}}</h1>
- {{else}}
- <div class="query-list">
- <TextField
- @value={{@controller.search}}
- @placeholderKey="explorer.search_placeholder"
- @onChange={{@controller.updateSearch}}
- />
- <DButton
- @action={{@controller.displayCreate}}
- @icon="plus"
- class="no-text btn-right"
- />
- <PickFilesButton
- @label="explorer.import.label"
- @icon="upload"
- @acceptedFormatsOverride={{@controller.acceptedImportFileTypes}}
- @showButton="true"
- @onFilesPicked={{@controller.import}}
- class="import-btn"
- />
- </div>
-
- {{#if @controller.showCreate}}
- <div class="query-create">
- <TextField
- @value={{@controller.newQueryName}}
- @placeholderKey="explorer.create_placeholder"
- @onChange={{@controller.updateNewQueryName}}
- />
- <DButton
- @action={{@controller.create}}
- @disabled={{@controller.createDisabled}}
- @label="explorer.create"
- @icon="plus"
- />
- </div>
- {{/if}}
-
- {{#if @controller.othersDirty}}
- <div class="warning">
- {{icon "triangle-exclamation"}}
- {{i18n "explorer.others_dirty"}}
- </div>
- {{/if}}
-
- {{#if @controller.model.content.length}}
- <ConditionalLoadingSpinner @condition={{@controller.loading}} />
-
- <div class="container">
- <table class="d-admin-table recent-queries">
- <thead class="heading-container">
- <th class="col heading name">
- <div
- role="button"
- class="heading-toggle"
- {{on "click" (fn @controller.updateSortProperty "name")}}
- >
- <TableHeaderToggle
- @field="name"
- @labelKey="explorer.query_name"
- @order={{@controller.order}}
- @asc={{not @controller.sortDescending}}
- @automatic="true"
- />
- </div>
- </th>
- <th class="col heading created-by">
- <div
- role="button"
- class="heading-toggle"
- {{on "click" (fn @controller.updateSortProperty "username")}}
- >
- <TableHeaderToggle
- @field="username"
- @labelKey="explorer.query_user"
- @order={{@controller.order}}
- @asc={{not @controller.sortDescending}}
- @automatic="true"
- />
- </div>
- </th>
- <th class="col heading group-names">
- <div class="group-names-header">
- {{i18n "explorer.query_groups"}}
- </div>
- </th>
- <th class="col heading created-at">
- <div
- role="button"
- class="heading-toggle"
- {{on "click" (fn @controller.updateSortProperty "last_run_at")}}
- >
- <TableHeaderToggle
- @field="last_run_at"
- @labelKey="explorer.query_time"
- @order={{@controller.order}}
- @asc={{not @controller.sortDescending}}
- @automatic="true"
- />
- </div>
- </th>
- </thead>
- <tbody>
- {{#each @controller.filteredContent as |query|}}
- <tr class="d-admin-row__content query-row">
- <td class="d-admin-row__overview">
- <a
- {{on "click" @controller.scrollTop}}
- href="/admin/plugins/explorer/queries/{{query.id}}"
- >
- <b class="query-name">{{query.name}}</b>
- <span class="query-desc">{{query.description}}</span>
- </a>
- </td>
- <td class="d-admin-row__detail query-created-by">
- <div class="d-admin-row__mobile-label">
- {{i18n "explorer.query_user"}}
- </div>
- {{#if query.username}}
- <div>
- <a href="/u/{{query.username}}/activity">
- <span>{{query.username}}</span>
- </a>
- </div>
- {{/if}}
- </td>
- <td class="d-admin-row__detail query-group-names">
- <div class="d-admin-row__mobile-label">
- {{i18n "explorer.query_groups"}}
- </div>
- <div class="group-names">
- {{#each query.group_names as |group|}}
- <ShareReport @group={{group}} @query={{query}} />
- {{/each}}
- </div>
- </td>
- <td class="d-admin-row__detail query-created-at">
- <div class="d-admin-row__mobile-label">
- {{i18n "explorer.query_time"}}
- </div>
- {{#if query.last_run_at}}
- <span>
- {{ageWithTooltip query.last_run_at format="medium"}}
- </span>
- {{else if query.created_at}}
- <span>
- {{ageWithTooltip query.created_at format="medium"}}
- </span>
- {{/if}}
- </td>
- </tr>
- {{else}}
- <br />
- <em class="no-search-results">
- {{i18n "explorer.no_search_results"}}
- </em>
- {{/each}}
- </tbody>
- </table>
- </div>
-
- <div class="explorer-pad-bottom"></div>
- {{/if}}
- {{/if}}
-</template>
diff --git a/plugins/discourse-data-explorer/assets/javascripts/discourse/templates/admin-plugins/explorer/queries/details.gjs b/plugins/discourse-data-explorer/assets/javascripts/discourse/templates/admin-plugins/show/explorer/details.gjs
similarity index 95%
rename from plugins/discourse-data-explorer/assets/javascripts/discourse/templates/admin-plugins/explorer/queries/details.gjs
rename to plugins/discourse-data-explorer/assets/javascripts/discourse/templates/admin-plugins/show/explorer/details.gjs
index 55275623cc8..f1e325de7cc 100644
--- a/plugins/discourse-data-explorer/assets/javascripts/discourse/templates/admin-plugins/explorer/queries/details.gjs
+++ b/plugins/discourse-data-explorer/assets/javascripts/discourse/templates/admin-plugins/show/explorer/details.gjs
@@ -63,7 +63,7 @@ export default class QueriesDetails extends Component {
class="previous"
/>
- <h1>
+ <h1 class="query-name-display">
<span>{{@controller.model.name}}</span>
{{#unless @controller.editDisabled}}
<DButton
@@ -145,6 +145,12 @@ export default class QueriesDetails extends Component {
<div class="clear"></div>
+ {{#if @controller.model.is_default}}
+ <div class="default-query-notice alert alert-info">{{i18n
+ "explorer.default_query_notice"
+ }}</div>
+ {{/if}}
+
<div class="pull-left left-buttons">
{{#if @controller.editingQuery}}
<DButton
@@ -224,14 +230,14 @@ export default class QueriesDetails extends Component {
<DButton
@label="explorer.run"
@disabled="true"
- class="btn-primary"
+ class="btn-primary query-run__submit"
/>
{{else}}
<DButton
@action={{@controller.saveAndRun}}
@icon="play"
@label="explorer.saverun"
- class="btn-primary"
+ class="btn-primary query-run__save-and-run"
/>
{{/if}}
{{else}}
@@ -242,7 +248,7 @@ export default class QueriesDetails extends Component {
@label="explorer.run"
@disabled={{@controller.runDisabled}}
@type="submit"
- class="btn-primary"
+ class="btn-primary query-run__submit"
/>
{{/if}}
diff --git a/plugins/discourse-data-explorer/assets/javascripts/discourse/templates/admin-plugins/show/explorer/index.gjs b/plugins/discourse-data-explorer/assets/javascripts/discourse/templates/admin-plugins/show/explorer/index.gjs
new file mode 100644
index 00000000000..1437b7a623a
--- /dev/null
+++ b/plugins/discourse-data-explorer/assets/javascripts/discourse/templates/admin-plugins/show/explorer/index.gjs
@@ -0,0 +1,229 @@
+import { array, fn } from "@ember/helper";
+import { on } from "@ember/modifier";
+import { LinkTo } from "@ember/routing";
+import AdminFilterControls from "discourse/admin/components/admin-filter-controls";
+import ConditionalLoadingSpinner from "discourse/components/conditional-loading-spinner";
+import DPageSubheader from "discourse/components/d-page-subheader";
+import Form from "discourse/components/form";
+import PickFilesButton from "discourse/components/pick-files-button";
+import TableHeaderToggle from "discourse/components/table-header-toggle";
+import ageWithTooltip from "discourse/helpers/age-with-tooltip";
+import icon from "discourse/helpers/d-icon";
+import { not } from "discourse/truth-helpers";
+import { i18n } from "discourse-i18n";
+import ShareReport from "../../../../components/share-report";
+
+export default <template>
+ <div class="admin-detail">
+ {{#if @controller.disallow}}
+ <h1>{{i18n "explorer.admins_only"}}</h1>
+ {{else}}
+ <DPageSubheader @titleLabel={{i18n "explorer.queries"}}>
+ <:actions as |actions|>
+ <actions.Primary
+ @action={{@controller.displayCreate}}
+ @icon="plus"
+ @label="explorer.create"
+ />
+ <actions.Wrapped>
+ <PickFilesButton
+ @label="explorer.import.label"
+ @icon="upload"
+ @acceptedFormatsOverride={{@controller.acceptedImportFileTypes}}
+ @showButton="true"
+ @onFilesPicked={{@controller.import}}
+ class="d-page-action-button btn-small"
+ />
+ </actions.Wrapped>
+ </:actions>
+ </DPageSubheader>
+
+ <AdminFilterControls
+ @array={{@controller.sortedQueries}}
+ @searchableProps={{array "name" "description"}}
+ @inputPlaceholder={{i18n "explorer.search_placeholder"}}
+ @noResultsMessage={{i18n "explorer.no_search_results"}}
+ >
+ <:aboveFilters>
+ {{#if @controller.showCreate}}
+ <div class="query-create">
+ <Form
+ @data={{@controller.createFormData}}
+ @onSubmit={{@controller.create}}
+ as |form|
+ >
+ <form.Field
+ @name="name"
+ @title={{i18n "explorer.create_placeholder"}}
+ @validation="required"
+ @format="large"
+ as |field|
+ >
+ <field.Input />
+ </form.Field>
+ <form.Actions>
+ <form.Submit @label="explorer.create" @icon="plus" />
+ <form.Button
+ @action={{@controller.hideCreate}}
+ class="btn-default"
+ >
+ {{i18n "cancel"}}
+ </form.Button>
+ </form.Actions>
+ </Form>
+ </div>
+ {{/if}}
+
+ {{#if @controller.othersDirty}}
+ <div class="warning">
+ {{icon "triangle-exclamation"}}
+ {{i18n "explorer.others_dirty"}}
+ </div>
+ {{/if}}
+ </:aboveFilters>
+
+ <:content as |filteredQueries|>
+ {{#if @controller.model.content.length}}
+ <ConditionalLoadingSpinner @condition={{@controller.loading}} />
+
+ <div class="container discourse-data-explorer-query-list">
+ <table class="d-admin-table recent-queries">
+ <thead class="heading-container">
+ <th class="col heading name">
+ <div
+ role="button"
+ class="heading-toggle"
+ {{on "click" (fn @controller.updateSortProperty "name")}}
+ >
+ <TableHeaderToggle
+ @field="name"
+ @labelKey="explorer.query_name"
+ @order={{@controller.order}}
+ @asc={{not @controller.sortDescending}}
+ @automatic="true"
+ />
+ </div>
+ </th>
+ <th class="col heading created-by">
+ <div
+ role="button"
+ class="heading-toggle"
+ {{on
+ "click"
+ (fn @controller.updateSortProperty "username")
+ }}
+ >
+ <TableHeaderToggle
+ @field="username"
+ @labelKey="explorer.query_user"
+ @order={{@controller.order}}
+ @asc={{not @controller.sortDescending}}
+ @automatic="true"
+ />
+ </div>
+ </th>
+ <th class="col heading group-names">
+ <div class="group-names-header">
+ {{i18n "explorer.query_groups"}}
+ </div>
+ </th>
+ <th class="col heading created-at">
+ <div
+ role="button"
+ class="heading-toggle"
+ {{on
+ "click"
+ (fn @controller.updateSortProperty "last_run_at")
+ }}
+ >
+ <TableHeaderToggle
+ @field="last_run_at"
+ @labelKey="explorer.query_time"
+ @order={{@controller.order}}
+ @asc={{not @controller.sortDescending}}
+ @automatic="true"
+ />
+ </div>
+ </th>
+ </thead>
+ <tbody>
+ {{#each filteredQueries as |query|}}
+ <tr class="d-admin-row__content query-row">
+ <td class="d-admin-row__overview">
+ <strong class="query-name">{{query.name}}</strong>
+ {{#if query.is_default}}
+ <span class="query-badge">{{i18n
+ "explorer.default_query"
+ }}</span>
+ {{/if}}
+ <div class="query-desc">{{query.description}}</div>
+ </td>
+ <td class="d-admin-row__detail query-created-by">
+ <div class="d-admin-row__mobile-label">
+ {{i18n "explorer.query_user"}}
+ </div>
+ {{#if query.username}}
+ <div>
+ <a href="/u/{{query.username}}/activity">
+ <span>{{query.username}}</span>
+ </a>
+ </div>
+ {{/if}}
+ </td>
+ <td class="d-admin-row__detail query-group-names">
+ <div class="d-admin-row__mobile-label">
+ {{i18n "explorer.query_groups"}}
+ </div>
+ <div class="group-names">
+ {{#each query.group_names as |group|}}
+ <ShareReport @group={{group}} @query={{query}} />
+ {{/each}}
+ {{#unless query.group_names.length}}
+ -
+ {{/unless}}
+ </div>
+ </td>
+ <td class="d-admin-row__detail query-created-at">
+ <div class="d-admin-row__mobile-label">
+ {{i18n "explorer.query_time"}}
+ </div>
+ {{#if query.last_run_at}}
+ <span>
+ {{ageWithTooltip query.last_run_at format="medium"}}
+ </span>
+ {{else if query.created_at}}
+ <span>
+ {{ageWithTooltip query.created_at format="medium"}}
+ </span>
+ {{else}}
+ -
+ {{/if}}
+ </td>
+ <td class="d-table__cell-actions">
+ <LinkTo
+ {{on "click" @controller.scrollTop}}
+ @route="adminPlugins.show.explorer.details"
+ @model={{query.id}}
+ class="btn btn-default btn-small"
+ >
+ {{i18n "edit"}}
+ </LinkTo>
+ </td>
+ </tr>
+ {{else}}
+ <br />
+ <em class="no-search-results">
+ {{i18n "explorer.no_search_results"}}
+ </em>
+ {{/each}}
+ </tbody>
+ </table>
+ </div>
+
+ <div class="explorer-pad-bottom"></div>
+ {{/if}}
+ </:content>
+ </AdminFilterControls>
+ {{/if}}
+ </div>
+</template>
diff --git a/plugins/discourse-data-explorer/assets/javascripts/discourse/templates/group/reports/show.gjs b/plugins/discourse-data-explorer/assets/javascripts/discourse/templates/group/reports/show.gjs
index 5bdfd927474..26dcb790ae3 100644
--- a/plugins/discourse-data-explorer/assets/javascripts/discourse/templates/group/reports/show.gjs
+++ b/plugins/discourse-data-explorer/assets/javascripts/discourse/templates/group/reports/show.gjs
@@ -25,7 +25,7 @@ export default <template>
@icon="play"
@label="explorer.run"
@type="submit"
- class="btn-primary"
+ class="btn-primary query-run__submit"
/>
<DButton
diff --git a/plugins/discourse-data-explorer/assets/stylesheets/explorer.scss b/plugins/discourse-data-explorer/assets/stylesheets/explorer.scss
index 7c07d87322a..4304ef79609 100644
--- a/plugins/discourse-data-explorer/assets/stylesheets/explorer.scss
+++ b/plugins/discourse-data-explorer/assets/stylesheets/explorer.scss
@@ -335,7 +335,7 @@ table.group-reports {
}
}
-.query-list,
+.disscourse-data-explorer-query-list,
.query-create,
.query-edit,
.query-results,
@@ -380,10 +380,7 @@ table.group-reports {
}
}
-.query-list {
- display: flex;
- align-items: flex-start;
-
+.discourse-data-explorer-query-list {
.btn-left {
margin-right: 0.5em;
}
@@ -448,9 +445,21 @@ table.group-reports {
color: var(--primary);
}
+ .query-badge {
+ font-size: var(--font-down-2);
+ padding: 0.15rem 0.3rem;
+ border-radius: 4px;
+ color: var(--primary-high);
+ background: var(--primary-low);
+ letter-spacing: 0.25px;
+ align-items: center;
+ display: inline-flex;
+ gap: var(--space-1);
+ }
+
.query-desc {
- display: block;
color: var(--primary-high);
+ max-width: 20vw;
}
.query-created-by {
@@ -458,10 +467,12 @@ table.group-reports {
}
.query-group-names {
- color: var(--tertiary);
+ .share-report {
+ color: var(--tertiary);
- a {
- display: inline;
+ a {
+ display: inline;
+ }
}
}
diff --git a/plugins/discourse-data-explorer/config/locales/client.en.yml b/plugins/discourse-data-explorer/config/locales/client.en.yml
index 6d0584e54c4..a78e77372b0 100644
--- a/plugins/discourse-data-explorer/config/locales/client.en.yml
+++ b/plugins/discourse-data-explorer/config/locales/client.en.yml
@@ -5,38 +5,41 @@ en:
no_semicolons: "Remove the semicolons from the query."
dirty: "You must save the query before running."
explorer:
+ default_query: "Default"
+ default_query_notice: "This is a default query, the SQL cannot be edited. To edit the SQL, create a new query."
+ queries: "Queries"
+ query_created: "Query created!"
or: "or"
admins_only: "The data explorer is only available to admins."
allow_groups: "Allow groups to access this query"
title: "Data Explorer"
- create: "Create New"
+ create: "Create"
create_placeholder: "Query name..."
description_placeholder: "Enter a description here"
import:
label: "Import"
- modal: "Import A Query"
unparseable_json: "Unparseable JSON file."
wrong_json: "Wrong JSON file. A JSON file should contain a 'query' object, which should at least have an 'sql' property."
help:
label: "Help"
modal_title: "Data Explorer Help"
- auto_resolution: "<h2>Automatic Entity Resolution</h2>
+ auto_resolution: "<h2>Automatic entity resolution</h2>
<p>When your query returns an entity id, Data Explorer may automatically substitute it with
the entity name and other useful information in query results. Automatic resolution is available for
<i><b>user_id</b></i>, <i><b>group_id</b></i>, <i><b>topic_id</b></i>, <i><b>category_id</b></i>
and <i><b>badge_id</b></i>. To try this out run this query:</p>
<pre><code>SELECT user_id\nFROM posts</code></pre>"
- custom_params: "<h2>Creating Custom Parameters</h2>
+ custom_params: "<h2>Creating custom parameters</h2>
<p>To create custom parameters for your queries, put this at the top of your query and follow the format:</p>
<pre><code>-- [params]\n-- int :num = 1\n\nSELECT :num</code></pre>
<p><i>Note: the first line with [params] is required, along with two dashes preceding it and every
custom parameter you want to declare.</i></p>"
- default_values: "<h3>Default Values</h3>
+ default_values: "<h3>Default values</h3>
<p>You can declare parameters with or without default values. Default values will show up in a text field
below the query editor, which you can edit to your needs. Parameters declared without default values will
still generate a text field, but will be empty and highlighted red.</p>
<pre><code>-- [params]\n-- text :username = my_username\n-- int :age</code></pre>"
- data_types: "<h3>Data Types</h3>
+ data_types: "<h3>Data types</h3>
<p>Here are common data types you can use:</p>
<ul>
<li><b>integer</b> - signed four-byte Integer</li>
@@ -58,13 +61,13 @@ en:
null_: "Null"
export: "Export"
view_json: "View JSON"
- save: "Save Changes"
- saverun: "Save Changes and Run"
+ save: "Save changes"
+ saverun: "Save changes and run"
run: "Run"
- undo: "Discard Changes"
+ undo: "Discard changes"
edit: "Edit"
delete: "Delete"
- recover: "Undelete Query"
+ recover: "Undelete query"
download_json: "JSON"
download_csv: "CSV"
show_table: "Table"
@@ -86,7 +89,7 @@ en:
query_user: "Created by"
column: "Column %{number}"
explain_label: "Include query plan?"
- save_params: "Set Defaults"
+ save_params: "Set defaults"
reset_params: "Reset"
search_placeholder: "Search..."
no_search_results: "Sorry, we couldn't find any results matching your text."
diff --git a/plugins/discourse-data-explorer/config/locales/server.en.yml b/plugins/discourse-data-explorer/config/locales/server.en.yml
index 55cf55f0f78..bf457988ca0 100644
--- a/plugins/discourse-data-explorer/config/locales/server.en.yml
+++ b/plugins/discourse-data-explorer/config/locales/server.en.yml
@@ -1,6 +1,6 @@
en:
site_settings:
- data_explorer_enabled: "Enable the Data Explorer at /admin/plugins/explorer"
+ data_explorer_enabled: "Enable data explorer"
discourse_automation:
scriptables:
recurring_data_explorer_result_pm:
@@ -23,7 +23,7 @@ en:
Here are the results:
%{table}
- <a href='%{base_url}/admin/plugins/explorer/queries/%{query_id}'>View query in Data Explorer</a>
+ <a href='%{base_url}/admin/plugins/discourse-data-explorer/queries/%{query_id}'>View query in Data Explorer</a>
Report created at %{created_at} (%{timezone})
post:
@@ -33,7 +33,7 @@ en:
Here are the results:
%{table}
- <a href='%{base_url}/admin/plugins/explorer/queries/%{query_id}'>View query in Data Explorer</a>
+ <a href='%{base_url}/admin/plugins/discourse-data-explorer/queries/%{query_id}'>View query in Data Explorer</a>
Report created at %{created_at} (%{timezone})
upload_appendix: "Appendix: [%{filename}|attachment](%{short_url})"
diff --git a/plugins/discourse-data-explorer/config/routes.rb b/plugins/discourse-data-explorer/config/routes.rb
index f0e11a76376..5b4a78c31f8 100644
--- a/plugins/discourse-data-explorer/config/routes.rb
+++ b/plugins/discourse-data-explorer/config/routes.rb
@@ -26,5 +26,8 @@ Discourse::Application.routes.draw do
format: /(json|csv)/,
}
- mount DiscourseDataExplorer::Engine, at: "/admin/plugins/explorer"
+ mount DiscourseDataExplorer::Engine, at: "/admin/plugins/discourse-data-explorer"
+ mount DiscourseDataExplorer::Engine,
+ at: "/admin/plugins/explorer",
+ as: :legacy_discourse_data_explorer
end
diff --git a/plugins/discourse-data-explorer/lib/discourse_data_explorer/data_explorer.rb b/plugins/discourse-data-explorer/lib/discourse_data_explorer/data_explorer.rb
index 4822ea3d0e4..5bd13b7d941 100644
--- a/plugins/discourse-data-explorer/lib/discourse_data_explorer/data_explorer.rb
+++ b/plugins/discourse-data-explorer/lib/discourse_data_explorer/data_explorer.rb
@@ -47,7 +47,7 @@ module DiscourseDataExplorer
sql = <<~SQL
/*
* DiscourseDataExplorer Query
- * Query: /admin/plugins/explorer/queries/#{query.id}
+ * Query: /admin/plugins/discourse-data-explorer/queries/#{query.id}
#{"* Started by: #{started_by}" if started_by}
*/
WITH query AS (
diff --git a/plugins/discourse-data-explorer/plugin.rb b/plugins/discourse-data-explorer/plugin.rb
index 3c47695e61a..e249b413396 100644
--- a/plugins/discourse-data-explorer/plugin.rb
+++ b/plugins/discourse-data-explorer/plugin.rb
@@ -20,7 +20,7 @@ register_svg_icon "info"
register_svg_icon "pencil"
register_svg_icon "upload"
-add_admin_route "explorer.title", "explorer"
+add_admin_route "explorer.title", "discourse-data-explorer", use_new_show_route: true
module ::DiscourseDataExplorer
PLUGIN_NAME = "discourse-data-explorer"
diff --git a/plugins/discourse-data-explorer/spec/requests/query_controller_spec.rb b/plugins/discourse-data-explorer/spec/requests/query_controller_spec.rb
index d125eade146..9724d55d79f 100644
--- a/plugins/discourse-data-explorer/spec/requests/query_controller_spec.rb
+++ b/plugins/discourse-data-explorer/spec/requests/query_controller_spec.rb
@@ -83,6 +83,36 @@ describe DiscourseDataExplorer::QueryController do
DiscourseDataExplorer::Queries.default.count + 1,
)
end
+
+ it "merges default query data with persisted last_run_at and groups" do
+ freeze_time
+
+ post "/admin/plugins/explorer/queries/-1/run.json"
+ expect(response.status).to eq(200)
+
+ # Run persists the default query in the local DB; update it to assert index merges it
+ group = Fabricate(:group)
+ persisted = DiscourseDataExplorer::Query.find_by(id: -1)
+ persisted.update!(last_run_at: 3.days.ago, groups: [group])
+
+ get "/admin/plugins/explorer/queries.json"
+ expect(response.status).to eq(200)
+
+ expect(response_json["queries"].count).to eq(DiscourseDataExplorer::Queries.default.count)
+ default_in_response = response_json["queries"].find { |q| q["id"] == -1 }
+ expect(default_in_response).to be_present
+ expect(Time.parse(default_in_response["last_run_at"])).to eq_time(3.days.ago)
+ expect(default_in_response["group_ids"]).to eq([group.id])
+ end
+
+ it "doesn't show double-ups of default queries" do
+ post "/admin/plugins/explorer/queries/-1/run.json"
+ expect(response.status).to eq(200)
+
+ get "/admin/plugins/explorer/queries.json"
+ expect(response.status).to eq(200)
+ expect(response_json["queries"].count).to eq(DiscourseDataExplorer::Queries.default.count)
+ end
end
describe "#update" do
diff --git a/plugins/discourse-data-explorer/spec/system/page_objects/pages/data_explorer_query_runner.rb b/plugins/discourse-data-explorer/spec/system/page_objects/pages/data_explorer_query_runner.rb
new file mode 100644
index 00000000000..d22c127d88f
--- /dev/null
+++ b/plugins/discourse-data-explorer/spec/system/page_objects/pages/data_explorer_query_runner.rb
@@ -0,0 +1,70 @@
+# frozen_string_literal: true
+
+module PageObjects
+ module Pages
+ class DataExplorerQueryRunner < PageObjects::Pages::Base
+ def visit_group_report(group_name, query_id)
+ page.visit("/g/#{group_name}/reports/#{query_id}")
+ self
+ end
+
+ def visit_admin_query(query_id, query_string: nil)
+ path = "/admin/plugins/discourse-data-explorer/queries/#{query_id}"
+ path += "?#{query_string}" if query_string.present?
+ page.visit(path)
+ self
+ end
+
+ def has_param_field?(name, value)
+ page.has_field?(name, with: value)
+ end
+
+ def run_query
+ page.find(".query-run .query-run__submit").click
+ self
+ end
+
+ def click_edit_name
+ page.find(".edit-query-name").click
+ self
+ end
+
+ def fill_query_name(text)
+ page.find(".name-text-field input").fill_in(with: text)
+ self
+ end
+
+ def click_save_and_run
+ page.find(".query-run .query-run__save-and-run").click
+ self
+ end
+
+ def has_query_name?(text)
+ page.has_css?(".query-name-display", text: text)
+ end
+
+ def has_no_params?
+ page.has_no_css?(".query-params")
+ end
+
+ def has_result_header?
+ page.has_css?(".query-results .result-header")
+ end
+
+ def has_result_row_count?(count)
+ page.has_css?(".query-results .query-result-row", count: count)
+ end
+
+ def has_result_cell?(text)
+ page.has_css?(".query-results .query-result-cell", text: text)
+ end
+
+ def has_result_cell_at?(row_index, col_index, text:)
+ page.has_css?(
+ ".query-results .query-result-row:nth-of-type(#{row_index}) .query-result-cell:nth-of-type(#{col_index})",
+ text: text,
+ )
+ end
+ end
+ end
+end
diff --git a/plugins/discourse-data-explorer/spec/system/param_input_spec.rb b/plugins/discourse-data-explorer/spec/system/param_input_spec.rb
index c12128eb22c..59659189362 100644
--- a/plugins/discourse-data-explorer/spec/system/param_input_spec.rb
+++ b/plugins/discourse-data-explorer/spec/system/param_input_spec.rb
@@ -62,7 +62,7 @@ RSpec.describe "Param input", type: :system do
end
it "correctly displays parameter input boxes" do
- visit("/admin/plugins/explorer/queries/#{all_params_query.id}")
+ visit("/admin/plugins/discourse-data-explorer/queries/#{all_params_query.id}")
DiscourseDataExplorer::Parameter
.create_from_sql(ALL_PARAMS_SQL)
diff --git a/plugins/discourse-data-explorer/spec/system/explorer_spec.rb b/plugins/discourse-data-explorer/spec/system/query_runner_spec.rb
similarity index 61%
rename from plugins/discourse-data-explorer/spec/system/explorer_spec.rb
rename to plugins/discourse-data-explorer/spec/system/query_runner_spec.rb
index 31047f669a6..88b7cacd303 100644
--- a/plugins/discourse-data-explorer/spec/system/explorer_spec.rb
+++ b/plugins/discourse-data-explorer/spec/system/query_runner_spec.rb
@@ -1,10 +1,12 @@
# frozen_string_literal: true
-RSpec.describe "Explorer", type: :system do
+RSpec.describe "Data explorer query runner", type: :system do
fab!(:admin)
fab!(:group) { Fabricate(:group, name: "group") }
fab!(:group_user) { Fabricate(:group_user, user: admin, group: group) }
+ let(:query_runner) { PageObjects::Pages::DataExplorerQueryRunner.new }
+
before do
SiteSetting.data_explorer_enabled = true
sign_in admin
@@ -19,12 +21,12 @@ RSpec.describe "Explorer", type: :system do
end
it "clears results from a previously run query" do
- visit("/admin/plugins/explorer/queries/#{query_a.id}")
+ visit("/admin/plugins/discourse-data-explorer/queries/#{query_a.id}")
find(".query-run .btn-primary").click
expect(page).to have_css(".query-results .result-header")
find(".query-edit .previous").click
- find("a[href='/admin/plugins/explorer/queries/#{query_b.id}']").click
+ find("a[href='/admin/plugins/discourse-data-explorer/queries/#{query_b.id}']").click
expect(page).to have_no_css(".query-results .result-header")
end
end
@@ -42,19 +44,16 @@ RSpec.describe "Explorer", type: :system do
fab!(:query_group_1) { Fabricate(:query_group, query: query_1, group: group) }
it "pre-fills the field with the default param" do
- visit("/g/group/reports/#{query_1.id}")
+ query_runner.visit_group_report("group", query_1.id)
- expect(page).to have_field("limit", with: 42)
+ expect(query_runner).to have_param_field("limit", "42")
end
it "allows to edit custom name" do
- visit("/admin/plugins/explorer/queries/#{query_1.id}")
- find(".query-run .btn-primary").click
- find(".edit-query-name").click
- find(".name-text-field input").fill_in(with: "My custom name edited")
- find(".btn-primary").click
- find("button span", text: "Save Changes and Run").click
- expect(page.find(".name h1")).to have_content("My custom name edited")
+ query_runner.visit_admin_query(query_1.id).run_query.click_edit_name
+ query_runner.fill_query_name("My custom name edited").click_save_and_run
+
+ expect(query_runner).to have_query_name("My custom name edited")
end
end
@@ -72,14 +71,16 @@ RSpec.describe "Explorer", type: :system do
it "redirects to the new url format" do
visit("/admin/plugins/explorer/?id=#{query_1.id}")
- expect(page).to have_current_path("/admin/plugins/explorer/queries/#{query_1.id}")
+ expect(page).to have_current_path(
+ "/admin/plugins/discourse-data-explorer/queries/#{query_1.id}",
+ )
end
it "redirects to the new url format with params" do
visit("/admin/plugins/explorer/?id=#{query_1.id}&params=%7B%22limit%22%3A%2210%22%7D")
expect(page).to have_current_path(
- "/admin/plugins/explorer/queries/#{query_1.id}?params=%7B%22limit%22%3A%2210%22%7D",
+ "/admin/plugins/discourse-data-explorer/queries/#{query_1.id}?params=%7B%22limit%22%3A%2210%22%7D",
)
end
end
@@ -97,21 +98,14 @@ RSpec.describe "Explorer", type: :system do
end
it "supports setting a group_list param" do
- visit(
- "/admin/plugins/explorer/queries/#{q2.id}?params=%7B\"groups\"%3A\"admins%2Ctrust_level_1\"%7D",
- )
- find(".query-run .btn-primary").click
-
- expect(page).to have_css(".query-results .result-header")
-
- expect(page).to have_css(
- ".query-results tbody tr:nth-child(1) td:nth-child(2)",
- text: "admins",
- )
- expect(page).to have_css(
- ".query-results tbody tr:nth-child(2) td:nth-child(2)",
- text: "trust_level_1",
- )
+ query_runner.visit_admin_query(
+ q2.id,
+ query_string: "params=%7B\"groups\"%3A\"admins%2Ctrust_level_1\"%7D",
+ ).run_query
+
+ expect(query_runner).to have_result_header
+ expect(query_runner).to have_result_cell_at(1, 2, text: "admins")
+ expect(query_runner).to have_result_cell_at(2, 2, text: "trust_level_1")
end
end
@@ -123,14 +117,14 @@ RSpec.describe "Explorer", type: :system do
SQL
it "auto-injects the current user's id without showing an input field" do
- visit("/admin/plugins/explorer/queries/#{query.id}")
+ query_runner.visit_admin_query(query.id)
- expect(page).to have_no_css(".query-params")
- find(".query-run .btn-primary").click
+ expect(query_runner).to have_no_params
+ query_runner.run_query
- expect(page).to have_css(".query-results .result-header")
- expect(page).to have_css(".query-results tbody tr", count: 1)
- expect(page).to have_css(".query-results tbody td", text: admin.username)
+ expect(query_runner).to have_result_header
+ expect(query_runner).to have_result_row_count(1)
+ expect(query_runner).to have_result_cell(admin.username)
end
end
end
diff --git a/plugins/discourse-data-explorer/test/javascripts/acceptance/list-queries-test.js b/plugins/discourse-data-explorer/test/javascripts/acceptance/list-queries-test.js
index af74c99cdb5..f855e0e27aa 100644
--- a/plugins/discourse-data-explorer/test/javascripts/acceptance/list-queries-test.js
+++ b/plugins/discourse-data-explorer/test/javascripts/acceptance/list-queries-test.js
@@ -8,11 +8,27 @@ acceptance("Data Explorer Plugin | List Queries", function (needs) {
needs.settings({ data_explorer_enabled: true });
needs.pretender((server, helper) => {
- server.get("/admin/plugins/explorer/groups.json", () => {
+ server.get("/admin/plugins/discourse-data-explorer.json", () => {
+ return helper.response({
+ id: "discourse-data-explorer",
+ name: "discourse-data-explorer",
+ enabled: true,
+ has_settings: true,
+ humanized_name: "Data Explorer",
+ is_discourse_owned: true,
+ admin_route: {
+ label: "explorer.title",
+ location: "discourse-data-explorer",
+ use_new_show_route: true,
+ },
+ });
+ });
+
+ server.get("/admin/plugins/discourse-data-explorer/groups.json", () => {
return helper.response([]);
});
- server.get("/admin/plugins/explorer/queries", () => {
+ server.get("/admin/plugins/discourse-data-explorer/queries", () => {
return helper.response({
queries: [
{
@@ -41,10 +57,10 @@ acceptance("Data Explorer Plugin | List Queries", function (needs) {
});
test("renders the page with the list of queries", async function (assert) {
- await visit("/admin/plugins/explorer");
+ await visit("/admin/plugins/discourse-data-explorer/queries");
assert
- .dom("div.query-list input.ember-text-field")
+ .dom(".admin-filter-controls__input")
.hasAttribute(
"placeholder",
i18n("explorer.search_placeholder"),
@@ -52,11 +68,11 @@ acceptance("Data Explorer Plugin | List Queries", function (needs) {
);
assert
- .dom("div.query-list button.btn-icon svg.d-icon-plus")
+ .dom(".d-page-subheader .btn-primary")
.exists("the add query button was rendered");
assert
- .dom("div.query-list button.btn-icon-text span.d-button-label")
+ .dom(".d-page-subheader .d-page-action-wrapped-button")
.hasText(i18n("explorer.import.label"), "the import button was rendered");
assert
@@ -64,11 +80,11 @@ acceptance("Data Explorer Plugin | List Queries", function (needs) {
.exists({ count: 2 }, "the list of queries was rendered");
assert
- .dom("div.container table.recent-queries tbody tr:nth-child(1) td a")
+ .dom("div.container table.recent-queries tbody tr:nth-child(1) td")
.hasText(/^\s*Top 100 Likers/, "The first query was rendered");
assert
- .dom("div.container table.recent-queries tbody tr:nth-child(2) td a")
+ .dom("div.container table.recent-queries tbody tr:nth-child(2) td")
.hasText(/^\s*Top 100 Active Topics/, "The second query was rendered");
});
});
diff --git a/plugins/discourse-data-explorer/test/javascripts/acceptance/new-query-test.js b/plugins/discourse-data-explorer/test/javascripts/acceptance/new-query-test.js
index 344f8a581bd..a8f88ed9fbe 100644
--- a/plugins/discourse-data-explorer/test/javascripts/acceptance/new-query-test.js
+++ b/plugins/discourse-data-explorer/test/javascripts/acceptance/new-query-test.js
@@ -7,21 +7,37 @@ acceptance("Data Explorer Plugin | New Query", function (needs) {
needs.settings({ data_explorer_enabled: true });
needs.pretender((server, helper) => {
- server.get("/admin/plugins/explorer/groups.json", () => {
+ server.get("/admin/plugins/discourse-data-explorer.json", () => {
+ return helper.response({
+ id: "discourse-data-explorer",
+ name: "discourse-data-explorer",
+ enabled: true,
+ has_settings: true,
+ humanized_name: "Data Explorer",
+ is_discourse_owned: true,
+ admin_route: {
+ label: "explorer.title",
+ location: "discourse-data-explorer",
+ use_new_show_route: true,
+ },
+ });
+ });
+
+ server.get("/admin/plugins/discourse-data-explorer/groups.json", () => {
return helper.response([]);
});
- server.get("/admin/plugins/explorer/schema.json", () => {
+ server.get("/admin/plugins/discourse-data-explorer/schema.json", () => {
return helper.response({});
});
- server.get("/admin/plugins/explorer/queries", () => {
+ server.get("/admin/plugins/discourse-data-explorer/queries", () => {
return helper.response({
queries: [],
});
});
- server.post("/admin/plugins/explorer/queries", () => {
+ server.post("/admin/plugins/discourse-data-explorer/queries", () => {
return helper.response({
query: {
id: -15,
@@ -47,7 +63,7 @@ acceptance("Data Explorer Plugin | New Query", function (needs) {
});
});
- server.get("/admin/plugins/explorer/queries/-15", () => {
+ server.get("/admin/plugins/discourse-data-explorer/queries/-15", () => {
return helper.response({
query: {
id: -15,
@@ -75,14 +91,15 @@ acceptance("Data Explorer Plugin | New Query", function (needs) {
});
test("creates a new query", async function (assert) {
- await visit("/admin/plugins/explorer");
+ await visit("/admin/plugins/discourse-data-explorer/queries");
- // select new query button
- await click(".query-list button");
+ await click(".d-page-subheader .btn-primary");
await fillIn(".query-create input", "foo");
- // select create new query button
await click(".query-create button");
- assert.strictEqual(currentURL(), "/admin/plugins/explorer/queries/-15");
+ assert.strictEqual(
+ currentURL(),
+ "/admin/plugins/discourse-data-explorer/queries/-15"
+ );
});
});
diff --git a/plugins/discourse-data-explorer/test/javascripts/acceptance/param-input-test.js b/plugins/discourse-data-explorer/test/javascripts/acceptance/param-input-test.js
index fd066555da7..d60c451caf0 100644
--- a/plugins/discourse-data-explorer/test/javascripts/acceptance/param-input-test.js
+++ b/plugins/discourse-data-explorer/test/javascripts/acceptance/param-input-test.js
@@ -13,15 +13,31 @@ acceptance("Data Explorer Plugin | Param Input", function (needs) {
needs.settings({ data_explorer_enabled: true });
needs.pretender((server, helper) => {
- server.get("/admin/plugins/explorer/groups.json", () => {
+ server.get("/admin/plugins/discourse-data-explorer.json", () => {
+ return helper.response({
+ id: "discourse-data-explorer",
+ name: "discourse-data-explorer",
+ enabled: true,
+ has_settings: true,
+ humanized_name: "Data Explorer",
+ is_discourse_owned: true,
+ admin_route: {
+ label: "explorer.title",
+ location: "discourse-data-explorer",
+ use_new_show_route: true,
+ },
+ });
+ });
+
+ server.get("/admin/plugins/discourse-data-explorer/groups.json", () => {
return helper.response([]);
});
- server.get("/admin/plugins/explorer/schema.json", () => {
+ server.get("/admin/plugins/discourse-data-explorer/schema.json", () => {
return helper.response({});
});
- server.get("/admin/plugins/explorer/queries", () => {
+ server.get("/admin/plugins/discourse-data-explorer/queries", () => {
return helper.response({
queries: [
{
@@ -56,7 +72,7 @@ acceptance("Data Explorer Plugin | Param Input", function (needs) {
});
});
- server.get("/admin/plugins/explorer/queries/-6", () => {
+ server.get("/admin/plugins/discourse-data-explorer/queries/-6", () => {
return helper.response({
query: {
id: -6,
@@ -82,7 +98,7 @@ acceptance("Data Explorer Plugin | Param Input", function (needs) {
});
});
- server.put("/admin/plugins/explorer/queries/-6", () => {
+ server.put("/admin/plugins/discourse-data-explorer/queries/-6", () => {
return helper.response({
success: true,
errors: [],
@@ -117,7 +133,7 @@ acceptance("Data Explorer Plugin | Param Input", function (needs) {
});
});
- server.post("/admin/plugins/explorer/queries/-6/run", () => {
+ server.post("/admin/plugins/discourse-data-explorer/queries/-6/run", () => {
return helper.response({
success: true,
errors: [],
@@ -179,7 +195,7 @@ acceptance("Data Explorer Plugin | Param Input", function (needs) {
});
});
- server.get("/admin/plugins/explorer/queries/-7", () => {
+ server.get("/admin/plugins/discourse-data-explorer/queries/-7", () => {
return helper.response({
query: {
id: -7,
@@ -204,7 +220,7 @@ acceptance("Data Explorer Plugin | Param Input", function (needs) {
});
});
- server.post("/admin/plugins/explorer/queries/-7/run", () => {
+ server.post("/admin/plugins/discourse-data-explorer/queries/-7/run", () => {
return helper.response({
success: true,
errors: [],
@@ -266,7 +282,7 @@ acceptance("Data Explorer Plugin | Param Input", function (needs) {
});
});
- server.get("/admin/plugins/explorer/queries/3", () => {
+ server.get("/admin/plugins/discourse-data-explorer/queries/3", () => {
return helper.response({
query: {
id: 3,
@@ -284,7 +300,7 @@ acceptance("Data Explorer Plugin | Param Input", function (needs) {
});
});
- server.put("/admin/plugins/explorer/queries/3", () => {
+ server.put("/admin/plugins/discourse-data-explorer/queries/3", () => {
return helper.response({
query: {
id: 3,
@@ -309,7 +325,7 @@ acceptance("Data Explorer Plugin | Param Input", function (needs) {
});
});
- server.get("/admin/plugins/explorer/queries/4", () => {
+ server.get("/admin/plugins/discourse-data-explorer/queries/4", () => {
return helper.response({
query: {
id: 4,
@@ -334,7 +350,7 @@ acceptance("Data Explorer Plugin | Param Input", function (needs) {
});
});
- server.post("/admin/plugins/explorer/queries/4/run", () => {
+ server.post("/admin/plugins/discourse-data-explorer/queries/4/run", () => {
return helper.response({});
});
});
@@ -345,7 +361,7 @@ acceptance("Data Explorer Plugin | Param Input", function (needs) {
}
test("puts params for the query into the url", async function (assert) {
- await visit("/admin/plugins/explorer/queries/-6");
+ await visit("/admin/plugins/discourse-data-explorer/queries/-6");
const monthsAgoValue = "2";
await fillIn(".query-params input", monthsAgoValue);
await runQuery();
@@ -363,7 +379,9 @@ acceptance("Data Explorer Plugin | Param Input", function (needs) {
});
test("loads the page if one of the parameter is null", async function (assert) {
- await visit('/admin/plugins/explorer/queries/-7?params={"user":null}');
+ await visit(
+ '/admin/plugins/discourse-data-explorer/queries/-7?params={"user":null}'
+ );
assert.dom(".query-params .user-chooser").exists();
assert.dom(".query-run .btn.btn-primary").exists();
});
@@ -383,7 +401,7 @@ acceptance("Data Explorer Plugin | Param Input", function (needs) {
});
test("creates input boxes if has parameters when save", async function (assert) {
- await visit("/admin/plugins/explorer/queries/3");
+ await visit("/admin/plugins/discourse-data-explorer/queries/3");
assert.dom(".query-params input").doesNotExist();
await click(".query-edit .btn-edit-query");
await fillIn(
@@ -396,7 +414,7 @@ acceptance("Data Explorer Plugin | Param Input", function (needs) {
});
test("nullable category_id param", async function (assert) {
- await visit("/admin/plugins/explorer/queries/4");
+ await visit("/admin/plugins/discourse-data-explorer/queries/4");
const catChooser = selectKit(".category-chooser");
assert.strictEqual(catChooser.header().value(), null);
diff --git a/plugins/discourse-data-explorer/test/javascripts/acceptance/run-query-test.js b/plugins/discourse-data-explorer/test/javascripts/acceptance/run-query-test.js
index 46f13510847..cf3751c78a8 100644
--- a/plugins/discourse-data-explorer/test/javascripts/acceptance/run-query-test.js
+++ b/plugins/discourse-data-explorer/test/javascripts/acceptance/run-query-test.js
@@ -17,7 +17,23 @@ acceptance("Data Explorer Plugin | Run Query", function (needs) {
});
needs.pretender((server, helper) => {
- server.get("/admin/plugins/explorer/groups.json", () => {
+ server.get("/admin/plugins/discourse-data-explorer.json", () => {
+ return helper.response({
+ id: "discourse-data-explorer",
+ name: "discourse-data-explorer",
+ enabled: true,
+ has_settings: true,
+ humanized_name: "Data Explorer",
+ is_discourse_owned: true,
+ admin_route: {
+ label: "explorer.title",
+ location: "discourse-data-explorer",
+ use_new_show_route: true,
+ },
+ });
+ });
+
+ server.get("/admin/plugins/discourse-data-explorer/groups.json", () => {
return helper.response([
{
id: 1,
@@ -58,7 +74,7 @@ acceptance("Data Explorer Plugin | Run Query", function (needs) {
]);
});
- server.get("/admin/plugins/explorer/schema.json", () => {
+ server.get("/admin/plugins/discourse-data-explorer/schema.json", () => {
return helper.response({
anonymous_users: [
{
@@ -92,7 +108,7 @@ acceptance("Data Explorer Plugin | Run Query", function (needs) {
});
});
- server.get("/admin/plugins/explorer/queries", () => {
+ server.get("/admin/plugins/discourse-data-explorer/queries", () => {
return helper.response({
queries: [
{
@@ -104,6 +120,7 @@ acceptance("Data Explorer Plugin | Run Query", function (needs) {
group_ids: [],
last_run_at: "2021-02-11T08:29:59.337Z",
user_id: -1,
+ is_default: true,
},
{
id: 2,
@@ -113,12 +130,13 @@ acceptance("Data Explorer Plugin | Run Query", function (needs) {
group_ids: [],
last_run_at: "2023-05-04T22:16:23.858Z",
user_id: 1,
+ is_default: false,
},
],
});
});
- server.get("/admin/plugins/explorer/queries/-6", () => {
+ server.get("/admin/plugins/discourse-data-explorer/queries/-6", () => {
return helper.response({
query: {
id: -6,
@@ -140,11 +158,12 @@ acceptance("Data Explorer Plugin | Run Query", function (needs) {
last_run_at: "2021-02-11T08:29:59.337Z",
hidden: false,
user_id: -1,
+ is_default: true,
},
});
});
- server.get("/admin/plugins/explorer/queries/2", () => {
+ server.get("/admin/plugins/discourse-data-explorer/queries/2", () => {
return helper.response({
query: {
id: 2,
@@ -162,7 +181,7 @@ acceptance("Data Explorer Plugin | Run Query", function (needs) {
});
});
- server.post("/admin/plugins/explorer/queries/-6/run", () => {
+ server.post("/admin/plugins/discourse-data-explorer/queries/-6/run", () => {
return helper.response({
success: true,
errors: [],
@@ -198,7 +217,7 @@ acceptance("Data Explorer Plugin | Run Query", function (needs) {
});
});
- server.post("/admin/plugins/explorer/queries/2/run", () => {
+ server.post("/admin/plugins/discourse-data-explorer/queries/2/run", () => {
return helper.response({
success: true,
errors: [],
@@ -268,7 +287,7 @@ acceptance("Data Explorer Plugin | Run Query", function (needs) {
});
test("runs query and renders data and a chart", async function (assert) {
- await visit("/admin/plugins/explorer/queries/-6");
+ await visit("/admin/plugins/discourse-data-explorer/queries/-6");
assert
.dom("div.name h1")
@@ -296,7 +315,7 @@ acceptance("Data Explorer Plugin | Run Query", function (needs) {
});
test("runs query and is able to download the results", async function (assert) {
- await visit("/admin/plugins/explorer/queries/-6");
+ await visit("/admin/plugins/discourse-data-explorer/queries/-6");
await click("form.query-run button");
@@ -367,7 +386,7 @@ acceptance("Data Explorer Plugin | Run Query", function (needs) {
});
test("runs query and renders 0, false, and NULL values correctly", async function (assert) {
- await visit("/admin/plugins/explorer/queries/2");
+ await visit("/admin/plugins/discourse-data-explorer/queries/2");
assert
.dom("div.name h1 span")
@@ -393,7 +412,7 @@ acceptance("Data Explorer Plugin | Run Query", function (needs) {
});
test("automatically runs query when run query parameter is present", async function (assert) {
- await visit("/admin/plugins/explorer/queries/2?run");
+ await visit("/admin/plugins/discourse-data-explorer/queries/2?run");
assert
.dom("div.query-results table tbody tr")