mirror of
https://github.com/discourse/discourse-data-explorer.git
synced 2025-03-06 17:39:08 +00:00
The code for listing all of the defined queries is mixed together with the code for editing a single query. Notably, this results in large amounts of unnecessary data being loaded for the list view, which causes substantial rendering slowdowns. To address this issue, we now only load the necessary data for the list view, and load the full data when it's actually needed (any endpoint that returns a single query). The primary changes that achieve this are: - Create a new `QueryDetailsSerializer` serialiser, which includes all of the query info, and change the existing `QuerySerializer` serialiser to only include the necessary attributes of each query for generating a list of them all. - Split the monolith `/plugins/explorer` route into `/plugins/explorer` for showing just the list of queries, and `/plugins/explorer/queries/:query_id`, for showing/editing/running a specific query.
89 lines
2.5 KiB
Ruby
89 lines
2.5 KiB
Ruby
# frozen_string_literal: true
|
|
|
|
RSpec.describe "Explorer", type: :system, js: true do
|
|
fab!(:admin)
|
|
fab!(:group) { Fabricate(:group, name: "group") }
|
|
fab!(:group_user) { Fabricate(:group_user, user: admin, group: group) }
|
|
|
|
before do
|
|
SiteSetting.data_explorer_enabled = true
|
|
sign_in admin
|
|
end
|
|
|
|
context "with a query using a default param" do
|
|
fab!(:query_1) do
|
|
Fabricate(
|
|
:query,
|
|
name: "My default param query",
|
|
description: "Test default param query",
|
|
sql: "-- [params]\n-- string :limit = 42\n\nSELECT * FROM users LIMIT :limit",
|
|
user: admin,
|
|
)
|
|
end
|
|
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}")
|
|
|
|
expect(page).to have_field("limit", with: 42)
|
|
end
|
|
end
|
|
|
|
context "with the old url format" do
|
|
fab!(:query_1) do
|
|
Fabricate(
|
|
:query,
|
|
name: "My query",
|
|
description: "Test query",
|
|
sql: "SELECT * FROM users",
|
|
user: admin,
|
|
)
|
|
end
|
|
|
|
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}")
|
|
end
|
|
|
|
it "redirects to the new url format with params" do
|
|
visit("/admin/plugins/explorer/?id=#{query_1.id}¶ms=%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",
|
|
)
|
|
end
|
|
end
|
|
|
|
context "with a group_list param" do
|
|
fab!(:q2) do
|
|
Fabricate(
|
|
:query,
|
|
name: "My query with group_list",
|
|
description: "Test group_list query",
|
|
sql:
|
|
"-- [params]\n-- group_list :groups\n\nSELECT g.id,g.name FROM groups g WHERE g.name IN(:groups) ORDER BY g.name ASC",
|
|
user: admin,
|
|
)
|
|
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",
|
|
)
|
|
end
|
|
end
|
|
end
|