A platform for community discussion. Free, open, simple.
UX: Link reviewable IDs in Data Explorer results (#44572)
Alan Guo Xiang Tan94d7d5fcceb8
diff --git a/plugins/discourse-data-explorer/assets/javascripts/discourse/components/result-types/reviewable.gjs b/plugins/discourse-data-explorer/assets/javascripts/discourse/components/result-types/reviewable.gjsnew file mode 100644index 00000000000..d9a1d89950a--- /dev/null+++ b/plugins/discourse-data-explorer/assets/javascripts/discourse/components/result-types/reviewable.gjs@@ -0,0 +1,22 @@+import { LinkTo } from "@ember/routing";++const Reviewable = <template>+ {{#let (reviewableId @ctx.value) as |id|}}+ {{#if id}}+ <LinkTo @model={{id}} @route="review.show">{{@ctx.value}}</LinkTo>+ {{else}}+ {{@ctx.value}}+ {{/if}}+ {{/let}}+</template>;++export default Reviewable;++function reviewableId(value) {+ if (typeof value !== "number" && typeof value !== "string") {+ return null;+ }++ const id = Number(value);+ return Number.isSafeInteger(id) && id > 0 ? id : null;+}diff --git a/plugins/discourse-data-explorer/assets/javascripts/discourse/lib/result-columns.js b/plugins/discourse-data-explorer/assets/javascripts/discourse/lib/result-columns.jsindex 897d7dda9b8..1088c569968 100644--- a/plugins/discourse-data-explorer/assets/javascripts/discourse/lib/result-columns.js+++ b/plugins/discourse-data-explorer/assets/javascripts/discourse/lib/result-columns.js@@ -6,6 +6,7 @@ import HtmlViewComponent from "../components/result-types/html";import JsonViewComponent from "../components/result-types/json";import PostViewComponent from "../components/result-types/post";import ReltimeViewComponent from "../components/result-types/reltime";+import ReviewableViewComponent from "../components/result-types/reviewable";import TagGroupViewComponent from "../components/result-types/tag-group";import TextViewComponent from "../components/result-types/text";import TopicViewComponent from "../components/result-types/topic";@@ -17,6 +18,7 @@ export const VIEW_COMPONENTS = {text: TextViewComponent,post: PostViewComponent,reltime: ReltimeViewComponent,+ reviewable: ReviewableViewComponent,badge: BadgeViewComponent,url: UrlViewComponent,user: UserViewComponent,diff --git a/plugins/discourse-data-explorer/config/locales/client.en.yml b/plugins/discourse-data-explorer/config/locales/client.en.ymlindex 483b150970b..3902ae2f6dc 100644--- a/plugins/discourse-data-explorer/config/locales/client.en.yml+++ b/plugins/discourse-data-explorer/config/locales/client.en.yml@@ -66,8 +66,8 @@ en:auto_resolution: "<h2>Automatic entity resolution</h2><p>When your query returns an entity id, Data Explorer may automatically substitute it withthe 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>+ <i><b>user_id</b></i>, <i><b>group_id</b></i>, <i><b>topic_id</b></i>, <i><b>category_id</b></i>,+ <i><b>badge_id</b></i> and <i><b>reviewable_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><p>To create custom parameters for your queries, put this at the top of your query and follow the format:</p>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.rbindex 21f8ceb16f2..9aefe2a7539 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@@ -334,6 +334,10 @@ module DiscourseDataExplorerclass: Category,ignore: true,},+ reviewable: {+ class: Reviewable,+ ignore: true,+ },reltime: {ignore: true,},diff --git a/plugins/discourse-data-explorer/spec/data_explorer_spec.rb b/plugins/discourse-data-explorer/spec/data_explorer_spec.rbindex a3d7ce1b6d3..1786af34065 100644--- a/plugins/discourse-data-explorer/spec/data_explorer_spec.rb+++ b/plugins/discourse-data-explorer/spec/data_explorer_spec.rb@@ -535,7 +535,10 @@ describe DiscourseDataExplorer::DataExplorer do1 AS last_editor_id,1 AS group_id,1 AS category_id,- 1 AS "author$user_id"+ 1 AS "author$user_id",+ 1 AS reviewable_id,+ 1 AS related_reviewable_id,+ 1 AS "reviewable$item"SQLrelations, colrender =@@ -558,9 +561,12 @@ describe DiscourseDataExplorer::DataExplorer do17 => :group,18 => :category,19 => :user,+ 20 => :reviewable,+ 21 => :reviewable,+ 22 => :reviewable,},)- expect(relations.keys).not_to include(:group, :category)+ expect(relations.keys).not_to include(:group, :category, :reviewable)endit "reports relations hidden by the guardian" dodiff --git a/plugins/discourse-data-explorer/test/javascripts/integration/components/query-result-test.gjs b/plugins/discourse-data-explorer/test/javascripts/integration/components/query-result-test.gjsindex a97a7c867ac..b93905b6903 100644--- a/plugins/discourse-data-explorer/test/javascripts/integration/components/query-result-test.gjs+++ b/plugins/discourse-data-explorer/test/javascripts/integration/components/query-result-test.gjs@@ -59,6 +59,24 @@ module("Integration | Component | QueryResult", function (hooks) {assert.dom(cell(2, 2)).hasText("20");});+ test("links reviewable IDs", async function (assert) {+ const content = {+ colrender: { 0: "reviewable" },+ result_count: 1,+ columns: ["reviewable_id"],+ rows: [[15318]],+ };++ await render(+ <template><QueryResult @content={{content}} @view="table" /></template>+ );++ assert+ .dom(`${cell(1, 1)} a`)+ .hasAttribute("href", "/review/15318", "links a numeric reviewable ID")+ .hasText("15318", "keeps the numeric ID as the link label");+ });+test("renders JSON columns as escaped text with a viewer action", async function (assert) {const content = {colrender: { 1: "json" },