From 85c88c5d80b5896e26fd972a3c87671354c8bf89 Mon Sep 17 00:00:00 2001 From: Isaac Janzen <50783505+janzenisaac@users.noreply.github.com> Date: Tue, 20 Dec 2022 16:55:11 -0600 Subject: [PATCH] DEV: Better handling of no results (#205) When there were no query results it would throw an error due to `this.resultCount` always passing as it is in the format of ``` "INTEGER - results returned" ``` so we need to grab the first index of the string and check if the integer is great than 0 --- .../discourse/components/query-result.js | 2 +- .../components/query-result-test.js | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/assets/javascripts/discourse/components/query-result.js b/assets/javascripts/discourse/components/query-result.js index bdf2a46..26255fb 100644 --- a/assets/javascripts/discourse/components/query-result.js +++ b/assets/javascripts/discourse/components/query-result.js @@ -126,7 +126,7 @@ export default class QueryResult extends Component { get canShowChart() { const hasTwoColumns = this.colCount === 2; const secondColumnContainsNumber = - this.resultCount.length && typeof this.rows[0][1] === "number"; + this.resultCount[0] > 0 && typeof this.rows[0][1] === "number"; const secondColumnContainsId = this.colRender[1]; return ( diff --git a/test/javascripts/integration/components/query-result-test.js b/test/javascripts/integration/components/query-result-test.js index 5d957f4..456b9d5 100644 --- a/test/javascripts/integration/components/query-result-test.js +++ b/test/javascripts/integration/components/query-result-test.js @@ -326,5 +326,23 @@ discourseModule( }, } ); + + componentTest("it handles no results", { + template: hbs``, + + beforeEach() { + const results = { + colrender: [], + result_count: 0, + columns: ["user_name", "like_count", "post_count"], + rows: [], + }; + this.set("content", results); + }, + + test(assert) { + assert.ok(!exists("table tbody tr"), "renders no results"); + }, + }); } );