Skip to content

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

FIX: No charts when there are text columns alongside numeric columns (#39126)

Natalie Tayc47498b3a9b9
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 b1d9d7a74bb..b50ea115fc6 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
@@ -197,8 +197,25 @@ export default class QueryResult extends Component {
return transformedRelTable(this.site.groups);
}
+ get hasTextColumns() {
+ if (!this.rows?.length || !this.columns?.length) {
+ return false;
+ }
+ const numericSet = new Set(this.numericColumnIndices);
+ for (let i = 1; i < this.columns.length; i++) {
+ if (!this.colRender[i] && !numericSet.has(i)) {
+ return true;
+ }
+ }
+ return false;
+ }
+
get canShowChart() {
- return this.rows?.length > 0 && this.numericColumnIndices.length > 0;
+ return (
+ this.rows?.length > 0 &&
+ this.numericColumnIndices.length > 0 &&
+ !this.hasTextColumns
+ );
}
get chartLabels() {
diff --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.gjs
index f01daa7aba7..391d3f54ed3 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
@@ -283,6 +283,22 @@ module(
assert.dom("canvas").exists("renders a chart canvas for multi-series");
});
+ test("doesn't render a chart when there are text columns alongside numeric columns", async function (assert) {
+ const content = {
+ colrender: [],
+ result_count: 2,
+ columns: ["name", "value", "description"],
+ rows: [
+ ["item1", 10, "some text"],
+ ["item2", 20, "other text"],
+ ],
+ };
+
+ await render(<template><QueryResult @content={{content}} /></template>);
+
+ assert.dom("canvas").doesNotExist();
+ });
+
test("handles no results", async function (assert) {
const content = {
colrender: [],